Fossil SCM

fossil-scm / extsrc / sqlite3.h
Blame History Raw 14439 lines
1
/*
2
** 2001-09-15
3
**
4
** The author disclaims copyright to this source code. In place of
5
** a legal notice, here is a blessing:
6
**
7
** May you do good and not evil.
8
** May you find forgiveness for yourself and forgive others.
9
** May you share freely, never taking more than you give.
10
**
11
*************************************************************************
12
** This header file defines the interface that the SQLite library
13
** presents to client programs. If a C-function, structure, datatype,
14
** or constant definition does not appear in this file, then it is
15
** not a published API of SQLite, is subject to change without
16
** notice, and should not be referenced by programs that use SQLite.
17
**
18
** Some of the definitions that are in this file are marked as
19
** "experimental". Experimental interfaces are normally new
20
** features recently added to SQLite. We do not anticipate changes
21
** to experimental interfaces but reserve the right to make minor changes
22
** if experience from use "in the wild" suggest such changes are prudent.
23
**
24
** The official C-language API documentation for SQLite is derived
25
** from comments in this file. This file is the authoritative source
26
** on how SQLite interfaces are supposed to operate.
27
**
28
** The name of this file under configuration management is "sqlite.h.in".
29
** The makefile makes some minor changes to this file (such as inserting
30
** the version number) and changes its name to "sqlite3.h" as
31
** part of the build process.
32
*/
33
#ifndef SQLITE3_H
34
#define SQLITE3_H
35
#include <stdarg.h> /* Needed for the definition of va_list */
36
37
/*
38
** Make sure we can call this stuff from C++.
39
*/
40
#ifdef __cplusplus
41
extern "C" {
42
#endif
43
44
45
/*
46
** Facilitate override of interface linkage and calling conventions.
47
** Be aware that these macros may not be used within this particular
48
** translation of the amalgamation and its associated header file.
49
**
50
** The SQLITE_EXTERN and SQLITE_API macros are used to instruct the
51
** compiler that the target identifier should have external linkage.
52
**
53
** The SQLITE_CDECL macro is used to set the calling convention for
54
** public functions that accept a variable number of arguments.
55
**
56
** The SQLITE_APICALL macro is used to set the calling convention for
57
** public functions that accept a fixed number of arguments.
58
**
59
** The SQLITE_STDCALL macro is no longer used and is now deprecated.
60
**
61
** The SQLITE_CALLBACK macro is used to set the calling convention for
62
** function pointers.
63
**
64
** The SQLITE_SYSAPI macro is used to set the calling convention for
65
** functions provided by the operating system.
66
**
67
** Currently, the SQLITE_CDECL, SQLITE_APICALL, SQLITE_CALLBACK, and
68
** SQLITE_SYSAPI macros are used only when building for environments
69
** that require non-default calling conventions.
70
*/
71
#ifndef SQLITE_EXTERN
72
# define SQLITE_EXTERN extern
73
#endif
74
#ifndef SQLITE_API
75
# define SQLITE_API
76
#endif
77
#ifndef SQLITE_CDECL
78
# define SQLITE_CDECL
79
#endif
80
#ifndef SQLITE_APICALL
81
# define SQLITE_APICALL
82
#endif
83
#ifndef SQLITE_STDCALL
84
# define SQLITE_STDCALL SQLITE_APICALL
85
#endif
86
#ifndef SQLITE_CALLBACK
87
# define SQLITE_CALLBACK
88
#endif
89
#ifndef SQLITE_SYSAPI
90
# define SQLITE_SYSAPI
91
#endif
92
93
/*
94
** These no-op macros are used in front of interfaces to mark those
95
** interfaces as either deprecated or experimental. New applications
96
** should not use deprecated interfaces - they are supported for backwards
97
** compatibility only. Application writers should be aware that
98
** experimental interfaces are subject to change in point releases.
99
**
100
** These macros used to resolve to various kinds of compiler magic that
101
** would generate warning messages when they were used. But that
102
** compiler magic ended up generating such a flurry of bug reports
103
** that we have taken it all out and gone back to using simple
104
** noop macros.
105
*/
106
#define SQLITE_DEPRECATED
107
#define SQLITE_EXPERIMENTAL
108
109
/*
110
** Ensure these symbols were not defined by some previous header file.
111
*/
112
#ifdef SQLITE_VERSION
113
# undef SQLITE_VERSION
114
#endif
115
#ifdef SQLITE_VERSION_NUMBER
116
# undef SQLITE_VERSION_NUMBER
117
#endif
118
119
/*
120
** CAPI3REF: Compile-Time Library Version Numbers
121
**
122
** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header
123
** evaluates to a string literal that is the SQLite version in the
124
** format "X.Y.Z" where X is the major version number (always 3 for
125
** SQLite3) and Y is the minor version number and Z is the release number.)^
126
** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer
127
** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
128
** numbers used in [SQLITE_VERSION].)^
129
** The SQLITE_VERSION_NUMBER for any given release of SQLite will also
130
** be larger than the release from which it is derived. Either Y will
131
** be held constant and Z will be incremented or else Y will be incremented
132
** and Z will be reset to zero.
133
**
134
** Since [version 3.6.18] ([dateof:3.6.18]),
135
** SQLite source code has been stored in the
136
** <a href="http://fossil-scm.org/">Fossil configuration management
137
** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to
138
** a string which identifies a particular check-in of SQLite
139
** within its configuration management system. ^The SQLITE_SOURCE_ID
140
** string contains the date and time of the check-in (UTC) and a SHA1
141
** or SHA3-256 hash of the entire source tree. If the source code has
142
** been edited in any way since it was last checked in, then the last
143
** four hexadecimal digits of the hash may be modified.
144
**
145
** See also: [sqlite3_libversion()],
146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147
** [sqlite_version()] and [sqlite_source_id()].
148
*/
149
#define SQLITE_VERSION "3.54.0"
150
#define SQLITE_VERSION_NUMBER 3054000
151
#define SQLITE_SOURCE_ID "2026-08-27 10:58:16 555f31c64d3fcc55df2715a7c8c1cb28503b2c0eb21d950ccdcbf6f577593dd5"
152
#define SQLITE_SCM_BRANCH "trunk"
153
#define SQLITE_SCM_TAGS ""
154
#define SQLITE_SCM_DATETIME "2026-08-27T10:58:16.680Z"
155
156
/*
157
** CAPI3REF: Run-Time Library Version Numbers
158
** KEYWORDS: sqlite3_version sqlite3_sourceid
159
**
160
** These interfaces provide the same information as the [SQLITE_VERSION],
161
** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
162
** but are associated with the library instead of the header file. ^(Cautious
163
** programmers might include assert() statements in their application to
164
** verify that values returned by these interfaces match the macros in
165
** the header, and thus ensure that the application is
166
** compiled with matching library and header files.
167
**
168
** <blockquote><pre>
169
** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
170
** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 );
171
** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
172
** </pre></blockquote>)^
173
**
174
** ^The sqlite3_version[] string constant contains the text of the
175
** [SQLITE_VERSION] macro. ^The sqlite3_libversion() function returns a
176
** pointer to the sqlite3_version[] string constant. The sqlite3_libversion()
177
** function is provided for use in DLLs since DLL users usually do not have
178
** direct access to string constants within the DLL. ^The
179
** sqlite3_libversion_number() function returns an integer equal to
180
** [SQLITE_VERSION_NUMBER]. ^(The sqlite3_sourceid() function returns
181
** a pointer to a string constant whose value is the same as the
182
** [SQLITE_SOURCE_ID] C preprocessor macro. Except if SQLite is built
183
** using an edited copy of [the amalgamation], then the last four characters
184
** of the hash might be different from [SQLITE_SOURCE_ID].)^
185
**
186
** See also: [sqlite_version()] and [sqlite_source_id()].
187
*/
188
SQLITE_API SQLITE_EXTERN const char sqlite3_version[];
189
SQLITE_API const char *sqlite3_libversion(void);
190
SQLITE_API const char *sqlite3_sourceid(void);
191
SQLITE_API int sqlite3_libversion_number(void);
192
193
/*
194
** CAPI3REF: Run-Time Library Compilation Options Diagnostics
195
**
196
** ^The sqlite3_compileoption_used() function returns 0 or 1
197
** indicating whether the specified option was defined at
198
** compile time. ^The SQLITE_ prefix may be omitted from the
199
** option name passed to sqlite3_compileoption_used().
200
**
201
** ^The sqlite3_compileoption_get() function allows iterating
202
** over the list of options that were defined at compile time by
203
** returning the N-th compile time option string. ^If N is out of range,
204
** sqlite3_compileoption_get() returns a NULL pointer. ^The SQLITE_
205
** prefix is omitted from any strings returned by
206
** sqlite3_compileoption_get().
207
**
208
** ^Support for the diagnostic functions sqlite3_compileoption_used()
209
** and sqlite3_compileoption_get() may be omitted by specifying the
210
** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
211
**
212
** See also: SQL functions [sqlite_compileoption_used()] and
213
** [sqlite_compileoption_get()] and the [compile_options pragma].
214
*/
215
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
216
SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
217
SQLITE_API const char *sqlite3_compileoption_get(int N);
218
#else
219
# define sqlite3_compileoption_used(X) 0
220
# define sqlite3_compileoption_get(X) ((void*)0)
221
#endif
222
223
/*
224
** CAPI3REF: Test To See If The Library Is Threadsafe
225
**
226
** ^The sqlite3_threadsafe() function returns zero if and only if
227
** SQLite was compiled with mutexing code omitted due to the
228
** [SQLITE_THREADSAFE] compile-time option being set to 0.
229
**
230
** SQLite can be compiled with or without mutexes. When
231
** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes
232
** are enabled and SQLite is threadsafe. When the
233
** [SQLITE_THREADSAFE] macro is 0,
234
** the mutexes are omitted. Without the mutexes, it is not safe
235
** to use SQLite concurrently from more than one thread.
236
**
237
** Enabling mutexes incurs a measurable performance penalty.
238
** So if speed is of utmost importance, it makes sense to disable
239
** the mutexes. But for maximum safety, mutexes should be enabled.
240
** ^The default behavior is for mutexes to be enabled.
241
**
242
** This interface can be used by an application to make sure that the
243
** version of SQLite that it is linking against was compiled with
244
** the desired setting of the [SQLITE_THREADSAFE] macro.
245
**
246
** This interface only reports on the compile-time mutex setting
247
** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with
248
** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
249
** can be fully or partially disabled using a call to [sqlite3_config()]
250
** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
251
** or [SQLITE_CONFIG_SERIALIZED]. ^(The return value of the
252
** sqlite3_threadsafe() function shows only the compile-time setting of
253
** thread safety, not any run-time changes to that setting made by
254
** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
255
** is unchanged by calls to sqlite3_config().)^
256
**
257
** See the [threading mode] documentation for additional information.
258
*/
259
SQLITE_API int sqlite3_threadsafe(void);
260
261
/*
262
** CAPI3REF: Database Connection Handle
263
** KEYWORDS: {database connection} {database connections}
264
**
265
** Each open SQLite database is represented by a pointer to an instance of
266
** the opaque structure named "sqlite3". It is useful to think of an sqlite3
267
** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and
268
** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]
269
** and [sqlite3_close_v2()] are its destructors. There are many other
270
** interfaces (such as
271
** [sqlite3_prepare_v2()], [sqlite3_create_function()], and
272
** [sqlite3_busy_timeout()] to name but three) that are methods on an
273
** sqlite3 object.
274
*/
275
typedef struct sqlite3 sqlite3;
276
277
/*
278
** CAPI3REF: 64-Bit Integer Types
279
** KEYWORDS: sqlite_int64 sqlite_uint64
280
**
281
** Because there is no cross-platform way to specify 64-bit integer types
282
** SQLite includes typedefs for 64-bit signed and unsigned integers.
283
**
284
** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions.
285
** The sqlite_int64 and sqlite_uint64 types are supported for backwards
286
** compatibility only.
287
**
288
** ^The sqlite3_int64 and sqlite_int64 types can store integer values
289
** between -9223372036854775808 and +9223372036854775807 inclusive. ^The
290
** sqlite3_uint64 and sqlite_uint64 types can store integer values
291
** between 0 and +18446744073709551615 inclusive.
292
*/
293
#ifdef SQLITE_INT64_TYPE
294
typedef SQLITE_INT64_TYPE sqlite_int64;
295
# ifdef SQLITE_UINT64_TYPE
296
typedef SQLITE_UINT64_TYPE sqlite_uint64;
297
# else
298
typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
299
# endif
300
#elif defined(_MSC_VER) || defined(__BORLANDC__)
301
typedef __int64 sqlite_int64;
302
typedef unsigned __int64 sqlite_uint64;
303
#else
304
typedef long long int sqlite_int64;
305
typedef unsigned long long int sqlite_uint64;
306
#endif
307
typedef sqlite_int64 sqlite3_int64;
308
typedef sqlite_uint64 sqlite3_uint64;
309
310
/*
311
** If compiling for a processor that lacks floating point support,
312
** substitute integer for floating-point.
313
*/
314
#ifdef SQLITE_OMIT_FLOATING_POINT
315
# define double sqlite3_int64
316
#endif
317
318
/*
319
** CAPI3REF: Closing A Database Connection
320
** DESTRUCTOR: sqlite3
321
**
322
** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
323
** for the [sqlite3] object.
324
** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
325
** the [sqlite3] object is successfully destroyed and all associated
326
** resources are deallocated.
327
**
328
** Ideally, applications should [sqlite3_finalize | finalize] all
329
** [prepared statements], [sqlite3_blob_close | close] all [BLOB handles], and
330
** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated
331
** with the [sqlite3] object prior to attempting to close the object.
332
** ^If the database connection is associated with unfinalized prepared
333
** statements, BLOB handlers, and/or unfinished sqlite3_backup objects then
334
** sqlite3_close() will leave the database connection open and return
335
** [SQLITE_BUSY]. ^If sqlite3_close_v2() is called with unfinalized prepared
336
** statements, unclosed BLOB handlers, and/or unfinished sqlite3_backups,
337
** it returns [SQLITE_OK] regardless, but instead of deallocating the database
338
** connection immediately, it marks the database connection as an unusable
339
** "zombie" and makes arrangements to automatically deallocate the database
340
** connection after all prepared statements are finalized, all BLOB handles
341
** are closed, and all backups have finished. The sqlite3_close_v2() interface
342
** is intended for use with host languages that are garbage collected, and
343
** where the order in which destructors are called is arbitrary.
344
**
345
** ^If an [sqlite3] object is destroyed while a transaction is open,
346
** the transaction is automatically rolled back.
347
**
348
** The C parameter to [sqlite3_close(C)] and [sqlite3_close_v2(C)]
349
** must be either a NULL
350
** pointer or an [sqlite3] object pointer obtained
351
** from [sqlite3_open()], [sqlite3_open16()], or
352
** [sqlite3_open_v2()], and not previously closed.
353
** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer
354
** argument is a harmless no-op.
355
*/
356
SQLITE_API int sqlite3_close(sqlite3*);
357
SQLITE_API int sqlite3_close_v2(sqlite3*);
358
359
/*
360
** The type for a callback function.
361
** This is legacy and deprecated. It is included for historical
362
** compatibility and is not documented.
363
*/
364
typedef int (*sqlite3_callback)(void*,int,char**, char**);
365
366
/*
367
** CAPI3REF: One-Step Query Execution Interface
368
** METHOD: sqlite3
369
**
370
** The sqlite3_exec() interface is a convenience wrapper around
371
** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
372
** that allows an application to run multiple statements of SQL
373
** without having to use a lot of C code.
374
**
375
** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
376
** semicolon-separated SQL statements passed into its 2nd argument,
377
** in the context of the [database connection] passed in as its 1st
378
** argument. ^If the callback function of the 3rd argument to
379
** sqlite3_exec() is not NULL, then it is invoked for each result row
380
** coming out of the evaluated SQL statements. ^The 4th argument to
381
** sqlite3_exec() is relayed through to the 1st argument of each
382
** callback invocation. ^If the callback pointer to sqlite3_exec()
383
** is NULL, then no callback is ever invoked and result rows are
384
** ignored.
385
**
386
** ^If an error occurs while evaluating the SQL statements passed into
387
** sqlite3_exec(), then execution of the current statement stops and
388
** subsequent statements are skipped. ^If the 5th parameter to sqlite3_exec()
389
** is not NULL then any error message is written into memory obtained
390
** from [sqlite3_malloc()] and passed back through the 5th parameter.
391
** To avoid memory leaks, the application should invoke [sqlite3_free()]
392
** on error message strings returned through the 5th parameter of
393
** sqlite3_exec() after the error message string is no longer needed.
394
** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors
395
** occur, then sqlite3_exec() sets the pointer in its 5th parameter to
396
** NULL before returning.
397
**
398
** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec()
399
** routine returns SQLITE_ABORT without invoking the callback again and
400
** without running any subsequent SQL statements.
401
**
402
** ^The 2nd argument to the sqlite3_exec() callback function is the
403
** number of columns in the result. ^The 3rd argument to the sqlite3_exec()
404
** callback is an array of pointers to strings obtained as if from
405
** [sqlite3_column_text()], one for each column. ^If an element of a
406
** result row is NULL then the corresponding string pointer for the
407
** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the
408
** sqlite3_exec() callback is an array of pointers to strings where each
409
** entry represents the name of a corresponding result column as obtained
410
** from [sqlite3_column_name()].
411
**
412
** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
413
** to an empty string, or a pointer that contains only whitespace and/or
414
** SQL comments, then no SQL statements are evaluated and the database
415
** is not changed.
416
**
417
** Restrictions:
418
**
419
** <ul>
420
** <li> The application must ensure that the 1st parameter to sqlite3_exec()
421
** is a valid and open [database connection].
422
** <li> The application must not close the [database connection] specified by
423
** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
424
** <li> The application must not modify the SQL statement text passed into
425
** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
426
** <li> The application must not dereference the arrays or string pointers
427
** passed as the 3rd and 4th callback parameters after it returns.
428
** </ul>
429
*/
430
SQLITE_API int sqlite3_exec(
431
sqlite3*, /* An open database */
432
const char *sql, /* SQL to be evaluated */
433
int (*callback)(void*,int,char**,char**), /* Callback function */
434
void *, /* 1st argument to callback */
435
char **errmsg /* Error msg written here */
436
);
437
438
/*
439
** CAPI3REF: Result Codes
440
** KEYWORDS: {result code definitions}
441
**
442
** Many SQLite functions return an integer result code from the set shown
443
** here in order to indicate success or failure.
444
**
445
** New error codes may be added in future versions of SQLite.
446
**
447
** See also: [extended result code definitions]
448
*/
449
#define SQLITE_OK 0 /* Successful result */
450
/* beginning-of-error-codes */
451
#define SQLITE_ERROR 1 /* Generic error */
452
#define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
453
#define SQLITE_PERM 3 /* Access permission denied */
454
#define SQLITE_ABORT 4 /* Callback routine requested an abort */
455
#define SQLITE_BUSY 5 /* The database file is locked */
456
#define SQLITE_LOCKED 6 /* A table in the database is locked */
457
#define SQLITE_NOMEM 7 /* A malloc() failed */
458
#define SQLITE_READONLY 8 /* Attempt to write a readonly database */
459
#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
460
#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
461
#define SQLITE_CORRUPT 11 /* The database disk image is malformed */
462
#define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
463
#define SQLITE_FULL 13 /* Insertion failed because database is full */
464
#define SQLITE_CANTOPEN 14 /* Unable to open the database file */
465
#define SQLITE_PROTOCOL 15 /* Database lock protocol error */
466
#define SQLITE_EMPTY 16 /* Internal use only */
467
#define SQLITE_SCHEMA 17 /* The database schema changed */
468
#define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
469
#define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
470
#define SQLITE_MISMATCH 20 /* Data type mismatch */
471
#define SQLITE_MISUSE 21 /* Library used incorrectly */
472
#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
473
#define SQLITE_AUTH 23 /* Authorization denied */
474
#define SQLITE_FORMAT 24 /* Not used */
475
#define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */
476
#define SQLITE_NOTADB 26 /* File opened that is not a database file */
477
#define SQLITE_NOTICE 27 /* Notifications from sqlite3_log() */
478
#define SQLITE_WARNING 28 /* Warnings from sqlite3_log() */
479
#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
480
#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
481
/* end-of-error-codes */
482
483
/*
484
** CAPI3REF: Extended Result Codes
485
** KEYWORDS: {extended result code definitions}
486
**
487
** In its default configuration, SQLite API routines return one of 30 integer
488
** [result codes]. However, experience has shown that many of
489
** these result codes are too coarse-grained. They do not provide as
490
** much information about problems as programmers might like. In an effort to
491
** address this, newer versions of SQLite (version 3.3.8 [dateof:3.3.8]
492
** and later) include
493
** support for additional result codes that provide more detailed information
494
** about errors. These [extended result codes] are enabled or disabled
495
** on a per database connection basis using the
496
** [sqlite3_extended_result_codes()] API. Or, the extended code for
497
** the most recent error can be obtained using
498
** [sqlite3_extended_errcode()].
499
*/
500
#define SQLITE_ERROR_MISSING_COLLSEQ (SQLITE_ERROR | (1<<8))
501
#define SQLITE_ERROR_RETRY (SQLITE_ERROR | (2<<8))
502
#define SQLITE_ERROR_SNAPSHOT (SQLITE_ERROR | (3<<8))
503
#define SQLITE_ERROR_RESERVESIZE (SQLITE_ERROR | (4<<8))
504
#define SQLITE_ERROR_KEY (SQLITE_ERROR | (5<<8))
505
#define SQLITE_ERROR_UNABLE (SQLITE_ERROR | (6<<8))
506
#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8))
507
#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8))
508
#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8))
509
#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8))
510
#define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8))
511
#define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8))
512
#define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8))
513
#define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8))
514
#define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8))
515
#define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8))
516
#define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8))
517
#define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8))
518
#define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8))
519
#define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))
520
#define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8))
521
#define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8))
522
#define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8))
523
#define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8))
524
#define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8))
525
#define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8))
526
#define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8))
527
#define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
528
#define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8))
529
#define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
530
#define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8))
531
#define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8))
532
#define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8))
533
#define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8))
534
#define SQLITE_IOERR_BEGIN_ATOMIC (SQLITE_IOERR | (29<<8))
535
#define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8))
536
#define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8))
537
#define SQLITE_IOERR_DATA (SQLITE_IOERR | (32<<8))
538
#define SQLITE_IOERR_CORRUPTFS (SQLITE_IOERR | (33<<8))
539
#define SQLITE_IOERR_IN_PAGE (SQLITE_IOERR | (34<<8))
540
#define SQLITE_IOERR_BADKEY (SQLITE_IOERR | (35<<8))
541
#define SQLITE_IOERR_CODEC (SQLITE_IOERR | (36<<8))
542
#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
543
#define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8))
544
#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
545
#define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
546
#define SQLITE_BUSY_TIMEOUT (SQLITE_BUSY | (3<<8))
547
#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
548
#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
549
#define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
550
#define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
551
#define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */
552
#define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8))
553
#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
554
#define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8))
555
#define SQLITE_CORRUPT_INDEX (SQLITE_CORRUPT | (3<<8))
556
#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
557
#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
558
#define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
559
#define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
560
#define SQLITE_READONLY_CANTINIT (SQLITE_READONLY | (5<<8))
561
#define SQLITE_READONLY_DIRECTORY (SQLITE_READONLY | (6<<8))
562
#define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
563
#define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
564
#define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
565
#define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
566
#define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
567
#define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8))
568
#define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8))
569
#define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
570
#define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
571
#define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
572
#define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
573
#define SQLITE_CONSTRAINT_PINNED (SQLITE_CONSTRAINT |(11<<8))
574
#define SQLITE_CONSTRAINT_DATATYPE (SQLITE_CONSTRAINT |(12<<8))
575
#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
576
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
577
#define SQLITE_NOTICE_RBU (SQLITE_NOTICE | (3<<8))
578
#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
579
#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
580
#define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
581
#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal only */
582
583
/*
584
** CAPI3REF: Flags For File Open Operations
585
**
586
** These bit values are intended for use in the
587
** 3rd parameter to the [sqlite3_open_v2()] interface and
588
** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
589
**
590
** Only those flags marked as "Ok for sqlite3_open_v2()" may be
591
** used as the third argument to the [sqlite3_open_v2()] interface.
592
** The other flags have historically been ignored by sqlite3_open_v2(),
593
** though future versions of SQLite might change so that an error is
594
** raised if any of the disallowed bits are passed into sqlite3_open_v2().
595
** Applications should not depend on the historical behavior.
596
**
597
** Note in particular that passing the SQLITE_OPEN_EXCLUSIVE flag into
598
** [sqlite3_open_v2()] does *not* cause the underlying database file
599
** to be opened using O_EXCL. Passing SQLITE_OPEN_EXCLUSIVE into
600
** [sqlite3_open_v2()] has historically been a no-op and might become an
601
** error in future versions of SQLite.
602
*/
603
#define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
604
#define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
605
#define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
606
#define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
607
#define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
608
#define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */
609
#define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */
610
#define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */
611
#define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */
612
#define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
613
#define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
614
#define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
615
#define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
616
#define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */
617
#define SQLITE_OPEN_SUPER_JOURNAL 0x00004000 /* VFS only */
618
#define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */
619
#define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
620
#define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
621
#define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
622
#define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
623
#define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */
624
#define SQLITE_OPEN_EXRESCODE 0x02000000 /* Extended result codes */
625
626
/* Reserved: 0x00F00000 */
627
/* Legacy compatibility: */
628
#define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */
629
630
631
/*
632
** CAPI3REF: Device Characteristics
633
**
634
** The xDeviceCharacteristics method of the [sqlite3_io_methods]
635
** object returns an integer which is a vector of these
636
** bit values expressing I/O characteristics of the mass storage
637
** device that holds the file that the [sqlite3_io_methods]
638
** refers to.
639
**
640
** The SQLITE_IOCAP_ATOMIC property means that all writes of
641
** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
642
** mean that writes of blocks that are nnn bytes in size and
643
** are aligned to an address which is an integer multiple of
644
** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
645
** that when data is appended to a file, the data is appended
646
** first then the size of the file is extended, never the other
647
** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
648
** information is written to disk in the same order as calls
649
** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
650
** after reboot following a crash or power loss, the only bytes in a
651
** file that were written at the application level might have changed
652
** and that adjacent bytes, even bytes within the same sector are
653
** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
654
** flag indicates that a file cannot be deleted when open. The
655
** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
656
** read-only media and cannot be changed even by processes with
657
** elevated privileges.
658
**
659
** The SQLITE_IOCAP_BATCH_ATOMIC property means that the underlying
660
** filesystem supports doing multiple write operations atomically when those
661
** write operations are bracketed by [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] and
662
** [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE].
663
**
664
** The SQLITE_IOCAP_SUBPAGE_READ property means that it is ok to read
665
** from the database file in amounts that are not a multiple of the
666
** page size and that do not begin at a page boundary. Without this
667
** property, SQLite is careful to only do full-page reads and write
668
** on aligned pages, with the one exception that it will do a sub-page
669
** read of the first page to access the database header.
670
*/
671
#define SQLITE_IOCAP_ATOMIC 0x00000001
672
#define SQLITE_IOCAP_ATOMIC512 0x00000002
673
#define SQLITE_IOCAP_ATOMIC1K 0x00000004
674
#define SQLITE_IOCAP_ATOMIC2K 0x00000008
675
#define SQLITE_IOCAP_ATOMIC4K 0x00000010
676
#define SQLITE_IOCAP_ATOMIC8K 0x00000020
677
#define SQLITE_IOCAP_ATOMIC16K 0x00000040
678
#define SQLITE_IOCAP_ATOMIC32K 0x00000080
679
#define SQLITE_IOCAP_ATOMIC64K 0x00000100
680
#define SQLITE_IOCAP_SAFE_APPEND 0x00000200
681
#define SQLITE_IOCAP_SEQUENTIAL 0x00000400
682
#define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800
683
#define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000
684
#define SQLITE_IOCAP_IMMUTABLE 0x00002000
685
#define SQLITE_IOCAP_BATCH_ATOMIC 0x00004000
686
#define SQLITE_IOCAP_SUBPAGE_READ 0x00008000
687
688
/*
689
** CAPI3REF: File Locking Levels
690
**
691
** SQLite uses one of these integer values as the second
692
** argument to calls it makes to the xLock() and xUnlock() methods
693
** of an [sqlite3_io_methods] object. These values are ordered from
694
** least restrictive to most restrictive.
695
**
696
** The argument to xLock() is always SHARED or higher. The argument to
697
** xUnlock is either SHARED or NONE.
698
*/
699
#define SQLITE_LOCK_NONE 0 /* xUnlock() only */
700
#define SQLITE_LOCK_SHARED 1 /* xLock() or xUnlock() */
701
#define SQLITE_LOCK_RESERVED 2 /* xLock() only */
702
#define SQLITE_LOCK_PENDING 3 /* xLock() only */
703
#define SQLITE_LOCK_EXCLUSIVE 4 /* xLock() only */
704
705
/*
706
** CAPI3REF: Synchronization Type Flags
707
**
708
** When SQLite invokes the xSync() method of an
709
** [sqlite3_io_methods] object it uses a combination of
710
** these integer values as the second argument.
711
**
712
** When the SQLITE_SYNC_DATAONLY flag is used, it means that the
713
** sync operation only needs to flush data to mass storage. Inode
714
** information need not be flushed. If the lower four bits of the flag
715
** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics.
716
** If the lower four bits equal SQLITE_SYNC_FULL, that means
717
** to use Mac OS X style fullsync instead of fsync().
718
**
719
** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags
720
** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL
721
** settings. The [synchronous pragma] determines when calls to the
722
** xSync VFS method occur and applies uniformly across all platforms.
723
** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how
724
** energetic or rigorous or forceful the sync operations are and
725
** only make a difference on Mac OSX for the default SQLite code.
726
** (Third-party VFS implementations might also make the distinction
727
** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the
728
** operating systems natively supported by SQLite, only Mac OSX
729
** cares about the difference.)
730
*/
731
#define SQLITE_SYNC_NORMAL 0x00002
732
#define SQLITE_SYNC_FULL 0x00003
733
#define SQLITE_SYNC_DATAONLY 0x00010
734
735
/*
736
** CAPI3REF: OS Interface Open File Handle
737
**
738
** An [sqlite3_file] object represents an open file in the
739
** [sqlite3_vfs | OS interface layer]. Individual OS interface
740
** implementations will
741
** want to subclass this object by appending additional fields
742
** for their own use. The pMethods entry is a pointer to an
743
** [sqlite3_io_methods] object that defines methods for performing
744
** I/O operations on the open file.
745
*/
746
typedef struct sqlite3_file sqlite3_file;
747
struct sqlite3_file {
748
const struct sqlite3_io_methods *pMethods; /* Methods for an open file */
749
};
750
751
/*
752
** CAPI3REF: OS Interface File Virtual Methods Object
753
**
754
** Every file opened by the [sqlite3_vfs.xOpen] method populates an
755
** [sqlite3_file] object (or, more commonly, a subclass of the
756
** [sqlite3_file] object) with a pointer to an instance of this object.
757
** This object defines the methods used to perform various operations
758
** against the open file represented by the [sqlite3_file] object.
759
**
760
** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element
761
** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
762
** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The
763
** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen]
764
** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element
765
** to NULL.
766
**
767
** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
768
** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().
769
** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY]
770
** flag may be ORed in to indicate that only the data of the file
771
** and not its inode needs to be synced.
772
**
773
** The integer values to xLock() and xUnlock() are one of
774
** <ul>
775
** <li> [SQLITE_LOCK_NONE],
776
** <li> [SQLITE_LOCK_SHARED],
777
** <li> [SQLITE_LOCK_RESERVED],
778
** <li> [SQLITE_LOCK_PENDING], or
779
** <li> [SQLITE_LOCK_EXCLUSIVE].
780
** </ul>
781
** xLock() upgrades the database file lock. In other words, xLock() moves the
782
** database file lock in the direction NONE toward EXCLUSIVE. The argument to
783
** xLock() is always one of SHARED, RESERVED, PENDING, or EXCLUSIVE, never
784
** SQLITE_LOCK_NONE. If the database file lock is already at or above the
785
** requested lock, then the call to xLock() is a no-op.
786
** xUnlock() downgrades the database file lock to either SHARED or NONE.
787
** If the lock is already at or below the requested lock state, then the call
788
** to xUnlock() is a no-op.
789
** The xCheckReservedLock() method checks whether any database connection,
790
** either in this process or in some other process, is holding a RESERVED,
791
** PENDING, or EXCLUSIVE lock on the file. It returns, via its output
792
** pointer parameter, true if such a lock exists and false otherwise.
793
**
794
** The xFileControl() method is a generic interface that allows custom
795
** VFS implementations to directly control an open file using the
796
** [sqlite3_file_control()] interface. The second "op" argument is an
797
** integer opcode. The third argument is a generic pointer intended to
798
** point to a structure that may contain arguments or space in which to
799
** write return values. Potential uses for xFileControl() might be
800
** functions to enable blocking locks with timeouts, to change the
801
** locking strategy (for example to use dot-file locks), to inquire
802
** about the status of a lock, or to break stale locks. The SQLite
803
** core reserves all opcodes less than 100 for its own use.
804
** A [file control opcodes | list of opcodes] less than 100 is available.
805
** Applications that define a custom xFileControl method should use opcodes
806
** greater than 100 to avoid conflicts. VFS implementations should
807
** return [SQLITE_NOTFOUND] for file control opcodes that they do not
808
** recognize.
809
**
810
** The xSectorSize() method returns the sector size of the
811
** device that underlies the file. The sector size is the
812
** minimum write that can be performed without disturbing
813
** other bytes in the file. The xDeviceCharacteristics()
814
** method returns a bit vector describing behaviors of the
815
** underlying device:
816
**
817
** <ul>
818
** <li> [SQLITE_IOCAP_ATOMIC]
819
** <li> [SQLITE_IOCAP_ATOMIC512]
820
** <li> [SQLITE_IOCAP_ATOMIC1K]
821
** <li> [SQLITE_IOCAP_ATOMIC2K]
822
** <li> [SQLITE_IOCAP_ATOMIC4K]
823
** <li> [SQLITE_IOCAP_ATOMIC8K]
824
** <li> [SQLITE_IOCAP_ATOMIC16K]
825
** <li> [SQLITE_IOCAP_ATOMIC32K]
826
** <li> [SQLITE_IOCAP_ATOMIC64K]
827
** <li> [SQLITE_IOCAP_SAFE_APPEND]
828
** <li> [SQLITE_IOCAP_SEQUENTIAL]
829
** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
830
** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
831
** <li> [SQLITE_IOCAP_IMMUTABLE]
832
** <li> [SQLITE_IOCAP_BATCH_ATOMIC]
833
** <li> [SQLITE_IOCAP_SUBPAGE_READ]
834
** </ul>
835
**
836
** The SQLITE_IOCAP_ATOMIC property means that all writes of
837
** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
838
** mean that writes of blocks that are nnn bytes in size and
839
** are aligned to an address which is an integer multiple of
840
** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means
841
** that when data is appended to a file, the data is appended
842
** first then the size of the file is extended, never the other
843
** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
844
** information is written to disk in the same order as calls
845
** to xWrite().
846
**
847
** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill
848
** in the unread portions of the buffer with zeros. A VFS that
849
** fails to zero-fill short reads might seem to work. However,
850
** failure to zero-fill short reads will eventually lead to
851
** database corruption.
852
*/
853
typedef struct sqlite3_io_methods sqlite3_io_methods;
854
struct sqlite3_io_methods {
855
int iVersion;
856
int (*xClose)(sqlite3_file*);
857
int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
858
int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);
859
int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);
860
int (*xSync)(sqlite3_file*, int flags);
861
int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);
862
int (*xLock)(sqlite3_file*, int);
863
int (*xUnlock)(sqlite3_file*, int);
864
int (*xCheckReservedLock)(sqlite3_file*, int *pResOut);
865
int (*xFileControl)(sqlite3_file*, int op, void *pArg);
866
int (*xSectorSize)(sqlite3_file*);
867
int (*xDeviceCharacteristics)(sqlite3_file*);
868
/* Methods above are valid for version 1 */
869
int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**);
870
int (*xShmLock)(sqlite3_file*, int offset, int n, int flags);
871
void (*xShmBarrier)(sqlite3_file*);
872
int (*xShmUnmap)(sqlite3_file*, int deleteFlag);
873
/* Methods above are valid for version 2 */
874
int (*xFetch)(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp);
875
int (*xUnfetch)(sqlite3_file*, sqlite3_int64 iOfst, void *p);
876
/* Methods above are valid for version 3 */
877
/* Additional methods may be added in future releases */
878
};
879
880
/*
881
** CAPI3REF: Standard File Control Opcodes
882
** KEYWORDS: {file control opcodes} {file control opcode}
883
**
884
** These integer constants are opcodes for the xFileControl method
885
** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
886
** interface.
887
**
888
** <ul>
889
** <li>[[SQLITE_FCNTL_LOCKSTATE]]
890
** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This
891
** opcode causes the xFileControl method to write the current state of
892
** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
893
** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
894
** into an integer that the pArg argument points to.
895
** This capability is only available if SQLite is compiled with [SQLITE_DEBUG].
896
**
897
** <li>[[SQLITE_FCNTL_SIZE_HINT]]
898
** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
899
** layer a hint of how large the database file will grow to be during the
900
** current transaction. This hint is not guaranteed to be accurate but it
901
** is often close. The underlying VFS might choose to preallocate database
902
** file space based on this hint in order to help writes to the database
903
** file run faster.
904
**
905
** <li>[[SQLITE_FCNTL_SIZE_LIMIT]]
906
** The [SQLITE_FCNTL_SIZE_LIMIT] opcode is used by in-memory VFS that
907
** implements [sqlite3_deserialize()] to set an upper bound on the size
908
** of the in-memory database. The argument is a pointer to a [sqlite3_int64].
909
** If the integer pointed to is negative, then it is filled in with the
910
** current limit. Otherwise the limit is set to the larger of the value
911
** of the integer pointed to and the current database size. The integer
912
** pointed to is set to the new limit.
913
**
914
** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
915
** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
916
** extends and truncates the database file in chunks of a size specified
917
** by the user. The fourth argument to [sqlite3_file_control()] should
918
** point to an integer (type int) containing the new chunk-size to use
919
** for the nominated database. Allocating database file space in large
920
** chunks (say 1MB at a time), may reduce file-system fragmentation and
921
** improve performance on some systems.
922
**
923
** <li>[[SQLITE_FCNTL_FILE_POINTER]]
924
** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
925
** to the [sqlite3_file] object associated with a particular database
926
** connection. See also [SQLITE_FCNTL_JOURNAL_POINTER].
927
**
928
** <li>[[SQLITE_FCNTL_JOURNAL_POINTER]]
929
** The [SQLITE_FCNTL_JOURNAL_POINTER] opcode is used to obtain a pointer
930
** to the [sqlite3_file] object associated with the journal file (either
931
** the [rollback journal] or the [write-ahead log]) for a particular database
932
** connection. See also [SQLITE_FCNTL_FILE_POINTER].
933
**
934
** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
935
** The SQLITE_FCNTL_SYNC_OMITTED file-control is no longer used.
936
**
937
** <li>[[SQLITE_FCNTL_SYNC]]
938
** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and
939
** sent to the VFS immediately before the xSync method is invoked on a
940
** database file descriptor. Or, if the xSync method is not invoked
941
** because the user has configured SQLite with
942
** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
943
** of the xSync method. In most cases, the pointer argument passed with
944
** this file-control is NULL. However, if the database file is being synced
945
** as part of a multi-database commit, the argument points to a nul-terminated
946
** string containing the transactions super-journal file name. VFSes that
947
** do not need this signal should silently ignore this opcode. Applications
948
** should not call [sqlite3_file_control()] with this opcode as doing so may
949
** disrupt the operation of the specialized VFSes that do require it.
950
**
951
** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
952
** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite
953
** and sent to the VFS after a transaction has been committed immediately
954
** but before the database is unlocked. VFSes that do not need this signal
955
** should silently ignore this opcode. Applications should not call
956
** [sqlite3_file_control()] with this opcode as doing so may disrupt the
957
** operation of the specialized VFSes that do require it.
958
**
959
** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
960
** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
961
** retry counts and intervals for certain disk I/O operations for the
962
** windows [VFS] in order to provide robustness in the presence of
963
** anti-virus programs. By default, the windows VFS will retry file read,
964
** file write, and file delete operations up to 10 times, with a delay
965
** of 25 milliseconds before the first retry and with the delay increasing
966
** by an additional 25 milliseconds with each subsequent retry. This
967
** opcode allows these two values (10 retries and 25 milliseconds of delay)
968
** to be adjusted. The values are changed for all database connections
969
** within the same process. The argument is a pointer to an array of two
970
** integers where the first integer is the new retry count and the second
971
** integer is the delay. If either integer is negative, then the setting
972
** is not changed but instead the prior value of that setting is written
973
** into the array entry, allowing the current retry settings to be
974
** interrogated. The zDbName parameter is ignored.
975
**
976
** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
977
** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
978
** persistent [WAL | Write Ahead Log] setting. By default, the auxiliary
979
** write ahead log ([WAL file]) and shared memory
980
** files used for transaction control
981
** are automatically deleted when the latest connection to the database
982
** closes. Setting persistent WAL mode causes those files to persist after
983
** close. Persisting the files is useful when other processes that do not
984
** have write permission on the directory containing the database file want
985
** to read the database file, as the WAL and shared memory files must exist
986
** in order for the database to be readable. The fourth parameter to
987
** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
988
** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
989
** WAL mode. If the integer is -1, then it is overwritten with the current
990
** WAL persistence setting.
991
**
992
** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]]
993
** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the
994
** persistent "powersafe-overwrite" or "PSOW" setting. The PSOW setting
995
** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the
996
** xDeviceCharacteristics methods. The fourth parameter to
997
** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
998
** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage
999
** mode. If the integer is -1, then it is overwritten with the current
1000
** zero-damage mode setting.
1001
**
1002
** <li>[[SQLITE_FCNTL_OVERWRITE]]
1003
** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening
1004
** a write transaction to indicate that, unless it is rolled back for some
1005
** reason, the entire database file will be overwritten by the current
1006
** transaction. This is used by VACUUM operations.
1007
**
1008
** <li>[[SQLITE_FCNTL_VFSNAME]]
1009
** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of
1010
** all [VFSes] in the VFS stack. The names of all VFS shims and the
1011
** final bottom-level VFS are written into memory obtained from
1012
** [sqlite3_malloc()] and the result is stored in the char* variable
1013
** that the fourth parameter of [sqlite3_file_control()] points to.
1014
** The caller is responsible for freeing the memory when done. As with
1015
** all file-control actions, there is no guarantee that this will actually
1016
** do anything. Callers should initialize the char* variable to a NULL
1017
** pointer in case this file-control is not implemented. This file-control
1018
** is intended for diagnostic use only.
1019
**
1020
** <li>[[SQLITE_FCNTL_VFS_POINTER]]
1021
** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level
1022
** [VFSes] currently in use. ^(The argument X in
1023
** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be
1024
** of type "[sqlite3_vfs] **". This opcode will set *X
1025
** to a pointer to the top-level VFS.)^
1026
** ^When there are multiple VFS shims in the stack, this opcode finds the
1027
** upper-most shim only.
1028
**
1029
** <li>[[SQLITE_FCNTL_PRAGMA]]
1030
** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA]
1031
** file control is sent to the open [sqlite3_file] object corresponding
1032
** to the database file to which the pragma statement refers. ^The argument
1033
** to the [SQLITE_FCNTL_PRAGMA] file control is an array of
1034
** pointers to strings (char**) in which the second element of the array
1035
** is the name of the pragma and the third element is the argument to the
1036
** pragma or NULL if the pragma has no argument. ^The handler for an
1037
** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element
1038
** of the char** argument point to a string obtained from [sqlite3_mprintf()]
1039
** or the equivalent and that string will become the result of the pragma or
1040
** the error message if the pragma fails. ^If the
1041
** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal
1042
** [PRAGMA] processing continues. ^If the [SQLITE_FCNTL_PRAGMA]
1043
** file control returns [SQLITE_OK], then the parser assumes that the
1044
** VFS has handled the PRAGMA itself and the parser generates a no-op
1045
** prepared statement if result string is NULL, or that returns a copy
1046
** of the result string if the string is non-NULL.
1047
** ^If the [SQLITE_FCNTL_PRAGMA] file control returns
1048
** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means
1049
** that the VFS encountered an error while handling the [PRAGMA] and the
1050
** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA]
1051
** file control occurs at the beginning of pragma statement analysis and so
1052
** it is able to override built-in [PRAGMA] statements.
1053
**
1054
** <li>[[SQLITE_FCNTL_BUSYHANDLER]]
1055
** ^The [SQLITE_FCNTL_BUSYHANDLER]
1056
** file-control may be invoked by SQLite on the database file handle
1057
** shortly after it is opened in order to provide a custom VFS with access
1058
** to the connection's busy-handler callback. The argument is of type (void**)
1059
** - an array of two (void *) values. The first (void *) actually points
1060
** to a function of type (int (*)(void *)). In order to invoke the connection's
1061
** busy-handler, this function should be invoked with the second (void *) in
1062
** the array as the only argument. If it returns non-zero, then the operation
1063
** should be retried. If it returns zero, the custom VFS should abandon the
1064
** current operation.
1065
**
1066
** <li>[[SQLITE_FCNTL_TEMPFILENAME]]
1067
** ^Applications can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
1068
** to have SQLite generate a
1069
** temporary filename using the same algorithm that is followed to generate
1070
** temporary filenames for TEMP tables and other internal uses. The
1071
** argument should be a char** which will be filled with the filename
1072
** written into memory obtained from [sqlite3_malloc()]. The caller should
1073
** invoke [sqlite3_free()] on the result to avoid a memory leak.
1074
**
1075
** <li>[[SQLITE_FCNTL_MMAP_SIZE]]
1076
** The [SQLITE_FCNTL_MMAP_SIZE] file control is used to query or set the
1077
** maximum number of bytes that will be used for memory-mapped I/O.
1078
** The argument is a pointer to a value of type sqlite3_int64 that
1079
** is an advisory maximum number of bytes in the file to memory map. The
1080
** pointer is overwritten with the old value. The limit is not changed if
1081
** the value originally pointed to is negative, and so the current limit
1082
** can be queried by passing in a pointer to a negative number. This
1083
** file-control is used internally to implement [PRAGMA mmap_size].
1084
**
1085
** <li>[[SQLITE_FCNTL_TRACE]]
1086
** The [SQLITE_FCNTL_TRACE] file control provides advisory information
1087
** to the VFS about what the higher layers of the SQLite stack are doing.
1088
** This file control is used by some VFS activity tracing [shims].
1089
** The argument is a zero-terminated string. Higher layers in the
1090
** SQLite stack may generate instances of this file control if
1091
** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
1092
**
1093
** <li>[[SQLITE_FCNTL_HAS_MOVED]]
1094
** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
1095
** pointer to an integer and it writes a boolean into that integer depending
1096
** on whether or not the file has been renamed, moved, or deleted since it
1097
** was first opened.
1098
**
1099
** <li>[[SQLITE_FCNTL_WIN32_GET_HANDLE]]
1100
** The [SQLITE_FCNTL_WIN32_GET_HANDLE] opcode can be used to obtain the
1101
** underlying native file handle associated with a file handle. This file
1102
** control interprets its argument as a pointer to a native file handle and
1103
** writes the resulting value there.
1104
**
1105
** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]]
1106
** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This
1107
** opcode causes the xFileControl method to swap the file handle with the one
1108
** pointed to by the pArg argument. This capability is used during testing
1109
** and only needs to be supported when SQLITE_TEST is defined.
1110
**
1111
** <li>[[SQLITE_FCNTL_NULL_IO]]
1112
** The [SQLITE_FCNTL_NULL_IO] opcode sets the low-level file descriptor
1113
** or file handle for the [sqlite3_file] object such that it will no longer
1114
** read or write to the database file.
1115
**
1116
** <li>[[SQLITE_FCNTL_WAL_BLOCK]]
1117
** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might
1118
** be advantageous to block on the next WAL lock if the lock is not immediately
1119
** available. The WAL subsystem issues this signal during rare
1120
** circumstances in order to fix a problem with priority inversion.
1121
** Applications should <em>not</em> use this file-control.
1122
**
1123
** <li>[[SQLITE_FCNTL_ZIPVFS]]
1124
** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other
1125
** VFS should return SQLITE_NOTFOUND for this opcode.
1126
**
1127
** <li>[[SQLITE_FCNTL_RBU]]
1128
** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
1129
** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for
1130
** this opcode.
1131
**
1132
** <li>[[SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]]
1133
** If the [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] opcode returns SQLITE_OK, then
1134
** the file descriptor is placed in "batch write mode", which
1135
** means all subsequent write operations will be deferred and done
1136
** atomically at the next [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]. Systems
1137
** that do not support batch atomic writes will return SQLITE_NOTFOUND.
1138
** ^Following a successful SQLITE_FCNTL_BEGIN_ATOMIC_WRITE and prior to
1139
** the closing [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] or
1140
** [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE], SQLite will make
1141
** no VFS interface calls on the same [sqlite3_file] file descriptor
1142
** except for calls to the xWrite method and the xFileControl method
1143
** with [SQLITE_FCNTL_SIZE_HINT].
1144
**
1145
** <li>[[SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]]
1146
** The [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] opcode causes all write
1147
** operations since the previous successful call to
1148
** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be performed atomically.
1149
** This file control returns [SQLITE_OK] if and only if the writes were
1150
** all performed successfully and have been committed to persistent storage.
1151
** ^Regardless of whether or not it is successful, this file control takes
1152
** the file descriptor out of batch write mode so that all subsequent
1153
** write operations are independent.
1154
** ^SQLite will never invoke SQLITE_FCNTL_COMMIT_ATOMIC_WRITE without
1155
** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
1156
**
1157
** <li>[[SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE]]
1158
** The [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE] opcode causes all write
1159
** operations since the previous successful call to
1160
** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be rolled back.
1161
** ^This file control takes the file descriptor out of batch write mode
1162
** so that all subsequent write operations are independent.
1163
** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without
1164
** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
1165
**
1166
** <li>[[SQLITE_FCNTL_LOCK_TIMEOUT]]
1167
** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode is used to configure a VFS
1168
** to block for up to M milliseconds before failing when attempting to
1169
** obtain a file lock using the xLock or xShmLock methods of the VFS.
1170
** The parameter is a pointer to a 32-bit signed integer that contains
1171
** the value that M is to be set to. Before returning, the 32-bit signed
1172
** integer is overwritten with the previous value of M.
1173
**
1174
** <li>[[SQLITE_FCNTL_BLOCK_ON_CONNECT]]
1175
** The [SQLITE_FCNTL_BLOCK_ON_CONNECT] opcode is used to configure the
1176
** VFS to block when taking a SHARED lock to connect to a wal mode database.
1177
** This is used to implement the functionality associated with
1178
** SQLITE_SETLK_BLOCK_ON_CONNECT.
1179
**
1180
** <li>[[SQLITE_FCNTL_DATA_VERSION]]
1181
** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to
1182
** a database file. The argument is a pointer to a 32-bit unsigned integer.
1183
** The "data version" for the pager is written into the pointer. The
1184
** "data version" changes whenever any change occurs to the corresponding
1185
** database file, either through SQL statements on the same database
1186
** connection or through transactions committed by separate database
1187
** connections possibly in other processes. The [sqlite3_total_changes()]
1188
** interface can be used to find if any database on the connection has changed,
1189
** but that interface responds to changes on TEMP as well as MAIN and does
1190
** not provide a mechanism to detect changes to MAIN only. Also, the
1191
** [sqlite3_total_changes()] interface responds to internal changes only and
1192
** omits changes made by other database connections. The
1193
** [PRAGMA data_version] command provides a mechanism to detect changes to
1194
** a single attached database that occur due to other database connections,
1195
** but omits changes implemented by the database connection on which it is
1196
** called. This file control is the only mechanism to detect changes that
1197
** happen either internally or externally and that are associated with
1198
** a particular attached database.
1199
**
1200
** <li>[[SQLITE_FCNTL_CKPT_START]]
1201
** The [SQLITE_FCNTL_CKPT_START] opcode is invoked from within a checkpoint
1202
** in wal mode before the client starts to copy pages from the wal
1203
** file to the database file.
1204
**
1205
** <li>[[SQLITE_FCNTL_CKPT_DONE]]
1206
** The [SQLITE_FCNTL_CKPT_DONE] opcode is invoked from within a checkpoint
1207
** in wal mode after the client has finished copying pages from the wal
1208
** file to the database file, but before the *-shm file is updated to
1209
** record the fact that the pages have been checkpointed.
1210
**
1211
** <li>[[SQLITE_FCNTL_EXTERNAL_READER]]
1212
** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect
1213
** whether or not there is a database client in another process with a wal-mode
1214
** transaction open on the database or not. It is only available on unix. The
1215
** (void*) argument passed with this file-control should be a pointer to a
1216
** value of type (int). The integer value is set to 1 if the database is a wal
1217
** mode database and there exists at least one client in another process that
1218
** currently has an SQL transaction open on the database. It is set to 0 if
1219
** the database is not a wal-mode db, or if there is no such connection in any
1220
** other process. This opcode cannot be used to detect transactions opened
1221
** by clients within the current process, only within other processes.
1222
**
1223
** <li>[[SQLITE_FCNTL_CKSM_FILE]]
1224
** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use internally by the
1225
** [checksum VFS shim] only.
1226
**
1227
** <li>[[SQLITE_FCNTL_RESET_CACHE]]
1228
** If there is currently no transaction open on the database, and the
1229
** database is not a temp db, then the [SQLITE_FCNTL_RESET_CACHE] file-control
1230
** purges the contents of the in-memory page cache. If there is an open
1231
** transaction, or if the db is a temp-db, this opcode is a no-op, not an error.
1232
**
1233
** <li>[[SQLITE_FCNTL_FILESTAT]]
1234
** The [SQLITE_FCNTL_FILESTAT] opcode returns low-level diagnostic information
1235
** about the [sqlite3_file] objects used access the database and journal files
1236
** for the given schema. The fourth parameter to [sqlite3_file_control()]
1237
** should be an initialized [sqlite3_str] pointer. JSON text describing
1238
** various aspects of the sqlite3_file object is appended to the sqlite3_str.
1239
** The SQLITE_FCNTL_FILESTAT opcode is usually a no-op, unless compile-time
1240
** options are used to enable it.
1241
** </ul>
1242
*/
1243
#define SQLITE_FCNTL_LOCKSTATE 1
1244
#define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
1245
#define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
1246
#define SQLITE_FCNTL_LAST_ERRNO 4
1247
#define SQLITE_FCNTL_SIZE_HINT 5
1248
#define SQLITE_FCNTL_CHUNK_SIZE 6
1249
#define SQLITE_FCNTL_FILE_POINTER 7
1250
#define SQLITE_FCNTL_SYNC_OMITTED 8
1251
#define SQLITE_FCNTL_WIN32_AV_RETRY 9
1252
#define SQLITE_FCNTL_PERSIST_WAL 10
1253
#define SQLITE_FCNTL_OVERWRITE 11
1254
#define SQLITE_FCNTL_VFSNAME 12
1255
#define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13
1256
#define SQLITE_FCNTL_PRAGMA 14
1257
#define SQLITE_FCNTL_BUSYHANDLER 15
1258
#define SQLITE_FCNTL_TEMPFILENAME 16
1259
#define SQLITE_FCNTL_MMAP_SIZE 18
1260
#define SQLITE_FCNTL_TRACE 19
1261
#define SQLITE_FCNTL_HAS_MOVED 20
1262
#define SQLITE_FCNTL_SYNC 21
1263
#define SQLITE_FCNTL_COMMIT_PHASETWO 22
1264
#define SQLITE_FCNTL_WIN32_SET_HANDLE 23
1265
#define SQLITE_FCNTL_WAL_BLOCK 24
1266
#define SQLITE_FCNTL_ZIPVFS 25
1267
#define SQLITE_FCNTL_RBU 26
1268
#define SQLITE_FCNTL_VFS_POINTER 27
1269
#define SQLITE_FCNTL_JOURNAL_POINTER 28
1270
#define SQLITE_FCNTL_WIN32_GET_HANDLE 29
1271
#define SQLITE_FCNTL_PDB 30
1272
#define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 31
1273
#define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32
1274
#define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33
1275
#define SQLITE_FCNTL_LOCK_TIMEOUT 34
1276
#define SQLITE_FCNTL_DATA_VERSION 35
1277
#define SQLITE_FCNTL_SIZE_LIMIT 36
1278
#define SQLITE_FCNTL_CKPT_DONE 37
1279
#define SQLITE_FCNTL_RESERVE_BYTES 38
1280
#define SQLITE_FCNTL_CKPT_START 39
1281
#define SQLITE_FCNTL_EXTERNAL_READER 40
1282
#define SQLITE_FCNTL_CKSM_FILE 41
1283
#define SQLITE_FCNTL_RESET_CACHE 42
1284
#define SQLITE_FCNTL_NULL_IO 43
1285
#define SQLITE_FCNTL_BLOCK_ON_CONNECT 44
1286
#define SQLITE_FCNTL_FILESTAT 45
1287
1288
/* deprecated names */
1289
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
1290
#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
1291
#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
1292
1293
/* reserved file-control numbers:
1294
** 101
1295
** 102
1296
** 103
1297
*/
1298
1299
1300
/*
1301
** CAPI3REF: Mutex Handle
1302
**
1303
** The mutex module within SQLite defines [sqlite3_mutex] to be an
1304
** abstract type for a mutex object. The SQLite core never looks
1305
** at the internal representation of an [sqlite3_mutex]. It only
1306
** deals with pointers to the [sqlite3_mutex] object.
1307
**
1308
** Mutexes are created using [sqlite3_mutex_alloc()].
1309
*/
1310
typedef struct sqlite3_mutex sqlite3_mutex;
1311
1312
/*
1313
** CAPI3REF: Loadable Extension Thunk
1314
**
1315
** A pointer to the opaque sqlite3_api_routines structure is passed as
1316
** the third parameter to entry points of [loadable extensions]. This
1317
** structure must be typedefed in order to work around compiler warnings
1318
** on some platforms.
1319
*/
1320
typedef struct sqlite3_api_routines sqlite3_api_routines;
1321
1322
/*
1323
** CAPI3REF: File Name
1324
**
1325
** Type [sqlite3_filename] is used by SQLite to pass filenames to the
1326
** xOpen method of a [VFS]. It may be cast to (const char*) and treated
1327
** as a normal, nul-terminated, UTF-8 buffer containing the filename, but
1328
** may also be passed to special APIs such as:
1329
**
1330
** <ul>
1331
** <li> sqlite3_filename_database()
1332
** <li> sqlite3_filename_journal()
1333
** <li> sqlite3_filename_wal()
1334
** <li> sqlite3_uri_parameter()
1335
** <li> sqlite3_uri_boolean()
1336
** <li> sqlite3_uri_int64()
1337
** <li> sqlite3_uri_key()
1338
** </ul>
1339
*/
1340
typedef const char *sqlite3_filename;
1341
1342
/*
1343
** CAPI3REF: OS Interface Object
1344
**
1345
** An instance of the sqlite3_vfs object defines the interface between
1346
** the SQLite core and the underlying operating system. The "vfs"
1347
** in the name of the object stands for "virtual file system". See
1348
** the [VFS | VFS documentation] for further information.
1349
**
1350
** The VFS interface is sometimes extended by adding new methods onto
1351
** the end. Each time such an extension occurs, the iVersion field
1352
** is incremented. The iVersion value started out as 1 in
1353
** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2
1354
** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased
1355
** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6]. Additional fields
1356
** may be appended to the sqlite3_vfs object and the iVersion value
1357
** may increase again in future versions of SQLite.
1358
** Note that due to an oversight, the structure
1359
** of the sqlite3_vfs object changed in the transition from
1360
** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0]
1361
** and yet the iVersion field was not increased.
1362
**
1363
** The szOsFile field is the size of the subclassed [sqlite3_file]
1364
** structure used by this VFS. mxPathname is the maximum length of
1365
** a pathname in this VFS.
1366
**
1367
** Registered sqlite3_vfs objects are kept on a linked list formed by
1368
** the pNext pointer. The [sqlite3_vfs_register()]
1369
** and [sqlite3_vfs_unregister()] interfaces manage this list
1370
** in a thread-safe way. The [sqlite3_vfs_find()] interface
1371
** searches the list. Neither the application code nor the VFS
1372
** implementation should use the pNext pointer.
1373
**
1374
** The pNext field is the only field in the sqlite3_vfs
1375
** structure that SQLite will ever modify. SQLite will only access
1376
** or modify this field while holding a particular static mutex.
1377
** The application should never modify anything within the sqlite3_vfs
1378
** object once the object has been registered.
1379
**
1380
** The zName field holds the name of the VFS module. The name must
1381
** be unique across all VFS modules.
1382
**
1383
** [[sqlite3_vfs.xOpen]]
1384
** ^SQLite guarantees that the zFilename parameter to xOpen
1385
** is either a NULL pointer or string obtained
1386
** from xFullPathname() with an optional suffix added.
1387
** ^If a suffix is added to the zFilename parameter, it will
1388
** consist of a single "-" character followed by no more than
1389
** 11 alphanumeric and/or "-" characters.
1390
** ^SQLite further guarantees that
1391
** the string will be valid and unchanged until xClose() is
1392
** called. Because of the previous sentence,
1393
** the [sqlite3_file] can safely store a pointer to the
1394
** filename if it needs to remember the filename for some reason.
1395
** If the zFilename parameter to xOpen is a NULL pointer then xOpen
1396
** must invent its own temporary name for the file. ^Whenever the
1397
** xFilename parameter is NULL it will also be the case that the
1398
** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
1399
**
1400
** The flags argument to xOpen() includes all bits set in
1401
** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()]
1402
** or [sqlite3_open16()] is used, then flags includes at least
1403
** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
1404
** If xOpen() opens a file read-only then it sets *pOutFlags to
1405
** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set.
1406
**
1407
** ^(SQLite will also add one of the following flags to the xOpen()
1408
** call, depending on the object being opened:
1409
**
1410
** <ul>
1411
** <li> [SQLITE_OPEN_MAIN_DB]
1412
** <li> [SQLITE_OPEN_MAIN_JOURNAL]
1413
** <li> [SQLITE_OPEN_TEMP_DB]
1414
** <li> [SQLITE_OPEN_TEMP_JOURNAL]
1415
** <li> [SQLITE_OPEN_TRANSIENT_DB]
1416
** <li> [SQLITE_OPEN_SUBJOURNAL]
1417
** <li> [SQLITE_OPEN_SUPER_JOURNAL]
1418
** <li> [SQLITE_OPEN_WAL]
1419
** </ul>)^
1420
**
1421
** The file I/O implementation can use the object type flags to
1422
** change the way it deals with files. For example, an application
1423
** that does not care about crash recovery or rollback might make
1424
** the open of a journal file a no-op. Writes to this journal would
1425
** also be no-ops, and any attempt to read the journal would return
1426
** SQLITE_IOERR. Or the implementation might recognize that a database
1427
** file will be doing page-aligned sector reads and writes in a random
1428
** order and set up its I/O subsystem accordingly.
1429
**
1430
** SQLite might also add one of the following flags to the xOpen method:
1431
**
1432
** <ul>
1433
** <li> [SQLITE_OPEN_DELETEONCLOSE]
1434
** <li> [SQLITE_OPEN_EXCLUSIVE]
1435
** </ul>
1436
**
1437
** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
1438
** deleted when it is closed. ^The [SQLITE_OPEN_DELETEONCLOSE]
1439
** will be set for TEMP databases and their journals, transient
1440
** databases, and subjournals.
1441
**
1442
** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
1443
** with the [SQLITE_OPEN_CREATE] flag, which are both directly
1444
** analogous to the O_EXCL and O_CREAT flags of the POSIX open()
1445
** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the
1446
** SQLITE_OPEN_CREATE, is used to indicate that file should always
1447
** be created, and that it is an error if it already exists.
1448
** It is <i>not</i> used to indicate the file should be opened
1449
** for exclusive access.
1450
**
1451
** ^At least szOsFile bytes of memory are allocated by SQLite
1452
** to hold the [sqlite3_file] structure passed as the third
1453
** argument to xOpen. The xOpen method does not have to
1454
** allocate the structure; it should just fill it in. Note that
1455
** the xOpen method must set the sqlite3_file.pMethods to either
1456
** a valid [sqlite3_io_methods] object or to NULL. xOpen must do
1457
** this even if the open fails. SQLite expects that the sqlite3_file.pMethods
1458
** element will be valid after xOpen returns regardless of the success
1459
** or failure of the xOpen call.
1460
**
1461
** [[sqlite3_vfs.xAccess]]
1462
** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
1463
** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
1464
** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
1465
** to test whether a file is at least readable. The SQLITE_ACCESS_READ
1466
** flag is never actually used and is not implemented in the built-in
1467
** VFSes of SQLite. The file is named by the second argument and can be a
1468
** directory. The xAccess method returns [SQLITE_OK] on success or some
1469
** non-zero error code if there is an I/O error or if the name of
1470
** the file given in the second argument is illegal. If SQLITE_OK
1471
** is returned, then non-zero or zero is written into *pResOut to indicate
1472
** whether or not the file is accessible.
1473
**
1474
** ^SQLite will always allocate at least mxPathname+1 bytes for the
1475
** output buffer xFullPathname. The exact size of the output buffer
1476
** is also passed as a parameter to both methods. If the output buffer
1477
** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
1478
** handled as a fatal error by SQLite, vfs implementations should endeavor
1479
** to prevent this by setting mxPathname to a sufficiently large value.
1480
**
1481
** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
1482
** interfaces are not strictly a part of the filesystem, but they are
1483
** included in the VFS structure for completeness.
1484
** The xRandomness() function attempts to return nBytes bytes
1485
** of good-quality randomness into zOut. The return value is
1486
** the actual number of bytes of randomness obtained.
1487
** The xSleep() method causes the calling thread to sleep for at
1488
** least the number of microseconds given. ^The xCurrentTime()
1489
** method returns a Julian Day Number for the current date and time as
1490
** a floating point value.
1491
** ^The xCurrentTimeInt64() method returns, as an integer, the Julian
1492
** Day Number multiplied by 86400000 (the number of milliseconds in
1493
** a 24-hour day).
1494
** ^SQLite will use the xCurrentTimeInt64() method to get the current
1495
** date and time if that method is available (if iVersion is 2 or
1496
** greater and the function pointer is not NULL) and will fall back
1497
** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
1498
**
1499
** ^The xSetSystemCall(), xGetSystemCall(), and xNextSystemCall() interfaces
1500
** are not used by the SQLite core. These optional interfaces are provided
1501
** by some VFSes to facilitate testing of the VFS code. By overriding
1502
** system calls with functions under its control, a test program can
1503
** simulate faults and error conditions that would otherwise be difficult
1504
** or impossible to induce. The set of system calls that can be overridden
1505
** varies from one VFS to another, and from one version of the same VFS to the
1506
** next. Applications that use these interfaces must be prepared for any
1507
** or all of these interfaces to be NULL or for their behavior to change
1508
** from one release to the next. Applications must not attempt to access
1509
** any of these methods if the iVersion of the VFS is less than 3.
1510
*/
1511
typedef struct sqlite3_vfs sqlite3_vfs;
1512
typedef void (*sqlite3_syscall_ptr)(void);
1513
struct sqlite3_vfs {
1514
int iVersion; /* Structure version number (currently 3) */
1515
int szOsFile; /* Size of subclassed sqlite3_file */
1516
int mxPathname; /* Maximum file pathname length */
1517
sqlite3_vfs *pNext; /* Next registered VFS */
1518
const char *zName; /* Name of this virtual file system */
1519
void *pAppData; /* Pointer to application-specific data */
1520
int (*xOpen)(sqlite3_vfs*, sqlite3_filename zName, sqlite3_file*,
1521
int flags, int *pOutFlags);
1522
int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
1523
int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);
1524
int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
1525
void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
1526
void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
1527
void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void);
1528
void (*xDlClose)(sqlite3_vfs*, void*);
1529
int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
1530
int (*xSleep)(sqlite3_vfs*, int microseconds);
1531
int (*xCurrentTime)(sqlite3_vfs*, double*);
1532
int (*xGetLastError)(sqlite3_vfs*, int, char *);
1533
/*
1534
** The methods above are in version 1 of the sqlite_vfs object
1535
** definition. Those that follow are added in version 2 or later
1536
*/
1537
int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
1538
/*
1539
** The methods above are in versions 1 and 2 of the sqlite_vfs object.
1540
** Those below are for version 3 and greater.
1541
*/
1542
int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr);
1543
sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName);
1544
const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName);
1545
/*
1546
** The methods above are in versions 1 through 3 of the sqlite_vfs object.
1547
** New fields may be appended in future versions. The iVersion
1548
** value will increment whenever this happens.
1549
*/
1550
};
1551
1552
/*
1553
** CAPI3REF: Flags for the xAccess VFS method
1554
**
1555
** These integer constants can be used as the third parameter to
1556
** the xAccess method of an [sqlite3_vfs] object. They determine
1557
** what kind of permissions the xAccess method is looking for.
1558
** With SQLITE_ACCESS_EXISTS, the xAccess method
1559
** simply checks whether the file exists.
1560
** With SQLITE_ACCESS_READWRITE, the xAccess method
1561
** checks whether the named directory is both readable and writable
1562
** (in other words, if files can be added, removed, and renamed within
1563
** the directory).
1564
** The SQLITE_ACCESS_READWRITE constant is currently used only by the
1565
** [temp_store_directory pragma], though this could change in a future
1566
** release of SQLite.
1567
** With SQLITE_ACCESS_READ, the xAccess method
1568
** checks whether the file is readable. The SQLITE_ACCESS_READ constant is
1569
** currently unused, though it might be used in a future release of
1570
** SQLite.
1571
*/
1572
#define SQLITE_ACCESS_EXISTS 0
1573
#define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */
1574
#define SQLITE_ACCESS_READ 2 /* Unused */
1575
1576
/*
1577
** CAPI3REF: Flags for the xShmLock VFS method
1578
**
1579
** These integer constants define the various locking operations
1580
** allowed by the xShmLock method of [sqlite3_io_methods]. The
1581
** following are the only legal combinations of flags to the
1582
** xShmLock method:
1583
**
1584
** <ul>
1585
** <li> SQLITE_SHM_LOCK | SQLITE_SHM_SHARED
1586
** <li> SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE
1587
** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED
1588
** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE
1589
** </ul>
1590
**
1591
** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as
1592
** was given on the corresponding lock.
1593
**
1594
** The xShmLock method can transition between unlocked and SHARED or
1595
** between unlocked and EXCLUSIVE. It cannot transition between SHARED
1596
** and EXCLUSIVE.
1597
*/
1598
#define SQLITE_SHM_UNLOCK 1
1599
#define SQLITE_SHM_LOCK 2
1600
#define SQLITE_SHM_SHARED 4
1601
#define SQLITE_SHM_EXCLUSIVE 8
1602
1603
/*
1604
** CAPI3REF: Maximum xShmLock index
1605
**
1606
** The xShmLock method on [sqlite3_io_methods] may use values
1607
** between 0 and this upper bound as its "offset" argument.
1608
** The SQLite core will never attempt to acquire or release a
1609
** lock outside of this range
1610
*/
1611
#define SQLITE_SHM_NLOCK 8
1612
1613
1614
/*
1615
** CAPI3REF: Initialize The SQLite Library
1616
**
1617
** ^The sqlite3_initialize() routine initializes the
1618
** SQLite library. ^The sqlite3_shutdown() routine
1619
** deallocates any resources that were allocated by sqlite3_initialize().
1620
** These routines are designed to aid in process initialization and
1621
** shutdown on embedded systems. Workstation applications using
1622
** SQLite normally do not need to invoke either of these routines.
1623
**
1624
** A call to sqlite3_initialize() is an "effective" call if it is
1625
** the first time sqlite3_initialize() is invoked during the lifetime of
1626
** the process, or if it is the first time sqlite3_initialize() is invoked
1627
** following a call to sqlite3_shutdown(). ^(Only an effective call
1628
** of sqlite3_initialize() does any initialization. All other calls
1629
** are harmless no-ops.)^
1630
**
1631
** A call to sqlite3_shutdown() is an "effective" call if it is the first
1632
** call to sqlite3_shutdown() since the last sqlite3_initialize(). ^(Only
1633
** an effective call to sqlite3_shutdown() does any deinitialization.
1634
** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^
1635
**
1636
** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown()
1637
** is not. The sqlite3_shutdown() interface must only be called from a
1638
** single thread. All open [database connections] must be closed and all
1639
** other SQLite resources must be deallocated prior to invoking
1640
** sqlite3_shutdown().
1641
**
1642
** Among other things, ^sqlite3_initialize() will invoke
1643
** sqlite3_os_init(). Similarly, ^sqlite3_shutdown()
1644
** will invoke sqlite3_os_end().
1645
**
1646
** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success.
1647
** ^If for some reason, sqlite3_initialize() is unable to initialize
1648
** the library (perhaps it is unable to allocate a needed resource such
1649
** as a mutex) it returns an [error code] other than [SQLITE_OK].
1650
**
1651
** ^The sqlite3_initialize() routine is called internally by many other
1652
** SQLite interfaces so that an application usually does not need to
1653
** invoke sqlite3_initialize() directly. For example, [sqlite3_open()]
1654
** calls sqlite3_initialize() so the SQLite library will be automatically
1655
** initialized when [sqlite3_open()] is called if it has not been initialized
1656
** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
1657
** compile-time option, then the automatic calls to sqlite3_initialize()
1658
** are omitted and the application must call sqlite3_initialize() directly
1659
** prior to using any other SQLite interface. For maximum portability,
1660
** it is recommended that applications always invoke sqlite3_initialize()
1661
** directly prior to using any other SQLite interface. Future releases
1662
** of SQLite may require this. In other words, the behavior exhibited
1663
** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the
1664
** default behavior in some future release of SQLite.
1665
**
1666
** The sqlite3_os_init() routine does operating-system specific
1667
** initialization of the SQLite library. The sqlite3_os_end()
1668
** routine undoes the effect of sqlite3_os_init(). Typical tasks
1669
** performed by these routines include allocation or deallocation
1670
** of static resources, initialization of global variables,
1671
** setting up a default [sqlite3_vfs] module, or setting up
1672
** a default configuration using [sqlite3_config()].
1673
**
1674
** The application should never invoke either sqlite3_os_init()
1675
** or sqlite3_os_end() directly. The application should only invoke
1676
** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init()
1677
** interface is called automatically by sqlite3_initialize() and
1678
** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate
1679
** implementations for sqlite3_os_init() and sqlite3_os_end()
1680
** are built into SQLite when it is compiled for Unix, Windows, or OS/2.
1681
** When [custom builds | built for other platforms]
1682
** (using the [SQLITE_OS_OTHER=1] compile-time
1683
** option) the application must supply a suitable implementation for
1684
** sqlite3_os_init() and sqlite3_os_end(). An application-supplied
1685
** implementation of sqlite3_os_init() or sqlite3_os_end()
1686
** must return [SQLITE_OK] on success and some other [error code] upon
1687
** failure.
1688
*/
1689
SQLITE_API int sqlite3_initialize(void);
1690
SQLITE_API int sqlite3_shutdown(void);
1691
SQLITE_API int sqlite3_os_init(void);
1692
SQLITE_API int sqlite3_os_end(void);
1693
1694
/*
1695
** CAPI3REF: Configuring The SQLite Library
1696
**
1697
** The sqlite3_config() interface is used to make global configuration
1698
** changes to SQLite in order to tune SQLite to the specific needs of
1699
** the application. The default configuration is recommended for most
1700
** applications and so this routine is usually not necessary. It is
1701
** provided to support rare applications with unusual needs.
1702
**
1703
** <b>The sqlite3_config() interface is not threadsafe. The application
1704
** must ensure that no other SQLite interfaces are invoked by other
1705
** threads while sqlite3_config() is running.</b>
1706
**
1707
** The first argument to sqlite3_config() is an integer
1708
** [configuration option] that determines
1709
** what property of SQLite is to be configured. Subsequent arguments
1710
** vary depending on the [configuration option]
1711
** in the first argument.
1712
**
1713
** For most configuration options, the sqlite3_config() interface
1714
** may only be invoked prior to library initialization using
1715
** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].
1716
** The exceptional configuration options that may be invoked at any time
1717
** are called "anytime configuration options".
1718
** ^If sqlite3_config() is called after [sqlite3_initialize()] and before
1719
** [sqlite3_shutdown()] with a first argument that is not an anytime
1720
** configuration option, then the sqlite3_config() call will
1721
** return SQLITE_MISUSE.
1722
** Note, however, that ^sqlite3_config() can be called as part of the
1723
** implementation of an application-defined [sqlite3_os_init()].
1724
**
1725
** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
1726
** ^If the option is unknown or SQLite is unable to set the option
1727
** then this routine returns a non-zero [error code].
1728
*/
1729
SQLITE_API int sqlite3_config(int, ...);
1730
1731
/*
1732
** CAPI3REF: Configure database connections
1733
** METHOD: sqlite3
1734
**
1735
** The sqlite3_db_config() interface is used to make configuration
1736
** changes to a [database connection]. The interface is similar to
1737
** [sqlite3_config()] except that the changes apply to a single
1738
** [database connection] (specified in the first argument).
1739
**
1740
** The second argument to sqlite3_db_config(D,V,...) is the
1741
** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code
1742
** that indicates what aspect of the [database connection] is being configured.
1743
** Subsequent arguments vary depending on the configuration verb.
1744
**
1745
** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
1746
** the call is considered successful.
1747
*/
1748
SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
1749
1750
/*
1751
** CAPI3REF: Memory Allocation Routines
1752
**
1753
** An instance of this object defines the interface between SQLite
1754
** and low-level memory allocation routines.
1755
**
1756
** This object is used in only one place in the SQLite interface.
1757
** A pointer to an instance of this object is the argument to
1758
** [sqlite3_config()] when the configuration option is
1759
** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC].
1760
** By creating an instance of this object
1761
** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC])
1762
** during configuration, an application can specify an alternative
1763
** memory allocation subsystem for SQLite to use for all of its
1764
** dynamic memory needs.
1765
**
1766
** Note that SQLite comes with several [built-in memory allocators]
1767
** that are perfectly adequate for the overwhelming majority of applications
1768
** and that this object is only useful to a tiny minority of applications
1769
** with specialized memory allocation requirements. This object is
1770
** also used during testing of SQLite in order to specify an alternative
1771
** memory allocator that simulates memory out-of-memory conditions in
1772
** order to verify that SQLite recovers gracefully from such
1773
** conditions.
1774
**
1775
** The xMalloc, xRealloc, and xFree methods must work like the
1776
** malloc(), realloc() and free() functions from the standard C library.
1777
** ^SQLite guarantees that the second argument to
1778
** xRealloc is always a value returned by a prior call to xRoundup.
1779
**
1780
** xSize should return the allocated size of a memory allocation
1781
** previously obtained from xMalloc or xRealloc. The allocated size
1782
** is always at least as big as the requested size but may be larger.
1783
**
1784
** The xRoundup method returns what would be the allocated size of
1785
** a memory allocation given a particular requested size. Most memory
1786
** allocators round up memory allocations at least to the next multiple
1787
** of 8. Some allocators round up to a larger multiple or to a power of 2.
1788
** Every memory allocation request coming in through [sqlite3_malloc()]
1789
** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,
1790
** that causes the corresponding memory allocation to fail.
1791
**
1792
** The xInit method initializes the memory allocator. For example,
1793
** it might allocate any required mutexes or initialize internal data
1794
** structures. The xShutdown method is invoked (indirectly) by
1795
** [sqlite3_shutdown()] and should deallocate any resources acquired
1796
** by xInit. The pAppData pointer is used as the only parameter to
1797
** xInit and xShutdown.
1798
**
1799
** SQLite holds the [SQLITE_MUTEX_STATIC_MAIN] mutex when it invokes
1800
** the xInit method, so the xInit method need not be threadsafe. The
1801
** xShutdown method is only called from [sqlite3_shutdown()] so it does
1802
** not need to be threadsafe either. For all other methods, SQLite
1803
** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the
1804
** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which
1805
** it is by default) and so the methods are automatically serialized.
1806
** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other
1807
** methods must be threadsafe or else make their own arrangements for
1808
** serialization.
1809
**
1810
** SQLite will never invoke xInit() more than once without an intervening
1811
** call to xShutdown().
1812
*/
1813
typedef struct sqlite3_mem_methods sqlite3_mem_methods;
1814
struct sqlite3_mem_methods {
1815
void *(*xMalloc)(int); /* Memory allocation function */
1816
void (*xFree)(void*); /* Free a prior allocation */
1817
void *(*xRealloc)(void*,int); /* Resize an allocation */
1818
int (*xSize)(void*); /* Return the size of an allocation */
1819
int (*xRoundup)(int); /* Round up request size to allocation size */
1820
int (*xInit)(void*); /* Initialize the memory allocator */
1821
void (*xShutdown)(void*); /* Deinitialize the memory allocator */
1822
void *pAppData; /* Argument to xInit() and xShutdown() */
1823
};
1824
1825
/*
1826
** CAPI3REF: Configuration Options
1827
** KEYWORDS: {configuration option}
1828
**
1829
** These constants are the available integer configuration options that
1830
** can be passed as the first argument to the [sqlite3_config()] interface.
1831
**
1832
** Most of the configuration options for sqlite3_config()
1833
** will only work if invoked prior to [sqlite3_initialize()] or after
1834
** [sqlite3_shutdown()]. The few exceptions to this rule are called
1835
** "anytime configuration options".
1836
** ^Calling [sqlite3_config()] with a first argument that is not an
1837
** anytime configuration option in between calls to [sqlite3_initialize()] and
1838
** [sqlite3_shutdown()] is a no-op that returns SQLITE_MISUSE.
1839
**
1840
** The set of anytime configuration options can change (by insertions
1841
** and/or deletions) from one release of SQLite to the next.
1842
** As of SQLite version 3.42.0, the complete set of anytime configuration
1843
** options is:
1844
** <ul>
1845
** <li> SQLITE_CONFIG_LOG
1846
** <li> SQLITE_CONFIG_PCACHE_HDRSZ
1847
** </ul>
1848
**
1849
** New configuration options may be added in future releases of SQLite.
1850
** Existing configuration options might be discontinued. Applications
1851
** should check the return code from [sqlite3_config()] to make sure that
1852
** the call worked. The [sqlite3_config()] interface will return a
1853
** non-zero [error code] if a discontinued or unsupported configuration option
1854
** is invoked.
1855
**
1856
** <dl>
1857
** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
1858
** <dd>There are no arguments to this option. ^This option sets the
1859
** [threading mode] to Single-thread. In other words, it disables
1860
** all mutexing and puts SQLite into a mode where it can only be used
1861
** by a single thread. ^If SQLite is compiled with
1862
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1863
** it is not possible to change the [threading mode] from its default
1864
** value of Single-thread and so [sqlite3_config()] will return
1865
** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
1866
** configuration option.</dd>
1867
**
1868
** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt>
1869
** <dd>There are no arguments to this option. ^This option sets the
1870
** [threading mode] to Multi-thread. In other words, it disables
1871
** mutexing on [database connection] and [prepared statement] objects.
1872
** The application is responsible for serializing access to
1873
** [database connections] and [prepared statements]. But other mutexes
1874
** are enabled so that SQLite will be safe to use in a multi-threaded
1875
** environment as long as no two threads attempt to use the same
1876
** [database connection] at the same time. ^If SQLite is compiled with
1877
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1878
** it is not possible to set the Multi-thread [threading mode] and
1879
** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1880
** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
1881
**
1882
** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt>
1883
** <dd>There are no arguments to this option. ^This option sets the
1884
** [threading mode] to Serialized. In other words, this option enables
1885
** all mutexes including the recursive
1886
** mutexes on [database connection] and [prepared statement] objects.
1887
** In this mode (which is the default when SQLite is compiled with
1888
** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access
1889
** to [database connections] and [prepared statements] so that the
1890
** application is free to use the same [database connection] or the
1891
** same [prepared statement] in different threads at the same time.
1892
** ^If SQLite is compiled with
1893
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1894
** it is not possible to set the Serialized [threading mode] and
1895
** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1896
** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
1897
**
1898
** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
1899
** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is
1900
** a pointer to an instance of the [sqlite3_mem_methods] structure.
1901
** The argument specifies
1902
** alternative low-level memory allocation routines to be used in place of
1903
** the memory allocation routines built into SQLite.)^ ^SQLite makes
1904
** its own private copy of the content of the [sqlite3_mem_methods] structure
1905
** before the [sqlite3_config()] call returns.</dd>
1906
**
1907
** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
1908
** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
1909
** is a pointer to an instance of the [sqlite3_mem_methods] structure.
1910
** The [sqlite3_mem_methods]
1911
** structure is filled with the currently defined memory allocation routines.)^
1912
** This option can be used to overload the default memory allocation
1913
** routines with a wrapper that simulates memory allocation failure or
1914
** tracks memory usage, for example. </dd>
1915
**
1916
** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt>
1917
** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes a single argument of
1918
** type int, interpreted as a boolean, which if true provides a hint to
1919
** SQLite that it should avoid large memory allocations if possible.
1920
** SQLite will run faster if it is free to make large memory allocations,
1921
** but some applications might prefer to run slower in exchange for
1922
** guarantees about memory fragmentation that are possible if large
1923
** allocations are avoided. This hint is normally off.
1924
** </dd>
1925
**
1926
** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1927
** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes a single argument of type int,
1928
** interpreted as a boolean, which enables or disables the collection of
1929
** memory allocation statistics. ^(When memory allocation statistics are
1930
** disabled, the following SQLite interfaces become non-operational:
1931
** <ul>
1932
** <li> [sqlite3_hard_heap_limit64()]
1933
** <li> [sqlite3_memory_used()]
1934
** <li> [sqlite3_memory_highwater()]
1935
** <li> [sqlite3_soft_heap_limit64()]
1936
** <li> [sqlite3_status64()]
1937
** </ul>)^
1938
** ^Memory allocation statistics are enabled by default unless SQLite is
1939
** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1940
** allocation statistics are disabled by default.
1941
** </dd>
1942
**
1943
** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
1944
** <dd> The SQLITE_CONFIG_SCRATCH option is no longer used.
1945
** </dd>
1946
**
1947
** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
1948
** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool
1949
** that SQLite can use for the database page cache with the default page
1950
** cache implementation.
1951
** This configuration option is a no-op if an application-defined page
1952
** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2].
1953
** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
1954
** 8-byte aligned memory (pMem), the size of each page cache line (sz),
1955
** and the number of cache lines (N).
1956
** The sz argument should be the size of the largest database page
1957
** (a power of two between 512 and 65536) plus some extra bytes for each
1958
** page header. ^The number of extra bytes needed by the page header
1959
** can be determined using [SQLITE_CONFIG_PCACHE_HDRSZ].
1960
** ^It is harmless, apart from the wasted memory,
1961
** for the sz parameter to be larger than necessary. The pMem
1962
** argument must be either a NULL pointer or a pointer to an 8-byte
1963
** aligned block of memory of at least sz*N bytes, otherwise
1964
** subsequent behavior is undefined.
1965
** ^When pMem is not NULL, SQLite will strive to use the memory provided
1966
** to satisfy page cache needs, falling back to [sqlite3_malloc()] if
1967
** a page cache line is larger than sz bytes or if all of the pMem buffer
1968
** is exhausted.
1969
** ^If pMem is NULL and N is non-zero, then each database connection
1970
** does an initial bulk allocation for page cache memory
1971
** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or
1972
** of -1024*N bytes if N is negative. ^If additional
1973
** page cache memory is needed beyond what is provided by the initial
1974
** allocation, then SQLite goes to [sqlite3_malloc()] separately for each
1975
** additional cache line. </dd>
1976
**
1977
** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
1978
** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
1979
** that SQLite will use for all of its dynamic memory allocation needs
1980
** beyond those provided for by [SQLITE_CONFIG_PAGECACHE].
1981
** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
1982
** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
1983
** [SQLITE_ERROR] if invoked otherwise.
1984
** ^There are three arguments to SQLITE_CONFIG_HEAP:
1985
** An 8-byte aligned pointer to the memory,
1986
** the number of bytes in the memory buffer, and the minimum allocation size.
1987
** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
1988
** to using its default memory allocator (the system malloc() implementation),
1989
** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
1990
** memory pointer is not NULL then the alternative memory
1991
** allocator is engaged to handle all of SQLites memory allocation needs.
1992
** The first pointer (the memory pointer) must be aligned to an 8-byte
1993
** boundary or subsequent behavior of SQLite will be undefined.
1994
** The minimum allocation size is capped at 2**12. Reasonable values
1995
** for the minimum allocation size are 2**5 through 2**8.</dd>
1996
**
1997
** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
1998
** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
1999
** pointer to an instance of the [sqlite3_mutex_methods] structure.
2000
** The argument specifies alternative low-level mutex routines to be used
2001
** in place of the mutex routines built into SQLite.)^ ^SQLite makes a copy of
2002
** the content of the [sqlite3_mutex_methods] structure before the call to
2003
** [sqlite3_config()] returns. ^If SQLite is compiled with
2004
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
2005
** the entire mutexing subsystem is omitted from the build and hence calls to
2006
** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
2007
** return [SQLITE_ERROR].</dd>
2008
**
2009
** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
2010
** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which
2011
** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The
2012
** [sqlite3_mutex_methods]
2013
** structure is filled with the currently defined mutex routines.)^
2014
** This option can be used to overload the default mutex allocation
2015
** routines with a wrapper used to track mutex usage for performance
2016
** profiling or testing, for example. ^If SQLite is compiled with
2017
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
2018
** the entire mutexing subsystem is omitted from the build and hence calls to
2019
** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
2020
** return [SQLITE_ERROR].</dd>
2021
**
2022
** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
2023
** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
2024
** the default size of [lookaside memory] on each [database connection].
2025
** The first argument is the
2026
** size of each lookaside buffer slot ("sz") and the second is the number of
2027
** slots allocated to each database connection ("cnt").)^
2028
** ^(SQLITE_CONFIG_LOOKASIDE sets the <i>default</i> lookaside size.
2029
** The [SQLITE_DBCONFIG_LOOKASIDE] option to [sqlite3_db_config()] can
2030
** be used to change the lookaside configuration on individual connections.)^
2031
** The [-DSQLITE_DEFAULT_LOOKASIDE] option can be used to change the
2032
** default lookaside configuration at compile-time.
2033
** </dd>
2034
**
2035
** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
2036
** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is
2037
** a pointer to an [sqlite3_pcache_methods2] object. This object specifies
2038
** the interface to a custom page cache implementation.)^
2039
** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
2040
**
2041
** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
2042
** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
2043
** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies off
2044
** the current page cache implementation into that object.)^ </dd>
2045
**
2046
** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
2047
** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
2048
** global [error log].
2049
** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
2050
** function with a call signature of void(*)(void*,int,const char*),
2051
** and a pointer to void. ^If the function pointer is not NULL, it is
2052
** invoked by [sqlite3_log()] to process each logging event. ^If the
2053
** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
2054
** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
2055
** passed through as the first parameter to the application-defined logger
2056
** function whenever that function is invoked. ^The second parameter to
2057
** the logger function is a copy of the first parameter to the corresponding
2058
** [sqlite3_log()] call and is intended to be a [result code] or an
2059
** [extended result code]. ^The third parameter passed to the logger is
2060
** a log message after formatting via [sqlite3_snprintf()].
2061
** The SQLite logging interface is not reentrant; the logger function
2062
** supplied by the application must not invoke any SQLite interface.
2063
** In a multi-threaded application, the application-defined logger
2064
** function must be threadsafe. </dd>
2065
**
2066
** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
2067
** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int.
2068
** If non-zero, then URI handling is globally enabled. If the parameter is zero,
2069
** then URI handling is globally disabled.)^ ^If URI handling is globally
2070
** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()],
2071
** [sqlite3_open16()] or
2072
** specified as part of [ATTACH] commands are interpreted as URIs, regardless
2073
** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
2074
** connection is opened. ^If it is globally disabled, filenames are
2075
** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
2076
** database connection is opened. ^(By default, URI handling is globally
2077
** disabled. The default value may be changed by compiling with the
2078
** [SQLITE_USE_URI] symbol defined.)^
2079
**
2080
** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
2081
** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer
2082
** argument which is interpreted as a boolean in order to enable or disable
2083
** the use of covering indices for full table scans in the query optimizer.
2084
** ^The default setting is determined
2085
** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
2086
** if that compile-time option is omitted.
2087
** The ability to disable the use of covering indices for full table scans
2088
** is because some incorrectly coded legacy applications might malfunction
2089
** when the optimization is enabled. Providing the ability to
2090
** disable the optimization allows the older, buggy application code to work
2091
** without change even with newer versions of SQLite.
2092
**
2093
** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]]
2094
** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE
2095
** <dd> These options are obsolete and should not be used by new code.
2096
** They are retained for backwards compatibility but are now no-ops.
2097
** </dd>
2098
**
2099
** [[SQLITE_CONFIG_SQLLOG]]
2100
** <dt>SQLITE_CONFIG_SQLLOG
2101
** <dd>This option is only available if sqlite is compiled with the
2102
** [SQLITE_ENABLE_SQLLOG] pre-processor macro defined. The first argument should
2103
** be a pointer to a function of type void(*)(void*,sqlite3*,const char*, int).
2104
** The second should be of type (void*). The callback is invoked by the library
2105
** in three separate circumstances, identified by the value passed as the
2106
** fourth parameter. If the fourth parameter is 0, then the database connection
2107
** passed as the second argument has just been opened. The third argument
2108
** points to a buffer containing the name of the main database file. If the
2109
** fourth parameter is 1, then the SQL statement that the third parameter
2110
** points to has just been executed. Or, if the fourth parameter is 2, then
2111
** the connection being passed as the second parameter is being closed. The
2112
** third parameter is passed NULL In this case. An example of using this
2113
** configuration option can be seen in the "test_sqllog.c" source file in
2114
** the canonical SQLite source tree.</dd>
2115
**
2116
** [[SQLITE_CONFIG_MMAP_SIZE]]
2117
** <dt>SQLITE_CONFIG_MMAP_SIZE
2118
** <dd>^SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values
2119
** that are the default mmap size limit (the default setting for
2120
** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
2121
** ^The default setting can be overridden by each database connection using
2122
** either the [PRAGMA mmap_size] command, or by using the
2123
** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size
2124
** will be silently truncated if necessary so that it does not exceed the
2125
** compile-time maximum mmap size set by the
2126
** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
2127
** ^If either argument to this option is negative, then that argument is
2128
** changed to its compile-time default.
2129
**
2130
** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
2131
** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
2132
** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
2133
** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro
2134
** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
2135
** that specifies the maximum size of the created heap.
2136
**
2137
** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
2138
** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
2139
** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
2140
** is a pointer to an integer and writes into that integer the number of extra
2141
** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
2142
** The amount of extra space required can change depending on the compiler,
2143
** target platform, and SQLite version.
2144
**
2145
** [[SQLITE_CONFIG_PMASZ]]
2146
** <dt>SQLITE_CONFIG_PMASZ
2147
** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which
2148
** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded
2149
** sorter to that integer. The default minimum PMA Size is set by the
2150
** [SQLITE_SORTER_PMASZ] compile-time option. New threads are launched
2151
** to help with sort operations when multithreaded sorting
2152
** is enabled (using the [PRAGMA threads] command) and the amount of content
2153
** to be sorted exceeds the page size times the minimum of the
2154
** [PRAGMA cache_size] setting and this value.
2155
**
2156
** [[SQLITE_CONFIG_STMTJRNL_SPILL]]
2157
** <dt>SQLITE_CONFIG_STMTJRNL_SPILL
2158
** <dd>^The SQLITE_CONFIG_STMTJRNL_SPILL option takes a single parameter which
2159
** becomes the [statement journal] spill-to-disk threshold.
2160
** [Statement journals] are held in memory until their size (in bytes)
2161
** exceeds this threshold, at which point they are written to disk.
2162
** Or if the threshold is -1, statement journals are always held
2163
** exclusively in memory.
2164
** Since many statement journals never become large, setting the spill
2165
** threshold to a value such as 64KiB can greatly reduce the amount of
2166
** I/O required to support statement rollback.
2167
** The default value for this setting is controlled by the
2168
** [SQLITE_STMTJRNL_SPILL] compile-time option.
2169
**
2170
** [[SQLITE_CONFIG_SORTERREF_SIZE]]
2171
** <dt>SQLITE_CONFIG_SORTERREF_SIZE
2172
** <dd>The SQLITE_CONFIG_SORTERREF_SIZE option accepts a single parameter
2173
** of type (int) - the new value of the sorter-reference size threshold.
2174
** Usually, when SQLite uses an external sort to order records according
2175
** to an ORDER BY clause, all fields required by the caller are present in the
2176
** sorted records. However, if SQLite determines based on the declared type
2177
** of a table column that its values are likely to be very large - larger
2178
** than the configured sorter-reference size threshold - then a reference
2179
** is stored in each sorted record and the required column values loaded
2180
** from the database as records are returned in sorted order. The default
2181
** value for this option is to never use this optimization. Specifying a
2182
** negative value for this option restores the default behavior.
2183
** This option is only available if SQLite is compiled with the
2184
** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option.
2185
**
2186
** [[SQLITE_CONFIG_MEMDB_MAXSIZE]]
2187
** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE
2188
** <dd>The SQLITE_CONFIG_MEMDB_MAXSIZE option accepts a single parameter
2189
** [sqlite3_int64] parameter which is the default maximum size for an in-memory
2190
** database created using [sqlite3_deserialize()]. This default maximum
2191
** size can be adjusted up or down for individual databases using the
2192
** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control]. If this
2193
** configuration setting is never used, then the default maximum is determined
2194
** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that
2195
** compile-time option is not set, then the default maximum is 1073741824.
2196
**
2197
** [[SQLITE_CONFIG_ROWID_IN_VIEW]]
2198
** <dt>SQLITE_CONFIG_ROWID_IN_VIEW
2199
** <dd>The SQLITE_CONFIG_ROWID_IN_VIEW option enables or disables the ability
2200
** for VIEWs to have a ROWID. The capability can only be enabled if SQLite is
2201
** compiled with -DSQLITE_ALLOW_ROWID_IN_VIEW, in which case the capability
2202
** defaults to on. This configuration option queries the current setting or
2203
** changes the setting to off or on. The argument is a pointer to an integer.
2204
** If that integer initially holds a value of 1, then the ability for VIEWs to
2205
** have ROWIDs is activated. If the integer initially holds zero, then the
2206
** ability is deactivated. Any other initial value for the integer leaves the
2207
** setting unchanged. After changes, if any, the integer is written with
2208
** a 1 or 0, if the ability for VIEWs to have ROWIDs is on or off. If SQLite
2209
** is compiled without -DSQLITE_ALLOW_ROWID_IN_VIEW (which is the usual and
2210
** recommended case) then the integer is always filled with zero, regardless
2211
** if its initial value.
2212
** </dl>
2213
*/
2214
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
2215
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
2216
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
2217
#define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
2218
#define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */
2219
#define SQLITE_CONFIG_SCRATCH 6 /* No longer used */
2220
#define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */
2221
#define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */
2222
#define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */
2223
#define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */
2224
#define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */
2225
/* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
2226
#define SQLITE_CONFIG_LOOKASIDE 13 /* int int */
2227
#define SQLITE_CONFIG_PCACHE 14 /* no-op */
2228
#define SQLITE_CONFIG_GETPCACHE 15 /* no-op */
2229
#define SQLITE_CONFIG_LOG 16 /* xFunc, void* */
2230
#define SQLITE_CONFIG_URI 17 /* int */
2231
#define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */
2232
#define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
2233
#define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
2234
#define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
2235
#define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
2236
#define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
2237
#define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
2238
#define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
2239
#define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */
2240
#define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */
2241
#define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */
2242
#define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */
2243
#define SQLITE_CONFIG_ROWID_IN_VIEW 30 /* int* */
2244
2245
/*
2246
** CAPI3REF: Database Connection Configuration Options
2247
**
2248
** These constants are the available integer configuration options that
2249
** can be passed as the second parameter to the [sqlite3_db_config()] interface.
2250
**
2251
** The [sqlite3_db_config()] interface is a var-args function. It takes a
2252
** variable number of parameters, though always at least two. The number of
2253
** parameters passed into sqlite3_db_config() depends on which of these
2254
** constants is given as the second parameter. This documentation page
2255
** refers to parameters beyond the second as "arguments". Thus, when this
2256
** page says "the N-th argument" it means "the N-th parameter past the
2257
** configuration option" or "the (N+2)-th parameter to sqlite3_db_config()".
2258
**
2259
** New configuration options may be added in future releases of SQLite.
2260
** Existing configuration options might be discontinued. Applications
2261
** should check the return code from [sqlite3_db_config()] to make sure that
2262
** the call worked. ^The [sqlite3_db_config()] interface will return a
2263
** non-zero [error code] if a discontinued or unsupported configuration option
2264
** is invoked.
2265
**
2266
** <dl>
2267
** [[SQLITE_DBCONFIG_LOOKASIDE]]
2268
** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
2269
** <dd> The SQLITE_DBCONFIG_LOOKASIDE option is used to adjust the
2270
** configuration of the [lookaside memory allocator] within a database
2271
** connection.
2272
** The arguments to the SQLITE_DBCONFIG_LOOKASIDE option are <i>not</i>
2273
** in the [DBCONFIG arguments|usual format].
2274
** The SQLITE_DBCONFIG_LOOKASIDE option takes three arguments, not two,
2275
** so that a call to [sqlite3_db_config()] that uses SQLITE_DBCONFIG_LOOKASIDE
2276
** should have a total of five parameters.
2277
** <ol>
2278
** <li><p>The first argument ("buf") is a
2279
** pointer to a memory buffer to use for lookaside memory.
2280
** The first argument may be NULL in which case SQLite will allocate the
2281
** lookaside buffer itself using [sqlite3_malloc()].
2282
** <li><P>The second argument ("sz") is the
2283
** size of each lookaside buffer slot. Lookaside is disabled if "sz"
2284
** is less than 8. The "sz" argument should be a multiple of 8 less than
2285
** 65536. If "sz" does not meet this constraint, it is reduced in size until
2286
** it does.
2287
** <li><p>The third argument ("cnt") is the number of slots.
2288
** Lookaside is disabled if "cnt"is less than 1.
2289
* The "cnt" value will be reduced, if necessary, so
2290
** that the product of "sz" and "cnt" does not exceed 2,147,418,112. The "cnt"
2291
** parameter is usually chosen so that the product of "sz" and "cnt" is less
2292
** than 1,000,000.
2293
** </ol>
2294
** <p>If the "buf" argument is not NULL, then it must
2295
** point to a memory buffer with a size that is greater than
2296
** or equal to the product of "sz" and "cnt".
2297
** The buffer must be aligned to an 8-byte boundary.
2298
** The lookaside memory
2299
** configuration for a database connection can only be changed when that
2300
** connection is not currently using lookaside memory, or in other words
2301
** when the value returned by [SQLITE_DBSTATUS_LOOKASIDE_USED] is zero.
2302
** Any attempt to change the lookaside memory configuration when lookaside
2303
** memory is in use leaves the configuration unchanged and returns
2304
** [SQLITE_BUSY].
2305
** If the "buf" argument is NULL and an attempt
2306
** to allocate memory based on "sz" and "cnt" fails, then
2307
** lookaside is silently disabled.
2308
** <p>
2309
** The [SQLITE_CONFIG_LOOKASIDE] configuration option can be used to set the
2310
** default lookaside configuration at initialization. The
2311
** [-DSQLITE_DEFAULT_LOOKASIDE] option can be used to set the default lookaside
2312
** configuration at compile-time. Typical values for lookaside are 1200 for
2313
** "sz" and 40 to 100 for "cnt".
2314
** </dd>
2315
**
2316
** [[SQLITE_DBCONFIG_ENABLE_FKEY]]
2317
** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
2318
** <dd> ^This option is used to enable or disable the enforcement of
2319
** [foreign key constraints]. This is the same setting that is
2320
** enabled or disabled by the [PRAGMA foreign_keys] statement.
2321
** The first argument is an integer which is 0 to disable FK enforcement,
2322
** positive to enable FK enforcement or negative to leave FK enforcement
2323
** unchanged. The second parameter is a pointer to an integer into which
2324
** is written 0 or 1 to indicate whether FK enforcement is off or on
2325
** following this call. The second parameter may be a NULL pointer, in
2326
** which case the FK enforcement setting is not reported back. </dd>
2327
**
2328
** [[SQLITE_DBCONFIG_ENABLE_TRIGGER]]
2329
** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>
2330
** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
2331
** There should be two additional arguments.
2332
** The first argument is an integer which is 0 to disable triggers,
2333
** positive to enable triggers or negative to leave the setting unchanged.
2334
** The second parameter is a pointer to an integer into which
2335
** is written 0 or 1 to indicate whether triggers are disabled or enabled
2336
** following this call. The second parameter may be a NULL pointer, in
2337
** which case the trigger setting is not reported back.
2338
**
2339
** <p>Originally this option disabled all triggers. ^(However, since
2340
** SQLite version 3.35.0, TEMP triggers are still allowed even if
2341
** this option is off. So, in other words, this option now only disables
2342
** triggers in the main database schema or in the schemas of [ATTACH]-ed
2343
** databases.)^ </dd>
2344
**
2345
** [[SQLITE_DBCONFIG_ENABLE_VIEW]]
2346
** <dt>SQLITE_DBCONFIG_ENABLE_VIEW</dt>
2347
** <dd> ^This option is used to enable or disable [CREATE VIEW | views].
2348
** There must be two additional arguments.
2349
** The first argument is an integer which is 0 to disable views,
2350
** positive to enable views or negative to leave the setting unchanged.
2351
** The second parameter is a pointer to an integer into which
2352
** is written 0 or 1 to indicate whether views are disabled or enabled
2353
** following this call. The second parameter may be a NULL pointer, in
2354
** which case the view setting is not reported back.
2355
**
2356
** <p>Originally this option disabled all views. ^(However, since
2357
** SQLite version 3.35.0, TEMP views are still allowed even if
2358
** this option is off. So, in other words, this option now only disables
2359
** views in the main database schema or in the schemas of ATTACH-ed
2360
** databases.)^ </dd>
2361
**
2362
** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
2363
** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
2364
** <dd> ^This option is used to enable or disable using the
2365
** [fts3_tokenizer()] function - part of the [FTS3] full-text search engine
2366
** extension - without using bound parameters as the parameters. Doing so
2367
** is disabled by default. There must be two additional arguments. The first
2368
** argument is an integer. If it is passed 0, then using fts3_tokenizer()
2369
** without bound parameters is disabled. If it is passed a positive value,
2370
** then calling fts3_tokenizer without bound parameters is enabled. If it
2371
** is passed a negative value, this setting is not modified - this can be
2372
** used to query for the current setting. The second parameter is a pointer
2373
** to an integer into which is written 0 or 1 to indicate the current value
2374
** of this setting (after it is modified, if applicable). The second
2375
** parameter may be a NULL pointer, in which case the value of the setting
2376
** is not reported back. Refer to [FTS3] documentation for further details.
2377
** </dd>
2378
**
2379
** [[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION]]
2380
** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
2381
** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
2382
** interface independently of the [load_extension()] SQL function.
2383
** The [sqlite3_enable_load_extension()] API enables or disables both the
2384
** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
2385
** There must be two additional arguments.
2386
** When the first argument to this interface is 1, then only the C-API is
2387
** enabled and the SQL function remains disabled. If the first argument to
2388
** this interface is 0, then both the C-API and the SQL function are disabled.
2389
** If the first argument is -1, then no changes are made to the state of either
2390
** the C-API or the SQL function.
2391
** The second parameter is a pointer to an integer into which
2392
** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
2393
** is disabled or enabled following this call. The second parameter may
2394
** be a NULL pointer, in which case the new setting is not reported back.
2395
** </dd>
2396
**
2397
** [[SQLITE_DBCONFIG_MAINDBNAME]] <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
2398
** <dd> ^This option is used to change the name of the "main" database
2399
** schema. This option does not follow the
2400
** [DBCONFIG arguments|usual SQLITE_DBCONFIG argument format].
2401
** This option takes exactly one additional argument so that the
2402
** [sqlite3_db_config()] call has a total of three parameters. The
2403
** extra argument must be a pointer to a constant UTF8 string which
2404
** will become the new schema name in place of "main". ^SQLite does
2405
** not make a copy of the new main schema name string, so the application
2406
** must ensure that the argument passed into SQLITE_DBCONFIG MAINDBNAME
2407
** is unchanged until after the database connection closes.
2408
** </dd>
2409
**
2410
** [[SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE]]
2411
** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>
2412
** <dd> Usually, when a database in [WAL mode] is closed or detached from a
2413
** database handle, SQLite checks if if there are other connections to the
2414
** same database, and if there are no other database connection (if the
2415
** connection being closed is the last open connection to the database),
2416
** then SQLite performs a [checkpoint] before closing the connection and
2417
** deletes the WAL file. The SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE option can
2418
** be used to override that behavior. The first argument passed to this
2419
** operation (the third parameter to [sqlite3_db_config()]) is an integer
2420
** which is positive to disable checkpoints-on-close, or zero (the default)
2421
** to enable them, and negative to leave the setting unchanged.
2422
** The second argument (the fourth parameter) is a pointer to an integer
2423
** into which is written 0 or 1 to indicate whether checkpoints-on-close
2424
** have been disabled - 0 if they are not disabled, 1 if they are.
2425
** </dd>
2426
**
2427
** [[SQLITE_DBCONFIG_ENABLE_QPSG]] <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
2428
** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates
2429
** the [query planner stability guarantee] (QPSG). When the QPSG is active,
2430
** a single SQL query statement will always use the same algorithm regardless
2431
** of values of [bound parameters].)^ The QPSG disables some query optimizations
2432
** that look at the values of bound parameters, which can make some queries
2433
** slower. But the QPSG has the advantage of more predictable behavior. With
2434
** the QPSG active, SQLite will always use the same query plan in the field as
2435
** was used during testing in the lab.
2436
** The first argument to this setting is an integer which is 0 to disable
2437
** the QPSG, positive to enable QPSG, or negative to leave the setting
2438
** unchanged. The second parameter is a pointer to an integer into which
2439
** is written 0 or 1 to indicate whether the QPSG is disabled or enabled
2440
** following this call.
2441
** </dd>
2442
**
2443
** [[SQLITE_DBCONFIG_TRIGGER_EQP]] <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt>
2444
** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not
2445
** include output for any operations performed by trigger programs. This
2446
** option is used to set or clear (the default) a flag that governs this
2447
** behavior. The first parameter passed to this operation is an integer -
2448
** positive to enable output for trigger programs, or zero to disable it,
2449
** or negative to leave the setting unchanged.
2450
** The second parameter is a pointer to an integer into which is written
2451
** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if
2452
** it is not disabled, 1 if it is.
2453
** </dd>
2454
**
2455
** [[SQLITE_DBCONFIG_RESET_DATABASE]] <dt>SQLITE_DBCONFIG_RESET_DATABASE</dt>
2456
** <dd> Set the SQLITE_DBCONFIG_RESET_DATABASE flag and then run
2457
** [VACUUM] in order to reset a database back to an empty database
2458
** with no schema and no content. The following process works even for
2459
** a badly corrupted database file:
2460
** <ol>
2461
** <li> If the database connection is newly opened, make sure it has read the
2462
** database schema by preparing then discarding some query against the
2463
** database, or calling sqlite3_table_column_metadata(), ignoring any
2464
** errors. This step is only necessary if the application desires to keep
2465
** the database in WAL mode after the reset if it was in WAL mode before
2466
** the reset.
2467
** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0);
2468
** <li> [sqlite3_exec](db, "[VACUUM]", 0, 0, 0);
2469
** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
2470
** </ol>
2471
** Because resetting a database is destructive and irreversible, the
2472
** process requires the use of this obscure API and multiple steps to
2473
** help ensure that it does not happen by accident. Because this
2474
** feature must be capable of resetting corrupt databases, and
2475
** shutting down virtual tables may require access to that corrupt
2476
** storage, the library must abandon any installed virtual tables
2477
** without calling their xDestroy() methods.
2478
**
2479
** [[SQLITE_DBCONFIG_DEFENSIVE]] <dt>SQLITE_DBCONFIG_DEFENSIVE</dt>
2480
** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the
2481
** "defensive" flag for a database connection. When the defensive
2482
** flag is enabled, language features that allow ordinary SQL to
2483
** deliberately corrupt the database file are disabled. The disabled
2484
** features include but are not limited to the following:
2485
** <ul>
2486
** <li> The [PRAGMA writable_schema=ON] statement.
2487
** <li> The [PRAGMA journal_mode=OFF] statement.
2488
** <li> The [PRAGMA schema_version=N] statement.
2489
** <li> Writes to the [sqlite_dbpage] virtual table.
2490
** <li> Direct writes to [shadow tables].
2491
** </ul>
2492
** </dd>
2493
**
2494
** [[SQLITE_DBCONFIG_WRITABLE_SCHEMA]] <dt>SQLITE_DBCONFIG_WRITABLE_SCHEMA</dt>
2495
** <dd>The SQLITE_DBCONFIG_WRITABLE_SCHEMA option activates or deactivates the
2496
** "writable_schema" flag. This has the same effect and is logically equivalent
2497
** to setting [PRAGMA writable_schema=ON] or [PRAGMA writable_schema=OFF].
2498
** The first argument to this setting is an integer which is 0 to disable
2499
** the writable_schema, positive to enable writable_schema, or negative to
2500
** leave the setting unchanged. The second parameter is a pointer to an
2501
** integer into which is written 0 or 1 to indicate whether the writable_schema
2502
** is enabled or disabled following this call.
2503
** </dd>
2504
**
2505
** [[SQLITE_DBCONFIG_LEGACY_ALTER_TABLE]]
2506
** <dt>SQLITE_DBCONFIG_LEGACY_ALTER_TABLE</dt>
2507
** <dd>The SQLITE_DBCONFIG_LEGACY_ALTER_TABLE option activates or deactivates
2508
** the legacy behavior of the [ALTER TABLE RENAME] command such that it
2509
** behaves as it did prior to [version 3.24.0] (2018-06-04). See the
2510
** "Compatibility Notice" on the [ALTER TABLE RENAME documentation] for
2511
** additional information. This feature can also be turned on and off
2512
** using the [PRAGMA legacy_alter_table] statement.
2513
** </dd>
2514
**
2515
** [[SQLITE_DBCONFIG_DQS_DML]]
2516
** <dt>SQLITE_DBCONFIG_DQS_DML</dt>
2517
** <dd>The SQLITE_DBCONFIG_DQS_DML option activates or deactivates
2518
** the legacy [double-quoted string literal] misfeature for DML statements
2519
** only, that is DELETE, INSERT, SELECT, and UPDATE statements. The
2520
** default value of this setting is determined by the [-DSQLITE_DQS]
2521
** compile-time option.
2522
** </dd>
2523
**
2524
** [[SQLITE_DBCONFIG_DQS_DDL]]
2525
** <dt>SQLITE_DBCONFIG_DQS_DDL</dt>
2526
** <dd>The SQLITE_DBCONFIG_DQS option activates or deactivates
2527
** the legacy [double-quoted string literal] misfeature for DDL statements,
2528
** such as CREATE TABLE and CREATE INDEX. The
2529
** default value of this setting is determined by the [-DSQLITE_DQS]
2530
** compile-time option.
2531
** </dd>
2532
**
2533
** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
2534
** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</dt>
2535
** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to
2536
** assume that database schemas are untainted by malicious content.
2537
** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
2538
** takes additional defensive steps to protect the application from harm
2539
** including:
2540
** <ul>
2541
** <li> Prohibit the use of SQL functions inside triggers, views,
2542
** CHECK constraints, DEFAULT clauses, expression indexes,
2543
** partial indexes, or generated columns
2544
** unless those functions are tagged with [SQLITE_INNOCUOUS].
2545
** <li> Prohibit the use of virtual tables inside of triggers or views
2546
** unless those virtual tables are tagged with [SQLITE_VTAB_INNOCUOUS].
2547
** </ul>
2548
** This setting defaults to "on" for legacy compatibility, however
2549
** all applications are advised to turn it off if possible. This setting
2550
** can also be controlled using the [PRAGMA trusted_schema] statement.
2551
** </dd>
2552
**
2553
** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
2554
** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</dt>
2555
** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
2556
** the legacy file format flag. When activated, this flag causes all newly
2557
** created database files to have a schema format version number (the 4-byte
2558
** integer found at offset 44 into the database header) of 1. This in turn
2559
** means that the resulting database file will be readable and writable by
2560
** any SQLite version back to 3.0.0 ([dateof:3.0.0]). Without this setting,
2561
** newly created databases are generally not understandable by SQLite versions
2562
** prior to 3.3.0 ([dateof:3.3.0]). As these words are written, there
2563
** is now scarcely any need to generate database files that are compatible
2564
** all the way back to version 3.0.0, and so this setting is of little
2565
** practical use, but is provided so that SQLite can continue to claim the
2566
** ability to generate new database files that are compatible with version
2567
** 3.0.0.
2568
** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on,
2569
** the [VACUUM] command will fail with an obscure error when attempting to
2570
** process a table with generated columns and a descending index. This is
2571
** not considered a bug since SQLite versions 3.3.0 and earlier do not support
2572
** either generated columns or descending indexes.
2573
** </dd>
2574
**
2575
** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]]
2576
** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt>
2577
** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in
2578
** [SQLITE_ENABLE_STMT_SCANSTATUS] builds. In this case, it sets or clears
2579
** a flag that enables collection of run-time performance statistics
2580
** used by [sqlite3_stmt_scanstatus_v2()] and the [nexec and ncycle]
2581
** columns of the [bytecode virtual table].
2582
** For statistics to be collected, the flag must be set on
2583
** the database handle both when the SQL statement is
2584
** [sqlite3_prepare|prepared] and when it is [sqlite3_step|stepped].
2585
** The flag is set (collection of statistics is enabled) by default.
2586
** <p>This option takes two arguments: an integer and a pointer to
2587
** an integer. The first argument is 1, 0, or -1 to enable, disable, or
2588
** leave unchanged the statement scanstatus option. If the second argument
2589
** is not NULL, then the value of the statement scanstatus setting after
2590
** processing the first argument is written into the integer that the second
2591
** argument points to.
2592
** </dd>
2593
**
2594
** [[SQLITE_DBCONFIG_REVERSE_SCANORDER]]
2595
** <dt>SQLITE_DBCONFIG_REVERSE_SCANORDER</dt>
2596
** <dd>The SQLITE_DBCONFIG_REVERSE_SCANORDER option changes the default order
2597
** in which tables and indexes are scanned so that the scans start at the end
2598
** and work toward the beginning rather than starting at the beginning and
2599
** working toward the end. Setting SQLITE_DBCONFIG_REVERSE_SCANORDER is the
2600
** same as setting [PRAGMA reverse_unordered_selects]. <p>This option takes
2601
** two arguments which are an integer and a pointer to an integer. The first
2602
** argument is 1, 0, or -1 to enable, disable, or leave unchanged the
2603
** reverse scan order flag, respectively. If the second argument is not NULL,
2604
** then 0 or 1 is written into the integer that the second argument points to
2605
** depending on if the reverse scan order flag is set after processing the
2606
** first argument.
2607
** </dd>
2608
**
2609
** [[SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE]]
2610
** <dt>SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE</dt>
2611
** <dd>The SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE option enables or disables
2612
** the ability of the [ATTACH DATABASE] SQL command to create a new database
2613
** file if the database filed named in the ATTACH command does not already
2614
** exist. This ability of ATTACH to create a new database is enabled by
2615
** default. Applications can disable or reenable the ability for ATTACH to
2616
** create new database files using this DBCONFIG option.<p>
2617
** This option takes two arguments which are an integer and a pointer
2618
** to an integer. The first argument is 1, 0, or -1 to enable, disable, or
2619
** leave unchanged the attach-create flag, respectively. If the second
2620
** argument is not NULL, then 0 or 1 is written into the integer that the
2621
** second argument points to depending on if the attach-create flag is set
2622
** after processing the first argument.
2623
** </dd>
2624
**
2625
** [[SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE]]
2626
** <dt>SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE</dt>
2627
** <dd>The SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE option enables or disables the
2628
** ability of the [ATTACH DATABASE] SQL command to open a database for writing.
2629
** This capability is enabled by default. Applications can disable or
2630
** reenable this capability using the current DBCONFIG option. If
2631
** this capability is disabled, the [ATTACH] command will still work,
2632
** but the database will be opened read-only. If this option is disabled,
2633
** then the ability to create a new database using [ATTACH] is also disabled,
2634
** regardless of the value of the [SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE]
2635
** option.<p>
2636
** This option takes two arguments which are an integer and a pointer
2637
** to an integer. The first argument is 1, 0, or -1 to enable, disable, or
2638
** leave unchanged the ability to ATTACH another database for writing,
2639
** respectively. If the second argument is not NULL, then 0 or 1 is written
2640
** into the integer to which the second argument points, depending on whether
2641
** the ability to ATTACH a read/write database is enabled or disabled
2642
** after processing the first argument.
2643
** </dd>
2644
**
2645
** [[SQLITE_DBCONFIG_ENABLE_COMMENTS]]
2646
** <dt>SQLITE_DBCONFIG_ENABLE_COMMENTS</dt>
2647
** <dd>The SQLITE_DBCONFIG_ENABLE_COMMENTS option enables or disables the
2648
** ability to include comments in SQL text. Comments are enabled by default.
2649
** An application can disable or reenable comments in SQL text using this
2650
** DBCONFIG option.<p>
2651
** This option takes two arguments which are an integer and a pointer
2652
** to an integer. The first argument is 1, 0, or -1 to enable, disable, or
2653
** leave unchanged the ability to use comments in SQL text,
2654
** respectively. If the second argument is not NULL, then 0 or 1 is written
2655
** into the integer that the second argument points to depending on if
2656
** comments are allowed in SQL text after processing the first argument.
2657
** </dd>
2658
**
2659
** [[SQLITE_DBCONFIG_FP_DIGITS]]
2660
** <dt>SQLITE_DBCONFIG_FP_DIGITS</dt>
2661
** <dd>The SQLITE_DBCONFIG_FP_DIGITS setting is a small integer that determines
2662
** the number of significant digits that SQLite will attempt to preserve when
2663
** converting floating point numbers (IEEE 754 "doubles") into text. The
2664
** default value 17, as of SQLite version 3.52.0. The value was 15 in all
2665
** prior versions.<p>
2666
** This option takes two arguments which are an integer and a pointer
2667
** to an integer. The first argument is a small integer, between 3 and 23, or
2668
** zero. The FP_DIGITS setting is changed to that small integer, or left
2669
** unaltered if the first argument is zero or out of range. The second argument
2670
** is a pointer to an integer. If the pointer is not NULL, then the value of
2671
** the FP_DIGITS setting, after possibly being modified by the first
2672
** arguments, is written into the integer to which the second argument points.
2673
** </dd>
2674
**
2675
** </dl>
2676
**
2677
** [[DBCONFIG arguments]] <h3>Arguments To SQLITE_DBCONFIG Options</h3>
2678
**
2679
** <p>Most of the SQLITE_DBCONFIG options take two arguments, so that the
2680
** overall call to [sqlite3_db_config()] has a total of four parameters.
2681
** The first argument (the third parameter to sqlite3_db_config()) is
2682
** an integer.
2683
** The second argument is a pointer to an integer. If the first argument is 1,
2684
** then the option becomes enabled. If the first integer argument is 0,
2685
** then the option is disabled.
2686
** If the first argument is -1, then the option setting
2687
** is unchanged. The second argument, the pointer to an integer, may be NULL.
2688
** If the second argument is not NULL, then a value of 0 or 1 is written into
2689
** the integer to which the second argument points, depending on whether the
2690
** setting is disabled or enabled after applying any changes specified by
2691
** the first argument.
2692
**
2693
** <p>While most SQLITE_DBCONFIG options use the argument format
2694
** described in the previous paragraph, the [SQLITE_DBCONFIG_MAINDBNAME],
2695
** [SQLITE_DBCONFIG_LOOKASIDE], and [SQLITE_DBCONFIG_FP_DIGITS] options
2696
** are different. See the documentation of those exceptional options for
2697
** details.
2698
*/
2699
#define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
2700
#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
2701
#define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
2702
#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
2703
#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
2704
#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
2705
#define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */
2706
#define SQLITE_DBCONFIG_ENABLE_QPSG 1007 /* int int* */
2707
#define SQLITE_DBCONFIG_TRIGGER_EQP 1008 /* int int* */
2708
#define SQLITE_DBCONFIG_RESET_DATABASE 1009 /* int int* */
2709
#define SQLITE_DBCONFIG_DEFENSIVE 1010 /* int int* */
2710
#define SQLITE_DBCONFIG_WRITABLE_SCHEMA 1011 /* int int* */
2711
#define SQLITE_DBCONFIG_LEGACY_ALTER_TABLE 1012 /* int int* */
2712
#define SQLITE_DBCONFIG_DQS_DML 1013 /* int int* */
2713
#define SQLITE_DBCONFIG_DQS_DDL 1014 /* int int* */
2714
#define SQLITE_DBCONFIG_ENABLE_VIEW 1015 /* int int* */
2715
#define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT 1016 /* int int* */
2716
#define SQLITE_DBCONFIG_TRUSTED_SCHEMA 1017 /* int int* */
2717
#define SQLITE_DBCONFIG_STMT_SCANSTATUS 1018 /* int int* */
2718
#define SQLITE_DBCONFIG_REVERSE_SCANORDER 1019 /* int int* */
2719
#define SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE 1020 /* int int* */
2720
#define SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE 1021 /* int int* */
2721
#define SQLITE_DBCONFIG_ENABLE_COMMENTS 1022 /* int int* */
2722
#define SQLITE_DBCONFIG_FP_DIGITS 1023 /* int int* */
2723
#define SQLITE_DBCONFIG_MAX 1023 /* Largest DBCONFIG */
2724
2725
/*
2726
** CAPI3REF: Enable Or Disable Extended Result Codes
2727
** METHOD: sqlite3
2728
**
2729
** ^The sqlite3_extended_result_codes() routine enables or disables the
2730
** [extended result codes] feature of SQLite. ^The extended result
2731
** codes are disabled by default for historical compatibility.
2732
*/
2733
SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
2734
2735
/*
2736
** CAPI3REF: Last Insert Rowid
2737
** METHOD: sqlite3
2738
**
2739
** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
2740
** has a unique 64-bit signed
2741
** integer key called the [ROWID | "rowid"]. ^The rowid is always available
2742
** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
2743
** names are not also used by explicitly declared columns. ^If
2744
** the table has a column of type [INTEGER PRIMARY KEY] then that column
2745
** is another alias for the rowid.
2746
**
2747
** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of
2748
** the most recent successful [INSERT] into a rowid table or [virtual table]
2749
** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not
2750
** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred
2751
** on the database connection D, then sqlite3_last_insert_rowid(D) returns
2752
** zero.
2753
**
2754
** As well as being set automatically as rows are inserted into database
2755
** tables, the value returned by this function may be set explicitly by
2756
** [sqlite3_set_last_insert_rowid()]
2757
**
2758
** Some virtual table implementations may INSERT rows into rowid tables as
2759
** part of committing a transaction (e.g. to flush data accumulated in memory
2760
** to disk). In this case subsequent calls to this function return the rowid
2761
** associated with these internal INSERT operations, which leads to
2762
** unintuitive results. Virtual table implementations that do write to rowid
2763
** tables in this way can avoid this problem by restoring the original
2764
** rowid value using [sqlite3_set_last_insert_rowid()] before returning
2765
** control to the user.
2766
**
2767
** ^(If an [INSERT] occurs within a trigger then this routine will
2768
** return the [rowid] of the inserted row as long as the trigger is
2769
** running. Once the trigger program ends, the value returned
2770
** by this routine reverts to what it was before the trigger was fired.)^
2771
**
2772
** ^An [INSERT] that fails due to a constraint violation is not a
2773
** successful [INSERT] and does not change the value returned by this
2774
** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
2775
** and INSERT OR ABORT make no changes to the return value of this
2776
** routine when their insertion fails. ^(When INSERT OR REPLACE
2777
** encounters a constraint violation, it does not fail. The
2778
** INSERT continues to completion after deleting rows that caused
2779
** the constraint problem so INSERT OR REPLACE will always change
2780
** the return value of this interface.)^
2781
**
2782
** ^For the purposes of this routine, an [INSERT] is considered to
2783
** be successful even if it is subsequently rolled back.
2784
**
2785
** This function is accessible to SQL statements via the
2786
** [last_insert_rowid() SQL function].
2787
**
2788
** If a separate thread performs a new [INSERT] on the same
2789
** database connection while the [sqlite3_last_insert_rowid()]
2790
** function is running and thus changes the last insert [rowid],
2791
** then the value returned by [sqlite3_last_insert_rowid()] is
2792
** unpredictable and might not equal either the old or the new
2793
** last insert [rowid].
2794
*/
2795
SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
2796
2797
/*
2798
** CAPI3REF: Set the Last Insert Rowid value.
2799
** METHOD: sqlite3
2800
**
2801
** The sqlite3_set_last_insert_rowid(D, R) method allows the application to
2802
** set the value returned by calling sqlite3_last_insert_rowid(D) to R
2803
** without inserting a row into the database.
2804
*/
2805
SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64);
2806
2807
/*
2808
** CAPI3REF: Count The Number Of Rows Modified
2809
** METHOD: sqlite3
2810
**
2811
** ^These functions return the number of rows modified, inserted or
2812
** deleted by the most recently completed INSERT, UPDATE or DELETE
2813
** statement on the database connection specified by the only parameter.
2814
** The two functions are identical except for the type of the return value
2815
** and that if the number of rows modified by the most recent INSERT, UPDATE,
2816
** or DELETE is greater than the maximum value supported by type "int", then
2817
** the return value of sqlite3_changes() is undefined. ^Executing any other
2818
** type of SQL statement does not modify the value returned by these functions.
2819
** For the purposes of this interface, a CREATE TABLE AS SELECT statement
2820
** does not count as an INSERT, UPDATE or DELETE statement and hence the rows
2821
** added to the new table by the CREATE TABLE AS SELECT statement are not
2822
** counted.
2823
**
2824
** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are
2825
** considered - auxiliary changes caused by [CREATE TRIGGER | triggers],
2826
** [foreign key actions] or [REPLACE] constraint resolution are not counted.
2827
**
2828
** Changes to a view that are intercepted by
2829
** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value
2830
** returned by sqlite3_changes() immediately after an INSERT, UPDATE or
2831
** DELETE statement run on a view is always zero. Only changes made to real
2832
** tables are counted.
2833
**
2834
** Things are more complicated if the sqlite3_changes() function is
2835
** executed while a trigger program is running. This may happen if the
2836
** program uses the [changes() SQL function], or if some other callback
2837
** function invokes sqlite3_changes() directly. Essentially:
2838
**
2839
** <ul>
2840
** <li> ^(Before entering a trigger program the value returned by
2841
** sqlite3_changes() function is saved. After the trigger program
2842
** has finished, the original value is restored.)^
2843
**
2844
** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE
2845
** statement sets the value returned by sqlite3_changes()
2846
** upon completion as normal. Of course, this value will not include
2847
** any changes performed by sub-triggers, as the sqlite3_changes()
2848
** value will be saved and restored after each sub-trigger has run.)^
2849
** </ul>
2850
**
2851
** ^This means that if the changes() SQL function (or similar) is used
2852
** by the first INSERT, UPDATE or DELETE statement within a trigger, it
2853
** returns the value as set when the calling statement began executing.
2854
** ^If it is used by the second or subsequent such statement within a trigger
2855
** program, the value returned reflects the number of rows modified by the
2856
** previous INSERT, UPDATE or DELETE statement within the same trigger.
2857
**
2858
** If a separate thread makes changes on the same database connection
2859
** while [sqlite3_changes()] is running then the value returned
2860
** is unpredictable and not meaningful.
2861
**
2862
** See also:
2863
** <ul>
2864
** <li> the [sqlite3_total_changes()] interface
2865
** <li> the [count_changes pragma]
2866
** <li> the [changes() SQL function]
2867
** <li> the [data_version pragma]
2868
** </ul>
2869
*/
2870
SQLITE_API int sqlite3_changes(sqlite3*);
2871
SQLITE_API sqlite3_int64 sqlite3_changes64(sqlite3*);
2872
2873
/*
2874
** CAPI3REF: Total Number Of Rows Modified
2875
** METHOD: sqlite3
2876
**
2877
** ^These functions return the total number of rows inserted, modified or
2878
** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
2879
** since the database connection was opened, including those executed as
2880
** part of trigger programs. The two functions are identical except for the
2881
** type of the return value and that if the number of rows modified by the
2882
** connection exceeds the maximum value supported by type "int", then
2883
** the return value of sqlite3_total_changes() is undefined. ^Executing
2884
** any other type of SQL statement does not affect the value returned by
2885
** sqlite3_total_changes().
2886
**
2887
** ^Changes made as part of [foreign key actions] are included in the
2888
** count, but those made as part of REPLACE constraint resolution are
2889
** not. ^Changes to a view that are intercepted by INSTEAD OF triggers
2890
** are not counted.
2891
**
2892
** The [sqlite3_total_changes(D)] interface only reports the number
2893
** of rows that changed due to SQL statement run against database
2894
** connection D. Any changes by other database connections are ignored.
2895
** To detect changes against a database file from other database
2896
** connections use the [PRAGMA data_version] command or the
2897
** [SQLITE_FCNTL_DATA_VERSION] [file control].
2898
**
2899
** If a separate thread makes changes on the same database connection
2900
** while [sqlite3_total_changes()] is running then the value
2901
** returned is unpredictable and not meaningful.
2902
**
2903
** See also:
2904
** <ul>
2905
** <li> the [sqlite3_changes()] interface
2906
** <li> the [count_changes pragma]
2907
** <li> the [changes() SQL function]
2908
** <li> the [data_version pragma]
2909
** <li> the [SQLITE_FCNTL_DATA_VERSION] [file control]
2910
** </ul>
2911
*/
2912
SQLITE_API int sqlite3_total_changes(sqlite3*);
2913
SQLITE_API sqlite3_int64 sqlite3_total_changes64(sqlite3*);
2914
2915
/*
2916
** CAPI3REF: Interrupt A Long-Running Query
2917
** METHOD: sqlite3
2918
**
2919
** ^This function causes any pending database operation to abort and
2920
** return at its earliest opportunity. This routine is typically
2921
** called in response to a user action such as pressing "Cancel"
2922
** or Ctrl-C where the user wants a long query operation to halt
2923
** immediately.
2924
**
2925
** ^It is safe to call this routine from a thread different from the
2926
** thread that is currently running the database operation. But it
2927
** is not safe to call this routine with a [database connection] that
2928
** is closed or might close before sqlite3_interrupt() returns.
2929
**
2930
** ^If an SQL operation is very nearly finished at the time when
2931
** sqlite3_interrupt() is called, then it might not have an opportunity
2932
** to be interrupted and might continue to completion.
2933
**
2934
** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT].
2935
** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE
2936
** that is inside an explicit transaction, then the entire transaction
2937
** will be rolled back automatically.
2938
**
2939
** ^The sqlite3_interrupt(D) call is in effect until all currently running
2940
** SQL statements on [database connection] D complete. ^Any new SQL statements
2941
** that are started after the sqlite3_interrupt() call and before the
2942
** running statement count reaches zero are interrupted as if they had been
2943
** running prior to the sqlite3_interrupt() call. ^New SQL statements
2944
** that are started after the running statement count reaches zero are
2945
** not effected by the sqlite3_interrupt().
2946
** ^A call to sqlite3_interrupt(D) that occurs when there are no running
2947
** SQL statements is a no-op and has no effect on SQL statements
2948
** that are started after the sqlite3_interrupt() call returns.
2949
**
2950
** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether
2951
** or not an interrupt is currently in effect for [database connection] D.
2952
** It returns 1 if an interrupt is currently in effect, or 0 otherwise.
2953
*/
2954
SQLITE_API void sqlite3_interrupt(sqlite3*);
2955
SQLITE_API int sqlite3_is_interrupted(sqlite3*);
2956
2957
/*
2958
** CAPI3REF: Determine If An SQL Statement Is Complete
2959
**
2960
** These routines are useful during command-line input to determine if the
2961
** currently entered text seems to form a complete SQL statement or
2962
** if additional input is needed before sending the text into
2963
** SQLite for parsing. ^The sqlite3_complete(X) and sqlite3_complete16(X)
2964
** routines return 1 if the input string X appears to be a complete SQL
2965
** statement. ^A statement is judged to be
2966
** complete if it ends with a semicolon token and is not a prefix of a
2967
** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within
2968
** string literals or quoted identifier names or comments are not
2969
** independent tokens (they are part of the token in which they are
2970
** embedded) and thus do not count as a statement terminator. ^Whitespace
2971
** and comments that follow the final semicolon are ignored.
2972
**
2973
** ^The sqlite3_complete(X) and sqlite3_complete16(X) routines return 0
2974
** if the statement is incomplete. ^If a memory allocation fails, then
2975
** SQLITE_NOMEM is returned.
2976
**
2977
** The [sqlite3_incomplete(X)] routine is similar to [sqlite3_complete(X)]
2978
** except that sqlite3_incomplete(X) returns 0 if the input X is complete
2979
** and non-zero if X is incomplete. The non-zero return from
2980
** sqlite3_incomplete(X) contains additional information about what is
2981
** needed to complete the input X. The sqlite3_incomplete(X) interface
2982
** is only available for UTF-8 text.
2983
**
2984
** ^None of these routines do a full parse the SQL statements and thus
2985
** will not detect syntactically incorrect SQL. They only determine if
2986
** input text has properly terminated comments, string literals, and
2987
** quoted identifiers, and if the statement ends with a semicolon.
2988
**
2989
** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior
2990
** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked
2991
** automatically by sqlite3_complete16(). If that initialization fails,
2992
** then the return value from sqlite3_complete16() will be non-zero
2993
** regardless of whether or not the input SQL is complete.)^
2994
**
2995
** The X input to [sqlite3_complete(X)] and [sqlite3_incomplete(X)]
2996
** must be a zero-terminated UTF-8 string.
2997
**
2998
** The input to [sqlite3_complete16()] must be a zero-terminated
2999
** UTF-16 string in native byte order.
3000
*/
3001
SQLITE_API int sqlite3_complete(const char *sql);
3002
SQLITE_API int sqlite3_complete16(const void *sql);
3003
SQLITE_API sqlite3_int64 sqlite3_incomplete(const char *sql);
3004
3005
/*
3006
** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
3007
** KEYWORDS: {busy-handler callback} {busy handler}
3008
** METHOD: sqlite3
3009
**
3010
** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
3011
** that might be invoked with argument P whenever
3012
** an attempt is made to access a database table associated with
3013
** [database connection] D when another thread
3014
** or process has the table locked.
3015
** The sqlite3_busy_handler() interface is used to implement
3016
** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout].
3017
**
3018
** ^If the busy callback is NULL, then [SQLITE_BUSY]
3019
** is returned immediately upon encountering the lock. ^If the busy callback
3020
** is not NULL, then the callback might be invoked with two arguments.
3021
**
3022
** ^The first argument to the busy handler is a copy of the void* pointer which
3023
** is the third argument to sqlite3_busy_handler(). ^The second argument to
3024
** the busy handler callback is the number of times that the busy handler has
3025
** been invoked previously for the same locking event. ^If the
3026
** busy callback returns 0, then no additional attempts are made to
3027
** access the database and [SQLITE_BUSY] is returned
3028
** to the application.
3029
** ^If the callback returns non-zero, then another attempt
3030
** is made to access the database and the cycle repeats.
3031
**
3032
** The presence of a busy handler does not guarantee that it will be invoked
3033
** when there is lock contention. ^If SQLite determines that invoking the busy
3034
** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
3035
** to the application instead of invoking the
3036
** busy handler.
3037
** Consider a scenario where one process is holding a read lock that
3038
** it is trying to promote to a reserved lock and
3039
** a second process is holding a reserved lock that it is trying
3040
** to promote to an exclusive lock. The first process cannot proceed
3041
** because it is blocked by the second and the second process cannot
3042
** proceed because it is blocked by the first. If both processes
3043
** invoke the busy handlers, neither will make any progress. Therefore,
3044
** SQLite returns [SQLITE_BUSY] for the first process, hoping that this
3045
** will induce the first process to release its read lock and allow
3046
** the second process to proceed.
3047
**
3048
** ^The default busy callback is NULL.
3049
**
3050
** ^(There can only be a single busy handler defined for each
3051
** [database connection]. Setting a new busy handler clears any
3052
** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()]
3053
** or evaluating [PRAGMA busy_timeout=N] will change the
3054
** busy handler and thus clear any previously set busy handler.
3055
**
3056
** The busy callback should not take any actions which modify the
3057
** database connection that invoked the busy handler. In other words,
3058
** the busy handler is not reentrant. Any such actions
3059
** result in undefined behavior.
3060
**
3061
** A busy handler must not close the database connection
3062
** or [prepared statement] that invoked the busy handler.
3063
*/
3064
SQLITE_API int sqlite3_busy_handler(sqlite3*,int(*)(void*,int),void*);
3065
3066
/*
3067
** CAPI3REF: Set A Busy Timeout
3068
** METHOD: sqlite3
3069
**
3070
** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
3071
** for a specified amount of time when a table is locked. ^The handler
3072
** will sleep multiple times until at least "ms" milliseconds of sleeping
3073
** have accumulated. ^After at least "ms" milliseconds of sleeping,
3074
** the handler returns 0 which causes [sqlite3_step()] to return
3075
** [SQLITE_BUSY].
3076
**
3077
** ^Calling this routine with an argument less than or equal to zero
3078
** turns off all busy handlers.
3079
**
3080
** ^(There can only be a single busy handler for a particular
3081
** [database connection] at any given moment. If another busy handler
3082
** was defined (using [sqlite3_busy_handler()]) prior to calling
3083
** this routine, that other busy handler is cleared.)^
3084
**
3085
** See also: [PRAGMA busy_timeout]
3086
*/
3087
SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
3088
3089
/*
3090
** CAPI3REF: Set the Setlk Timeout
3091
** METHOD: sqlite3
3092
**
3093
** This routine is only useful in SQLITE_ENABLE_SETLK_TIMEOUT builds. If
3094
** the VFS supports blocking locks, it sets the timeout in ms used by
3095
** eligible locks taken on wal mode databases by the specified database
3096
** handle. In non-SQLITE_ENABLE_SETLK_TIMEOUT builds, or if the VFS does
3097
** not support blocking locks, this function is a no-op.
3098
**
3099
** Passing 0 to this function disables blocking locks altogether. Passing
3100
** -1 to this function requests that the VFS blocks for a long time -
3101
** indefinitely if possible. The results of passing any other negative value
3102
** are undefined.
3103
**
3104
** Internally, each SQLite database handle stores two timeout values - the
3105
** busy-timeout (used for rollback mode databases, or if the VFS does not
3106
** support blocking locks) and the setlk-timeout (used for blocking locks
3107
** on wal-mode databases). The sqlite3_busy_timeout() method sets both
3108
** values, this function sets only the setlk-timeout value. Therefore,
3109
** to configure separate busy-timeout and setlk-timeout values for a single
3110
** database handle, call sqlite3_busy_timeout() followed by this function.
3111
**
3112
** Whenever the number of connections to a wal mode database falls from
3113
** 1 to 0, the last connection takes an exclusive lock on the database,
3114
** then checkpoints and deletes the wal file. While it is doing this, any
3115
** new connection that tries to read from the database fails with an
3116
** SQLITE_BUSY error. Or, if the SQLITE_SETLK_BLOCK_ON_CONNECT flag is
3117
** passed to this API, the new connection blocks until the exclusive lock
3118
** has been released.
3119
*/
3120
SQLITE_API int sqlite3_setlk_timeout(sqlite3*, int ms, int flags);
3121
3122
/*
3123
** CAPI3REF: Flags for sqlite3_setlk_timeout()
3124
*/
3125
#define SQLITE_SETLK_BLOCK_ON_CONNECT 0x01
3126
3127
/*
3128
** CAPI3REF: Convenience Routines For Running Queries
3129
** METHOD: sqlite3
3130
**
3131
** This is a legacy interface that is preserved for backwards compatibility.
3132
** Use of this interface is not recommended.
3133
**
3134
** Definition: A <b>result table</b> is a memory data structure created by the
3135
** [sqlite3_get_table()] interface. A result table records the
3136
** complete query results from one or more queries.
3137
**
3138
** The table conceptually has a number of rows and columns. But
3139
** these numbers are not part of the result table itself. These
3140
** numbers are obtained separately. Let N be the number of rows
3141
** and M be the number of columns.
3142
**
3143
** A result table is an array of pointers to zero-terminated UTF-8 strings.
3144
** There are (N+1)*M elements in the array. The first M pointers point
3145
** to zero-terminated strings that contain the names of the columns.
3146
** The remaining entries all point to query results. NULL values result
3147
** in NULL pointers. All other values are in their UTF-8 zero-terminated
3148
** string representation as returned by [sqlite3_column_text()].
3149
**
3150
** A result table might consist of one or more memory allocations.
3151
** It is not safe to pass a result table directly to [sqlite3_free()].
3152
** A result table should be deallocated using [sqlite3_free_table()].
3153
**
3154
** ^(As an example of the result table format, suppose a query result
3155
** is as follows:
3156
**
3157
** <blockquote><pre>
3158
** Name | Age
3159
** -----------------------
3160
** Alice | 43
3161
** Bob | 28
3162
** Cindy | 21
3163
** </pre></blockquote>
3164
**
3165
** There are two columns (M==2) and three rows (N==3). Thus the
3166
** result table has 8 entries. Suppose the result table is stored
3167
** in an array named azResult. Then azResult holds this content:
3168
**
3169
** <blockquote><pre>
3170
** azResult&#91;0] = "Name";
3171
** azResult&#91;1] = "Age";
3172
** azResult&#91;2] = "Alice";
3173
** azResult&#91;3] = "43";
3174
** azResult&#91;4] = "Bob";
3175
** azResult&#91;5] = "28";
3176
** azResult&#91;6] = "Cindy";
3177
** azResult&#91;7] = "21";
3178
** </pre></blockquote>)^
3179
**
3180
** ^The sqlite3_get_table() function evaluates one or more
3181
** semicolon-separated SQL statements in the zero-terminated UTF-8
3182
** string of its 2nd parameter and returns a result table to the
3183
** pointer given in its 3rd parameter.
3184
**
3185
** After the application has finished with the result from sqlite3_get_table(),
3186
** it must pass the result table pointer to sqlite3_free_table() in order to
3187
** release the memory that was malloced. Because of the way the
3188
** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
3189
** function must not try to call [sqlite3_free()] directly. Only
3190
** [sqlite3_free_table()] is able to release the memory properly and safely.
3191
**
3192
** The sqlite3_get_table() interface is implemented as a wrapper around
3193
** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access
3194
** to any internal data structures of SQLite. It uses only the public
3195
** interface defined here. As a consequence, errors that occur in the
3196
** wrapper layer outside of the internal [sqlite3_exec()] call are not
3197
** reflected in subsequent calls to [sqlite3_errcode()] or
3198
** [sqlite3_errmsg()].
3199
*/
3200
SQLITE_API int sqlite3_get_table(
3201
sqlite3 *db, /* An open database */
3202
const char *zSql, /* SQL to be evaluated */
3203
char ***pazResult, /* Results of the query */
3204
int *pnRow, /* Number of result rows written here */
3205
int *pnColumn, /* Number of result columns written here */
3206
char **pzErrmsg /* Error msg written here */
3207
);
3208
SQLITE_API void sqlite3_free_table(char **result);
3209
3210
/*
3211
** CAPI3REF: Formatted String Printing Functions
3212
**
3213
** These routines are work-alikes of the "printf()" family of functions
3214
** from the standard C library.
3215
** These routines understand most of the common formatting options from
3216
** the standard library printf()
3217
** plus some additional non-standard formats ([%q], [%Q], [%w], and [%z]).
3218
** See the [built-in printf()] documentation for details.
3219
**
3220
** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
3221
** results into memory obtained from [sqlite3_malloc64()].
3222
** The strings returned by these two routines should be
3223
** released by [sqlite3_free()]. ^Both routines return a
3224
** NULL pointer if [sqlite3_malloc64()] is unable to allocate enough
3225
** memory to hold the resulting string.
3226
**
3227
** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from
3228
** the standard C library. The result is written into the
3229
** buffer supplied as the second parameter whose size is given by
3230
** the first parameter. Note that the order of the
3231
** first two parameters is reversed from snprintf().)^ This is an
3232
** historical accident that cannot be fixed without breaking
3233
** backwards compatibility. ^(Note also that sqlite3_snprintf()
3234
** returns a pointer to its buffer instead of the number of
3235
** characters actually written into the buffer.)^ We admit that
3236
** the number of characters written would be a more useful return
3237
** value but we cannot change the implementation of sqlite3_snprintf()
3238
** now without breaking compatibility.
3239
**
3240
** ^As long as the buffer size is greater than zero, sqlite3_snprintf()
3241
** guarantees that the buffer is always zero-terminated. ^The first
3242
** parameter "n" is the total size of the buffer, including space for
3243
** the zero terminator. So the longest string that can be completely
3244
** written will be n-1 characters.
3245
**
3246
** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
3247
**
3248
** See also: [built-in printf()], [printf() SQL function]
3249
*/
3250
SQLITE_API char *sqlite3_mprintf(const char*,...);
3251
SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
3252
SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
3253
SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
3254
3255
/*
3256
** CAPI3REF: Memory Allocation Subsystem
3257
**
3258
** The SQLite core uses these three routines for all of its own
3259
** internal memory allocation needs. "Core" in the previous sentence
3260
** does not include operating-system specific [VFS] implementation. The
3261
** Windows VFS uses native malloc() and free() for some operations.
3262
**
3263
** ^The sqlite3_malloc() routine returns a pointer to a block
3264
** of memory at least N bytes in length, where N is the parameter.
3265
** ^If sqlite3_malloc() is unable to obtain sufficient free
3266
** memory, it returns a NULL pointer. ^If the parameter N to
3267
** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
3268
** a NULL pointer.
3269
**
3270
** ^The sqlite3_malloc64(N) routine works just like
3271
** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead
3272
** of a signed 32-bit integer.
3273
**
3274
** ^Calling sqlite3_free() with a pointer previously returned
3275
** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
3276
** that it might be reused. ^The sqlite3_free() routine is
3277
** a no-op if it is called with a NULL pointer. Passing a NULL pointer
3278
** to sqlite3_free() is harmless. After being freed, memory
3279
** should neither be read nor written. Even reading previously freed
3280
** memory might result in a segmentation fault or other severe error.
3281
** Memory corruption, a segmentation fault, or other severe error
3282
** might result if sqlite3_free() is called with a non-NULL pointer that
3283
** was not obtained from sqlite3_malloc() or sqlite3_realloc().
3284
**
3285
** ^The sqlite3_realloc(X,N) interface attempts to resize a
3286
** prior memory allocation X to be at least N bytes.
3287
** ^If the X parameter to sqlite3_realloc(X,N)
3288
** is a NULL pointer then its behavior is identical to calling
3289
** sqlite3_malloc(N).
3290
** ^If the N parameter to sqlite3_realloc(X,N) is zero or
3291
** negative then the behavior is exactly the same as calling
3292
** sqlite3_free(X).
3293
** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation
3294
** of at least N bytes in size or NULL if insufficient memory is available.
3295
** ^If M is the size of the prior allocation, then min(N,M) bytes of the
3296
** prior allocation are copied into the beginning of the buffer returned
3297
** by sqlite3_realloc(X,N) and the prior allocation is freed.
3298
** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the
3299
** prior allocation is not freed.
3300
**
3301
** ^The sqlite3_realloc64(X,N) interface works the same as
3302
** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead
3303
** of a 32-bit signed integer.
3304
**
3305
** ^If X is a memory allocation previously obtained from sqlite3_malloc(),
3306
** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then
3307
** sqlite3_msize(X) returns the size of that memory allocation in bytes.
3308
** ^The value returned by sqlite3_msize(X) might be larger than the number
3309
** of bytes requested when X was allocated. ^If X is a NULL pointer then
3310
** sqlite3_msize(X) returns zero. If X points to something that is not
3311
** the beginning of memory allocation, or if it points to a formerly
3312
** valid memory allocation that has now been freed, then the behavior
3313
** of sqlite3_msize(X) is undefined and possibly harmful.
3314
**
3315
** ^The memory returned by sqlite3_malloc(), sqlite3_realloc(),
3316
** sqlite3_malloc64(), and sqlite3_realloc64()
3317
** is always aligned to at least an 8 byte boundary, or to a
3318
** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
3319
** option is used.
3320
**
3321
** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
3322
** must be either NULL or else pointers obtained from a prior
3323
** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
3324
** not yet been released.
3325
**
3326
** The application must not read or write any part of
3327
** a block of memory after it has been released using
3328
** [sqlite3_free()] or [sqlite3_realloc()].
3329
*/
3330
SQLITE_API void *sqlite3_malloc(int);
3331
SQLITE_API void *sqlite3_malloc64(sqlite3_uint64);
3332
SQLITE_API void *sqlite3_realloc(void*, int);
3333
SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64);
3334
SQLITE_API void sqlite3_free(void*);
3335
SQLITE_API sqlite3_uint64 sqlite3_msize(void*);
3336
3337
/*
3338
** CAPI3REF: Memory Allocator Statistics
3339
**
3340
** SQLite provides these two interfaces for reporting on the status
3341
** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()]
3342
** routines, which form the built-in memory allocation subsystem.
3343
**
3344
** ^The [sqlite3_memory_used()] routine returns the number of bytes
3345
** of memory currently outstanding (malloced but not freed).
3346
** ^The [sqlite3_memory_highwater()] routine returns the maximum
3347
** value of [sqlite3_memory_used()] since the high-water mark
3348
** was last reset. ^The values returned by [sqlite3_memory_used()] and
3349
** [sqlite3_memory_highwater()] include any overhead
3350
** added by SQLite in its implementation of [sqlite3_malloc()],
3351
** but not overhead added by any underlying system library
3352
** routines that [sqlite3_malloc()] may call.
3353
**
3354
** ^The memory high-water mark is reset to the current value of
3355
** [sqlite3_memory_used()] if and only if the parameter to
3356
** [sqlite3_memory_highwater()] is true. ^The value returned
3357
** by [sqlite3_memory_highwater(1)] is the high-water mark
3358
** prior to the reset.
3359
*/
3360
SQLITE_API sqlite3_int64 sqlite3_memory_used(void);
3361
SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag);
3362
3363
/*
3364
** CAPI3REF: Pseudo-Random Number Generator
3365
**
3366
** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
3367
** select random [ROWID | ROWIDs] when inserting new records into a table that
3368
** already uses the largest possible [ROWID]. The PRNG is also used for
3369
** the built-in random() and randomblob() SQL functions. This interface allows
3370
** applications to access the same PRNG for other purposes.
3371
**
3372
** ^A call to this routine stores N bytes of randomness into buffer P.
3373
** ^The P parameter can be a NULL pointer.
3374
**
3375
** ^If this routine has not been previously called or if the previous
3376
** call had N less than one or a NULL pointer for P, then the PRNG is
3377
** seeded using randomness obtained from the xRandomness method of
3378
** the default [sqlite3_vfs] object.
3379
** ^If the previous call to this routine had an N of 1 or more and a
3380
** non-NULL P then the pseudo-randomness is generated
3381
** internally and without recourse to the [sqlite3_vfs] xRandomness
3382
** method.
3383
*/
3384
SQLITE_API void sqlite3_randomness(int N, void *P);
3385
3386
/*
3387
** CAPI3REF: Compile-Time Authorization Callbacks
3388
** METHOD: sqlite3
3389
** KEYWORDS: {authorizer callback}
3390
**
3391
** ^This routine registers an authorizer callback with a particular
3392
** [database connection], supplied in the first argument.
3393
** ^The authorizer callback is invoked as SQL statements are being compiled
3394
** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
3395
** [sqlite3_prepare_v3()], [sqlite3_prepare16()], [sqlite3_prepare16_v2()],
3396
** and [sqlite3_prepare16_v3()]. ^At various
3397
** points during the compilation process, as logic is being created
3398
** to perform various actions, the authorizer callback is invoked to
3399
** see if those actions are allowed. ^The authorizer callback should
3400
** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the
3401
** specific action but allow the SQL statement to continue to be
3402
** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be
3403
** rejected with an error. ^If the authorizer callback returns
3404
** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY]
3405
** then the [sqlite3_prepare_v2()] or equivalent call that triggered
3406
** the authorizer will fail with an error message.
3407
**
3408
** When the callback returns [SQLITE_OK], that means the operation
3409
** requested is ok. ^When the callback returns [SQLITE_DENY], the
3410
** [sqlite3_prepare_v2()] or equivalent call that triggered the
3411
** authorizer will fail with an error message explaining that
3412
** access is denied.
3413
**
3414
** ^The first parameter to the authorizer callback is a copy of the third
3415
** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
3416
** to the callback is an integer [SQLITE_READ | action code] that specifies
3417
** the particular action to be authorized. ^The third through sixth parameters
3418
** to the callback are either NULL pointers or zero-terminated strings
3419
** that contain additional details about the action to be authorized.
3420
** Applications must always be prepared to encounter a NULL pointer in any
3421
** of the third through the sixth parameters of the authorization callback.
3422
**
3423
** ^If the action code is [SQLITE_READ]
3424
** and the callback returns [SQLITE_IGNORE] then the
3425
** [prepared statement] statement is constructed to substitute
3426
** a NULL value in place of the table column that would have
3427
** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE]
3428
** return can be used to deny an untrusted user access to individual
3429
** columns of a table.
3430
** ^When a table is referenced by a [SELECT] but no column values are
3431
** extracted from that table (for example in a query like
3432
** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback
3433
** is invoked once for that table with a column name that is an empty string.
3434
** ^If the action code is [SQLITE_DELETE] and the callback returns
3435
** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
3436
** [truncate optimization] is disabled and all rows are deleted individually.
3437
**
3438
** An authorizer is used when [sqlite3_prepare | preparing]
3439
** SQL statements from an untrusted source, to ensure that the SQL statements
3440
** do not try to access data they are not allowed to see, or that they do not
3441
** try to execute malicious statements that damage the database. For
3442
** example, an application may allow a user to enter arbitrary
3443
** SQL queries for evaluation by a database. But the application does
3444
** not want the user to be able to make arbitrary changes to the
3445
** database. An authorizer could then be put in place while the
3446
** user-entered SQL is being [sqlite3_prepare | prepared] that
3447
** disallows everything except [SELECT] statements.
3448
**
3449
** Applications that need to process SQL from untrusted sources
3450
** might also consider lowering resource limits using [sqlite3_limit()]
3451
** and limiting database size using the [max_page_count] [PRAGMA]
3452
** in addition to using an authorizer.
3453
**
3454
** ^(Only a single authorizer can be in place on a database connection
3455
** at a time. Each call to sqlite3_set_authorizer overrides the
3456
** previous call.)^ ^Disable the authorizer by installing a NULL callback.
3457
** The authorizer is disabled by default.
3458
**
3459
** <h3>Limitations And Caveats</h3><ul>
3460
**
3461
** <li>The authorizer callback must not do anything that will modify
3462
** the database connection that invoked the authorizer callback.
3463
** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
3464
** database connections for the meaning of "modify" in this paragraph.
3465
**
3466
** <li>^When [sqlite3_prepare_v2()] is used to prepare a statement, the
3467
** statement might be re-prepared during [sqlite3_step()] due to a
3468
** schema change. Hence, the application should ensure that the
3469
** correct authorizer callback remains in place during the [sqlite3_step()].
3470
**
3471
** <li>^The authorizer callback is invoked only during
3472
** [sqlite3_prepare()] or its variants. Authorization is not
3473
** performed during statement evaluation in [sqlite3_step()], unless
3474
** as stated in the previous paragraph, sqlite3_step() invokes
3475
** sqlite3_prepare_v2() to reprepare a statement after a schema change.
3476
**
3477
** <li>Authorizer callbacks for the expressions of a
3478
** [generated column] are invoked when the schema is parsed (and specifically
3479
** when the [CREATE TABLE] statement that contains the generated column is
3480
** parsed) not when the generated column is used in a DML statement.
3481
** This is deliberate, as one of the purposes of generated columns
3482
** is to give schema designers the ability to provide gated access
3483
** to privileged columns and/or functions.
3484
**
3485
** </ul>
3486
*/
3487
SQLITE_API int sqlite3_set_authorizer(
3488
sqlite3*,
3489
int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
3490
void *pUserData
3491
);
3492
3493
/*
3494
** CAPI3REF: Authorizer Return Codes
3495
**
3496
** The [sqlite3_set_authorizer | authorizer callback function] must
3497
** return either [SQLITE_OK] or one of these two constants in order
3498
** to signal SQLite whether or not the action is permitted. See the
3499
** [sqlite3_set_authorizer | authorizer documentation] for additional
3500
** information.
3501
**
3502
** Note that SQLITE_IGNORE is also used as a [conflict resolution mode]
3503
** returned from the [sqlite3_vtab_on_conflict()] interface.
3504
*/
3505
#define SQLITE_DENY 1 /* Abort the SQL statement with an error */
3506
#define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */
3507
3508
/*
3509
** CAPI3REF: Authorizer Action Codes
3510
**
3511
** The [sqlite3_set_authorizer()] interface registers a callback function
3512
** that is invoked to authorize certain SQL statement actions. The
3513
** second parameter to the callback is an integer code that specifies
3514
** what action is being authorized. These are the integer action codes that
3515
** the authorizer callback may be passed.
3516
**
3517
** These action code values signify what kind of operation is to be
3518
** authorized. The 3rd and 4th parameters to the authorization
3519
** callback function will be parameters or NULL depending on which of these
3520
** codes is used as the second parameter. ^(The 5th parameter to the
3521
** authorizer callback is the name of the database ("main", "temp",
3522
** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback
3523
** is the name of the inner-most trigger or view that is responsible for
3524
** the access attempt or NULL if this access attempt is directly from
3525
** top-level SQL code.
3526
*/
3527
/******************************************* 3rd ************ 4th ***********/
3528
#define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */
3529
#define SQLITE_CREATE_TABLE 2 /* Table Name NULL */
3530
#define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */
3531
#define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */
3532
#define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */
3533
#define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */
3534
#define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */
3535
#define SQLITE_CREATE_VIEW 8 /* View Name NULL */
3536
#define SQLITE_DELETE 9 /* Table Name NULL */
3537
#define SQLITE_DROP_INDEX 10 /* Index Name Table Name */
3538
#define SQLITE_DROP_TABLE 11 /* Table Name NULL */
3539
#define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */
3540
#define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */
3541
#define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */
3542
#define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */
3543
#define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */
3544
#define SQLITE_DROP_VIEW 17 /* View Name NULL */
3545
#define SQLITE_INSERT 18 /* Table Name NULL */
3546
#define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */
3547
#define SQLITE_READ 20 /* Table Name Column Name */
3548
#define SQLITE_SELECT 21 /* NULL NULL */
3549
#define SQLITE_TRANSACTION 22 /* Operation NULL */
3550
#define SQLITE_UPDATE 23 /* Table Name Column Name */
3551
#define SQLITE_ATTACH 24 /* Filename NULL */
3552
#define SQLITE_DETACH 25 /* Database Name NULL */
3553
#define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
3554
#define SQLITE_REINDEX 27 /* Index Name NULL */
3555
#define SQLITE_ANALYZE 28 /* Table Name NULL */
3556
#define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
3557
#define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
3558
#define SQLITE_FUNCTION 31 /* NULL Function Name */
3559
#define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
3560
#define SQLITE_RECURSIVE 33 /* NULL NULL */
3561
3562
/*
3563
** Note: The SQLITE_COPY macro (with value 0) used to be one of the
3564
** action codes above. That macro has now been repurposed as a possible
3565
** value to the 3rd argument to sqlite3_result_str().
3566
*/
3567
3568
/*
3569
** CAPI3REF: Deprecated Tracing And Profiling Functions
3570
** DEPRECATED
3571
**
3572
** These routines are deprecated. Use the [sqlite3_trace_v2()] interface
3573
** instead of the routines described here.
3574
**
3575
** These routines register callback functions that can be used for
3576
** tracing and profiling the execution of SQL statements.
3577
**
3578
** ^The callback function registered by sqlite3_trace() is invoked at
3579
** various times when an SQL statement is being run by [sqlite3_step()].
3580
** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the
3581
** SQL statement text as the statement first begins executing.
3582
** ^(Additional sqlite3_trace() callbacks might occur
3583
** as each triggered subprogram is entered. The callbacks for triggers
3584
** contain a UTF-8 SQL comment that identifies the trigger.)^
3585
**
3586
** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit
3587
** the length of [bound parameter] expansion in the output of sqlite3_trace().
3588
**
3589
** ^The callback function registered by sqlite3_profile() is invoked
3590
** as each SQL statement finishes. ^The profile callback contains
3591
** the original statement text and an estimate of wall-clock time
3592
** of how long that statement took to run. ^The profile callback
3593
** time is in units of nanoseconds, however the current implementation
3594
** is only capable of millisecond resolution so the six least significant
3595
** digits in the time are meaningless. Future versions of SQLite
3596
** might provide greater resolution on the profiler callback. Invoking
3597
** either [sqlite3_trace()] or [sqlite3_trace_v2()] will cancel the
3598
** profile callback.
3599
*/
3600
SQLITE_API SQLITE_DEPRECATED void *sqlite3_trace(sqlite3*,
3601
void(*xTrace)(void*,const char*), void*);
3602
SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3*,
3603
void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
3604
3605
/*
3606
** CAPI3REF: SQL Trace Event Codes
3607
** KEYWORDS: SQLITE_TRACE
3608
**
3609
** These constants identify classes of events that can be monitored
3610
** using the [sqlite3_trace_v2()] tracing logic. The M argument
3611
** to [sqlite3_trace_v2(D,M,X,P)] is an OR-ed combination of one or more of
3612
** the following constants. ^The first argument to the trace callback
3613
** is one of the following constants.
3614
**
3615
** New tracing constants may be added in future releases.
3616
**
3617
** ^A trace callback has four arguments: xCallback(T,C,P,X).
3618
** ^The T argument is one of the integer type codes above.
3619
** ^The C argument is a copy of the context pointer passed in as the
3620
** fourth argument to [sqlite3_trace_v2()].
3621
** The P and X arguments are pointers whose meanings depend on T.
3622
**
3623
** <dl>
3624
** [[SQLITE_TRACE_STMT]] <dt>SQLITE_TRACE_STMT</dt>
3625
** <dd>^An SQLITE_TRACE_STMT callback is invoked when a prepared statement
3626
** first begins running and possibly at other times during the
3627
** execution of the prepared statement, such as at the start of each
3628
** trigger subprogram. ^The P argument is a pointer to the
3629
** [prepared statement]. ^The X argument is a pointer to a string which
3630
** is the unexpanded SQL text of the prepared statement or an SQL comment
3631
** that indicates the invocation of a trigger. ^The callback can compute
3632
** the same text that would have been returned by the legacy [sqlite3_trace()]
3633
** interface by using the X argument when X begins with "--" and invoking
3634
** [sqlite3_expanded_sql(P)] otherwise.
3635
**
3636
** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt>
3637
** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same
3638
** information as is provided by the [sqlite3_profile()] callback.
3639
** ^The P argument is a pointer to the [prepared statement] and the
3640
** X argument points to a 64-bit integer which is approximately
3641
** the number of nanoseconds that the prepared statement took to run.
3642
** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.
3643
**
3644
** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt>
3645
** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared
3646
** statement generates a single row of result.
3647
** ^The P argument is a pointer to the [prepared statement] and the
3648
** X argument is unused.
3649
**
3650
** [[SQLITE_TRACE_CLOSE]] <dt>SQLITE_TRACE_CLOSE</dt>
3651
** <dd>^An SQLITE_TRACE_CLOSE callback is invoked when a database
3652
** connection closes.
3653
** ^The P argument is a pointer to the [database connection] object
3654
** and the X argument is unused.
3655
** </dl>
3656
*/
3657
#define SQLITE_TRACE_STMT 0x01
3658
#define SQLITE_TRACE_PROFILE 0x02
3659
#define SQLITE_TRACE_ROW 0x04
3660
#define SQLITE_TRACE_CLOSE 0x08
3661
3662
/*
3663
** CAPI3REF: SQL Trace Hook
3664
** METHOD: sqlite3
3665
**
3666
** ^The sqlite3_trace_v2(D,M,X,P) interface registers a trace callback
3667
** function X against [database connection] D, using property mask M
3668
** and context pointer P. ^If the X callback is
3669
** NULL or if the M mask is zero, then tracing is disabled. The
3670
** M argument should be the bitwise OR-ed combination of
3671
** zero or more [SQLITE_TRACE] constants.
3672
**
3673
** ^Each call to either sqlite3_trace(D,X,P) or sqlite3_trace_v2(D,M,X,P)
3674
** overrides (cancels) all prior calls to sqlite3_trace(D,X,P) or
3675
** sqlite3_trace_v2(D,M,X,P) for the [database connection] D. Each
3676
** database connection may have at most one trace callback.
3677
**
3678
** ^The X callback is invoked whenever any of the events identified by
3679
** mask M occur. ^The integer return value from the callback is currently
3680
** ignored, though this may change in future releases. Callback
3681
** implementations should return zero to ensure future compatibility.
3682
**
3683
** ^A trace callback is invoked with four arguments: callback(T,C,P,X).
3684
** ^The T argument is one of the [SQLITE_TRACE]
3685
** constants to indicate why the callback was invoked.
3686
** ^The C argument is a copy of the context pointer.
3687
** The P and X arguments are pointers whose meanings depend on T.
3688
**
3689
** The sqlite3_trace_v2() interface is intended to replace the legacy
3690
** interfaces [sqlite3_trace()] and [sqlite3_profile()], both of which
3691
** are deprecated.
3692
*/
3693
SQLITE_API int sqlite3_trace_v2(
3694
sqlite3*,
3695
unsigned uMask,
3696
int(*xCallback)(unsigned,void*,void*,void*),
3697
void *pCtx
3698
);
3699
3700
/*
3701
** CAPI3REF: Query Progress Callbacks
3702
** METHOD: sqlite3
3703
**
3704
** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
3705
** function X to be invoked periodically during long running calls to
3706
** [sqlite3_step()] and [sqlite3_prepare()] and similar for
3707
** database connection D. An example use for this
3708
** interface is to keep a GUI updated during a large query.
3709
**
3710
** ^The parameter P is passed through as the only parameter to the
3711
** callback function X. ^The parameter N is the approximate number of
3712
** [virtual machine instructions] that are evaluated between successive
3713
** invocations of the callback X. ^If N is less than one then the progress
3714
** handler is disabled.
3715
**
3716
** ^Only a single progress handler may be defined at one time per
3717
** [database connection]; setting a new progress handler cancels the
3718
** old one. ^Setting parameter X to NULL disables the progress handler.
3719
** ^The progress handler is also disabled by setting N to a value less
3720
** than 1.
3721
**
3722
** ^If the progress callback returns non-zero, the operation is
3723
** interrupted. This feature can be used to implement a
3724
** "Cancel" button on a GUI progress dialog box.
3725
**
3726
** The progress handler callback must not do anything that will modify
3727
** the database connection that invoked the progress handler.
3728
** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
3729
** database connections for the meaning of "modify" in this paragraph.
3730
**
3731
** The progress handler callback would originally only be invoked from the
3732
** bytecode engine. It still might be invoked during [sqlite3_prepare()]
3733
** and similar because those routines might force a reparse of the schema
3734
** which involves running the bytecode engine. However, beginning with
3735
** SQLite version 3.41.0, the progress handler callback might also be
3736
** invoked directly from [sqlite3_prepare()] while analyzing and generating
3737
** code for complex queries.
3738
*/
3739
SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
3740
3741
/*
3742
** CAPI3REF: Opening A New Database Connection
3743
** CONSTRUCTOR: sqlite3
3744
**
3745
** ^These routines open an SQLite database file as specified by the
3746
** filename argument. ^The filename argument is interpreted as UTF-8 for
3747
** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
3748
** order for sqlite3_open16(). ^(A [database connection] handle is usually
3749
** returned in *ppDb, even if an error occurs. The only exception is that
3750
** if SQLite is unable to allocate memory to hold the [sqlite3] object,
3751
** a NULL will be written into *ppDb instead of a pointer to the [sqlite3]
3752
** object.)^ ^(If the database is opened (and/or created) successfully, then
3753
** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The
3754
** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
3755
** an English language description of the error following a failure of any
3756
** of the sqlite3_open() routines.
3757
**
3758
** ^The default encoding will be UTF-8 for databases created using
3759
** sqlite3_open() or sqlite3_open_v2(). ^The default encoding for databases
3760
** created using sqlite3_open16() will be UTF-16 in the native byte order.
3761
**
3762
** Whether or not an error occurs when it is opened, resources
3763
** associated with the [database connection] handle should be released by
3764
** passing it to [sqlite3_close()] when it is no longer required.
3765
**
3766
** The sqlite3_open_v2() interface works like sqlite3_open()
3767
** except that it accepts two additional parameters for additional control
3768
** over the new database connection. ^(The flags parameter to
3769
** sqlite3_open_v2() must include, at a minimum, one of the following
3770
** three flag combinations:)^
3771
**
3772
** <dl>
3773
** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
3774
** <dd>The database is opened in read-only mode. If the database does
3775
** not already exist, an error is returned.</dd>)^
3776
**
3777
** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
3778
** <dd>The database is opened for reading and writing if possible, or
3779
** reading only if the file is write protected by the operating
3780
** system. In either case the database must already exist, otherwise
3781
** an error is returned. For historical reasons, if opening in
3782
** read-write mode fails due to OS-level permissions, an attempt is
3783
** made to open it in read-only mode. [sqlite3_db_readonly()] can be
3784
** used to determine whether the database is actually
3785
** read-write.</dd>)^
3786
**
3787
** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
3788
** <dd>The database is opened for reading and writing, and is created if
3789
** it does not already exist. This is the behavior that is always used for
3790
** sqlite3_open() and sqlite3_open16().</dd>)^
3791
** </dl>
3792
**
3793
** In addition to the required flags, the following optional flags are
3794
** also supported:
3795
**
3796
** <dl>
3797
** ^(<dt>[SQLITE_OPEN_URI]</dt>
3798
** <dd>The filename can be interpreted as a URI if this flag is set.</dd>)^
3799
**
3800
** ^(<dt>[SQLITE_OPEN_MEMORY]</dt>
3801
** <dd>The database will be opened as an in-memory database. The database
3802
** is named by the "filename" argument for the purposes of cache-sharing,
3803
** if shared cache mode is enabled, but the "filename" is otherwise ignored.
3804
** </dd>)^
3805
**
3806
** ^(<dt>[SQLITE_OPEN_NOMUTEX]</dt>
3807
** <dd>The new database connection will use the "multi-thread"
3808
** [threading mode].)^ This means that separate threads are allowed
3809
** to use SQLite at the same time, as long as each thread is using
3810
** a different [database connection].
3811
**
3812
** ^(<dt>[SQLITE_OPEN_FULLMUTEX]</dt>
3813
** <dd>The new database connection will use the "serialized"
3814
** [threading mode].)^ This means the multiple threads can safely
3815
** attempt to use the same database connection at the same time.
3816
** (Mutexes will block any actual concurrency, but in this mode
3817
** there is no harm in trying.)
3818
**
3819
** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt>
3820
** <dd>The database is opened with [shared cache] enabled, overriding
3821
** the default shared cache setting provided by
3822
** [sqlite3_enable_shared_cache()].)^
3823
** The [use of shared cache mode is discouraged] and hence shared cache
3824
** capabilities may be omitted from many builds of SQLite. In such cases,
3825
** this option is a no-op.
3826
**
3827
** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>
3828
** <dd>The database is opened with [shared cache] disabled, overriding
3829
** the default shared cache setting provided by
3830
** [sqlite3_enable_shared_cache()].)^
3831
**
3832
** [[OPEN_EXRESCODE]] ^(<dt>[SQLITE_OPEN_EXRESCODE]</dt>
3833
** <dd>The database connection comes up in "extended result code mode".
3834
** In other words, the database behaves as if
3835
** [sqlite3_extended_result_codes(db,1)] were called on the database
3836
** connection as soon as the connection is created. In addition to setting
3837
** the extended result code mode, this flag also causes [sqlite3_open_v2()]
3838
** to return an extended result code.</dd>
3839
**
3840
** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>
3841
** <dd>The database filename is not allowed to contain a symbolic link</dd>
3842
** </dl>)^
3843
**
3844
** If the 3rd parameter to sqlite3_open_v2() is not one of the
3845
** required combinations shown above optionally combined with other
3846
** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
3847
** then the behavior is undefined. Historic versions of SQLite
3848
** have silently ignored surplus bits in the flags parameter to
3849
** sqlite3_open_v2(), however that behavior might not be carried through
3850
** into future versions of SQLite and so applications should not rely
3851
** upon it. Note in particular that the SQLITE_OPEN_EXCLUSIVE flag is a no-op
3852
** for sqlite3_open_v2(). The SQLITE_OPEN_EXCLUSIVE does *not* cause
3853
** the open to fail if the database already exists. The SQLITE_OPEN_EXCLUSIVE
3854
** flag is intended for use by the [sqlite3_vfs|VFS interface] only, and not
3855
** by sqlite3_open_v2().
3856
**
3857
** ^The fourth parameter to sqlite3_open_v2() is the name of the
3858
** [sqlite3_vfs] object that defines the operating system interface that
3859
** the new database connection should use. ^If the fourth parameter is
3860
** a NULL pointer then the default [sqlite3_vfs] object is used.
3861
**
3862
** ^If the filename is ":memory:", then a private, temporary in-memory database
3863
** is created for the connection. ^This in-memory database will vanish when
3864
** the database connection is closed. Future versions of SQLite might
3865
** make use of additional special filenames that begin with the ":" character.
3866
** It is recommended that when a database filename actually does begin with
3867
** a ":" character you should prefix the filename with a pathname such as
3868
** "./" to avoid ambiguity.
3869
**
3870
** ^If the filename is an empty string, then a private, temporary
3871
** on-disk database will be created. ^This private database will be
3872
** automatically deleted as soon as the database connection is closed.
3873
**
3874
** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
3875
**
3876
** ^If [URI filename] interpretation is enabled, and the filename argument
3877
** begins with "file:", then the filename is interpreted as a URI. ^URI
3878
** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
3879
** set in the third argument to sqlite3_open_v2(), or if it has
3880
** been enabled globally using the [SQLITE_CONFIG_URI] option with the
3881
** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
3882
** URI filename interpretation is turned off
3883
** by default, but future releases of SQLite might enable URI filename
3884
** interpretation by default. See "[URI filenames]" for additional
3885
** information.
3886
**
3887
** URI filenames are parsed according to RFC 3986. ^If the URI contains an
3888
** authority, then it must be either an empty string or the string
3889
** "localhost". ^If the authority is not an empty string or "localhost", an
3890
** error is returned to the caller. ^The fragment component of a URI, if
3891
** present, is ignored.
3892
**
3893
** ^SQLite uses the path component of the URI as the name of the disk file
3894
** which contains the database. ^If the path begins with a '/' character,
3895
** then it is interpreted as an absolute path. ^If the path does not begin
3896
** with a '/' (meaning that the authority section is omitted from the URI)
3897
** then the path is interpreted as a relative path.
3898
** ^(On windows, the first component of an absolute path
3899
** is a drive specification (e.g. "C:").)^
3900
**
3901
** [[core URI query parameters]]
3902
** The query component of a URI may contain parameters that are interpreted
3903
** either by SQLite itself, or by a [VFS | custom VFS implementation].
3904
** SQLite and its built-in [VFSes] interpret the
3905
** following query parameters:
3906
**
3907
** <ul>
3908
** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
3909
** a VFS object that provides the operating system interface that should
3910
** be used to access the database file on disk. ^If this option is set to
3911
** an empty string the default VFS object is used. ^Specifying an unknown
3912
** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is
3913
** present, then the VFS specified by the option takes precedence over
3914
** the value passed as the fourth parameter to sqlite3_open_v2().
3915
**
3916
** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",
3917
** "rwc", or "memory". Attempting to set it to any other value is
3918
** an error)^.
3919
** ^If "ro" is specified, then the database is opened for read-only
3920
** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
3921
** third argument to sqlite3_open_v2(). ^If the mode option is set to
3922
** "rw", then the database is opened for read-write (but not create)
3923
** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
3924
** been set. ^Value "rwc" is equivalent to setting both
3925
** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is
3926
** set to "memory" then a pure [in-memory database] that never reads
3927
** or writes from disk is used. ^It is an error to specify a value for
3928
** the mode parameter that is less restrictive than that specified by
3929
** the flags passed in the third parameter to sqlite3_open_v2().
3930
**
3931
** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or
3932
** "private". ^Setting it to "shared" is equivalent to setting the
3933
** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
3934
** sqlite3_open_v2(). ^Setting the cache parameter to "private" is
3935
** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
3936
** ^If sqlite3_open_v2() is used and the "cache" parameter is present in
3937
** a URI filename, its value overrides any behavior requested by setting
3938
** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
3939
**
3940
** <li> <b>psow</b>: ^The psow parameter indicates whether or not the
3941
** [powersafe overwrite] property does or does not apply to the
3942
** storage media on which the database file resides.
3943
**
3944
** <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter
3945
** which if set disables file locking in rollback journal modes. This
3946
** is useful for accessing a database on a filesystem that does not
3947
** support locking. Caution: Database corruption might result if two
3948
** or more processes write to the same database and any one of those
3949
** processes uses nolock=1.
3950
**
3951
** <li> <b>immutable</b>: ^The immutable parameter is a boolean query
3952
** parameter that indicates that the database file is stored on
3953
** read-only media. ^When immutable is set, SQLite assumes that the
3954
** database file cannot be changed, even by a process with higher
3955
** privilege, and so the database is opened read-only and all locking
3956
** and change detection is disabled. Caution: Setting the immutable
3957
** property on a database file that does in fact change can result
3958
** in incorrect query results and/or [SQLITE_CORRUPT] errors.
3959
** See also: [SQLITE_IOCAP_IMMUTABLE].
3960
**
3961
** </ul>
3962
**
3963
** ^Specifying an unknown parameter in the query component of a URI is not an
3964
** error. Future versions of SQLite might understand additional query
3965
** parameters. See "[query parameters with special meaning to SQLite]" for
3966
** additional information.
3967
**
3968
** [[URI filename examples]] <h3>URI filename examples</h3>
3969
**
3970
** <table border="1" align=center cellpadding=5>
3971
** <tr><th> URI filenames <th> Results
3972
** <tr><td> file:data.db <td>
3973
** Open the file "data.db" in the current directory.
3974
** <tr><td> file:/home/fred/data.db<br>
3975
** file:///home/fred/data.db <br>
3976
** file://localhost/home/fred/data.db <br> <td>
3977
** Open the database file "/home/fred/data.db".
3978
** <tr><td> file://darkstar/home/fred/data.db <td>
3979
** An error. "darkstar" is not a recognized authority.
3980
** <tr><td style="white-space:nowrap">
3981
** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
3982
** <td> Windows only: Open the file "data.db" on fred's desktop on drive
3983
** C:. Note that the %20 escaping in this example is not strictly
3984
** necessary - space characters can be used literally
3985
** in URI filenames.
3986
** <tr><td> file:data.db?mode=ro&cache=private <td>
3987
** Open file "data.db" in the current directory for read-only access.
3988
** Regardless of whether or not shared-cache mode is enabled by
3989
** default, use a private cache.
3990
** <tr><td> file:/home/fred/data.db?vfs=unix-dotfile <td>
3991
** Open file "/home/fred/data.db". Use the special VFS "unix-dotfile"
3992
** that uses dot-files in place of posix advisory locking.
3993
** <tr><td> file:data.db?mode=readonly <td>
3994
** An error. "readonly" is not a valid option for the "mode" parameter.
3995
** Use "ro" instead: "file:data.db?mode=ro".
3996
** </table>
3997
**
3998
** ^URI hexadecimal escape sequences (%HH) are supported within the path and
3999
** query components of a URI. A hexadecimal escape sequence consists of a
4000
** percent sign - "%" - followed by exactly two hexadecimal digits
4001
** specifying an octet value. ^Before the path or query components of a
4002
** URI filename are interpreted, they are encoded using UTF-8 and all
4003
** hexadecimal escape sequences replaced by a single byte containing the
4004
** corresponding octet. If this process generates an invalid UTF-8 encoding,
4005
** the results are undefined.
4006
**
4007
** <b>Note to Windows users:</b> The encoding used for the filename argument
4008
** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
4009
** codepage is currently defined. Filenames containing international
4010
** characters must be converted to UTF-8 prior to passing them into
4011
** sqlite3_open() or sqlite3_open_v2().
4012
**
4013
** <b>Note to Windows Runtime users:</b> The temporary directory must be set
4014
** prior to calling sqlite3_open() or sqlite3_open_v2(). Otherwise, various
4015
** features that require the use of temporary files may fail.
4016
**
4017
** See also: [sqlite3_temp_directory]
4018
*/
4019
SQLITE_API int sqlite3_open(
4020
const char *filename, /* Database filename (UTF-8) */
4021
sqlite3 **ppDb /* OUT: SQLite db handle */
4022
);
4023
SQLITE_API int sqlite3_open16(
4024
const void *filename, /* Database filename (UTF-16) */
4025
sqlite3 **ppDb /* OUT: SQLite db handle */
4026
);
4027
SQLITE_API int sqlite3_open_v2(
4028
const char *filename, /* Database filename (UTF-8) */
4029
sqlite3 **ppDb, /* OUT: SQLite db handle */
4030
int flags, /* Flags */
4031
const char *zVfs /* Name of VFS module to use */
4032
);
4033
4034
/*
4035
** CAPI3REF: Obtain Values For URI Parameters
4036
**
4037
** These are utility routines, useful to [VFS|custom VFS implementations],
4038
** that check if a database file was a URI that contained a specific query
4039
** parameter, and if so obtains the value of that query parameter.
4040
**
4041
** The first parameter to these interfaces (hereafter referred to
4042
** as F) must be one of:
4043
** <ul>
4044
** <li> A database filename pointer created by the SQLite core and
4045
** passed into the xOpen() method of a VFS implementation, or
4046
** <li> A filename obtained from [sqlite3_db_filename()], or
4047
** <li> A new filename constructed using [sqlite3_create_filename()].
4048
** </ul>
4049
** If the F parameter is not one of the above, then the behavior is
4050
** undefined and probably undesirable. Older versions of SQLite were
4051
** more tolerant of invalid F parameters than newer versions.
4052
**
4053
** If F is a suitable filename (as described in the previous paragraph)
4054
** and if P is the name of the query parameter, then
4055
** sqlite3_uri_parameter(F,P) returns the value of the P
4056
** parameter if it exists or a NULL pointer if P does not appear as a
4057
** query parameter on F. If P is a query parameter of F and it
4058
** has no explicit value, then sqlite3_uri_parameter(F,P) returns
4059
** a pointer to an empty string.
4060
**
4061
** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean
4062
** parameter and returns true (1) or false (0) according to the value
4063
** of P. The sqlite3_uri_boolean(F,P,B) routine returns true (1) if the
4064
** value of query parameter P is one of "yes", "true", or "on" in any
4065
** case or if the value begins with a non-zero number. The
4066
** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of
4067
** query parameter P is one of "no", "false", or "off" in any case or
4068
** if the value begins with a numeric zero. If P is not a query
4069
** parameter on F or if the value of P does not match any of the
4070
** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
4071
**
4072
** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
4073
** 64-bit signed integer and returns that integer, or D if P does not
4074
** exist or ff the value of P is something other than an integer.
4075
**
4076
** The sqlite3_uri_key(F,N) returns a pointer to the name (not
4077
** the value) of the N-th query parameter for filename F, or a NULL
4078
** pointer if N is less than zero or greater than the number of query
4079
** parameters minus 1. The N value is zero-based so N should be 0 to obtain
4080
** the name of the first query parameter, 1 for the second parameter, and
4081
** so forth.
4082
**
4083
** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
4084
** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and
4085
** is not a database file pathname pointer that the SQLite core passed
4086
** into the xOpen VFS method, then the behavior of this routine is undefined
4087
** and probably undesirable.
4088
**
4089
** Beginning with SQLite [version 3.31.0] ([dateof:3.31.0]) the input F
4090
** parameter can also be the name of a rollback journal file or WAL file
4091
** in addition to the main database file. Prior to version 3.31.0, these
4092
** routines would only work if F was the name of the main database file.
4093
** When the F parameter is the name of the rollback journal or WAL file,
4094
** it has access to all the same query parameters as were found on the
4095
** main database file.
4096
**
4097
** See the [URI filename] documentation for additional information.
4098
*/
4099
SQLITE_API const char *sqlite3_uri_parameter(sqlite3_filename z, const char *zParam);
4100
SQLITE_API int sqlite3_uri_boolean(sqlite3_filename z, const char *zParam, int bDefault);
4101
SQLITE_API sqlite3_int64 sqlite3_uri_int64(sqlite3_filename, const char*, sqlite3_int64);
4102
SQLITE_API const char *sqlite3_uri_key(sqlite3_filename z, int N);
4103
4104
/*
4105
** CAPI3REF: Translate filenames
4106
**
4107
** These routines are available to [VFS|custom VFS implementations] for
4108
** translating filenames between the main database file, the journal file,
4109
** and the WAL file.
4110
**
4111
** If F is the name of an sqlite database file, journal file, or WAL file
4112
** passed by the SQLite core into the VFS, then sqlite3_filename_database(F)
4113
** returns the name of the corresponding database file.
4114
**
4115
** If F is the name of an sqlite database file, journal file, or WAL file
4116
** passed by the SQLite core into the VFS, or if F is a database filename
4117
** obtained from [sqlite3_db_filename()], then sqlite3_filename_journal(F)
4118
** returns the name of the corresponding rollback journal file.
4119
**
4120
** If F is the name of an sqlite database file, journal file, or WAL file
4121
** that was passed by the SQLite core into the VFS, or if F is a database
4122
** filename obtained from [sqlite3_db_filename()], then
4123
** sqlite3_filename_wal(F) returns the name of the corresponding
4124
** WAL file.
4125
**
4126
** In all of the above, if F is not the name of a database, journal or WAL
4127
** filename passed into the VFS from the SQLite core and F is not the
4128
** return value from [sqlite3_db_filename()], then the result is
4129
** undefined and is likely a memory access violation.
4130
*/
4131
SQLITE_API const char *sqlite3_filename_database(sqlite3_filename);
4132
SQLITE_API const char *sqlite3_filename_journal(sqlite3_filename);
4133
SQLITE_API const char *sqlite3_filename_wal(sqlite3_filename);
4134
4135
/*
4136
** CAPI3REF: Database File Corresponding To A Journal
4137
**
4138
** ^If X is the name of a rollback or WAL-mode journal file that is
4139
** passed into the xOpen method of [sqlite3_vfs], then
4140
** sqlite3_database_file_object(X) returns a pointer to the [sqlite3_file]
4141
** object that represents the main database file.
4142
**
4143
** This routine is intended for use in custom [VFS] implementations
4144
** only. It is not a general-purpose interface.
4145
** The argument sqlite3_file_object(X) must be a filename pointer that
4146
** has been passed into [sqlite3_vfs].xOpen method where the
4147
** flags parameter to xOpen contains one of the bits
4148
** [SQLITE_OPEN_MAIN_JOURNAL] or [SQLITE_OPEN_WAL]. Any other use
4149
** of this routine results in undefined and probably undesirable
4150
** behavior.
4151
*/
4152
SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*);
4153
4154
/*
4155
** CAPI3REF: Create and Destroy VFS Filenames
4156
**
4157
** These interfaces are provided for use by [VFS shim] implementations and
4158
** are not useful outside of that context.
4159
**
4160
** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of
4161
** database filename D with corresponding journal file J and WAL file W and
4162
** an array P of N URI Key/Value pairs. The result from
4163
** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that
4164
** is safe to pass to routines like:
4165
** <ul>
4166
** <li> [sqlite3_uri_parameter()],
4167
** <li> [sqlite3_uri_boolean()],
4168
** <li> [sqlite3_uri_int64()],
4169
** <li> [sqlite3_uri_key()],
4170
** <li> [sqlite3_filename_database()],
4171
** <li> [sqlite3_filename_journal()], or
4172
** <li> [sqlite3_filename_wal()].
4173
** </ul>
4174
** If a memory allocation error occurs, sqlite3_create_filename() might
4175
** return a NULL pointer. The memory obtained from sqlite3_create_filename(X)
4176
** must be released by a corresponding call to sqlite3_free_filename(Y).
4177
**
4178
** The P parameter in sqlite3_create_filename(D,J,W,N,P) should be an array
4179
** of 2*N pointers to strings. Each pair of pointers in this array corresponds
4180
** to a key and value for a query parameter. The P parameter may be a NULL
4181
** pointer if N is zero. None of the 2*N pointers in the P array may be
4182
** NULL pointers and key pointers should not be empty strings.
4183
** None of the D, J, or W parameters to sqlite3_create_filename(D,J,W,N,P) may
4184
** be NULL pointers, though they can be empty strings.
4185
**
4186
** The sqlite3_free_filename(Y) routine releases a memory allocation
4187
** previously obtained from sqlite3_create_filename(). Invoking
4188
** sqlite3_free_filename(Y) where Y is a NULL pointer is a harmless no-op.
4189
**
4190
** If the Y parameter to sqlite3_free_filename(Y) is anything other
4191
** than a NULL pointer or a pointer previously acquired from
4192
** sqlite3_create_filename(), then bad things such as heap
4193
** corruption or segfaults may occur. The value Y should not be
4194
** used again after sqlite3_free_filename(Y) has been called. This means
4195
** that if the [sqlite3_vfs.xOpen()] method of a VFS has been called using Y,
4196
** then the corresponding [sqlite3_module.xClose() method should also be
4197
** invoked prior to calling sqlite3_free_filename(Y).
4198
*/
4199
SQLITE_API sqlite3_filename sqlite3_create_filename(
4200
const char *zDatabase,
4201
const char *zJournal,
4202
const char *zWal,
4203
int nParam,
4204
const char **azParam
4205
);
4206
SQLITE_API void sqlite3_free_filename(sqlite3_filename);
4207
4208
/*
4209
** CAPI3REF: Error Codes And Messages
4210
** METHOD: sqlite3
4211
**
4212
** ^If the most recent sqlite3_* API call associated with
4213
** [database connection] D failed, then the sqlite3_errcode(D) interface
4214
** returns the numeric [result code] or [extended result code] for that
4215
** API call.
4216
** ^The sqlite3_extended_errcode()
4217
** interface is the same except that it always returns the
4218
** [extended result code] even when extended result codes are
4219
** disabled.
4220
**
4221
** The values returned by sqlite3_errcode() and/or
4222
** sqlite3_extended_errcode() might change with each API call.
4223
** Except, there are some interfaces that are guaranteed to never
4224
** change the value of the error code. The error-code preserving
4225
** interfaces include the following:
4226
**
4227
** <ul>
4228
** <li> sqlite3_errcode()
4229
** <li> sqlite3_extended_errcode()
4230
** <li> sqlite3_errmsg()
4231
** <li> sqlite3_errmsg16()
4232
** <li> sqlite3_error_offset()
4233
** <li> sqlite3_db_handle()
4234
** </ul>
4235
**
4236
** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
4237
** text that describes the error, as either UTF-8 or UTF-16 respectively,
4238
** or NULL if no error message is available.
4239
** (See how SQLite handles [invalid UTF] for exceptions to this rule.)
4240
** ^(Memory to hold the error message string is managed internally.
4241
** The application does not need to worry about freeing the result.
4242
** However, the error string might be overwritten or deallocated by
4243
** subsequent calls to other SQLite interface functions.)^
4244
**
4245
** ^The sqlite3_errstr(E) interface returns the English-language text
4246
** that describes the [result code] E, as UTF-8, or NULL if E is not a
4247
** result code for which a text error message is available.
4248
** ^(Memory to hold the error message string is managed internally
4249
** and must not be freed by the application)^.
4250
**
4251
** ^If the most recent error references a specific token in the input
4252
** SQL, the sqlite3_error_offset() interface returns the byte offset
4253
** of the start of that token. ^The byte offset returned by
4254
** sqlite3_error_offset() assumes that the input SQL is UTF-8.
4255
** ^If the most recent error does not reference a specific token in the input
4256
** SQL, then the sqlite3_error_offset() function returns -1.
4257
**
4258
** When the serialized [threading mode] is in use, it might be the
4259
** case that a second error occurs on a separate thread in between
4260
** the time of the first error and the call to these interfaces.
4261
** When that happens, the second error will be reported since these
4262
** interfaces always report the most recent result. To avoid
4263
** this, each thread can obtain exclusive use of the [database connection] D
4264
** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning
4265
** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after
4266
** all calls to the interfaces listed here are completed.
4267
**
4268
** If an interface fails with SQLITE_MISUSE, that means the interface
4269
** was invoked incorrectly by the application. In that case, the
4270
** error code and message may or may not be set.
4271
*/
4272
SQLITE_API int sqlite3_errcode(sqlite3 *db);
4273
SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
4274
SQLITE_API const char *sqlite3_errmsg(sqlite3*);
4275
SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
4276
SQLITE_API const char *sqlite3_errstr(int);
4277
SQLITE_API int sqlite3_error_offset(sqlite3 *db);
4278
4279
/*
4280
** CAPI3REF: Set Error Code And Message
4281
** METHOD: sqlite3
4282
**
4283
** Set the error code of the database handle passed as the first argument
4284
** to errcode, and the error message to a copy of nul-terminated string
4285
** zErrMsg. If zErrMsg is passed NULL, then the error message is set to
4286
** the default message associated with the supplied error code. Subsequent
4287
** calls to [sqlite3_errcode()] and [sqlite3_errmsg()] and similar will
4288
** return the values set by this routine in place of what was previously
4289
** set by SQLite itself.
4290
**
4291
** This function returns SQLITE_OK if the error code and error message are
4292
** successfully set, SQLITE_NOMEM if an OOM occurs, and SQLITE_MISUSE if
4293
** the database handle is NULL or invalid.
4294
**
4295
** The error code and message set by this routine remains in effect until
4296
** they are changed, either by another call to this routine or until they are
4297
** changed to by SQLite itself to reflect the result of some subsquent
4298
** API call.
4299
**
4300
** This function is intended for use by SQLite extensions or wrappers. The
4301
** idea is that an extension or wrapper can use this routine to set error
4302
** messages and error codes and thus behave more like a core SQLite
4303
** feature from the point of view of an application.
4304
*/
4305
SQLITE_API int sqlite3_set_errmsg(sqlite3 *db, int errcode, const char *zErrMsg);
4306
4307
/*
4308
** CAPI3REF: Prepared Statement Object
4309
** KEYWORDS: {prepared statement} {prepared statements}
4310
**
4311
** An instance of this object represents a single SQL statement that
4312
** has been compiled into binary form and is ready to be evaluated.
4313
**
4314
** Think of each SQL statement as a separate computer program. The
4315
** original SQL text is source code. A prepared statement object
4316
** is the compiled object code. All SQL must be converted into a
4317
** prepared statement before it can be run.
4318
**
4319
** The life-cycle of a prepared statement object usually goes like this:
4320
**
4321
** <ol>
4322
** <li> Create the prepared statement object using [sqlite3_prepare_v2()].
4323
** <li> Bind values to [parameters] using the sqlite3_bind_*()
4324
** interfaces.
4325
** <li> Run the SQL by calling [sqlite3_step()] one or more times.
4326
** <li> Reset the prepared statement using [sqlite3_reset()] then go back
4327
** to step 2. Do this zero or more times.
4328
** <li> Destroy the object using [sqlite3_finalize()].
4329
** </ol>
4330
*/
4331
typedef struct sqlite3_stmt sqlite3_stmt;
4332
4333
/*
4334
** CAPI3REF: Run-time Limits
4335
** METHOD: sqlite3
4336
**
4337
** ^(This interface allows the size of various constructs to be limited
4338
** on a connection by connection basis. The first parameter is the
4339
** [database connection] whose limit is to be set or queried. The
4340
** second parameter is one of the [limit categories] that define a
4341
** class of constructs to be size limited. The third parameter is the
4342
** new limit for that construct.)^
4343
**
4344
** ^If the new limit is a negative number, the limit is unchanged.
4345
** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a
4346
** [limits | hard upper bound]
4347
** set at compile-time by a C preprocessor macro called
4348
** [limits | SQLITE_MAX_<i>NAME</i>].
4349
** (The "_LIMIT_" in the name is changed to "_MAX_".))^
4350
** ^Attempts to increase a limit above its hard upper bound are
4351
** silently truncated to the hard upper bound.
4352
**
4353
** ^Regardless of whether or not the limit was changed, the
4354
** [sqlite3_limit()] interface returns the prior value of the limit.
4355
** ^Hence, to find the current value of a limit without changing it,
4356
** simply invoke this interface with the third parameter set to -1.
4357
**
4358
** Run-time limits are intended for use in applications that manage
4359
** both their own internal database and also databases that are controlled
4360
** by untrusted external sources. An example application might be a
4361
** web browser that has its own databases for storing history and
4362
** separate databases controlled by JavaScript applications downloaded
4363
** off the Internet. The internal databases can be given the
4364
** large, default limits. Databases managed by external sources can
4365
** be given much smaller limits designed to prevent a denial of service
4366
** attack. Developers might also want to use the [sqlite3_set_authorizer()]
4367
** interface to further control untrusted SQL. The size of the database
4368
** created by an untrusted script can be contained using the
4369
** [max_page_count] [PRAGMA].
4370
**
4371
** New run-time limit categories may be added in future releases.
4372
*/
4373
SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
4374
4375
/*
4376
** CAPI3REF: Run-Time Limit Categories
4377
** KEYWORDS: {limit category} {*limit categories}
4378
**
4379
** These constants define various performance limits
4380
** that can be lowered at run-time using [sqlite3_limit()].
4381
** A concise description of these limits follows, and additional information
4382
** is available at [limits | Limits in SQLite].
4383
**
4384
** <dl>
4385
** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
4386
** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
4387
**
4388
** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
4389
** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
4390
**
4391
** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt>
4392
** <dd>The maximum number of columns in a table definition or in the
4393
** result set of a [SELECT] or the maximum number of columns in an index
4394
** or in an ORDER BY or GROUP BY clause.</dd>)^
4395
**
4396
** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
4397
** <dd>The maximum depth of the parse tree on any expression and
4398
** the maximum nesting depth for subqueries and VIEWs</dd>)^
4399
**
4400
** [[SQLITE_LIMIT_PARSER_DEPTH]] ^(<dt>SQLITE_LIMIT_PARSER_DEPTH</dt>
4401
** <dd>The maximum depth of the LALR(1) parser stack used to analyze
4402
** input SQL statements.</dd>)^
4403
**
4404
** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
4405
** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
4406
**
4407
** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
4408
** <dd>The maximum number of instructions in a virtual machine program
4409
** used to implement an SQL statement. If [sqlite3_prepare_v2()] or
4410
** the equivalent tries to allocate space for more than this many opcodes
4411
** in a single prepared statement, an SQLITE_NOMEM error is returned.</dd>)^
4412
**
4413
** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
4414
** <dd>The maximum number of arguments on a function.</dd>)^
4415
**
4416
** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
4417
** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
4418
**
4419
** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]]
4420
** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
4421
** <dd>The maximum length of the pattern argument to the [LIKE] or
4422
** [GLOB] operators.</dd>)^
4423
**
4424
** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
4425
** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
4426
** <dd>The maximum index number of any [parameter] in an SQL statement.)^
4427
**
4428
** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
4429
** <dd>The maximum depth of recursion for triggers, and the maximum
4430
** nesting depth for separate triggers.</dd>)^
4431
**
4432
** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
4433
** <dd>The maximum number of auxiliary worker threads that a single
4434
** [prepared statement] may start.</dd>)^
4435
**
4436
** [[SQLITE_LIMIT_SCHEMA]] ^(<dt>SQLITE_LIMIT_SCHEMA</dt>
4437
** <dd>The maximum number of objects (tables, indexes, triggers, and views)
4438
** defined by the database schema.</dd>)^
4439
**
4440
** [[SQLITE_LIMIT_TRIGGER_STEPS]] ^(<dt>SQLITE_LIMIT_TRIGGER_STEPS</dt>
4441
** <dd>The maximum number of SQL statements that can be contained within
4442
** a single trigger.</dd>)^
4443
** </dl>
4444
*/
4445
#define SQLITE_LIMIT_LENGTH 0
4446
#define SQLITE_LIMIT_SQL_LENGTH 1
4447
#define SQLITE_LIMIT_COLUMN 2
4448
#define SQLITE_LIMIT_EXPR_DEPTH 3
4449
#define SQLITE_LIMIT_COMPOUND_SELECT 4
4450
#define SQLITE_LIMIT_VDBE_OP 5
4451
#define SQLITE_LIMIT_FUNCTION_ARG 6
4452
#define SQLITE_LIMIT_ATTACHED 7
4453
#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
4454
#define SQLITE_LIMIT_VARIABLE_NUMBER 9
4455
#define SQLITE_LIMIT_TRIGGER_DEPTH 10
4456
#define SQLITE_LIMIT_WORKER_THREADS 11
4457
#define SQLITE_LIMIT_PARSER_DEPTH 12
4458
#define SQLITE_LIMIT_SCHEMA 13
4459
#define SQLITE_LIMIT_TRIGGER_STEPS 14
4460
4461
/*
4462
** CAPI3REF: Prepare Flags
4463
**
4464
** These constants define various flags that can be passed into the
4465
** "prepFlags" parameter of the [sqlite3_prepare_v3()] and
4466
** [sqlite3_prepare16_v3()] interfaces.
4467
**
4468
** New flags may be added in future releases of SQLite.
4469
**
4470
** <dl>
4471
** [[SQLITE_PREPARE_PERSISTENT]] ^(<dt>SQLITE_PREPARE_PERSISTENT</dt>
4472
** <dd>The SQLITE_PREPARE_PERSISTENT flag is a hint to the query planner
4473
** that the prepared statement will be retained for a long time and
4474
** probably reused many times.)^ ^Without this flag, [sqlite3_prepare_v3()]
4475
** and [sqlite3_prepare16_v3()] assume that the prepared statement will
4476
** be used just once or at most a few times and then destroyed using
4477
** [sqlite3_finalize()] relatively soon. The current implementation acts
4478
** on this hint by avoiding the use of [lookaside memory] so as not to
4479
** deplete the limited store of lookaside memory. Future versions of
4480
** SQLite may act on this hint differently.
4481
**
4482
** [[SQLITE_PREPARE_NORMALIZE]] <dt>SQLITE_PREPARE_NORMALIZE</dt>
4483
** <dd>The SQLITE_PREPARE_NORMALIZE flag is a no-op. This flag used
4484
** to be required for any prepared statement that wanted to use the
4485
** [sqlite3_normalized_sql()] interface. However, the
4486
** [sqlite3_normalized_sql()] interface is now available to all
4487
** prepared statements, regardless of whether or not they use this
4488
** flag.
4489
**
4490
** [[SQLITE_PREPARE_NO_VTAB]] <dt>SQLITE_PREPARE_NO_VTAB</dt>
4491
** <dd>The SQLITE_PREPARE_NO_VTAB flag causes the SQL compiler
4492
** to return an error (error code SQLITE_ERROR) if the statement uses
4493
** any virtual tables.
4494
**
4495
** [[SQLITE_PREPARE_DONT_LOG]] <dt>SQLITE_PREPARE_DONT_LOG</dt>
4496
** <dd>The SQLITE_PREPARE_DONT_LOG flag prevents SQL compiler
4497
** errors from being sent to the error log defined by
4498
** [SQLITE_CONFIG_LOG]. This can be used, for example, to do test
4499
** compiles to see if some SQL syntax is well-formed, without generating
4500
** messages on the global error log when it is not. If the test compile
4501
** fails, the sqlite3_prepare_v3() call returns the same error indications
4502
** with or without this flag; it just omits the call to [sqlite3_log()] that
4503
** logs the error.
4504
**
4505
** [[SQLITE_PREPARE_FROM_DDL]] <dt>SQLITE_PREPARE_FROM_DDL</dt>
4506
** <dd>The SQLITE_PREPARE_FROM_DDL flag causes the SQL compiler to enforce
4507
** security constraints that would otherwise only be enforced when parsing
4508
** the database schema. In other words, the SQLITE_PREPARE_FROM_DDL flag
4509
** causes the SQL compiler to treat the SQL statement being prepared as if
4510
** it had come from an attacker. When SQLITE_PREPARE_FROM_DDL is used and
4511
** [SQLITE_DBCONFIG_TRUSTED_SCHEMA] is off, SQL functions may only be called
4512
** if they are tagged with [SQLITE_INNOCUOUS] and virtual tables may only
4513
** be used if they are tagged with [SQLITE_VTAB_INNOCUOUS]. Best practice
4514
** is to use the SQLITE_PREPARE_FROM_DDL option when preparing any SQL that
4515
** is derived from parts of the database schema. In particular, virtual
4516
** table implementations that run SQL statements that are derived from
4517
** arguments to their CREATE VIRTUAL TABLE statement should always use
4518
** [sqlite3_prepare_v3()] and set the SQLITE_PREPARE_FROM_DDL flag to
4519
** prevent bypass of the [SQLITE_DBCONFIG_TRUSTED_SCHEMA] security checks.
4520
** </dl>
4521
*/
4522
#define SQLITE_PREPARE_PERSISTENT 0x01
4523
#define SQLITE_PREPARE_NORMALIZE 0x02
4524
#define SQLITE_PREPARE_NO_VTAB 0x04
4525
#define SQLITE_PREPARE_DONT_LOG 0x10
4526
#define SQLITE_PREPARE_FROM_DDL 0x20
4527
4528
/*
4529
** CAPI3REF: Compiling An SQL Statement
4530
** KEYWORDS: {SQL statement compiler}
4531
** METHOD: sqlite3
4532
** CONSTRUCTOR: sqlite3_stmt
4533
**
4534
** To execute an SQL statement, it must first be compiled into a byte-code
4535
** program using one of these routines. Or, in other words, these routines
4536
** are constructors for the [prepared statement] object.
4537
**
4538
** The preferred routine to use is [sqlite3_prepare_v2()]. The
4539
** [sqlite3_prepare()] interface is legacy and should be avoided.
4540
** [sqlite3_prepare_v3()] has an extra
4541
** [SQLITE_PREPARE_FROM_DDL|"prepFlags" option] that is sometimes
4542
** needed for special purpose or to pass along security restrictions.
4543
**
4544
** The use of the UTF-8 interfaces is preferred, as SQLite currently
4545
** does all parsing using UTF-8. The UTF-16 interfaces are provided
4546
** as a convenience. The UTF-16 interfaces work by converting the
4547
** input text into UTF-8, then invoking the corresponding UTF-8 interface.
4548
**
4549
** The first argument, "db", is a [database connection] obtained from a
4550
** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or
4551
** [sqlite3_open16()]. The database connection must not have been closed.
4552
**
4553
** The second argument, "zSql", is the statement to be compiled, encoded
4554
** as either UTF-8 or UTF-16. The sqlite3_prepare(), sqlite3_prepare_v2(),
4555
** and sqlite3_prepare_v3()
4556
** interfaces use UTF-8, and sqlite3_prepare16(), sqlite3_prepare16_v2(),
4557
** and sqlite3_prepare16_v3() use UTF-16.
4558
**
4559
** ^If the nByte argument is negative, then zSql is read up to the
4560
** first zero terminator. ^If nByte is positive, then it is the maximum
4561
** number of bytes read from zSql. When nByte is positive, zSql is read
4562
** up to the first zero terminator or until the nByte bytes have been read,
4563
** whichever comes first. ^If nByte is zero, then no prepared
4564
** statement is generated.
4565
** If the caller knows that the supplied string is nul-terminated, then
4566
** there is a small performance advantage to passing an nByte parameter that
4567
** is the number of bytes in the input string <i>including</i>
4568
** the nul-terminator.
4569
** Note that nByte measures the length of the input in bytes, not
4570
** characters, even for the UTF-16 interfaces.
4571
** For the sqlite3_prepare16() and sqlite3_prepare16_v2() interfaces,
4572
** the nByte value must be even or undefined behavior can result.
4573
**
4574
** ^If pzTail is not NULL then *pzTail is made to point to the first byte
4575
** past the end of the first SQL statement in zSql. These routines only
4576
** compile the first statement in zSql, so *pzTail is left pointing to
4577
** what remains uncompiled.
4578
**
4579
** ^*ppStmt is left pointing to a compiled [prepared statement] that can be
4580
** executed using [sqlite3_step()]. ^If there is an error, *ppStmt is set
4581
** to NULL. ^If the input text contains no SQL (if the input is an empty
4582
** string or a comment) then *ppStmt is set to NULL.
4583
** The calling procedure is responsible for deleting the compiled
4584
** SQL statement using [sqlite3_finalize()] after it has finished with it.
4585
** ppStmt may not be NULL.
4586
**
4587
** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK];
4588
** otherwise an [error code] is returned.
4589
**
4590
** The sqlite3_prepare_v2(), sqlite3_prepare_v3(), sqlite3_prepare16_v2(),
4591
** and sqlite3_prepare16_v3() interfaces are recommended for all new programs.
4592
** The older interfaces (sqlite3_prepare() and sqlite3_prepare16())
4593
** are retained for backwards compatibility, but their use is discouraged.
4594
** ^In the "vX" interfaces, the prepared statement
4595
** that is returned (the [sqlite3_stmt] object) contains a copy of the
4596
** original SQL text. This causes the [sqlite3_step()] interface to
4597
** behave differently in three ways:
4598
**
4599
** <ol>
4600
** <li>
4601
** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
4602
** always used to do, [sqlite3_step()] will automatically recompile the SQL
4603
** statement and try to run it again. As many as [SQLITE_MAX_SCHEMA_RETRY]
4604
** retries will occur before sqlite3_step() gives up and returns an error.
4605
** </li>
4606
**
4607
** <li>
4608
** ^When an error occurs, [sqlite3_step()] will return one of the detailed
4609
** [error codes] or [extended error codes]. ^The legacy behavior was that
4610
** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code
4611
** and the application would have to make a second call to [sqlite3_reset()]
4612
** in order to find the underlying cause of the problem. With the "v2" prepare
4613
** interfaces, the underlying reason for the error is returned immediately.
4614
** </li>
4615
**
4616
** <li>
4617
** ^If the specific value bound to a [parameter | host parameter] in the
4618
** WHERE clause might influence the choice of query plan for a statement,
4619
** then the statement will be automatically recompiled, as if there had been
4620
** a schema change, on the first [sqlite3_step()] call following any change
4621
** to the [sqlite3_bind_text | bindings] of that [parameter].
4622
** ^The specific value of a WHERE-clause [parameter] might influence the
4623
** choice of query plan if the parameter is the left-hand side of a [LIKE]
4624
** or [GLOB] operator or if the parameter is compared to an indexed column
4625
** and the [SQLITE_ENABLE_STAT4] compile-time option is enabled.
4626
** </li>
4627
** </ol>
4628
**
4629
** <p>^sqlite3_prepare_v3() differs from sqlite3_prepare_v2() only in having
4630
** the extra prepFlags parameter, which is a bit array consisting of zero or
4631
** more of the [SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_*] flags. ^The
4632
** sqlite3_prepare_v2() interface works exactly the same as
4633
** sqlite3_prepare_v3() with a zero prepFlags parameter.
4634
*/
4635
SQLITE_API int sqlite3_prepare(
4636
sqlite3 *db, /* Database handle */
4637
const char *zSql, /* SQL statement, UTF-8 encoded */
4638
int nByte, /* Maximum length of zSql in bytes. */
4639
sqlite3_stmt **ppStmt, /* OUT: Statement handle */
4640
const char **pzTail /* OUT: Pointer to unused portion of zSql */
4641
);
4642
SQLITE_API int sqlite3_prepare_v2(
4643
sqlite3 *db, /* Database handle */
4644
const char *zSql, /* SQL statement, UTF-8 encoded */
4645
int nByte, /* Maximum length of zSql in bytes. */
4646
sqlite3_stmt **ppStmt, /* OUT: Statement handle */
4647
const char **pzTail /* OUT: Pointer to unused portion of zSql */
4648
);
4649
SQLITE_API int sqlite3_prepare_v3(
4650
sqlite3 *db, /* Database handle */
4651
const char *zSql, /* SQL statement, UTF-8 encoded */
4652
int nByte, /* Maximum length of zSql in bytes. */
4653
unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */
4654
sqlite3_stmt **ppStmt, /* OUT: Statement handle */
4655
const char **pzTail /* OUT: Pointer to unused portion of zSql */
4656
);
4657
SQLITE_API int sqlite3_prepare16(
4658
sqlite3 *db, /* Database handle */
4659
const void *zSql, /* SQL statement, UTF-16 encoded */
4660
int nByte, /* Maximum length of zSql in bytes. */
4661
sqlite3_stmt **ppStmt, /* OUT: Statement handle */
4662
const void **pzTail /* OUT: Pointer to unused portion of zSql */
4663
);
4664
SQLITE_API int sqlite3_prepare16_v2(
4665
sqlite3 *db, /* Database handle */
4666
const void *zSql, /* SQL statement, UTF-16 encoded */
4667
int nByte, /* Maximum length of zSql in bytes. */
4668
sqlite3_stmt **ppStmt, /* OUT: Statement handle */
4669
const void **pzTail /* OUT: Pointer to unused portion of zSql */
4670
);
4671
SQLITE_API int sqlite3_prepare16_v3(
4672
sqlite3 *db, /* Database handle */
4673
const void *zSql, /* SQL statement, UTF-16 encoded */
4674
int nByte, /* Maximum length of zSql in bytes. */
4675
unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */
4676
sqlite3_stmt **ppStmt, /* OUT: Statement handle */
4677
const void **pzTail /* OUT: Pointer to unused portion of zSql */
4678
);
4679
4680
/*
4681
** CAPI3REF: Retrieving Statement SQL
4682
** METHOD: sqlite3_stmt
4683
**
4684
** ^The sqlite3_sql(P) interface returns a pointer to a copy of the UTF-8
4685
** SQL text used to create [prepared statement] P if P was
4686
** created by [sqlite3_prepare_v2()], [sqlite3_prepare_v3()],
4687
** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()].
4688
** ^The sqlite3_expanded_sql(P) interface returns a pointer to a UTF-8
4689
** string containing the SQL text of prepared statement P with
4690
** [bound parameters] expanded.
4691
** ^The sqlite3_normalized_sql(P) interface returns a pointer to a UTF-8
4692
** string containing the normalized SQL text of prepared statement P. The
4693
** semantics used to normalize a SQL statement are unspecified and subject
4694
** to change. At a minimum, literal values will be replaced with suitable
4695
** placeholders.
4696
**
4697
** ^(For example, if a prepared statement is created using the SQL
4698
** text "SELECT $abc,:xyz" and if parameter $abc is bound to integer 2345
4699
** and parameter :xyz is unbound, then sqlite3_sql() will return
4700
** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
4701
** will return "SELECT 2345,NULL".)^
4702
**
4703
** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
4704
** is available to hold the result, or if the result would exceed the
4705
** maximum string length determined by the [SQLITE_LIMIT_LENGTH].
4706
**
4707
** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
4708
** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time
4709
** option causes sqlite3_expanded_sql() to always return NULL.
4710
**
4711
** ^The strings returned by sqlite3_sql(P) and sqlite3_normalized_sql(P)
4712
** are managed by SQLite and are automatically freed when the prepared
4713
** statement is finalized.
4714
** ^The string returned by sqlite3_expanded_sql(P), on the other hand,
4715
** is obtained from [sqlite3_malloc()] and must be freed by the application
4716
** by passing it to [sqlite3_free()].
4717
**
4718
** ^The sqlite3_normalized_sql() interface is only available if
4719
** the [SQLITE_ENABLE_NORMALIZE] compile-time option is defined.
4720
*/
4721
SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
4722
SQLITE_API char *sqlite3_expanded_sql(sqlite3_stmt *pStmt);
4723
#ifdef SQLITE_ENABLE_NORMALIZE
4724
SQLITE_API const char *sqlite3_normalized_sql(sqlite3_stmt *pStmt);
4725
#endif
4726
4727
/*
4728
** CAPI3REF: Determine If An SQL Statement Writes The Database
4729
** METHOD: sqlite3_stmt
4730
**
4731
** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
4732
** and only if the [prepared statement] X makes no direct changes to
4733
** the content of the database file.
4734
**
4735
** Note that [application-defined SQL functions] or
4736
** [virtual tables] might change the database indirectly as a side effect.
4737
** ^(For example, if an application defines a function "eval()" that
4738
** calls [sqlite3_exec()], then the following SQL statement would
4739
** change the database file through side-effects:
4740
**
4741
** <blockquote><pre>
4742
** SELECT eval('DELETE FROM t1') FROM t2;
4743
** </pre></blockquote>
4744
**
4745
** But because the [SELECT] statement does not change the database file
4746
** directly, sqlite3_stmt_readonly() would still return true.)^
4747
**
4748
** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
4749
** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,
4750
** since the statements themselves do not actually modify the database but
4751
** rather they control the timing of when other statements modify the
4752
** database. ^The [ATTACH] and [DETACH] statements also cause
4753
** sqlite3_stmt_readonly() to return true since, while those statements
4754
** change the configuration of a database connection, they do not make
4755
** changes to the content of the database files on disk.
4756
** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
4757
** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
4758
** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
4759
** sqlite3_stmt_readonly() returns false for those commands.
4760
**
4761
** ^This routine returns false if there is any possibility that the
4762
** statement might change the database file. ^A false return does
4763
** not guarantee that the statement will change the database file.
4764
** ^For example, an UPDATE statement might have a WHERE clause that
4765
** makes it a no-op, but the sqlite3_stmt_readonly() result would still
4766
** be false. ^Similarly, a CREATE TABLE IF NOT EXISTS statement is a
4767
** read-only no-op if the table already exists, but
4768
** sqlite3_stmt_readonly() still returns false for such a statement.
4769
**
4770
** ^If prepared statement X is an [EXPLAIN] or [EXPLAIN QUERY PLAN]
4771
** statement, then sqlite3_stmt_readonly(X) returns the same value as
4772
** if the EXPLAIN or EXPLAIN QUERY PLAN prefix were omitted.
4773
*/
4774
SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
4775
4776
/*
4777
** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement
4778
** METHOD: sqlite3_stmt
4779
**
4780
** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the
4781
** prepared statement S is an EXPLAIN statement, or 2 if the
4782
** statement S is an EXPLAIN QUERY PLAN.
4783
** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is
4784
** an ordinary statement or a NULL pointer.
4785
*/
4786
SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt);
4787
4788
/*
4789
** CAPI3REF: Change The EXPLAIN Setting For A Prepared Statement
4790
** METHOD: sqlite3_stmt
4791
**
4792
** The sqlite3_stmt_explain(S,E) interface changes the EXPLAIN
4793
** setting for [prepared statement] S. If E is zero, then S becomes
4794
** a normal prepared statement. If E is 1, then S behaves as if
4795
** its SQL text began with "[EXPLAIN]". If E is 2, then S behaves as if
4796
** its SQL text began with "[EXPLAIN QUERY PLAN]".
4797
**
4798
** Calling sqlite3_stmt_explain(S,E) might cause S to be reprepared.
4799
** SQLite tries to avoid a reprepare, but a reprepare might be necessary
4800
** on the first transition into EXPLAIN or EXPLAIN QUERY PLAN mode.
4801
**
4802
** Because of the potential need to reprepare, a call to
4803
** sqlite3_stmt_explain(S,E) will fail with SQLITE_ERROR if S cannot be
4804
** reprepared because it was created using [sqlite3_prepare()] instead of
4805
** the newer [sqlite3_prepare_v2()] or [sqlite3_prepare_v3()] interfaces and
4806
** hence has no saved SQL text with which to reprepare.
4807
**
4808
** Changing the explain setting for a prepared statement does not change
4809
** the original SQL text for the statement. Hence, if the SQL text originally
4810
** began with EXPLAIN or EXPLAIN QUERY PLAN, but sqlite3_stmt_explain(S,0)
4811
** is called to convert the statement into an ordinary statement, the EXPLAIN
4812
** or EXPLAIN QUERY PLAN keywords will still appear in the sqlite3_sql(S)
4813
** output, even though the statement now acts like a normal SQL statement.
4814
**
4815
** This routine returns SQLITE_OK if the explain mode is successfully
4816
** changed, or an error code if the explain mode could not be changed.
4817
** The explain mode cannot be changed while a statement is active.
4818
** Hence, it is good practice to call [sqlite3_reset(S)]
4819
** immediately prior to calling sqlite3_stmt_explain(S,E).
4820
*/
4821
SQLITE_API int sqlite3_stmt_explain(sqlite3_stmt *pStmt, int eMode);
4822
4823
/*
4824
** CAPI3REF: Determine If A Prepared Statement Has Been Reset
4825
** METHOD: sqlite3_stmt
4826
**
4827
** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
4828
** [prepared statement] S has been stepped at least once using
4829
** [sqlite3_step(S)] but has neither run to completion (returned
4830
** [SQLITE_DONE] from [sqlite3_step(S)]) nor
4831
** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)
4832
** interface returns false if S is a NULL pointer. If S is not a
4833
** NULL pointer and is not a pointer to a valid [prepared statement]
4834
** object, then the behavior is undefined and probably undesirable.
4835
**
4836
** This interface can be used in combination [sqlite3_next_stmt()]
4837
** to locate all prepared statements associated with a database
4838
** connection that are in need of being reset. This can be used,
4839
** for example, in diagnostic routines to search for prepared
4840
** statements that are holding a transaction open.
4841
*/
4842
SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*);
4843
4844
/*
4845
** CAPI3REF: Dynamically Typed Value Object
4846
** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
4847
**
4848
** SQLite uses the sqlite3_value object to represent all values
4849
** that can be stored in a database table. SQLite uses dynamic typing
4850
** for the values it stores. ^Values stored in sqlite3_value objects
4851
** can be integers, floating point values, strings, BLOBs, or NULL.
4852
**
4853
** An sqlite3_value object may be either "protected" or "unprotected".
4854
** Some interfaces require a protected sqlite3_value. Other interfaces
4855
** will accept either a protected or an unprotected sqlite3_value.
4856
** Every interface that accepts sqlite3_value arguments specifies
4857
** whether or not it requires a protected sqlite3_value. The
4858
** [sqlite3_value_dup()] interface can be used to construct a new
4859
** protected sqlite3_value from an unprotected sqlite3_value.
4860
**
4861
** The terms "protected" and "unprotected" refer to whether or not
4862
** a mutex is held. An internal mutex is held for a protected
4863
** sqlite3_value object but no mutex is held for an unprotected
4864
** sqlite3_value object. If SQLite is compiled to be single-threaded
4865
** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)
4866
** or if SQLite is run in one of reduced mutex modes
4867
** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
4868
** then there is no distinction between protected and unprotected
4869
** sqlite3_value objects and they can be used interchangeably. However,
4870
** for maximum code portability it is recommended that applications
4871
** still make the distinction between protected and unprotected
4872
** sqlite3_value objects even when not strictly required.
4873
**
4874
** ^The sqlite3_value objects that are passed as parameters into the
4875
** implementation of [application-defined SQL functions] are protected.
4876
** ^The sqlite3_value objects returned by [sqlite3_vtab_rhs_value()]
4877
** are protected.
4878
** ^The sqlite3_value object returned by
4879
** [sqlite3_column_value()] is unprotected.
4880
** Unprotected sqlite3_value objects may only be used as arguments
4881
** to [sqlite3_result_value()], [sqlite3_bind_value()], and
4882
** [sqlite3_value_dup()].
4883
** The [sqlite3_value_blob | sqlite3_value_type()] family of
4884
** interfaces require protected sqlite3_value objects.
4885
*/
4886
typedef struct sqlite3_value sqlite3_value;
4887
4888
/*
4889
** CAPI3REF: SQL Function Context Object
4890
**
4891
** The context in which an SQL function executes is stored in an
4892
** sqlite3_context object. ^A pointer to an sqlite3_context object
4893
** is always the first parameter to [application-defined SQL functions].
4894
** The application-defined SQL function implementation will pass this
4895
** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
4896
** [sqlite3_aggregate_context()], [sqlite3_user_data()],
4897
** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
4898
** and/or [sqlite3_set_auxdata()].
4899
*/
4900
typedef struct sqlite3_context sqlite3_context;
4901
4902
/*
4903
** CAPI3REF: Binding Values To Prepared Statements
4904
** KEYWORDS: {host parameter} {host parameters} {host parameter name}
4905
** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
4906
** METHOD: sqlite3_stmt
4907
**
4908
** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
4909
** literals may be replaced by a [parameter] that matches one of the following
4910
** templates:
4911
**
4912
** <ul>
4913
** <li> ?
4914
** <li> ?NNN
4915
** <li> :VVV
4916
** <li> @VVV
4917
** <li> $VVV
4918
** </ul>
4919
**
4920
** In the templates above, NNN represents an integer literal,
4921
** and VVV represents an alphanumeric identifier.)^ ^The values of these
4922
** parameters (also called "host parameter names" or "SQL parameters")
4923
** can be set using the sqlite3_bind_*() routines defined here.
4924
**
4925
** ^The first argument to the sqlite3_bind_*() routines is always
4926
** a pointer to the [sqlite3_stmt] object returned from
4927
** [sqlite3_prepare_v2()] or its variants.
4928
**
4929
** ^The second argument is the index of the SQL parameter to be set.
4930
** ^The leftmost SQL parameter has an index of 1. ^When the same named
4931
** SQL parameter is used more than once, second and subsequent
4932
** occurrences have the same index as the first occurrence.
4933
** ^The index for named parameters can be looked up using the
4934
** [sqlite3_bind_parameter_index()] API if desired. ^The index
4935
** for "?NNN" parameters is the value of NNN.
4936
** ^The NNN value must be between 1 and the [sqlite3_limit()]
4937
** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 32766).
4938
**
4939
** ^The third argument is the value to bind to the parameter.
4940
** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16()
4941
** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter
4942
** is ignored and the end result is the same as sqlite3_bind_null().
4943
** ^If the third parameter to sqlite3_bind_text() is not NULL, then
4944
** it should be a pointer to well-formed UTF8 text.
4945
** ^If the third parameter to sqlite3_bind_text16() is not NULL, then
4946
** it should be a pointer to well-formed UTF16 text.
4947
** ^If the third parameter to sqlite3_bind_text64() is not NULL, then
4948
** it should be a pointer to a well-formed unicode string that is
4949
** either UTF8 if the sixth parameter is SQLITE_UTF8 or SQLITE_UTF8_ZT,
4950
** or UTF16 otherwise.
4951
**
4952
** [[byte-order determination rules]] ^The byte-order of
4953
** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF)
4954
** found in the first character, which is removed, or in the absence of a BOM
4955
** the byte order is the native byte order of the host
4956
** machine for sqlite3_bind_text16() or the byte order specified in
4957
** the 6th parameter for sqlite3_bind_text64().)^
4958
** ^If UTF16 input text contains invalid unicode
4959
** characters, then SQLite might change those invalid characters
4960
** into the unicode replacement character: U+FFFD.
4961
**
4962
** ^(In those routines that have a fourth argument, its value is the
4963
** number of bytes in the parameter. To be clear: the value is the
4964
** number of <u>bytes</u> in the value, not the number of characters.)^
4965
** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
4966
** is negative, then the length of the string is
4967
** the number of bytes up to the first zero terminator.
4968
** If the fourth parameter to sqlite3_bind_blob() is negative, then
4969
** the behavior is undefined.
4970
** If a non-negative fourth parameter is provided to sqlite3_bind_text()
4971
** or sqlite3_bind_text16() or sqlite3_bind_text64() then
4972
** that parameter must be the byte offset
4973
** where the NUL terminator would occur assuming the string were NUL
4974
** terminated. If any NUL characters occur at byte offsets less than
4975
** the value of the fourth parameter then the resulting string value will
4976
** contain embedded NULs. The result of expressions involving strings
4977
** with embedded NULs is undefined.
4978
**
4979
** ^The fifth argument to the BLOB and string binding interfaces controls
4980
** or indicates the lifetime of the object referenced by the third parameter.
4981
** These three options exist:
4982
** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished
4983
** with it may be passed. ^It is called to dispose of the BLOB or string even
4984
** if the call to the bind API fails, except the destructor is not called if
4985
** the third parameter is a NULL pointer or the fourth parameter is negative.
4986
** ^ (2) The special constant, [SQLITE_STATIC], may be passed to indicate that
4987
** the application remains responsible for disposing of the object. ^In this
4988
** case, the object and the provided pointer to it must remain valid until
4989
** either the prepared statement is finalized or the same SQL parameter is
4990
** bound to something else, whichever occurs sooner.
4991
** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the
4992
** object is to be copied prior to the return from sqlite3_bind_*(). ^The
4993
** object and pointer to it must remain valid until then. ^SQLite will then
4994
** manage the lifetime of its private copy.
4995
**
4996
** ^The sixth argument (the E argument)
4997
** to sqlite3_bind_text64(S,K,Z,N,D,E) must be one of
4998
** [SQLITE_UTF8], [SQLITE_UTF8_ZT], [SQLITE_UTF16], [SQLITE_UTF16BE],
4999
** or [SQLITE_UTF16LE] to specify the encoding of the text in the
5000
** third parameter, Z. The special value [SQLITE_UTF8_ZT] means that the
5001
** string argument is both UTF-8 encoded and is zero-terminated. In other
5002
** words, SQLITE_UTF8_ZT means that the Z array is allocated to hold at
5003
** least N+1 bytes and that the Z&#91;N&#93; byte is zero. If
5004
** the E argument to sqlite3_bind_text64(S,K,Z,N,D,E) is not one of the
5005
** allowed values shown above, or if the text encoding is different
5006
** from the encoding specified by the sixth parameter, then the behavior
5007
** is undefined.
5008
**
5009
** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
5010
** is filled with zeroes. ^A zeroblob uses a fixed amount of memory
5011
** (just an integer to hold its size) while it is being processed.
5012
** Zeroblobs are intended to serve as placeholders for BLOBs whose
5013
** content is later written using
5014
** [sqlite3_blob_open | incremental BLOB I/O] routines.
5015
** ^A negative value for the zeroblob results in a zero-length BLOB.
5016
**
5017
** ^The sqlite3_bind_pointer(S,I,P,T,D) routine causes the I-th parameter in
5018
** [prepared statement] S to have an SQL value of NULL, but to also be
5019
** associated with the pointer P of type T. ^D is either a NULL pointer or
5020
** a pointer to a destructor function for P. ^SQLite will invoke the
5021
** destructor D with a single argument of P when it is finished using
5022
** P, even if the call to sqlite3_bind_pointer() fails. Due to a
5023
** historical design quirk, results are undefined if D is
5024
** SQLITE_TRANSIENT. The T parameter should be a static string,
5025
** preferably a string literal. The sqlite3_bind_pointer() routine is
5026
** part of the [pointer passing interface] added for SQLite 3.20.0.
5027
**
5028
** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
5029
** for the [prepared statement] or with a prepared statement for which
5030
** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
5031
** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_()
5032
** routine is passed a [prepared statement] that has been finalized, the
5033
** result is undefined and probably harmful.
5034
**
5035
** ^Bindings are not cleared by the [sqlite3_reset()] routine.
5036
** ^Unbound parameters are interpreted as NULL.
5037
**
5038
** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an
5039
** [error code] if anything goes wrong.
5040
** ^[SQLITE_TOOBIG] might be returned if the size of a string or BLOB
5041
** exceeds limits imposed by [sqlite3_limit]([SQLITE_LIMIT_LENGTH]) or
5042
** [SQLITE_MAX_LENGTH].
5043
** ^[SQLITE_RANGE] is returned if the parameter
5044
** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails.
5045
**
5046
** See also: [sqlite3_bind_parameter_count()],
5047
** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
5048
*/
5049
SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
5050
SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,
5051
void(*)(void*));
5052
SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
5053
SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);
5054
SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
5055
SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
5056
SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
5057
SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
5058
SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
5059
void(*)(void*), unsigned char encoding);
5060
SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
5061
SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt*, int, void*, const char*,void(*)(void*));
5062
SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
5063
SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
5064
5065
/*
5066
** CAPI3REF: Number Of SQL Parameters
5067
** METHOD: sqlite3_stmt
5068
**
5069
** ^This routine can be used to find the number of [SQL parameters]
5070
** in a [prepared statement]. SQL parameters are tokens of the
5071
** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
5072
** placeholders for values that are [sqlite3_bind_blob | bound]
5073
** to the parameters at a later time.
5074
**
5075
** ^(This routine actually returns the index of the largest (rightmost)
5076
** parameter. For all forms except ?NNN, this will correspond to the
5077
** number of unique parameters. If parameters of the ?NNN form are used,
5078
** there may be gaps in the list.)^
5079
**
5080
** See also: [sqlite3_bind_blob|sqlite3_bind()],
5081
** [sqlite3_bind_parameter_name()], and
5082
** [sqlite3_bind_parameter_index()].
5083
*/
5084
SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*);
5085
5086
/*
5087
** CAPI3REF: Name Of A Host Parameter
5088
** METHOD: sqlite3_stmt
5089
**
5090
** ^The sqlite3_bind_parameter_name(P,N) interface returns
5091
** the name of the N-th [SQL parameter] in the [prepared statement] P.
5092
** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
5093
** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
5094
** respectively.
5095
** In other words, the initial ":" or "$" or "@" or "?"
5096
** is included as part of the name.)^
5097
** ^Parameters of the form "?" without a following integer have no name
5098
** and are referred to as "nameless" or "anonymous parameters".
5099
**
5100
** ^The first host parameter has an index of 1, not 0.
5101
**
5102
** ^If the value N is out of range or if the N-th parameter is
5103
** nameless, then NULL is returned. ^The returned string is
5104
** always in UTF-8 encoding even if the named parameter was
5105
** originally specified as UTF-16 in [sqlite3_prepare16()],
5106
** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()].
5107
**
5108
** See also: [sqlite3_bind_blob|sqlite3_bind()],
5109
** [sqlite3_bind_parameter_count()], and
5110
** [sqlite3_bind_parameter_index()].
5111
*/
5112
SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
5113
5114
/*
5115
** CAPI3REF: Index Of A Parameter With A Given Name
5116
** METHOD: sqlite3_stmt
5117
**
5118
** ^Return the index of an SQL parameter given its name. ^The
5119
** index value returned is suitable for use as the second
5120
** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero
5121
** is returned if no matching parameter is found. ^The parameter
5122
** name must be given in UTF-8 even if the original statement
5123
** was prepared from UTF-16 text using [sqlite3_prepare16_v2()] or
5124
** [sqlite3_prepare16_v3()].
5125
**
5126
** See also: [sqlite3_bind_blob|sqlite3_bind()],
5127
** [sqlite3_bind_parameter_count()], and
5128
** [sqlite3_bind_parameter_name()].
5129
*/
5130
SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
5131
5132
/*
5133
** CAPI3REF: Reset All Bindings On A Prepared Statement
5134
** METHOD: sqlite3_stmt
5135
**
5136
** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
5137
** the [sqlite3_bind_blob | bindings] on a [prepared statement].
5138
** ^Use this routine to reset all host parameters to NULL.
5139
*/
5140
SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*);
5141
5142
/*
5143
** CAPI3REF: Number Of Columns In A Result Set
5144
** METHOD: sqlite3_stmt
5145
**
5146
** ^Return the number of columns in the result set returned by the
5147
** [prepared statement]. ^If this routine returns 0, that means the
5148
** [prepared statement] returns no data (for example an [UPDATE]).
5149
** ^However, just because this routine returns a positive number does not
5150
** mean that one or more rows of data will be returned. ^A SELECT statement
5151
** will always have a positive sqlite3_column_count() but depending on the
5152
** WHERE clause constraints and the table content, it might return no rows.
5153
**
5154
** See also: [sqlite3_data_count()]
5155
*/
5156
SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);
5157
5158
/*
5159
** CAPI3REF: Column Names In A Result Set
5160
** METHOD: sqlite3_stmt
5161
**
5162
** ^These routines return the name assigned to a particular column
5163
** in the result set of a [SELECT] statement. ^The sqlite3_column_name()
5164
** interface returns a pointer to a zero-terminated UTF-8 string
5165
** and sqlite3_column_name16() returns a pointer to a zero-terminated
5166
** UTF-16 string. ^The first parameter is the [prepared statement]
5167
** that implements the [SELECT] statement. ^The second parameter is the
5168
** column number. ^The leftmost column is number 0.
5169
**
5170
** ^The returned string pointer is valid until either the [prepared statement]
5171
** is destroyed by [sqlite3_finalize()] or until the statement is automatically
5172
** reprepared by the first call to [sqlite3_step()] for a particular run
5173
** or until the next call to
5174
** sqlite3_column_name() or sqlite3_column_name16() on the same column.
5175
**
5176
** ^If sqlite3_malloc() fails during the processing of either routine
5177
** (for example during a conversion from UTF-8 to UTF-16) then a
5178
** NULL pointer is returned.
5179
**
5180
** ^The name of a result column is the value of the "AS" clause for
5181
** that column, if there is an AS clause. If there is no AS clause
5182
** then the name of the column is unspecified and may change from
5183
** one release of SQLite to the next.
5184
*/
5185
SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N);
5186
SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N);
5187
5188
/*
5189
** CAPI3REF: Source Of Data In A Query Result
5190
** METHOD: sqlite3_stmt
5191
**
5192
** ^These routines provide a means to determine the database, table, and
5193
** table column that is the origin of a particular result column in a
5194
** [SELECT] statement.
5195
** ^The name of the database or table or column can be returned as
5196
** either a UTF-8 or UTF-16 string. ^The _database_ routines return
5197
** the database name, the _table_ routines return the table name, and
5198
** the origin_ routines return the column name.
5199
** ^The returned string is valid until the [prepared statement] is destroyed
5200
** using [sqlite3_finalize()] or until the statement is automatically
5201
** reprepared by the first call to [sqlite3_step()] for a particular run
5202
** or until the same information is requested
5203
** again in a different encoding.
5204
**
5205
** ^The names returned are the original un-aliased names of the
5206
** database, table, and column.
5207
**
5208
** ^The first argument to these interfaces is a [prepared statement].
5209
** ^These functions return information about the Nth result column returned by
5210
** the statement, where N is the second function argument.
5211
** ^The left-most column is column 0 for these routines.
5212
**
5213
** ^If the Nth column returned by the statement is an expression or
5214
** subquery and is not a column value, then all of these functions return
5215
** NULL. ^These routines might also return NULL if a memory allocation error
5216
** occurs. ^Otherwise, they return the name of the attached database, table,
5217
** or column that query result column was extracted from.
5218
**
5219
** ^As with all other SQLite APIs, those whose names end with "16" return
5220
** UTF-16 encoded strings and the other functions return UTF-8.
5221
**
5222
** ^These APIs are only available if the library was compiled with the
5223
** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
5224
**
5225
** If two or more threads call one or more
5226
** [sqlite3_column_database_name | column metadata interfaces]
5227
** for the same [prepared statement] and result column
5228
** at the same time then the results are undefined.
5229
*/
5230
SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int);
5231
SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
5232
SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int);
5233
SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
5234
SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
5235
SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);
5236
5237
/*
5238
** CAPI3REF: Declared Datatype Of A Query Result
5239
** METHOD: sqlite3_stmt
5240
**
5241
** ^(The first parameter is a [prepared statement].
5242
** If this statement is a [SELECT] statement and the Nth column of the
5243
** returned result set of that [SELECT] is a table column (not an
5244
** expression or subquery) then the declared type of the table
5245
** column is returned.)^ ^If the Nth column of the result set is an
5246
** expression or subquery, then a NULL pointer is returned.
5247
** ^The returned string is always UTF-8 encoded.
5248
**
5249
** ^(For example, given the database schema:
5250
**
5251
** CREATE TABLE t1(c1 VARIANT);
5252
**
5253
** and the following statement to be compiled:
5254
**
5255
** SELECT c1 + 1, c1 FROM t1;
5256
**
5257
** this routine would return the string "VARIANT" for the second result
5258
** column (i==1), and a NULL pointer for the first result column (i==0).)^
5259
**
5260
** ^SQLite uses dynamic run-time typing. ^So just because a column
5261
** is declared to contain a particular type does not mean that the
5262
** data stored in that column is of the declared type. SQLite is
5263
** strongly typed, but the typing is dynamic not static. ^Type
5264
** is associated with individual values, not with the containers
5265
** used to hold those values.
5266
*/
5267
SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int);
5268
SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int);
5269
5270
/*
5271
** CAPI3REF: Evaluate An SQL Statement
5272
** METHOD: sqlite3_stmt
5273
**
5274
** After a [prepared statement] has been prepared using any of
5275
** [sqlite3_prepare_v2()], [sqlite3_prepare_v3()], [sqlite3_prepare16_v2()],
5276
** or [sqlite3_prepare16_v3()] or one of the legacy
5277
** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
5278
** must be called one or more times to evaluate the statement.
5279
**
5280
** The details of the behavior of the sqlite3_step() interface depend
5281
** on whether the statement was prepared using the newer "vX" interfaces
5282
** [sqlite3_prepare_v3()], [sqlite3_prepare_v2()], [sqlite3_prepare16_v3()],
5283
** [sqlite3_prepare16_v2()] or the older legacy
5284
** interfaces [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the
5285
** new "vX" interface is recommended for new applications but the legacy
5286
** interface will continue to be supported.
5287
**
5288
** ^In the legacy interface, the return value will be either [SQLITE_BUSY],
5289
** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
5290
** ^With the "v2" interface, any of the other [result codes] or
5291
** [extended result codes] might be returned as well.
5292
**
5293
** ^[SQLITE_BUSY] means that the database engine was unable to acquire the
5294
** database locks it needs to do its job. ^If the statement is a [COMMIT]
5295
** or occurs outside of an explicit transaction, then you can retry the
5296
** statement. If the statement is not a [COMMIT] and occurs within an
5297
** explicit transaction then you should rollback the transaction before
5298
** continuing.
5299
**
5300
** ^[SQLITE_DONE] means that the statement has finished executing
5301
** successfully. sqlite3_step() should not be called again on this virtual
5302
** machine without first calling [sqlite3_reset()] to reset the virtual
5303
** machine back to its initial state.
5304
**
5305
** ^If the SQL statement being executed returns any data, then [SQLITE_ROW]
5306
** is returned each time a new row of data is ready for processing by the
5307
** caller. The values may be accessed using the [column access functions].
5308
** sqlite3_step() is called again to retrieve the next row of data.
5309
**
5310
** ^[SQLITE_ERROR] means that a run-time error (such as a constraint
5311
** violation) has occurred. sqlite3_step() should not be called again on
5312
** the VM. More information may be found by calling [sqlite3_errmsg()].
5313
** ^With the legacy interface, a more specific error code (for example,
5314
** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
5315
** can be obtained by calling [sqlite3_reset()] on the
5316
** [prepared statement]. ^In the "v2" interface,
5317
** the more specific error code is returned directly by sqlite3_step().
5318
**
5319
** [SQLITE_MISUSE] means that this routine was called inappropriately.
5320
** Perhaps it was called on a [prepared statement] that has
5321
** already been [sqlite3_finalize | finalized] or on one that had
5322
** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could
5323
** be the case that the same database connection is being used by two or
5324
** more threads at the same moment in time.
5325
**
5326
** For all versions of SQLite up to and including 3.6.23.1, a call to
5327
** [sqlite3_reset()] was required after sqlite3_step() returned anything
5328
** other than [SQLITE_ROW] before any subsequent invocation of
5329
** sqlite3_step(). Failure to reset the prepared statement using
5330
** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
5331
** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1]),
5332
** sqlite3_step() began
5333
** calling [sqlite3_reset()] automatically in this circumstance rather
5334
** than returning [SQLITE_MISUSE]. This is not considered a compatibility
5335
** break because any application that ever receives an SQLITE_MISUSE error
5336
** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option
5337
** can be used to restore the legacy behavior.
5338
**
5339
** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step()
5340
** API always returns a generic error code, [SQLITE_ERROR], following any
5341
** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call
5342
** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the
5343
** specific [error codes] that better describes the error.
5344
** We admit that this is a goofy design. The problem has been fixed
5345
** with the "v2" interface. If you prepare all of your SQL statements
5346
** using [sqlite3_prepare_v3()] or [sqlite3_prepare_v2()]
5347
** or [sqlite3_prepare16_v2()] or [sqlite3_prepare16_v3()] instead
5348
** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces,
5349
** then the more specific [error codes] are returned directly
5350
** by sqlite3_step(). The use of the "vX" interfaces is recommended.
5351
*/
5352
SQLITE_API int sqlite3_step(sqlite3_stmt*);
5353
5354
/*
5355
** CAPI3REF: Number of columns in a result set
5356
** METHOD: sqlite3_stmt
5357
**
5358
** ^The sqlite3_data_count(P) interface returns the number of columns in the
5359
** current row of the result set of [prepared statement] P.
5360
** ^If prepared statement P does not have results ready to return
5361
** (via calls to the [sqlite3_column_int | sqlite3_column()] family of
5362
** interfaces) then sqlite3_data_count(P) returns 0.
5363
** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
5364
** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
5365
** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P)
5366
** will return non-zero if previous call to [sqlite3_step](P) returned
5367
** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum]
5368
** where it always returns zero since each step of that multi-step
5369
** pragma returns 0 columns of data.
5370
**
5371
** See also: [sqlite3_column_count()]
5372
*/
5373
SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
5374
5375
/*
5376
** CAPI3REF: Fundamental Datatypes
5377
** KEYWORDS: SQLITE_TEXT
5378
**
5379
** ^(Every value in SQLite has one of five fundamental datatypes:
5380
**
5381
** <ul>
5382
** <li> 64-bit signed integer
5383
** <li> 64-bit IEEE floating point number
5384
** <li> string
5385
** <li> BLOB
5386
** <li> NULL
5387
** </ul>)^
5388
**
5389
** These constants are codes for each of those types.
5390
**
5391
** Note that the SQLITE_TEXT constant was also used in SQLite version 2
5392
** for a completely different meaning. Software that links against both
5393
** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not
5394
** SQLITE_TEXT.
5395
*/
5396
#define SQLITE_INTEGER 1
5397
#define SQLITE_FLOAT 2
5398
#define SQLITE_BLOB 4
5399
#define SQLITE_NULL 5
5400
#ifdef SQLITE_TEXT
5401
# undef SQLITE_TEXT
5402
#else
5403
# define SQLITE_TEXT 3
5404
#endif
5405
#define SQLITE3_TEXT 3
5406
5407
/*
5408
** CAPI3REF: Result Values From A Query
5409
** KEYWORDS: {column access functions}
5410
** METHOD: sqlite3_stmt
5411
**
5412
** <b>Summary:</b>
5413
** <blockquote><table border=0 cellpadding=0 cellspacing=0>
5414
** <tr><td><b>sqlite3_column_blob</b><td>&rarr;<td>BLOB result
5415
** <tr><td><b>sqlite3_column_double</b><td>&rarr;<td>REAL result
5416
** <tr><td><b>sqlite3_column_int</b><td>&rarr;<td>32-bit INTEGER result
5417
** <tr><td><b>sqlite3_column_int64</b><td>&rarr;<td>64-bit INTEGER result
5418
** <tr><td><b>sqlite3_column_text</b><td>&rarr;<td>UTF-8 TEXT result
5419
** <tr><td><b>sqlite3_column_text16</b><td>&rarr;<td>UTF-16 TEXT result
5420
** <tr><td><b>sqlite3_column_value</b><td>&rarr;<td>The result as an
5421
** [sqlite3_value|unprotected sqlite3_value] object.
5422
** <tr><td>&nbsp;<td>&nbsp;<td>&nbsp;
5423
** <tr><td><b>sqlite3_column_bytes</b><td>&rarr;<td>Size of a BLOB
5424
** or a UTF-8 TEXT result in bytes
5425
** <tr><td><b>sqlite3_column_bytes16&nbsp;&nbsp;</b>
5426
** <td>&rarr;&nbsp;&nbsp;<td>Size of UTF-16
5427
** TEXT in bytes
5428
** <tr><td><b>sqlite3_column_type</b><td>&rarr;<td>Default
5429
** datatype of the result
5430
** </table></blockquote>
5431
**
5432
** <b>Details:</b>
5433
**
5434
** ^These routines return information about a single column of the current
5435
** result row of a query. ^In every case the first argument is a pointer
5436
** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*]
5437
** that was returned from [sqlite3_prepare_v2()] or one of its variants)
5438
** and the second argument is the index of the column for which information
5439
** should be returned. ^The leftmost column of the result set has the index 0.
5440
** ^The number of columns in the result can be determined using
5441
** [sqlite3_column_count()].
5442
**
5443
** If the SQL statement does not currently point to a valid row, or if the
5444
** column index is out of range, the result is undefined.
5445
** These routines may only be called when the most recent call to
5446
** [sqlite3_step()] has returned [SQLITE_ROW] and neither
5447
** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently.
5448
** If any of these routines are called after [sqlite3_reset()] or
5449
** [sqlite3_finalize()] or after [sqlite3_step()] has returned
5450
** something other than [SQLITE_ROW], the results are undefined.
5451
** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()]
5452
** are called from a different thread while any of these routines
5453
** are pending, then the results are undefined.
5454
**
5455
** The first six interfaces (_blob, _double, _int, _int64, _text, and _text16)
5456
** each return the value of a result column in a specific data format. If
5457
** the result column is not initially in the requested format (for example,
5458
** if the query returns an integer but the sqlite3_column_text() interface
5459
** is used to extract the value) then an automatic type conversion is performed.
5460
**
5461
** ^The sqlite3_column_type() routine returns the
5462
** [SQLITE_INTEGER | datatype code] for the initial data type
5463
** of the result column. ^The returned value is one of [SQLITE_INTEGER],
5464
** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].
5465
** The return value of sqlite3_column_type() can be used to decide which
5466
** of the first six interface should be used to extract the column value.
5467
** The value returned by sqlite3_column_type() is only meaningful if no
5468
** automatic type conversions have occurred for the value in question.
5469
** After a type conversion, the result of calling sqlite3_column_type()
5470
** is undefined, though harmless. Future
5471
** versions of SQLite may change the behavior of sqlite3_column_type()
5472
** following a type conversion.
5473
**
5474
** If the result is a BLOB or a TEXT string, then the sqlite3_column_bytes()
5475
** or sqlite3_column_bytes16() interfaces can be used to determine the size
5476
** of that BLOB or string.
5477
**
5478
** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes()
5479
** routine returns the number of bytes in that BLOB or string.
5480
** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts
5481
** the string to UTF-8 and then returns the number of bytes.
5482
** ^If the result is a numeric value then sqlite3_column_bytes() uses
5483
** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
5484
** the number of bytes in that string.
5485
** ^If the result is NULL, then sqlite3_column_bytes() returns zero.
5486
**
5487
** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16()
5488
** routine returns the number of bytes in that BLOB or string.
5489
** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts
5490
** the string to UTF-16 and then returns the number of bytes.
5491
** ^If the result is a numeric value then sqlite3_column_bytes16() uses
5492
** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns
5493
** the number of bytes in that string.
5494
** ^If the result is NULL, then sqlite3_column_bytes16() returns zero.
5495
**
5496
** ^The values returned by [sqlite3_column_bytes()] and
5497
** [sqlite3_column_bytes16()] do not include the zero terminators at the end
5498
** of the string. ^For clarity: the values returned by
5499
** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of
5500
** bytes in the string, not the number of characters.
5501
**
5502
** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
5503
** even empty strings, are always zero-terminated. ^The return
5504
** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.
5505
**
5506
** ^Strings returned by sqlite3_column_text16() always have the endianness
5507
** which is native to the platform, regardless of the text encoding set
5508
** for the database.
5509
**
5510
** <b>Warning:</b> ^The object returned by [sqlite3_column_value()] is an
5511
** [unprotected sqlite3_value] object. In a multithreaded environment,
5512
** an unprotected sqlite3_value object may only be used safely with
5513
** [sqlite3_bind_value()] and [sqlite3_result_value()].
5514
** If the [unprotected sqlite3_value] object returned by
5515
** [sqlite3_column_value()] is used in any other way, including calls
5516
** to routines like [sqlite3_value_int()], [sqlite3_value_text()],
5517
** or [sqlite3_value_bytes()], the behavior is not threadsafe.
5518
** Hence, the sqlite3_column_value() interface
5519
** is normally only useful within the implementation of
5520
** [application-defined SQL functions] or [virtual tables], not within
5521
** top-level application code.
5522
**
5523
** These routines may attempt to convert the datatype of the result.
5524
** ^For example, if the internal representation is FLOAT and a text result
5525
** is requested, [sqlite3_snprintf()] is used internally to perform the
5526
** conversion automatically. ^(The following table details the conversions
5527
** that are applied:
5528
**
5529
** <blockquote>
5530
** <table border="1">
5531
** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion
5532
**
5533
** <tr><td> NULL <td> INTEGER <td> Result is 0
5534
** <tr><td> NULL <td> FLOAT <td> Result is 0.0
5535
** <tr><td> NULL <td> TEXT <td> Result is a NULL pointer
5536
** <tr><td> NULL <td> BLOB <td> Result is a NULL pointer
5537
** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float
5538
** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer
5539
** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT
5540
** <tr><td> FLOAT <td> INTEGER <td> [CAST] to INTEGER
5541
** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float
5542
** <tr><td> FLOAT <td> BLOB <td> [CAST] to BLOB
5543
** <tr><td> TEXT <td> INTEGER <td> [CAST] to INTEGER
5544
** <tr><td> TEXT <td> FLOAT <td> [CAST] to REAL
5545
** <tr><td> TEXT <td> BLOB <td> No change
5546
** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER
5547
** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL
5548
** <tr><td> BLOB <td> TEXT <td> [CAST] to TEXT, ensure zero terminator
5549
** </table>
5550
** </blockquote>)^
5551
**
5552
** Note that when type conversions occur, pointers returned by prior
5553
** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
5554
** sqlite3_column_text16() may be invalidated.
5555
** Type conversions and pointer invalidations might occur
5556
** in the following cases:
5557
**
5558
** <ul>
5559
** <li> The initial content is a BLOB and sqlite3_column_text() or
5560
** sqlite3_column_text16() is called. A zero-terminator might
5561
** need to be added to the string.</li>
5562
** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or
5563
** sqlite3_column_text16() is called. The content must be converted
5564
** to UTF-16.</li>
5565
** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or
5566
** sqlite3_column_text() is called. The content must be converted
5567
** to UTF-8.</li>
5568
** </ul>
5569
**
5570
** ^Conversions between UTF-16be and UTF-16le are always done in place and do
5571
** not invalidate a prior pointer, though of course the content of the buffer
5572
** that the prior pointer references will have been modified. Other kinds
5573
** of conversion are done in place when it is possible, but sometimes they
5574
** are not possible and in those cases prior pointers are invalidated.
5575
**
5576
** The safest policy is to invoke these routines
5577
** in one of the following ways:
5578
**
5579
** <ul>
5580
** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
5581
** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
5582
** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
5583
** </ul>
5584
**
5585
** In other words, you should call sqlite3_column_text(),
5586
** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result
5587
** into the desired format, then invoke sqlite3_column_bytes() or
5588
** sqlite3_column_bytes16() to find the size of the result. Do not mix calls
5589
** to sqlite3_column_text() or sqlite3_column_blob() with calls to
5590
** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16()
5591
** with calls to sqlite3_column_bytes().
5592
**
5593
** ^The pointers returned are valid until a type conversion occurs as
5594
** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
5595
** [sqlite3_finalize()] is called. ^The memory space used to hold strings
5596
** and BLOBs is freed automatically. Do not pass the pointers returned
5597
** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
5598
** [sqlite3_free()].
5599
**
5600
** As long as the input parameters are correct, these routines will only
5601
** fail if an out-of-memory error occurs during a format conversion.
5602
** Only the following subset of interfaces are subject to out-of-memory
5603
** errors:
5604
**
5605
** <ul>
5606
** <li> sqlite3_column_blob()
5607
** <li> sqlite3_column_text()
5608
** <li> sqlite3_column_text16()
5609
** <li> sqlite3_column_bytes()
5610
** <li> sqlite3_column_bytes16()
5611
** </ul>
5612
**
5613
** If an out-of-memory error occurs, then the return value from these
5614
** routines is the same as if the column had contained an SQL NULL value.
5615
** Valid SQL NULL returns can be distinguished from out-of-memory errors
5616
** by invoking the [sqlite3_errcode()] immediately after the suspect
5617
** return value is obtained and before any
5618
** other SQLite interface is called on the same [database connection].
5619
*/
5620
SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
5621
SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol);
5622
SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol);
5623
SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
5624
SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
5625
SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
5626
SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
5627
SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
5628
SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
5629
SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol);
5630
5631
/*
5632
** CAPI3REF: Destroy A Prepared Statement Object
5633
** DESTRUCTOR: sqlite3_stmt
5634
**
5635
** ^The sqlite3_finalize() function is called to delete a [prepared statement].
5636
** ^If the most recent evaluation of the statement encountered no errors
5637
** or if the statement has never been evaluated, then sqlite3_finalize() returns
5638
** SQLITE_OK. ^If the most recent evaluation of statement S failed, then
5639
** sqlite3_finalize(S) returns the appropriate [error code] or
5640
** [extended error code].
5641
**
5642
** ^The sqlite3_finalize(S) routine can be called at any point during
5643
** the life cycle of [prepared statement] S:
5644
** before statement S is ever evaluated, after
5645
** one or more calls to [sqlite3_reset()], or after any call
5646
** to [sqlite3_step()] regardless of whether or not the statement has
5647
** completed execution.
5648
**
5649
** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op.
5650
**
5651
** The application must finalize every [prepared statement] in order to avoid
5652
** resource leaks. It is a grievous error for the application to try to use
5653
** a prepared statement after it has been finalized. Any use of a prepared
5654
** statement after it has been finalized can result in undefined and
5655
** undesirable behavior such as segfaults and heap corruption.
5656
*/
5657
SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);
5658
5659
/*
5660
** CAPI3REF: Reset A Prepared Statement Object
5661
** METHOD: sqlite3_stmt
5662
**
5663
** The sqlite3_reset() function is called to reset a [prepared statement]
5664
** object back to its initial state, ready to be re-executed.
5665
** ^Any SQL statement variables that had values bound to them using
5666
** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
5667
** Use [sqlite3_clear_bindings()] to reset the bindings.
5668
**
5669
** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S
5670
** back to the beginning of its program.
5671
**
5672
** ^The return code from [sqlite3_reset(S)] indicates whether or not
5673
** the previous evaluation of prepared statement S completed successfully.
5674
** ^If [sqlite3_step(S)] has never before been called on S or if
5675
** [sqlite3_step(S)] has not been called since the previous call
5676
** to [sqlite3_reset(S)], then [sqlite3_reset(S)] will return
5677
** [SQLITE_OK].
5678
**
5679
** ^If the most recent call to [sqlite3_step(S)] for the
5680
** [prepared statement] S indicated an error, then
5681
** [sqlite3_reset(S)] returns an appropriate [error code].
5682
** ^The [sqlite3_reset(S)] interface might also return an [error code]
5683
** if there were no prior errors but the process of resetting
5684
** the prepared statement caused a new error. ^For example, if an
5685
** [INSERT] statement with a [RETURNING] clause is only stepped one time,
5686
** that one call to [sqlite3_step(S)] might return SQLITE_ROW but
5687
** the overall statement might still fail and the [sqlite3_reset(S)] call
5688
** might return SQLITE_BUSY if locking constraints prevent the
5689
** database change from committing. Therefore, it is important that
5690
** applications check the return code from [sqlite3_reset(S)] even if
5691
** no prior call to [sqlite3_step(S)] indicated a problem.
5692
**
5693
** ^The [sqlite3_reset(S)] interface does not change the values
5694
** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
5695
*/
5696
SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
5697
5698
5699
/*
5700
** CAPI3REF: Create Or Redefine SQL Functions
5701
** KEYWORDS: {function creation routines}
5702
** METHOD: sqlite3
5703
**
5704
** ^These functions (collectively known as "function creation routines")
5705
** are used to add SQL functions or aggregates or to redefine the behavior
5706
** of existing SQL functions or aggregates. The only differences between
5707
** the three "sqlite3_create_function*" routines are the text encoding
5708
** expected for the second parameter (the name of the function being
5709
** created) and the presence or absence of a destructor callback for
5710
** the application data pointer. Function sqlite3_create_window_function()
5711
** is similar, but allows the user to supply the extra callback functions
5712
** needed by [aggregate window functions].
5713
**
5714
** ^The first parameter is the [database connection] to which the SQL
5715
** function is to be added. ^If an application uses more than one database
5716
** connection then application-defined SQL functions must be added
5717
** to each database connection separately.
5718
**
5719
** ^The second parameter is the name of the SQL function to be created or
5720
** redefined. ^The length of the name is limited to 255 bytes in a UTF-8
5721
** representation, exclusive of the zero-terminator. ^Note that the name
5722
** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes.
5723
** ^Any attempt to create a function with a longer name
5724
** will result in [SQLITE_MISUSE] being returned.
5725
**
5726
** ^The third parameter (nArg)
5727
** is the number of arguments that the SQL function or
5728
** aggregate takes. ^If this parameter is -1, then the SQL function or
5729
** aggregate may take any number of arguments between 0 and the limit
5730
** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third
5731
** parameter is less than -1 or greater than 127 then the behavior is
5732
** undefined.
5733
**
5734
** ^The fourth parameter, eTextRep, specifies what
5735
** [SQLITE_UTF8 | text encoding] this SQL function prefers for
5736
** its parameters. The application should set this parameter to
5737
** [SQLITE_UTF16LE] if the function implementation invokes
5738
** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the
5739
** implementation invokes [sqlite3_value_text16be()] on an input, or
5740
** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8]
5741
** otherwise. ^The same SQL function may be registered multiple times using
5742
** different preferred text encodings, with different implementations for
5743
** each encoding.
5744
** ^When multiple implementations of the same function are available, SQLite
5745
** will pick the one that involves the least amount of data conversion.
5746
**
5747
** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC]
5748
** to signal that the function will always return the same result given
5749
** the same inputs within a single SQL statement. Most SQL functions are
5750
** deterministic. The built-in [random()] SQL function is an example of a
5751
** function that is not deterministic. The SQLite query planner is able to
5752
** perform additional optimizations on deterministic functions, so use
5753
** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
5754
**
5755
** ^The fourth parameter may also optionally include the [SQLITE_DIRECTONLY]
5756
** flag, which if present prevents the function from being invoked from
5757
** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions,
5758
** index expressions, or the WHERE clause of partial indexes.
5759
**
5760
** For best security, the [SQLITE_DIRECTONLY] flag is recommended for
5761
** all application-defined SQL functions that do not need to be
5762
** used inside of triggers, views, CHECK constraints, or other elements of
5763
** the database schema. This flag is especially recommended for SQL
5764
** functions that have side effects or reveal internal application state.
5765
** Without this flag, an attacker might be able to modify the schema of
5766
** a database file to include invocations of the function with parameters
5767
** chosen by the attacker, which the application will then execute when
5768
** the database file is opened and read.
5769
**
5770
** ^(The fifth parameter is an arbitrary pointer. The implementation of the
5771
** function can gain access to this pointer using [sqlite3_user_data()].)^
5772
**
5773
** ^The sixth, seventh and eighth parameters passed to the three
5774
** "sqlite3_create_function*" functions, xFunc, xStep and xFinal, are
5775
** pointers to C-language functions that implement the SQL function or
5776
** aggregate. ^A scalar SQL function requires an implementation of the xFunc
5777
** callback only; NULL pointers must be passed as the xStep and xFinal
5778
** parameters. ^An aggregate SQL function requires an implementation of xStep
5779
** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
5780
** SQL function or aggregate, pass NULL pointers for all three function
5781
** callbacks.
5782
**
5783
** ^The sixth, seventh, eighth and ninth parameters (xStep, xFinal, xValue
5784
** and xInverse) passed to sqlite3_create_window_function are pointers to
5785
** C-language callbacks that implement the new function. xStep and xFinal
5786
** must both be non-NULL. xValue and xInverse may either both be NULL, in
5787
** which case a regular aggregate function is created, or must both be
5788
** non-NULL, in which case the new function may be used as either an aggregate
5789
** or aggregate window function. More details regarding the implementation
5790
** of aggregate window functions are
5791
** [user-defined window functions|available here].
5792
**
5793
** ^(If the final parameter to sqlite3_create_function_v2() or
5794
** sqlite3_create_window_function() is not NULL, then it is the destructor for
5795
** the application data pointer. The destructor is invoked when the function
5796
** is deleted, either by being overloaded or when the database connection
5797
** closes.)^ ^The destructor is also invoked if the call to
5798
** sqlite3_create_function_v2() fails. ^When the destructor callback is
5799
** invoked, it is passed a single argument which is a copy of the application
5800
** data pointer which was the fifth parameter to sqlite3_create_function_v2().
5801
**
5802
** ^It is permitted to register multiple implementations of the same
5803
** functions with the same name but with either differing numbers of
5804
** arguments or differing preferred text encodings. ^SQLite will use
5805
** the implementation that most closely matches the way in which the
5806
** SQL function is used. ^A function implementation with a non-negative
5807
** nArg parameter is a better match than a function implementation with
5808
** a negative nArg. ^A function where the preferred text encoding
5809
** matches the database encoding is a better
5810
** match than a function where the encoding is different.
5811
** ^A function where the encoding difference is between UTF16le and UTF16be
5812
** is a closer match than a function where the encoding difference is
5813
** between UTF8 and UTF16.
5814
**
5815
** ^Built-in functions may be overloaded by new application-defined functions.
5816
**
5817
** ^An application-defined function is permitted to call other
5818
** SQLite interfaces. However, such calls must not
5819
** close the database connection nor finalize or reset the prepared
5820
** statement in which the function is running.
5821
*/
5822
SQLITE_API int sqlite3_create_function(
5823
sqlite3 *db,
5824
const char *zFunctionName,
5825
int nArg,
5826
int eTextRep,
5827
void *pApp,
5828
void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
5829
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
5830
void (*xFinal)(sqlite3_context*)
5831
);
5832
SQLITE_API int sqlite3_create_function16(
5833
sqlite3 *db,
5834
const void *zFunctionName,
5835
int nArg,
5836
int eTextRep,
5837
void *pApp,
5838
void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
5839
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
5840
void (*xFinal)(sqlite3_context*)
5841
);
5842
SQLITE_API int sqlite3_create_function_v2(
5843
sqlite3 *db,
5844
const char *zFunctionName,
5845
int nArg,
5846
int eTextRep,
5847
void *pApp,
5848
void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
5849
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
5850
void (*xFinal)(sqlite3_context*),
5851
void(*xDestroy)(void*)
5852
);
5853
SQLITE_API int sqlite3_create_window_function(
5854
sqlite3 *db,
5855
const char *zFunctionName,
5856
int nArg,
5857
int eTextRep,
5858
void *pApp,
5859
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
5860
void (*xFinal)(sqlite3_context*),
5861
void (*xValue)(sqlite3_context*),
5862
void (*xInverse)(sqlite3_context*,int,sqlite3_value**),
5863
void(*xDestroy)(void*)
5864
);
5865
5866
/*
5867
** CAPI3REF: Text Encodings
5868
**
5869
** These constants define integer codes that represent the various
5870
** text encodings supported by SQLite.
5871
**
5872
** <dl>
5873
** [[SQLITE_UTF8]] <dt>SQLITE_UTF8</dt><dd>Text is encoding as UTF-8</dd>
5874
**
5875
** [[SQLITE_UTF16LE]] <dt>SQLITE_UTF16LE</dt><dd>Text is encoding as UTF-16
5876
** with each code point being expressed "little endian" - the least significant
5877
** byte first. This is the usual encoding, for example on Windows.</dd>
5878
**
5879
** [[SQLITE_UTF16BE]] <dt>SQLITE_UTF16BE</dt><dd>Text is encoding as UTF-16
5880
** with each code point being expressed "big endian" - the most significant
5881
** byte first. This encoding is less common, but is still sometimes seen,
5882
** specially on older systems.
5883
**
5884
** [[SQLITE_UTF16]] <dt>SQLITE_UTF16</dt><dd>Text is encoding as UTF-16
5885
** with each code point being expressed either little endian or as big
5886
** endian, according to the native endianness of the host computer.
5887
**
5888
** [[SQLITE_ANY]] <dt>SQLITE_ANY</dt><dd>This encoding value may only be used
5889
** to declare the preferred text for [application-defined SQL functions]
5890
** created using [sqlite3_create_function()] and similar. If the preferred
5891
** encoding (the 4th parameter to sqlite3_create_function() - the eTextRep
5892
** parameter) is SQLITE_ANY, that indicates that the function does not have
5893
** a preference regarding the text encoding of its parameters and can take
5894
** any text encoding that the SQLite core find convenient to supply. This
5895
** option is deprecated. Please do not use it in new applications.
5896
**
5897
** [[SQLITE_UTF16_ALIGNED]] <dt>SQLITE_UTF16_ALIGNED</dt><dd>This encoding
5898
** value may be used as the 3rd parameter (the eTextRep parameter) to
5899
** [sqlite3_create_collation()] and similar. This encoding value means
5900
** that the application-defined collating sequence created expects its
5901
** input strings to be in UTF16 in native byte order, and that the start
5902
** of the strings must be aligned to a 2-byte boundary.
5903
**
5904
** [[SQLITE_UTF8_ZT]] <dt>SQLITE_UTF8_ZT</dt><dd>This option can only be
5905
** used to specify the text encoding to strings input to
5906
** [sqlite3_result_text64()] and [sqlite3_bind_text64()].
5907
** The SQLITE_UTF8_ZT encoding means that the input string (call it "z")
5908
** is UTF-8 encoded and that it is zero-terminated. If the length parameter
5909
** (call it "n") is non-negative, this encoding option means that the caller
5910
** guarantees that z array contains at least n+1 bytes and that the z&#91;n&#93;
5911
** byte has a value of zero.
5912
** This option gives the same output as SQLITE_UTF8, but can be more efficient
5913
** by avoiding the need to make a copy of the input string, in some cases.
5914
** However, if z is allocated to hold fewer than n+1 bytes or if the
5915
** z&#91;n&#93; byte is not zero, undefined behavior may result.
5916
** </dl>
5917
*/
5918
#define SQLITE_UTF8 1 /* IMP: R-37514-35566 */
5919
#define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */
5920
#define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */
5921
#define SQLITE_UTF16 4 /* Use native byte order */
5922
#define SQLITE_ANY 5 /* Deprecated */
5923
#define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
5924
#define SQLITE_UTF8_ZT 16 /* Zero-terminated UTF8 */
5925
5926
/*
5927
** CAPI3REF: Function Flags
5928
**
5929
** These constants may be ORed together with the
5930
** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
5931
** to [sqlite3_create_function()], [sqlite3_create_function16()], or
5932
** [sqlite3_create_function_v2()].
5933
**
5934
** <dl>
5935
** [[SQLITE_DETERMINISTIC]] <dt>SQLITE_DETERMINISTIC</dt><dd>
5936
** The SQLITE_DETERMINISTIC flag means that the new function always gives
5937
** the same output when the input parameters are the same.
5938
** The [abs|abs() function] is deterministic, for example, but
5939
** [randomblob|randomblob()] is not. Functions must
5940
** be deterministic in order to be used in certain contexts such as
5941
** with the WHERE clause of [partial indexes] or in [generated columns].
5942
** SQLite might also optimize deterministic functions by factoring them
5943
** out of inner loops.
5944
** </dd>
5945
**
5946
** [[SQLITE_DIRECTONLY]] <dt>SQLITE_DIRECTONLY</dt><dd>
5947
** The SQLITE_DIRECTONLY flag means that the function may only be invoked
5948
** from top-level SQL, and cannot be used in VIEWs or TRIGGERs nor in
5949
** schema structures such as [CHECK constraints], [DEFAULT clauses],
5950
** [expression indexes], [partial indexes], or [generated columns].
5951
** <p>
5952
** The SQLITE_DIRECTONLY flag is recommended for any
5953
** [application-defined SQL function]
5954
** that has side-effects or that could potentially leak sensitive information.
5955
** This will prevent attacks in which an application is tricked