1 /++ Auto-generated C API bindings. +/
2 /*
3 ** 2001-09-15
4 **
5 ** The author disclaims copyright to this source code.  In place of
6 ** a legal notice, here is a blessing:
7 **
8 **    May you do good and not evil.
9 **    May you find forgiveness for yourself and forgive others.
10 **    May you share freely, never taking more than you give.
11 **
12 *************************************************************************
13 ** This header file defines the interface that the SQLite library
14 ** presents to client programs.  If a C-function, structure, datatype,
15 ** or constant definition does not appear in this file, then it is
16 ** not a published API of SQLite, is subject to change without
17 ** notice, and should not be referenced by programs that use SQLite.
18 **
19 ** Some of the definitions that are in this file are marked as
20 ** "experimental".  Experimental interfaces are normally new
21 ** features recently added to SQLite.  We do not anticipate changes
22 ** to experimental interfaces but reserve the right to make minor changes
23 ** if experience from use "in the wild" suggest such changes are prudent.
24 **
25 ** The official C-language API documentation for SQLite is derived
26 ** from comments in this file.  This file is the authoritative source
27 ** on how SQLite interfaces are supposed to operate.
28 **
29 ** The name of this file under configuration management is "sqlite.h.in".
30 ** The makefile makes some minor changes to this file (such as inserting
31 ** the version number) and changes its name to "sqlite3.h" as
32 ** part of the build process.
33 */
34 
35 module d2sqlite3.sqlite3;
36 
37 import core.stdc.config;
38 import core.stdc.stdarg;
39 
40 extern (C):
41 nothrow:
42 @nogc:
43 
44 /* Needed for the definition of va_list */
45 
46 /*
47 ** Make sure we can call this stuff from C++.
48 */
49 
50 /*
51 ** Provide the ability to override linkage features of the interface.
52 */
53 
54 /*
55 ** These no-op macros are used in front of interfaces to mark those
56 ** interfaces as either deprecated or experimental.  New applications
57 ** should not use deprecated interfaces - they are supported for backwards
58 ** compatibility only.  Application writers should be aware that
59 ** experimental interfaces are subject to change in point releases.
60 **
61 ** These macros used to resolve to various kinds of compiler magic that
62 ** would generate warning messages when they were used.  But that
63 ** compiler magic ended up generating such a flurry of bug reports
64 ** that we have taken it all out and gone back to using simple
65 ** noop macros.
66 */
67 
68 /*
69 ** Ensure these symbols were not defined by some previous header file.
70 */
71 
72 /*
73 ** CAPI3REF: Compile-Time Library Version Numbers
74 **
75 ** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header
76 ** evaluates to a string literal that is the SQLite version in the
77 ** format "X.Y.Z" where X is the major version number (always 3 for
78 ** SQLite3) and Y is the minor version number and Z is the release number.)^
79 ** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer
80 ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
81 ** numbers used in [SQLITE_VERSION].)^
82 ** The SQLITE_VERSION_NUMBER for any given release of SQLite will also
83 ** be larger than the release from which it is derived.  Either Y will
84 ** be held constant and Z will be incremented or else Y will be incremented
85 ** and Z will be reset to zero.
86 **
87 ** Since [version 3.6.18] ([dateof:3.6.18]),
88 ** SQLite source code has been stored in the
89 ** <a href="http://www.fossil-scm.org/">Fossil configuration management
90 ** system</a>.  ^The SQLITE_SOURCE_ID macro evaluates to
91 ** a string which identifies a particular check-in of SQLite
92 ** within its configuration management system.  ^The SQLITE_SOURCE_ID
93 ** string contains the date and time of the check-in (UTC) and a SHA1
94 ** or SHA3-256 hash of the entire source tree.  If the source code has
95 ** been edited in any way since it was last checked in, then the last
96 ** four hexadecimal digits of the hash may be modified.
97 **
98 ** See also: [sqlite3_libversion()],
99 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
100 ** [sqlite_version()] and [sqlite_source_id()].
101 */
102 enum SQLITE_VERSION = "3.25.3";
103 enum SQLITE_VERSION_NUMBER = 3025003;
104 enum SQLITE_SOURCE_ID = "2018-11-05 20:37:38 89e099fbe5e13c33e683bef07361231ca525b88f7907be7092058007b75036f2";
105 
106 /*
107 ** CAPI3REF: Run-Time Library Version Numbers
108 ** KEYWORDS: sqlite3_version sqlite3_sourceid
109 **
110 ** These interfaces provide the same information as the [SQLITE_VERSION],
111 ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
112 ** but are associated with the library instead of the header file.  ^(Cautious
113 ** programmers might include assert() statements in their application to
114 ** verify that values returned by these interfaces match the macros in
115 ** the header, and thus ensure that the application is
116 ** compiled with matching library and header files.
117 **
118 ** <blockquote><pre>
119 ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
120 ** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 );
121 ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
122 ** </pre></blockquote>)^
123 **
124 ** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
125 ** macro.  ^The sqlite3_libversion() function returns a pointer to the
126 ** to the sqlite3_version[] string constant.  The sqlite3_libversion()
127 ** function is provided for use in DLLs since DLL users usually do not have
128 ** direct access to string constants within the DLL.  ^The
129 ** sqlite3_libversion_number() function returns an integer equal to
130 ** [SQLITE_VERSION_NUMBER].  ^(The sqlite3_sourceid() function returns
131 ** a pointer to a string constant whose value is the same as the
132 ** [SQLITE_SOURCE_ID] C preprocessor macro.  Except if SQLite is built
133 ** using an edited copy of [the amalgamation], then the last four characters
134 ** of the hash might be different from [SQLITE_SOURCE_ID].)^
135 **
136 ** See also: [sqlite_version()] and [sqlite_source_id()].
137 */
138 extern __gshared const(char)[] sqlite3_version;
139 const(char)* sqlite3_libversion();
140 const(char)* sqlite3_sourceid();
141 int sqlite3_libversion_number();
142 
143 /*
144 ** CAPI3REF: Run-Time Library Compilation Options Diagnostics
145 **
146 ** ^The sqlite3_compileoption_used() function returns 0 or 1
147 ** indicating whether the specified option was defined at
148 ** compile time.  ^The SQLITE_ prefix may be omitted from the
149 ** option name passed to sqlite3_compileoption_used().
150 **
151 ** ^The sqlite3_compileoption_get() function allows iterating
152 ** over the list of options that were defined at compile time by
153 ** returning the N-th compile time option string.  ^If N is out of range,
154 ** sqlite3_compileoption_get() returns a NULL pointer.  ^The SQLITE_
155 ** prefix is omitted from any strings returned by
156 ** sqlite3_compileoption_get().
157 **
158 ** ^Support for the diagnostic functions sqlite3_compileoption_used()
159 ** and sqlite3_compileoption_get() may be omitted by specifying the
160 ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
161 **
162 ** See also: SQL functions [sqlite_compileoption_used()] and
163 ** [sqlite_compileoption_get()] and the [compile_options pragma].
164 */
165 
166 int sqlite3_compileoption_used(const(char)* zOptName);
167 const(char)* sqlite3_compileoption_get(int N);
168 
169 /*
170 ** CAPI3REF: Test To See If The Library Is Threadsafe
171 **
172 ** ^The sqlite3_threadsafe() function returns zero if and only if
173 ** SQLite was compiled with mutexing code omitted due to the
174 ** [SQLITE_THREADSAFE] compile-time option being set to 0.
175 **
176 ** SQLite can be compiled with or without mutexes.  When
177 ** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes
178 ** are enabled and SQLite is threadsafe.  When the
179 ** [SQLITE_THREADSAFE] macro is 0,
180 ** the mutexes are omitted.  Without the mutexes, it is not safe
181 ** to use SQLite concurrently from more than one thread.
182 **
183 ** Enabling mutexes incurs a measurable performance penalty.
184 ** So if speed is of utmost importance, it makes sense to disable
185 ** the mutexes.  But for maximum safety, mutexes should be enabled.
186 ** ^The default behavior is for mutexes to be enabled.
187 **
188 ** This interface can be used by an application to make sure that the
189 ** version of SQLite that it is linking against was compiled with
190 ** the desired setting of the [SQLITE_THREADSAFE] macro.
191 **
192 ** This interface only reports on the compile-time mutex setting
193 ** of the [SQLITE_THREADSAFE] flag.  If SQLite is compiled with
194 ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
195 ** can be fully or partially disabled using a call to [sqlite3_config()]
196 ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
197 ** or [SQLITE_CONFIG_SERIALIZED].  ^(The return value of the
198 ** sqlite3_threadsafe() function shows only the compile-time setting of
199 ** thread safety, not any run-time changes to that setting made by
200 ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
201 ** is unchanged by calls to sqlite3_config().)^
202 **
203 ** See the [threading mode] documentation for additional information.
204 */
205 int sqlite3_threadsafe();
206 
207 /*
208 ** CAPI3REF: Database Connection Handle
209 ** KEYWORDS: {database connection} {database connections}
210 **
211 ** Each open SQLite database is represented by a pointer to an instance of
212 ** the opaque structure named "sqlite3".  It is useful to think of an sqlite3
213 ** pointer as an object.  The [sqlite3_open()], [sqlite3_open16()], and
214 ** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]
215 ** and [sqlite3_close_v2()] are its destructors.  There are many other
216 ** interfaces (such as
217 ** [sqlite3_prepare_v2()], [sqlite3_create_function()], and
218 ** [sqlite3_busy_timeout()] to name but three) that are methods on an
219 ** sqlite3 object.
220 */
221 struct sqlite3;
222 
223 /*
224 ** CAPI3REF: 64-Bit Integer Types
225 ** KEYWORDS: sqlite_int64 sqlite_uint64
226 **
227 ** Because there is no cross-platform way to specify 64-bit integer types
228 ** SQLite includes typedefs for 64-bit signed and unsigned integers.
229 **
230 ** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions.
231 ** The sqlite_int64 and sqlite_uint64 types are supported for backwards
232 ** compatibility only.
233 **
234 ** ^The sqlite3_int64 and sqlite_int64 types can store integer values
235 ** between -9223372036854775808 and +9223372036854775807 inclusive.  ^The
236 ** sqlite3_uint64 and sqlite_uint64 types can store integer values
237 ** between 0 and +18446744073709551615 inclusive.
238 */
239 
240 alias sqlite_int64 = long;
241 alias sqlite_uint64 = ulong;
242 
243 alias sqlite3_int64 = long;
244 alias sqlite3_uint64 = ulong;
245 
246 /*
247 ** If compiling for a processor that lacks floating point support,
248 ** substitute integer for floating-point.
249 */
250 
251 /*
252 ** CAPI3REF: Closing A Database Connection
253 ** DESTRUCTOR: sqlite3
254 **
255 ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
256 ** for the [sqlite3] object.
257 ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
258 ** the [sqlite3] object is successfully destroyed and all associated
259 ** resources are deallocated.
260 **
261 ** ^If the database connection is associated with unfinalized prepared
262 ** statements or unfinished sqlite3_backup objects then sqlite3_close()
263 ** will leave the database connection open and return [SQLITE_BUSY].
264 ** ^If sqlite3_close_v2() is called with unfinalized prepared statements
265 ** and/or unfinished sqlite3_backups, then the database connection becomes
266 ** an unusable "zombie" which will automatically be deallocated when the
267 ** last prepared statement is finalized or the last sqlite3_backup is
268 ** finished.  The sqlite3_close_v2() interface is intended for use with
269 ** host languages that are garbage collected, and where the order in which
270 ** destructors are called is arbitrary.
271 **
272 ** Applications should [sqlite3_finalize | finalize] all [prepared statements],
273 ** [sqlite3_blob_close | close] all [BLOB handles], and
274 ** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated
275 ** with the [sqlite3] object prior to attempting to close the object.  ^If
276 ** sqlite3_close_v2() is called on a [database connection] that still has
277 ** outstanding [prepared statements], [BLOB handles], and/or
278 ** [sqlite3_backup] objects then it returns [SQLITE_OK] and the deallocation
279 ** of resources is deferred until all [prepared statements], [BLOB handles],
280 ** and [sqlite3_backup] objects are also destroyed.
281 **
282 ** ^If an [sqlite3] object is destroyed while a transaction is open,
283 ** the transaction is automatically rolled back.
284 **
285 ** The C parameter to [sqlite3_close(C)] and [sqlite3_close_v2(C)]
286 ** must be either a NULL
287 ** pointer or an [sqlite3] object pointer obtained
288 ** from [sqlite3_open()], [sqlite3_open16()], or
289 ** [sqlite3_open_v2()], and not previously closed.
290 ** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer
291 ** argument is a harmless no-op.
292 */
293 int sqlite3_close(sqlite3*);
294 int sqlite3_close_v2(sqlite3*);
295 
296 /*
297 ** The type for a callback function.
298 ** This is legacy and deprecated.  It is included for historical
299 ** compatibility and is not documented.
300 */
301 alias sqlite3_callback = int function(void*, int, char**, char**);
302 
303 /*
304 ** CAPI3REF: One-Step Query Execution Interface
305 ** METHOD: sqlite3
306 **
307 ** The sqlite3_exec() interface is a convenience wrapper around
308 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
309 ** that allows an application to run multiple statements of SQL
310 ** without having to use a lot of C code.
311 **
312 ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
313 ** semicolon-separate SQL statements passed into its 2nd argument,
314 ** in the context of the [database connection] passed in as its 1st
315 ** argument.  ^If the callback function of the 3rd argument to
316 ** sqlite3_exec() is not NULL, then it is invoked for each result row
317 ** coming out of the evaluated SQL statements.  ^The 4th argument to
318 ** sqlite3_exec() is relayed through to the 1st argument of each
319 ** callback invocation.  ^If the callback pointer to sqlite3_exec()
320 ** is NULL, then no callback is ever invoked and result rows are
321 ** ignored.
322 **
323 ** ^If an error occurs while evaluating the SQL statements passed into
324 ** sqlite3_exec(), then execution of the current statement stops and
325 ** subsequent statements are skipped.  ^If the 5th parameter to sqlite3_exec()
326 ** is not NULL then any error message is written into memory obtained
327 ** from [sqlite3_malloc()] and passed back through the 5th parameter.
328 ** To avoid memory leaks, the application should invoke [sqlite3_free()]
329 ** on error message strings returned through the 5th parameter of
330 ** sqlite3_exec() after the error message string is no longer needed.
331 ** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors
332 ** occur, then sqlite3_exec() sets the pointer in its 5th parameter to
333 ** NULL before returning.
334 **
335 ** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec()
336 ** routine returns SQLITE_ABORT without invoking the callback again and
337 ** without running any subsequent SQL statements.
338 **
339 ** ^The 2nd argument to the sqlite3_exec() callback function is the
340 ** number of columns in the result.  ^The 3rd argument to the sqlite3_exec()
341 ** callback is an array of pointers to strings obtained as if from
342 ** [sqlite3_column_text()], one for each column.  ^If an element of a
343 ** result row is NULL then the corresponding string pointer for the
344 ** sqlite3_exec() callback is a NULL pointer.  ^The 4th argument to the
345 ** sqlite3_exec() callback is an array of pointers to strings where each
346 ** entry represents the name of corresponding result column as obtained
347 ** from [sqlite3_column_name()].
348 **
349 ** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
350 ** to an empty string, or a pointer that contains only whitespace and/or
351 ** SQL comments, then no SQL statements are evaluated and the database
352 ** is not changed.
353 **
354 ** Restrictions:
355 **
356 ** <ul>
357 ** <li> The application must ensure that the 1st parameter to sqlite3_exec()
358 **      is a valid and open [database connection].
359 ** <li> The application must not close the [database connection] specified by
360 **      the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
361 ** <li> The application must not modify the SQL statement text passed into
362 **      the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
363 ** </ul>
364 */
365 /* An open database */
366 /* SQL to be evaluated */
367 /* Callback function */
368 /* 1st argument to callback */
369 /* Error msg written here */
370 int sqlite3_exec(
371     sqlite3*,
372     const(char)* sql,
373     int function(void*, int, char**, char**) callback,
374     void*,
375     char** errmsg);
376 
377 /*
378 ** CAPI3REF: Result Codes
379 ** KEYWORDS: {result code definitions}
380 **
381 ** Many SQLite functions return an integer result code from the set shown
382 ** here in order to indicate success or failure.
383 **
384 ** New error codes may be added in future versions of SQLite.
385 **
386 ** See also: [extended result code definitions]
387 */
388 enum SQLITE_OK = 0; /* Successful result */
389 /* beginning-of-error-codes */
390 enum SQLITE_ERROR = 1; /* Generic error */
391 enum SQLITE_INTERNAL = 2; /* Internal logic error in SQLite */
392 enum SQLITE_PERM = 3; /* Access permission denied */
393 enum SQLITE_ABORT = 4; /* Callback routine requested an abort */
394 enum SQLITE_BUSY = 5; /* The database file is locked */
395 enum SQLITE_LOCKED = 6; /* A table in the database is locked */
396 enum SQLITE_NOMEM = 7; /* A malloc() failed */
397 enum SQLITE_READONLY = 8; /* Attempt to write a readonly database */
398 enum SQLITE_INTERRUPT = 9; /* Operation terminated by sqlite3_interrupt()*/
399 enum SQLITE_IOERR = 10; /* Some kind of disk I/O error occurred */
400 enum SQLITE_CORRUPT = 11; /* The database disk image is malformed */
401 enum SQLITE_NOTFOUND = 12; /* Unknown opcode in sqlite3_file_control() */
402 enum SQLITE_FULL = 13; /* Insertion failed because database is full */
403 enum SQLITE_CANTOPEN = 14; /* Unable to open the database file */
404 enum SQLITE_PROTOCOL = 15; /* Database lock protocol error */
405 enum SQLITE_EMPTY = 16; /* Internal use only */
406 enum SQLITE_SCHEMA = 17; /* The database schema changed */
407 enum SQLITE_TOOBIG = 18; /* String or BLOB exceeds size limit */
408 enum SQLITE_CONSTRAINT = 19; /* Abort due to constraint violation */
409 enum SQLITE_MISMATCH = 20; /* Data type mismatch */
410 enum SQLITE_MISUSE = 21; /* Library used incorrectly */
411 enum SQLITE_NOLFS = 22; /* Uses OS features not supported on host */
412 enum SQLITE_AUTH = 23; /* Authorization denied */
413 enum SQLITE_FORMAT = 24; /* Not used */
414 enum SQLITE_RANGE = 25; /* 2nd parameter to sqlite3_bind out of range */
415 enum SQLITE_NOTADB = 26; /* File opened that is not a database file */
416 enum SQLITE_NOTICE = 27; /* Notifications from sqlite3_log() */
417 enum SQLITE_WARNING = 28; /* Warnings from sqlite3_log() */
418 enum SQLITE_ROW = 100; /* sqlite3_step() has another row ready */
419 enum SQLITE_DONE = 101; /* sqlite3_step() has finished executing */
420 /* end-of-error-codes */
421 
422 /*
423 ** CAPI3REF: Extended Result Codes
424 ** KEYWORDS: {extended result code definitions}
425 **
426 ** In its default configuration, SQLite API routines return one of 30 integer
427 ** [result codes].  However, experience has shown that many of
428 ** these result codes are too coarse-grained.  They do not provide as
429 ** much information about problems as programmers might like.  In an effort to
430 ** address this, newer versions of SQLite (version 3.3.8 [dateof:3.3.8]
431 ** and later) include
432 ** support for additional result codes that provide more detailed information
433 ** about errors. These [extended result codes] are enabled or disabled
434 ** on a per database connection basis using the
435 ** [sqlite3_extended_result_codes()] API.  Or, the extended code for
436 ** the most recent error can be obtained using
437 ** [sqlite3_extended_errcode()].
438 */
439 enum SQLITE_ERROR_MISSING_COLLSEQ = SQLITE_ERROR | (1 << 8);
440 enum SQLITE_ERROR_RETRY = SQLITE_ERROR | (2 << 8);
441 enum SQLITE_ERROR_SNAPSHOT = SQLITE_ERROR | (3 << 8);
442 enum SQLITE_IOERR_READ = SQLITE_IOERR | (1 << 8);
443 enum SQLITE_IOERR_SHORT_READ = SQLITE_IOERR | (2 << 8);
444 enum SQLITE_IOERR_WRITE = SQLITE_IOERR | (3 << 8);
445 enum SQLITE_IOERR_FSYNC = SQLITE_IOERR | (4 << 8);
446 enum SQLITE_IOERR_DIR_FSYNC = SQLITE_IOERR | (5 << 8);
447 enum SQLITE_IOERR_TRUNCATE = SQLITE_IOERR | (6 << 8);
448 enum SQLITE_IOERR_FSTAT = SQLITE_IOERR | (7 << 8);
449 enum SQLITE_IOERR_UNLOCK = SQLITE_IOERR | (8 << 8);
450 enum SQLITE_IOERR_RDLOCK = SQLITE_IOERR | (9 << 8);
451 enum SQLITE_IOERR_DELETE = SQLITE_IOERR | (10 << 8);
452 enum SQLITE_IOERR_BLOCKED = SQLITE_IOERR | (11 << 8);
453 enum SQLITE_IOERR_NOMEM = SQLITE_IOERR | (12 << 8);
454 enum SQLITE_IOERR_ACCESS = SQLITE_IOERR | (13 << 8);
455 enum SQLITE_IOERR_CHECKRESERVEDLOCK = SQLITE_IOERR | (14 << 8);
456 enum SQLITE_IOERR_LOCK = SQLITE_IOERR | (15 << 8);
457 enum SQLITE_IOERR_CLOSE = SQLITE_IOERR | (16 << 8);
458 enum SQLITE_IOERR_DIR_CLOSE = SQLITE_IOERR | (17 << 8);
459 enum SQLITE_IOERR_SHMOPEN = SQLITE_IOERR | (18 << 8);
460 enum SQLITE_IOERR_SHMSIZE = SQLITE_IOERR | (19 << 8);
461 enum SQLITE_IOERR_SHMLOCK = SQLITE_IOERR | (20 << 8);
462 enum SQLITE_IOERR_SHMMAP = SQLITE_IOERR | (21 << 8);
463 enum SQLITE_IOERR_SEEK = SQLITE_IOERR | (22 << 8);
464 enum SQLITE_IOERR_DELETE_NOENT = SQLITE_IOERR | (23 << 8);
465 enum SQLITE_IOERR_MMAP = SQLITE_IOERR | (24 << 8);
466 enum SQLITE_IOERR_GETTEMPPATH = SQLITE_IOERR | (25 << 8);
467 enum SQLITE_IOERR_CONVPATH = SQLITE_IOERR | (26 << 8);
468 enum SQLITE_IOERR_VNODE = SQLITE_IOERR | (27 << 8);
469 enum SQLITE_IOERR_AUTH = SQLITE_IOERR | (28 << 8);
470 enum SQLITE_IOERR_BEGIN_ATOMIC = SQLITE_IOERR | (29 << 8);
471 enum SQLITE_IOERR_COMMIT_ATOMIC = SQLITE_IOERR | (30 << 8);
472 enum SQLITE_IOERR_ROLLBACK_ATOMIC = SQLITE_IOERR | (31 << 8);
473 enum SQLITE_LOCKED_SHAREDCACHE = SQLITE_LOCKED | (1 << 8);
474 enum SQLITE_LOCKED_VTAB = SQLITE_LOCKED | (2 << 8);
475 enum SQLITE_BUSY_RECOVERY = SQLITE_BUSY | (1 << 8);
476 enum SQLITE_BUSY_SNAPSHOT = SQLITE_BUSY | (2 << 8);
477 enum SQLITE_CANTOPEN_NOTEMPDIR = SQLITE_CANTOPEN | (1 << 8);
478 enum SQLITE_CANTOPEN_ISDIR = SQLITE_CANTOPEN | (2 << 8);
479 enum SQLITE_CANTOPEN_FULLPATH = SQLITE_CANTOPEN | (3 << 8);
480 enum SQLITE_CANTOPEN_CONVPATH = SQLITE_CANTOPEN | (4 << 8);
481 enum SQLITE_CANTOPEN_DIRTYWAL = SQLITE_CANTOPEN | (5 << 8); /* Not Used */
482 enum SQLITE_CORRUPT_VTAB = SQLITE_CORRUPT | (1 << 8);
483 enum SQLITE_CORRUPT_SEQUENCE = SQLITE_CORRUPT | (2 << 8);
484 enum SQLITE_READONLY_RECOVERY = SQLITE_READONLY | (1 << 8);
485 enum SQLITE_READONLY_CANTLOCK = SQLITE_READONLY | (2 << 8);
486 enum SQLITE_READONLY_ROLLBACK = SQLITE_READONLY | (3 << 8);
487 enum SQLITE_READONLY_DBMOVED = SQLITE_READONLY | (4 << 8);
488 enum SQLITE_READONLY_CANTINIT = SQLITE_READONLY | (5 << 8);
489 enum SQLITE_READONLY_DIRECTORY = SQLITE_READONLY | (6 << 8);
490 enum SQLITE_ABORT_ROLLBACK = SQLITE_ABORT | (2 << 8);
491 enum SQLITE_CONSTRAINT_CHECK = SQLITE_CONSTRAINT | (1 << 8);
492 enum SQLITE_CONSTRAINT_COMMITHOOK = SQLITE_CONSTRAINT | (2 << 8);
493 enum SQLITE_CONSTRAINT_FOREIGNKEY = SQLITE_CONSTRAINT | (3 << 8);
494 enum SQLITE_CONSTRAINT_FUNCTION = SQLITE_CONSTRAINT | (4 << 8);
495 enum SQLITE_CONSTRAINT_NOTNULL = SQLITE_CONSTRAINT | (5 << 8);
496 enum SQLITE_CONSTRAINT_PRIMARYKEY = SQLITE_CONSTRAINT | (6 << 8);
497 enum SQLITE_CONSTRAINT_TRIGGER = SQLITE_CONSTRAINT | (7 << 8);
498 enum SQLITE_CONSTRAINT_UNIQUE = SQLITE_CONSTRAINT | (8 << 8);
499 enum SQLITE_CONSTRAINT_VTAB = SQLITE_CONSTRAINT | (9 << 8);
500 enum SQLITE_CONSTRAINT_ROWID = SQLITE_CONSTRAINT | (10 << 8);
501 enum SQLITE_NOTICE_RECOVER_WAL = SQLITE_NOTICE | (1 << 8);
502 enum SQLITE_NOTICE_RECOVER_ROLLBACK = SQLITE_NOTICE | (2 << 8);
503 enum SQLITE_WARNING_AUTOINDEX = SQLITE_WARNING | (1 << 8);
504 enum SQLITE_AUTH_USER = SQLITE_AUTH | (1 << 8);
505 enum SQLITE_OK_LOAD_PERMANENTLY = SQLITE_OK | (1 << 8);
506 
507 /*
508 ** CAPI3REF: Flags For File Open Operations
509 **
510 ** These bit values are intended for use in the
511 ** 3rd parameter to the [sqlite3_open_v2()] interface and
512 ** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
513 */
514 enum SQLITE_OPEN_READONLY = 0x00000001; /* Ok for sqlite3_open_v2() */
515 enum SQLITE_OPEN_READWRITE = 0x00000002; /* Ok for sqlite3_open_v2() */
516 enum SQLITE_OPEN_CREATE = 0x00000004; /* Ok for sqlite3_open_v2() */
517 enum SQLITE_OPEN_DELETEONCLOSE = 0x00000008; /* VFS only */
518 enum SQLITE_OPEN_EXCLUSIVE = 0x00000010; /* VFS only */
519 enum SQLITE_OPEN_AUTOPROXY = 0x00000020; /* VFS only */
520 enum SQLITE_OPEN_URI = 0x00000040; /* Ok for sqlite3_open_v2() */
521 enum SQLITE_OPEN_MEMORY = 0x00000080; /* Ok for sqlite3_open_v2() */
522 enum SQLITE_OPEN_MAIN_DB = 0x00000100; /* VFS only */
523 enum SQLITE_OPEN_TEMP_DB = 0x00000200; /* VFS only */
524 enum SQLITE_OPEN_TRANSIENT_DB = 0x00000400; /* VFS only */
525 enum SQLITE_OPEN_MAIN_JOURNAL = 0x00000800; /* VFS only */
526 enum SQLITE_OPEN_TEMP_JOURNAL = 0x00001000; /* VFS only */
527 enum SQLITE_OPEN_SUBJOURNAL = 0x00002000; /* VFS only */
528 enum SQLITE_OPEN_MASTER_JOURNAL = 0x00004000; /* VFS only */
529 enum SQLITE_OPEN_NOMUTEX = 0x00008000; /* Ok for sqlite3_open_v2() */
530 enum SQLITE_OPEN_FULLMUTEX = 0x00010000; /* Ok for sqlite3_open_v2() */
531 enum SQLITE_OPEN_SHAREDCACHE = 0x00020000; /* Ok for sqlite3_open_v2() */
532 enum SQLITE_OPEN_PRIVATECACHE = 0x00040000; /* Ok for sqlite3_open_v2() */
533 enum SQLITE_OPEN_WAL = 0x00080000; /* VFS only */
534 
535 /* Reserved:                         0x00F00000 */
536 
537 /*
538 ** CAPI3REF: Device Characteristics
539 **
540 ** The xDeviceCharacteristics method of the [sqlite3_io_methods]
541 ** object returns an integer which is a vector of these
542 ** bit values expressing I/O characteristics of the mass storage
543 ** device that holds the file that the [sqlite3_io_methods]
544 ** refers to.
545 **
546 ** The SQLITE_IOCAP_ATOMIC property means that all writes of
547 ** any size are atomic.  The SQLITE_IOCAP_ATOMICnnn values
548 ** mean that writes of blocks that are nnn bytes in size and
549 ** are aligned to an address which is an integer multiple of
550 ** nnn are atomic.  The SQLITE_IOCAP_SAFE_APPEND value means
551 ** that when data is appended to a file, the data is appended
552 ** first then the size of the file is extended, never the other
553 ** way around.  The SQLITE_IOCAP_SEQUENTIAL property means that
554 ** information is written to disk in the same order as calls
555 ** to xWrite().  The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
556 ** after reboot following a crash or power loss, the only bytes in a
557 ** file that were written at the application level might have changed
558 ** and that adjacent bytes, even bytes within the same sector are
559 ** guaranteed to be unchanged.  The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
560 ** flag indicates that a file cannot be deleted when open.  The
561 ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
562 ** read-only media and cannot be changed even by processes with
563 ** elevated privileges.
564 **
565 ** The SQLITE_IOCAP_BATCH_ATOMIC property means that the underlying
566 ** filesystem supports doing multiple write operations atomically when those
567 ** write operations are bracketed by [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] and
568 ** [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE].
569 */
570 enum SQLITE_IOCAP_ATOMIC = 0x00000001;
571 enum SQLITE_IOCAP_ATOMIC512 = 0x00000002;
572 enum SQLITE_IOCAP_ATOMIC1K = 0x00000004;
573 enum SQLITE_IOCAP_ATOMIC2K = 0x00000008;
574 enum SQLITE_IOCAP_ATOMIC4K = 0x00000010;
575 enum SQLITE_IOCAP_ATOMIC8K = 0x00000020;
576 enum SQLITE_IOCAP_ATOMIC16K = 0x00000040;
577 enum SQLITE_IOCAP_ATOMIC32K = 0x00000080;
578 enum SQLITE_IOCAP_ATOMIC64K = 0x00000100;
579 enum SQLITE_IOCAP_SAFE_APPEND = 0x00000200;
580 enum SQLITE_IOCAP_SEQUENTIAL = 0x00000400;
581 enum SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN = 0x00000800;
582 enum SQLITE_IOCAP_POWERSAFE_OVERWRITE = 0x00001000;
583 enum SQLITE_IOCAP_IMMUTABLE = 0x00002000;
584 enum SQLITE_IOCAP_BATCH_ATOMIC = 0x00004000;
585 
586 /*
587 ** CAPI3REF: File Locking Levels
588 **
589 ** SQLite uses one of these integer values as the second
590 ** argument to calls it makes to the xLock() and xUnlock() methods
591 ** of an [sqlite3_io_methods] object.
592 */
593 enum SQLITE_LOCK_NONE = 0;
594 enum SQLITE_LOCK_SHARED = 1;
595 enum SQLITE_LOCK_RESERVED = 2;
596 enum SQLITE_LOCK_PENDING = 3;
597 enum SQLITE_LOCK_EXCLUSIVE = 4;
598 
599 /*
600 ** CAPI3REF: Synchronization Type Flags
601 **
602 ** When SQLite invokes the xSync() method of an
603 ** [sqlite3_io_methods] object it uses a combination of
604 ** these integer values as the second argument.
605 **
606 ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the
607 ** sync operation only needs to flush data to mass storage.  Inode
608 ** information need not be flushed. If the lower four bits of the flag
609 ** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics.
610 ** If the lower four bits equal SQLITE_SYNC_FULL, that means
611 ** to use Mac OS X style fullsync instead of fsync().
612 **
613 ** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags
614 ** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL
615 ** settings.  The [synchronous pragma] determines when calls to the
616 ** xSync VFS method occur and applies uniformly across all platforms.
617 ** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how
618 ** energetic or rigorous or forceful the sync operations are and
619 ** only make a difference on Mac OSX for the default SQLite code.
620 ** (Third-party VFS implementations might also make the distinction
621 ** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the
622 ** operating systems natively supported by SQLite, only Mac OSX
623 ** cares about the difference.)
624 */
625 enum SQLITE_SYNC_NORMAL = 0x00002;
626 enum SQLITE_SYNC_FULL = 0x00003;
627 enum SQLITE_SYNC_DATAONLY = 0x00010;
628 
629 /*
630 ** CAPI3REF: OS Interface Open File Handle
631 **
632 ** An [sqlite3_file] object represents an open file in the
633 ** [sqlite3_vfs | OS interface layer].  Individual OS interface
634 ** implementations will
635 ** want to subclass this object by appending additional fields
636 ** for their own use.  The pMethods entry is a pointer to an
637 ** [sqlite3_io_methods] object that defines methods for performing
638 ** I/O operations on the open file.
639 */
640 struct sqlite3_file
641 {
642  /* Methods for an open file */
643 
644     /*
645     ** CAPI3REF: OS Interface File Virtual Methods Object
646     **
647     ** Every file opened by the [sqlite3_vfs.xOpen] method populates an
648     ** [sqlite3_file] object (or, more commonly, a subclass of the
649     ** [sqlite3_file] object) with a pointer to an instance of this object.
650     ** This object defines the methods used to perform various operations
651     ** against the open file represented by the [sqlite3_file] object.
652     **
653     ** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element
654     ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
655     ** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed.  The
656     ** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen]
657     ** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element
658     ** to NULL.
659     **
660     ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
661     ** [SQLITE_SYNC_FULL].  The first choice is the normal fsync().
662     ** The second choice is a Mac OS X style fullsync.  The [SQLITE_SYNC_DATAONLY]
663     ** flag may be ORed in to indicate that only the data of the file
664     ** and not its inode needs to be synced.
665     **
666     ** The integer values to xLock() and xUnlock() are one of
667     ** <ul>
668     ** <li> [SQLITE_LOCK_NONE],
669     ** <li> [SQLITE_LOCK_SHARED],
670     ** <li> [SQLITE_LOCK_RESERVED],
671     ** <li> [SQLITE_LOCK_PENDING], or
672     ** <li> [SQLITE_LOCK_EXCLUSIVE].
673     ** </ul>
674     ** xLock() increases the lock. xUnlock() decreases the lock.
675     ** The xCheckReservedLock() method checks whether any database connection,
676     ** either in this process or in some other process, is holding a RESERVED,
677     ** PENDING, or EXCLUSIVE lock on the file.  It returns true
678     ** if such a lock exists and false otherwise.
679     **
680     ** The xFileControl() method is a generic interface that allows custom
681     ** VFS implementations to directly control an open file using the
682     ** [sqlite3_file_control()] interface.  The second "op" argument is an
683     ** integer opcode.  The third argument is a generic pointer intended to
684     ** point to a structure that may contain arguments or space in which to
685     ** write return values.  Potential uses for xFileControl() might be
686     ** functions to enable blocking locks with timeouts, to change the
687     ** locking strategy (for example to use dot-file locks), to inquire
688     ** about the status of a lock, or to break stale locks.  The SQLite
689     ** core reserves all opcodes less than 100 for its own use.
690     ** A [file control opcodes | list of opcodes] less than 100 is available.
691     ** Applications that define a custom xFileControl method should use opcodes
692     ** greater than 100 to avoid conflicts.  VFS implementations should
693     ** return [SQLITE_NOTFOUND] for file control opcodes that they do not
694     ** recognize.
695     **
696     ** The xSectorSize() method returns the sector size of the
697     ** device that underlies the file.  The sector size is the
698     ** minimum write that can be performed without disturbing
699     ** other bytes in the file.  The xDeviceCharacteristics()
700     ** method returns a bit vector describing behaviors of the
701     ** underlying device:
702     **
703     ** <ul>
704     ** <li> [SQLITE_IOCAP_ATOMIC]
705     ** <li> [SQLITE_IOCAP_ATOMIC512]
706     ** <li> [SQLITE_IOCAP_ATOMIC1K]
707     ** <li> [SQLITE_IOCAP_ATOMIC2K]
708     ** <li> [SQLITE_IOCAP_ATOMIC4K]
709     ** <li> [SQLITE_IOCAP_ATOMIC8K]
710     ** <li> [SQLITE_IOCAP_ATOMIC16K]
711     ** <li> [SQLITE_IOCAP_ATOMIC32K]
712     ** <li> [SQLITE_IOCAP_ATOMIC64K]
713     ** <li> [SQLITE_IOCAP_SAFE_APPEND]
714     ** <li> [SQLITE_IOCAP_SEQUENTIAL]
715     ** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
716     ** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
717     ** <li> [SQLITE_IOCAP_IMMUTABLE]
718     ** <li> [SQLITE_IOCAP_BATCH_ATOMIC]
719     ** </ul>
720     **
721     ** The SQLITE_IOCAP_ATOMIC property means that all writes of
722     ** any size are atomic.  The SQLITE_IOCAP_ATOMICnnn values
723     ** mean that writes of blocks that are nnn bytes in size and
724     ** are aligned to an address which is an integer multiple of
725     ** nnn are atomic.  The SQLITE_IOCAP_SAFE_APPEND value means
726     ** that when data is appended to a file, the data is appended
727     ** first then the size of the file is extended, never the other
728     ** way around.  The SQLITE_IOCAP_SEQUENTIAL property means that
729     ** information is written to disk in the same order as calls
730     ** to xWrite().
731     **
732     ** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill
733     ** in the unread portions of the buffer with zeros.  A VFS that
734     ** fails to zero-fill short reads might seem to work.  However,
735     ** failure to zero-fill short reads will eventually lead to
736     ** database corruption.
737     */
738 
739     struct sqlite3_io_methods
740     {
741         int iVersion;
742         int function(sqlite3_file*) xClose;
743         int function(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst) xRead;
744         int function(sqlite3_file*, const(void)*, int iAmt, sqlite3_int64 iOfst) xWrite;
745         int function(sqlite3_file*, sqlite3_int64 size) xTruncate;
746         int function(sqlite3_file*, int flags) xSync;
747         int function(sqlite3_file*, sqlite3_int64* pSize) xFileSize;
748         int function(sqlite3_file*, int) xLock;
749         int function(sqlite3_file*, int) xUnlock;
750         int function(sqlite3_file*, int* pResOut) xCheckReservedLock;
751         int function(sqlite3_file*, int op, void* pArg) xFileControl;
752         int function(sqlite3_file*) xSectorSize;
753         int function(sqlite3_file*) xDeviceCharacteristics;
754         /* Methods above are valid for version 1 */
755         int function(sqlite3_file*, int iPg, int pgsz, int, void**) xShmMap;
756         int function(sqlite3_file*, int offset, int n, int flags) xShmLock;
757         void function(sqlite3_file*) xShmBarrier;
758         int function(sqlite3_file*, int deleteFlag) xShmUnmap;
759         /* Methods above are valid for version 2 */
760         int function(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void** pp) xFetch;
761         int function(sqlite3_file*, sqlite3_int64 iOfst, void* p) xUnfetch;
762         /* Methods above are valid for version 3 */
763         /* Additional methods may be added in future releases */
764     }
765 
766     const(sqlite3_io_methods)* pMethods;
767 }
768 
769 struct sqlite3_io_methods
770 {
771     int iVersion;
772     int function(sqlite3_file*) xClose;
773     int function(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst) xRead;
774     int function(sqlite3_file*, const(void)*, int iAmt, sqlite3_int64 iOfst) xWrite;
775     int function(sqlite3_file*, sqlite3_int64 size) xTruncate;
776     int function(sqlite3_file*, int flags) xSync;
777     int function(sqlite3_file*, sqlite3_int64* pSize) xFileSize;
778     int function(sqlite3_file*, int) xLock;
779     int function(sqlite3_file*, int) xUnlock;
780     int function(sqlite3_file*, int* pResOut) xCheckReservedLock;
781     int function(sqlite3_file*, int op, void* pArg) xFileControl;
782     int function(sqlite3_file*) xSectorSize;
783     int function(sqlite3_file*) xDeviceCharacteristics;
784     int function(sqlite3_file*, int iPg, int pgsz, int, void**) xShmMap;
785     int function(sqlite3_file*, int offset, int n, int flags) xShmLock;
786     void function(sqlite3_file*) xShmBarrier;
787     int function(sqlite3_file*, int deleteFlag) xShmUnmap;
788     int function(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void** pp) xFetch;
789     int function(sqlite3_file*, sqlite3_int64 iOfst, void* p) xUnfetch;
790 }
791 
792 /*
793 ** CAPI3REF: Standard File Control Opcodes
794 ** KEYWORDS: {file control opcodes} {file control opcode}
795 **
796 ** These integer constants are opcodes for the xFileControl method
797 ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
798 ** interface.
799 **
800 ** <ul>
801 ** <li>[[SQLITE_FCNTL_LOCKSTATE]]
802 ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging.  This
803 ** opcode causes the xFileControl method to write the current state of
804 ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
805 ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
806 ** into an integer that the pArg argument points to. This capability
807 ** is used during testing and is only available when the SQLITE_TEST
808 ** compile-time option is used.
809 **
810 ** <li>[[SQLITE_FCNTL_SIZE_HINT]]
811 ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
812 ** layer a hint of how large the database file will grow to be during the
813 ** current transaction.  This hint is not guaranteed to be accurate but it
814 ** is often close.  The underlying VFS might choose to preallocate database
815 ** file space based on this hint in order to help writes to the database
816 ** file run faster.
817 **
818 ** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
819 ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
820 ** extends and truncates the database file in chunks of a size specified
821 ** by the user. The fourth argument to [sqlite3_file_control()] should
822 ** point to an integer (type int) containing the new chunk-size to use
823 ** for the nominated database. Allocating database file space in large
824 ** chunks (say 1MB at a time), may reduce file-system fragmentation and
825 ** improve performance on some systems.
826 **
827 ** <li>[[SQLITE_FCNTL_FILE_POINTER]]
828 ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
829 ** to the [sqlite3_file] object associated with a particular database
830 ** connection.  See also [SQLITE_FCNTL_JOURNAL_POINTER].
831 **
832 ** <li>[[SQLITE_FCNTL_JOURNAL_POINTER]]
833 ** The [SQLITE_FCNTL_JOURNAL_POINTER] opcode is used to obtain a pointer
834 ** to the [sqlite3_file] object associated with the journal file (either
835 ** the [rollback journal] or the [write-ahead log]) for a particular database
836 ** connection.  See also [SQLITE_FCNTL_FILE_POINTER].
837 **
838 ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
839 ** No longer in use.
840 **
841 ** <li>[[SQLITE_FCNTL_SYNC]]
842 ** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and
843 ** sent to the VFS immediately before the xSync method is invoked on a
844 ** database file descriptor. Or, if the xSync method is not invoked
845 ** because the user has configured SQLite with
846 ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
847 ** of the xSync method. In most cases, the pointer argument passed with
848 ** this file-control is NULL. However, if the database file is being synced
849 ** as part of a multi-database commit, the argument points to a nul-terminated
850 ** string containing the transactions master-journal file name. VFSes that
851 ** do not need this signal should silently ignore this opcode. Applications
852 ** should not call [sqlite3_file_control()] with this opcode as doing so may
853 ** disrupt the operation of the specialized VFSes that do require it.
854 **
855 ** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
856 ** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite
857 ** and sent to the VFS after a transaction has been committed immediately
858 ** but before the database is unlocked. VFSes that do not need this signal
859 ** should silently ignore this opcode. Applications should not call
860 ** [sqlite3_file_control()] with this opcode as doing so may disrupt the
861 ** operation of the specialized VFSes that do require it.
862 **
863 ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
864 ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
865 ** retry counts and intervals for certain disk I/O operations for the
866 ** windows [VFS] in order to provide robustness in the presence of
867 ** anti-virus programs.  By default, the windows VFS will retry file read,
868 ** file write, and file delete operations up to 10 times, with a delay
869 ** of 25 milliseconds before the first retry and with the delay increasing
870 ** by an additional 25 milliseconds with each subsequent retry.  This
871 ** opcode allows these two values (10 retries and 25 milliseconds of delay)
872 ** to be adjusted.  The values are changed for all database connections
873 ** within the same process.  The argument is a pointer to an array of two
874 ** integers where the first integer is the new retry count and the second
875 ** integer is the delay.  If either integer is negative, then the setting
876 ** is not changed but instead the prior value of that setting is written
877 ** into the array entry, allowing the current retry settings to be
878 ** interrogated.  The zDbName parameter is ignored.
879 **
880 ** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
881 ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
882 ** persistent [WAL | Write Ahead Log] setting.  By default, the auxiliary
883 ** write ahead log ([WAL file]) and shared memory
884 ** files used for transaction control
885 ** are automatically deleted when the latest connection to the database
886 ** closes.  Setting persistent WAL mode causes those files to persist after
887 ** close.  Persisting the files is useful when other processes that do not
888 ** have write permission on the directory containing the database file want
889 ** to read the database file, as the WAL and shared memory files must exist
890 ** in order for the database to be readable.  The fourth parameter to
891 ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
892 ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
893 ** WAL mode.  If the integer is -1, then it is overwritten with the current
894 ** WAL persistence setting.
895 **
896 ** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]]
897 ** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the
898 ** persistent "powersafe-overwrite" or "PSOW" setting.  The PSOW setting
899 ** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the
900 ** xDeviceCharacteristics methods. The fourth parameter to
901 ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
902 ** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage
903 ** mode.  If the integer is -1, then it is overwritten with the current
904 ** zero-damage mode setting.
905 **
906 ** <li>[[SQLITE_FCNTL_OVERWRITE]]
907 ** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening
908 ** a write transaction to indicate that, unless it is rolled back for some
909 ** reason, the entire database file will be overwritten by the current
910 ** transaction. This is used by VACUUM operations.
911 **
912 ** <li>[[SQLITE_FCNTL_VFSNAME]]
913 ** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of
914 ** all [VFSes] in the VFS stack.  The names are of all VFS shims and the
915 ** final bottom-level VFS are written into memory obtained from
916 ** [sqlite3_malloc()] and the result is stored in the char* variable
917 ** that the fourth parameter of [sqlite3_file_control()] points to.
918 ** The caller is responsible for freeing the memory when done.  As with
919 ** all file-control actions, there is no guarantee that this will actually
920 ** do anything.  Callers should initialize the char* variable to a NULL
921 ** pointer in case this file-control is not implemented.  This file-control
922 ** is intended for diagnostic use only.
923 **
924 ** <li>[[SQLITE_FCNTL_VFS_POINTER]]
925 ** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level
926 ** [VFSes] currently in use.  ^(The argument X in
927 ** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be
928 ** of type "[sqlite3_vfs] **".  This opcodes will set *X
929 ** to a pointer to the top-level VFS.)^
930 ** ^When there are multiple VFS shims in the stack, this opcode finds the
931 ** upper-most shim only.
932 **
933 ** <li>[[SQLITE_FCNTL_PRAGMA]]
934 ** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA]
935 ** file control is sent to the open [sqlite3_file] object corresponding
936 ** to the database file to which the pragma statement refers. ^The argument
937 ** to the [SQLITE_FCNTL_PRAGMA] file control is an array of
938 ** pointers to strings (char**) in which the second element of the array
939 ** is the name of the pragma and the third element is the argument to the
940 ** pragma or NULL if the pragma has no argument.  ^The handler for an
941 ** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element
942 ** of the char** argument point to a string obtained from [sqlite3_mprintf()]
943 ** or the equivalent and that string will become the result of the pragma or
944 ** the error message if the pragma fails. ^If the
945 ** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal
946 ** [PRAGMA] processing continues.  ^If the [SQLITE_FCNTL_PRAGMA]
947 ** file control returns [SQLITE_OK], then the parser assumes that the
948 ** VFS has handled the PRAGMA itself and the parser generates a no-op
949 ** prepared statement if result string is NULL, or that returns a copy
950 ** of the result string if the string is non-NULL.
951 ** ^If the [SQLITE_FCNTL_PRAGMA] file control returns
952 ** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means
953 ** that the VFS encountered an error while handling the [PRAGMA] and the
954 ** compilation of the PRAGMA fails with an error.  ^The [SQLITE_FCNTL_PRAGMA]
955 ** file control occurs at the beginning of pragma statement analysis and so
956 ** it is able to override built-in [PRAGMA] statements.
957 **
958 ** <li>[[SQLITE_FCNTL_BUSYHANDLER]]
959 ** ^The [SQLITE_FCNTL_BUSYHANDLER]
960 ** file-control may be invoked by SQLite on the database file handle
961 ** shortly after it is opened in order to provide a custom VFS with access
962 ** to the connections busy-handler callback. The argument is of type (void **)
963 ** - an array of two (void *) values. The first (void *) actually points
964 ** to a function of type (int (*)(void *)). In order to invoke the connections
965 ** busy-handler, this function should be invoked with the second (void *) in
966 ** the array as the only argument. If it returns non-zero, then the operation
967 ** should be retried. If it returns zero, the custom VFS should abandon the
968 ** current operation.
969 **
970 ** <li>[[SQLITE_FCNTL_TEMPFILENAME]]
971 ** ^Application can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
972 ** to have SQLite generate a
973 ** temporary filename using the same algorithm that is followed to generate
974 ** temporary filenames for TEMP tables and other internal uses.  The
975 ** argument should be a char** which will be filled with the filename
976 ** written into memory obtained from [sqlite3_malloc()].  The caller should
977 ** invoke [sqlite3_free()] on the result to avoid a memory leak.
978 **
979 ** <li>[[SQLITE_FCNTL_MMAP_SIZE]]
980 ** The [SQLITE_FCNTL_MMAP_SIZE] file control is used to query or set the
981 ** maximum number of bytes that will be used for memory-mapped I/O.
982 ** The argument is a pointer to a value of type sqlite3_int64 that
983 ** is an advisory maximum number of bytes in the file to memory map.  The
984 ** pointer is overwritten with the old value.  The limit is not changed if
985 ** the value originally pointed to is negative, and so the current limit
986 ** can be queried by passing in a pointer to a negative number.  This
987 ** file-control is used internally to implement [PRAGMA mmap_size].
988 **
989 ** <li>[[SQLITE_FCNTL_TRACE]]
990 ** The [SQLITE_FCNTL_TRACE] file control provides advisory information
991 ** to the VFS about what the higher layers of the SQLite stack are doing.
992 ** This file control is used by some VFS activity tracing [shims].
993 ** The argument is a zero-terminated string.  Higher layers in the
994 ** SQLite stack may generate instances of this file control if
995 ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
996 **
997 ** <li>[[SQLITE_FCNTL_HAS_MOVED]]
998 ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
999 ** pointer to an integer and it writes a boolean into that integer depending
1000 ** on whether or not the file has been renamed, moved, or deleted since it
1001 ** was first opened.
1002 **
1003 ** <li>[[SQLITE_FCNTL_WIN32_GET_HANDLE]]
1004 ** The [SQLITE_FCNTL_WIN32_GET_HANDLE] opcode can be used to obtain the
1005 ** underlying native file handle associated with a file handle.  This file
1006 ** control interprets its argument as a pointer to a native file handle and
1007 ** writes the resulting value there.
1008 **
1009 ** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]]
1010 ** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging.  This
1011 ** opcode causes the xFileControl method to swap the file handle with the one
1012 ** pointed to by the pArg argument.  This capability is used during testing
1013 ** and only needs to be supported when SQLITE_TEST is defined.
1014 **
1015 ** <li>[[SQLITE_FCNTL_WAL_BLOCK]]
1016 ** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might
1017 ** be advantageous to block on the next WAL lock if the lock is not immediately
1018 ** available.  The WAL subsystem issues this signal during rare
1019 ** circumstances in order to fix a problem with priority inversion.
1020 ** Applications should <em>not</em> use this file-control.
1021 **
1022 ** <li>[[SQLITE_FCNTL_ZIPVFS]]
1023 ** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other
1024 ** VFS should return SQLITE_NOTFOUND for this opcode.
1025 **
1026 ** <li>[[SQLITE_FCNTL_RBU]]
1027 ** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
1028 ** the RBU extension only.  All other VFS should return SQLITE_NOTFOUND for
1029 ** this opcode.
1030 **
1031 ** <li>[[SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]]
1032 ** If the [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] opcode returns SQLITE_OK, then
1033 ** the file descriptor is placed in "batch write mode", which
1034 ** means all subsequent write operations will be deferred and done
1035 ** atomically at the next [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE].  Systems
1036 ** that do not support batch atomic writes will return SQLITE_NOTFOUND.
1037 ** ^Following a successful SQLITE_FCNTL_BEGIN_ATOMIC_WRITE and prior to
1038 ** the closing [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] or
1039 ** [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE], SQLite will make
1040 ** no VFS interface calls on the same [sqlite3_file] file descriptor
1041 ** except for calls to the xWrite method and the xFileControl method
1042 ** with [SQLITE_FCNTL_SIZE_HINT].
1043 **
1044 ** <li>[[SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]]
1045 ** The [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] opcode causes all write
1046 ** operations since the previous successful call to
1047 ** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be performed atomically.
1048 ** This file control returns [SQLITE_OK] if and only if the writes were
1049 ** all performed successfully and have been committed to persistent storage.
1050 ** ^Regardless of whether or not it is successful, this file control takes
1051 ** the file descriptor out of batch write mode so that all subsequent
1052 ** write operations are independent.
1053 ** ^SQLite will never invoke SQLITE_FCNTL_COMMIT_ATOMIC_WRITE without
1054 ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
1055 **
1056 ** <li>[[SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE]]
1057 ** The [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE] opcode causes all write
1058 ** operations since the previous successful call to
1059 ** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be rolled back.
1060 ** ^This file control takes the file descriptor out of batch write mode
1061 ** so that all subsequent write operations are independent.
1062 ** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without
1063 ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
1064 **
1065 ** <li>[[SQLITE_FCNTL_LOCK_TIMEOUT]]
1066 ** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode causes attempts to obtain
1067 ** a file lock using the xLock or xShmLock methods of the VFS to wait
1068 ** for up to M milliseconds before failing, where M is the single
1069 ** unsigned integer parameter.
1070 **
1071 ** <li>[[SQLITE_FCNTL_DATA_VERSION]]
1072 ** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to
1073 ** a database file.  The argument is a pointer to a 32-bit unsigned integer.
1074 ** The "data version" for the pager is written into the pointer.  The
1075 ** "data version" changes whenever any change occurs to the corresponding
1076 ** database file, either through SQL statements on the same database
1077 ** connection or through transactions committed by separate database
1078 ** connections possibly in other processes. The [sqlite3_total_changes()]
1079 ** interface can be used to find if any database on the connection has changed,
1080 ** but that interface responds to changes on TEMP as well as MAIN and does
1081 ** not provide a mechanism to detect changes to MAIN only.  Also, the
1082 ** [sqlite3_total_changes()] interface responds to internal changes only and
1083 ** omits changes made by other database connections.  The
1084 ** [PRAGMA data_version] command provide a mechanism to detect changes to
1085 ** a single attached database that occur due to other database connections,
1086 ** but omits changes implemented by the database connection on which it is
1087 ** called.  This file control is the only mechanism to detect changes that
1088 ** happen either internally or externally and that are associated with
1089 ** a particular attached database.
1090 ** </ul>
1091 */
1092 enum SQLITE_FCNTL_LOCKSTATE = 1;
1093 enum SQLITE_FCNTL_GET_LOCKPROXYFILE = 2;
1094 enum SQLITE_FCNTL_SET_LOCKPROXYFILE = 3;
1095 enum SQLITE_FCNTL_LAST_ERRNO = 4;
1096 enum SQLITE_FCNTL_SIZE_HINT = 5;
1097 enum SQLITE_FCNTL_CHUNK_SIZE = 6;
1098 enum SQLITE_FCNTL_FILE_POINTER = 7;
1099 enum SQLITE_FCNTL_SYNC_OMITTED = 8;
1100 enum SQLITE_FCNTL_WIN32_AV_RETRY = 9;
1101 enum SQLITE_FCNTL_PERSIST_WAL = 10;
1102 enum SQLITE_FCNTL_OVERWRITE = 11;
1103 enum SQLITE_FCNTL_VFSNAME = 12;
1104 enum SQLITE_FCNTL_POWERSAFE_OVERWRITE = 13;
1105 enum SQLITE_FCNTL_PRAGMA = 14;
1106 enum SQLITE_FCNTL_BUSYHANDLER = 15;
1107 enum SQLITE_FCNTL_TEMPFILENAME = 16;
1108 enum SQLITE_FCNTL_MMAP_SIZE = 18;
1109 enum SQLITE_FCNTL_TRACE = 19;
1110 enum SQLITE_FCNTL_HAS_MOVED = 20;
1111 enum SQLITE_FCNTL_SYNC = 21;
1112 enum SQLITE_FCNTL_COMMIT_PHASETWO = 22;
1113 enum SQLITE_FCNTL_WIN32_SET_HANDLE = 23;
1114 enum SQLITE_FCNTL_WAL_BLOCK = 24;
1115 enum SQLITE_FCNTL_ZIPVFS = 25;
1116 enum SQLITE_FCNTL_RBU = 26;
1117 enum SQLITE_FCNTL_VFS_POINTER = 27;
1118 enum SQLITE_FCNTL_JOURNAL_POINTER = 28;
1119 enum SQLITE_FCNTL_WIN32_GET_HANDLE = 29;
1120 enum SQLITE_FCNTL_PDB = 30;
1121 enum SQLITE_FCNTL_BEGIN_ATOMIC_WRITE = 31;
1122 enum SQLITE_FCNTL_COMMIT_ATOMIC_WRITE = 32;
1123 enum SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE = 33;
1124 enum SQLITE_FCNTL_LOCK_TIMEOUT = 34;
1125 enum SQLITE_FCNTL_DATA_VERSION = 35;
1126 
1127 /* deprecated names */
1128 enum SQLITE_GET_LOCKPROXYFILE = SQLITE_FCNTL_GET_LOCKPROXYFILE;
1129 enum SQLITE_SET_LOCKPROXYFILE = SQLITE_FCNTL_SET_LOCKPROXYFILE;
1130 enum SQLITE_LAST_ERRNO = SQLITE_FCNTL_LAST_ERRNO;
1131 
1132 /*
1133 ** CAPI3REF: Mutex Handle
1134 **
1135 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
1136 ** abstract type for a mutex object.  The SQLite core never looks
1137 ** at the internal representation of an [sqlite3_mutex].  It only
1138 ** deals with pointers to the [sqlite3_mutex] object.
1139 **
1140 ** Mutexes are created using [sqlite3_mutex_alloc()].
1141 */
1142 struct sqlite3_mutex;
1143 
1144 /*
1145 ** CAPI3REF: Loadable Extension Thunk
1146 **
1147 ** A pointer to the opaque sqlite3_api_routines structure is passed as
1148 ** the third parameter to entry points of [loadable extensions].  This
1149 ** structure must be typedefed in order to work around compiler warnings
1150 ** on some platforms.
1151 */
1152 struct sqlite3_api_routines;
1153 
1154 /*
1155 ** CAPI3REF: OS Interface Object
1156 **
1157 ** An instance of the sqlite3_vfs object defines the interface between
1158 ** the SQLite core and the underlying operating system.  The "vfs"
1159 ** in the name of the object stands for "virtual file system".  See
1160 ** the [VFS | VFS documentation] for further information.
1161 **
1162 ** The VFS interface is sometimes extended by adding new methods onto
1163 ** the end.  Each time such an extension occurs, the iVersion field
1164 ** is incremented.  The iVersion value started out as 1 in
1165 ** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2
1166 ** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased
1167 ** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6].  Additional fields
1168 ** may be appended to the sqlite3_vfs object and the iVersion value
1169 ** may increase again in future versions of SQLite.
1170 ** Note that the structure
1171 ** of the sqlite3_vfs object changes in the transition from
1172 ** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0]
1173 ** and yet the iVersion field was not modified.
1174 **
1175 ** The szOsFile field is the size of the subclassed [sqlite3_file]
1176 ** structure used by this VFS.  mxPathname is the maximum length of
1177 ** a pathname in this VFS.
1178 **
1179 ** Registered sqlite3_vfs objects are kept on a linked list formed by
1180 ** the pNext pointer.  The [sqlite3_vfs_register()]
1181 ** and [sqlite3_vfs_unregister()] interfaces manage this list
1182 ** in a thread-safe way.  The [sqlite3_vfs_find()] interface
1183 ** searches the list.  Neither the application code nor the VFS
1184 ** implementation should use the pNext pointer.
1185 **
1186 ** The pNext field is the only field in the sqlite3_vfs
1187 ** structure that SQLite will ever modify.  SQLite will only access
1188 ** or modify this field while holding a particular static mutex.
1189 ** The application should never modify anything within the sqlite3_vfs
1190 ** object once the object has been registered.
1191 **
1192 ** The zName field holds the name of the VFS module.  The name must
1193 ** be unique across all VFS modules.
1194 **
1195 ** [[sqlite3_vfs.xOpen]]
1196 ** ^SQLite guarantees that the zFilename parameter to xOpen
1197 ** is either a NULL pointer or string obtained
1198 ** from xFullPathname() with an optional suffix added.
1199 ** ^If a suffix is added to the zFilename parameter, it will
1200 ** consist of a single "-" character followed by no more than
1201 ** 11 alphanumeric and/or "-" characters.
1202 ** ^SQLite further guarantees that
1203 ** the string will be valid and unchanged until xClose() is
1204 ** called. Because of the previous sentence,
1205 ** the [sqlite3_file] can safely store a pointer to the
1206 ** filename if it needs to remember the filename for some reason.
1207 ** If the zFilename parameter to xOpen is a NULL pointer then xOpen
1208 ** must invent its own temporary name for the file.  ^Whenever the
1209 ** xFilename parameter is NULL it will also be the case that the
1210 ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
1211 **
1212 ** The flags argument to xOpen() includes all bits set in
1213 ** the flags argument to [sqlite3_open_v2()].  Or if [sqlite3_open()]
1214 ** or [sqlite3_open16()] is used, then flags includes at least
1215 ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
1216 ** If xOpen() opens a file read-only then it sets *pOutFlags to
1217 ** include [SQLITE_OPEN_READONLY].  Other bits in *pOutFlags may be set.
1218 **
1219 ** ^(SQLite will also add one of the following flags to the xOpen()
1220 ** call, depending on the object being opened:
1221 **
1222 ** <ul>
1223 ** <li>  [SQLITE_OPEN_MAIN_DB]
1224 ** <li>  [SQLITE_OPEN_MAIN_JOURNAL]
1225 ** <li>  [SQLITE_OPEN_TEMP_DB]
1226 ** <li>  [SQLITE_OPEN_TEMP_JOURNAL]
1227 ** <li>  [SQLITE_OPEN_TRANSIENT_DB]
1228 ** <li>  [SQLITE_OPEN_SUBJOURNAL]
1229 ** <li>  [SQLITE_OPEN_MASTER_JOURNAL]
1230 ** <li>  [SQLITE_OPEN_WAL]
1231 ** </ul>)^
1232 **
1233 ** The file I/O implementation can use the object type flags to
1234 ** change the way it deals with files.  For example, an application
1235 ** that does not care about crash recovery or rollback might make
1236 ** the open of a journal file a no-op.  Writes to this journal would
1237 ** also be no-ops, and any attempt to read the journal would return
1238 ** SQLITE_IOERR.  Or the implementation might recognize that a database
1239 ** file will be doing page-aligned sector reads and writes in a random
1240 ** order and set up its I/O subsystem accordingly.
1241 **
1242 ** SQLite might also add one of the following flags to the xOpen method:
1243 **
1244 ** <ul>
1245 ** <li> [SQLITE_OPEN_DELETEONCLOSE]
1246 ** <li> [SQLITE_OPEN_EXCLUSIVE]
1247 ** </ul>
1248 **
1249 ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
1250 ** deleted when it is closed.  ^The [SQLITE_OPEN_DELETEONCLOSE]
1251 ** will be set for TEMP databases and their journals, transient
1252 ** databases, and subjournals.
1253 **
1254 ** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
1255 ** with the [SQLITE_OPEN_CREATE] flag, which are both directly
1256 ** analogous to the O_EXCL and O_CREAT flags of the POSIX open()
1257 ** API.  The SQLITE_OPEN_EXCLUSIVE flag, when paired with the
1258 ** SQLITE_OPEN_CREATE, is used to indicate that file should always
1259 ** be created, and that it is an error if it already exists.
1260 ** It is <i>not</i> used to indicate the file should be opened
1261 ** for exclusive access.
1262 **
1263 ** ^At least szOsFile bytes of memory are allocated by SQLite
1264 ** to hold the  [sqlite3_file] structure passed as the third
1265 ** argument to xOpen.  The xOpen method does not have to
1266 ** allocate the structure; it should just fill it in.  Note that
1267 ** the xOpen method must set the sqlite3_file.pMethods to either
1268 ** a valid [sqlite3_io_methods] object or to NULL.  xOpen must do
1269 ** this even if the open fails.  SQLite expects that the sqlite3_file.pMethods
1270 ** element will be valid after xOpen returns regardless of the success
1271 ** or failure of the xOpen call.
1272 **
1273 ** [[sqlite3_vfs.xAccess]]
1274 ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
1275 ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
1276 ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
1277 ** to test whether a file is at least readable.   The file can be a
1278 ** directory.
1279 **
1280 ** ^SQLite will always allocate at least mxPathname+1 bytes for the
1281 ** output buffer xFullPathname.  The exact size of the output buffer
1282 ** is also passed as a parameter to both  methods. If the output buffer
1283 ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
1284 ** handled as a fatal error by SQLite, vfs implementations should endeavor
1285 ** to prevent this by setting mxPathname to a sufficiently large value.
1286 **
1287 ** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
1288 ** interfaces are not strictly a part of the filesystem, but they are
1289 ** included in the VFS structure for completeness.
1290 ** The xRandomness() function attempts to return nBytes bytes
1291 ** of good-quality randomness into zOut.  The return value is
1292 ** the actual number of bytes of randomness obtained.
1293 ** The xSleep() method causes the calling thread to sleep for at
1294 ** least the number of microseconds given.  ^The xCurrentTime()
1295 ** method returns a Julian Day Number for the current date and time as
1296 ** a floating point value.
1297 ** ^The xCurrentTimeInt64() method returns, as an integer, the Julian
1298 ** Day Number multiplied by 86400000 (the number of milliseconds in
1299 ** a 24-hour day).
1300 ** ^SQLite will use the xCurrentTimeInt64() method to get the current
1301 ** date and time if that method is available (if iVersion is 2 or
1302 ** greater and the function pointer is not NULL) and will fall back
1303 ** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
1304 **
1305 ** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces
1306 ** are not used by the SQLite core.  These optional interfaces are provided
1307 ** by some VFSes to facilitate testing of the VFS code. By overriding
1308 ** system calls with functions under its control, a test program can
1309 ** simulate faults and error conditions that would otherwise be difficult
1310 ** or impossible to induce.  The set of system calls that can be overridden
1311 ** varies from one VFS to another, and from one version of the same VFS to the
1312 ** next.  Applications that use these interfaces must be prepared for any
1313 ** or all of these interfaces to be NULL or for their behavior to change
1314 ** from one release to the next.  Applications must not attempt to access
1315 ** any of these methods if the iVersion of the VFS is less than 3.
1316 */
1317 alias sqlite3_syscall_ptr = void function();
1318 
1319 struct sqlite3_vfs
1320 {
1321     int iVersion; /* Structure version number (currently 3) */
1322     int szOsFile; /* Size of subclassed sqlite3_file */
1323     int mxPathname; /* Maximum file pathname length */
1324     sqlite3_vfs* pNext; /* Next registered VFS */
1325     const(char)* zName; /* Name of this virtual file system */
1326     void* pAppData; /* Pointer to application-specific data */
1327     int function(sqlite3_vfs*, const(char)* zName, sqlite3_file*, int flags, int* pOutFlags) xOpen;
1328     int function(sqlite3_vfs*, const(char)* zName, int syncDir) xDelete;
1329     int function(sqlite3_vfs*, const(char)* zName, int flags, int* pResOut) xAccess;
1330     int function(sqlite3_vfs*, const(char)* zName, int nOut, char* zOut) xFullPathname;
1331     void* function(sqlite3_vfs*, const(char)* zFilename) xDlOpen;
1332     void function(sqlite3_vfs*, int nByte, char* zErrMsg) xDlError;
1333     void function(sqlite3_vfs*, void*, const(char)* zSymbol) function(sqlite3_vfs*, void*, const(char)* zSymbol) xDlSym;
1334     void function(sqlite3_vfs*, void*) xDlClose;
1335     int function(sqlite3_vfs*, int nByte, char* zOut) xRandomness;
1336     int function(sqlite3_vfs*, int microseconds) xSleep;
1337     int function(sqlite3_vfs*, double*) xCurrentTime;
1338     int function(sqlite3_vfs*, int, char*) xGetLastError;
1339     /*
1340     ** The methods above are in version 1 of the sqlite_vfs object
1341     ** definition.  Those that follow are added in version 2 or later
1342     */
1343     int function(sqlite3_vfs*, sqlite3_int64*) xCurrentTimeInt64;
1344     /*
1345     ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
1346     ** Those below are for version 3 and greater.
1347     */
1348     int function(sqlite3_vfs*, const(char)* zName, sqlite3_syscall_ptr) xSetSystemCall;
1349     sqlite3_syscall_ptr function(sqlite3_vfs*, const(char)* zName) xGetSystemCall;
1350     const(char)* function(sqlite3_vfs*, const(char)* zName) xNextSystemCall;
1351     /*
1352     ** The methods above are in versions 1 through 3 of the sqlite_vfs object.
1353     ** New fields may be appended in future versions.  The iVersion
1354     ** value will increment whenever this happens.
1355     */
1356 }
1357 
1358 /*
1359 ** CAPI3REF: Flags for the xAccess VFS method
1360 **
1361 ** These integer constants can be used as the third parameter to
1362 ** the xAccess method of an [sqlite3_vfs] object.  They determine
1363 ** what kind of permissions the xAccess method is looking for.
1364 ** With SQLITE_ACCESS_EXISTS, the xAccess method
1365 ** simply checks whether the file exists.
1366 ** With SQLITE_ACCESS_READWRITE, the xAccess method
1367 ** checks whether the named directory is both readable and writable
1368 ** (in other words, if files can be added, removed, and renamed within
1369 ** the directory).
1370 ** The SQLITE_ACCESS_READWRITE constant is currently used only by the
1371 ** [temp_store_directory pragma], though this could change in a future
1372 ** release of SQLite.
1373 ** With SQLITE_ACCESS_READ, the xAccess method
1374 ** checks whether the file is readable.  The SQLITE_ACCESS_READ constant is
1375 ** currently unused, though it might be used in a future release of
1376 ** SQLite.
1377 */
1378 enum SQLITE_ACCESS_EXISTS = 0;
1379 enum SQLITE_ACCESS_READWRITE = 1; /* Used by PRAGMA temp_store_directory */
1380 enum SQLITE_ACCESS_READ = 2; /* Unused */
1381 
1382 /*
1383 ** CAPI3REF: Flags for the xShmLock VFS method
1384 **
1385 ** These integer constants define the various locking operations
1386 ** allowed by the xShmLock method of [sqlite3_io_methods].  The
1387 ** following are the only legal combinations of flags to the
1388 ** xShmLock method:
1389 **
1390 ** <ul>
1391 ** <li>  SQLITE_SHM_LOCK | SQLITE_SHM_SHARED
1392 ** <li>  SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE
1393 ** <li>  SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED
1394 ** <li>  SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE
1395 ** </ul>
1396 **
1397 ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as
1398 ** was given on the corresponding lock.
1399 **
1400 ** The xShmLock method can transition between unlocked and SHARED or
1401 ** between unlocked and EXCLUSIVE.  It cannot transition between SHARED
1402 ** and EXCLUSIVE.
1403 */
1404 enum SQLITE_SHM_UNLOCK = 1;
1405 enum SQLITE_SHM_LOCK = 2;
1406 enum SQLITE_SHM_SHARED = 4;
1407 enum SQLITE_SHM_EXCLUSIVE = 8;
1408 
1409 /*
1410 ** CAPI3REF: Maximum xShmLock index
1411 **
1412 ** The xShmLock method on [sqlite3_io_methods] may use values
1413 ** between 0 and this upper bound as its "offset" argument.
1414 ** The SQLite core will never attempt to acquire or release a
1415 ** lock outside of this range
1416 */
1417 enum SQLITE_SHM_NLOCK = 8;
1418 
1419 /*
1420 ** CAPI3REF: Initialize The SQLite Library
1421 **
1422 ** ^The sqlite3_initialize() routine initializes the
1423 ** SQLite library.  ^The sqlite3_shutdown() routine
1424 ** deallocates any resources that were allocated by sqlite3_initialize().
1425 ** These routines are designed to aid in process initialization and
1426 ** shutdown on embedded systems.  Workstation applications using
1427 ** SQLite normally do not need to invoke either of these routines.
1428 **
1429 ** A call to sqlite3_initialize() is an "effective" call if it is
1430 ** the first time sqlite3_initialize() is invoked during the lifetime of
1431 ** the process, or if it is the first time sqlite3_initialize() is invoked
1432 ** following a call to sqlite3_shutdown().  ^(Only an effective call
1433 ** of sqlite3_initialize() does any initialization.  All other calls
1434 ** are harmless no-ops.)^
1435 **
1436 ** A call to sqlite3_shutdown() is an "effective" call if it is the first
1437 ** call to sqlite3_shutdown() since the last sqlite3_initialize().  ^(Only
1438 ** an effective call to sqlite3_shutdown() does any deinitialization.
1439 ** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^
1440 **
1441 ** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown()
1442 ** is not.  The sqlite3_shutdown() interface must only be called from a
1443 ** single thread.  All open [database connections] must be closed and all
1444 ** other SQLite resources must be deallocated prior to invoking
1445 ** sqlite3_shutdown().
1446 **
1447 ** Among other things, ^sqlite3_initialize() will invoke
1448 ** sqlite3_os_init().  Similarly, ^sqlite3_shutdown()
1449 ** will invoke sqlite3_os_end().
1450 **
1451 ** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success.
1452 ** ^If for some reason, sqlite3_initialize() is unable to initialize
1453 ** the library (perhaps it is unable to allocate a needed resource such
1454 ** as a mutex) it returns an [error code] other than [SQLITE_OK].
1455 **
1456 ** ^The sqlite3_initialize() routine is called internally by many other
1457 ** SQLite interfaces so that an application usually does not need to
1458 ** invoke sqlite3_initialize() directly.  For example, [sqlite3_open()]
1459 ** calls sqlite3_initialize() so the SQLite library will be automatically
1460 ** initialized when [sqlite3_open()] is called if it has not be initialized
1461 ** already.  ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
1462 ** compile-time option, then the automatic calls to sqlite3_initialize()
1463 ** are omitted and the application must call sqlite3_initialize() directly
1464 ** prior to using any other SQLite interface.  For maximum portability,
1465 ** it is recommended that applications always invoke sqlite3_initialize()
1466 ** directly prior to using any other SQLite interface.  Future releases
1467 ** of SQLite may require this.  In other words, the behavior exhibited
1468 ** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the
1469 ** default behavior in some future release of SQLite.
1470 **
1471 ** The sqlite3_os_init() routine does operating-system specific
1472 ** initialization of the SQLite library.  The sqlite3_os_end()
1473 ** routine undoes the effect of sqlite3_os_init().  Typical tasks
1474 ** performed by these routines include allocation or deallocation
1475 ** of static resources, initialization of global variables,
1476 ** setting up a default [sqlite3_vfs] module, or setting up
1477 ** a default configuration using [sqlite3_config()].
1478 **
1479 ** The application should never invoke either sqlite3_os_init()
1480 ** or sqlite3_os_end() directly.  The application should only invoke
1481 ** sqlite3_initialize() and sqlite3_shutdown().  The sqlite3_os_init()
1482 ** interface is called automatically by sqlite3_initialize() and
1483 ** sqlite3_os_end() is called by sqlite3_shutdown().  Appropriate
1484 ** implementations for sqlite3_os_init() and sqlite3_os_end()
1485 ** are built into SQLite when it is compiled for Unix, Windows, or OS/2.
1486 ** When [custom builds | built for other platforms]
1487 ** (using the [SQLITE_OS_OTHER=1] compile-time
1488 ** option) the application must supply a suitable implementation for
1489 ** sqlite3_os_init() and sqlite3_os_end().  An application-supplied
1490 ** implementation of sqlite3_os_init() or sqlite3_os_end()
1491 ** must return [SQLITE_OK] on success and some other [error code] upon
1492 ** failure.
1493 */
1494 int sqlite3_initialize();
1495 int sqlite3_shutdown();
1496 int sqlite3_os_init();
1497 int sqlite3_os_end();
1498 
1499 /*
1500 ** CAPI3REF: Configuring The SQLite Library
1501 **
1502 ** The sqlite3_config() interface is used to make global configuration
1503 ** changes to SQLite in order to tune SQLite to the specific needs of
1504 ** the application.  The default configuration is recommended for most
1505 ** applications and so this routine is usually not necessary.  It is
1506 ** provided to support rare applications with unusual needs.
1507 **
1508 ** <b>The sqlite3_config() interface is not threadsafe. The application
1509 ** must ensure that no other SQLite interfaces are invoked by other
1510 ** threads while sqlite3_config() is running.</b>
1511 **
1512 ** The sqlite3_config() interface
1513 ** may only be invoked prior to library initialization using
1514 ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].
1515 ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before
1516 ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE.
1517 ** Note, however, that ^sqlite3_config() can be called as part of the
1518 ** implementation of an application-defined [sqlite3_os_init()].
1519 **
1520 ** The first argument to sqlite3_config() is an integer
1521 ** [configuration option] that determines
1522 ** what property of SQLite is to be configured.  Subsequent arguments
1523 ** vary depending on the [configuration option]
1524 ** in the first argument.
1525 **
1526 ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
1527 ** ^If the option is unknown or SQLite is unable to set the option
1528 ** then this routine returns a non-zero [error code].
1529 */
1530 int sqlite3_config(int, ...);
1531 
1532 /*
1533 ** CAPI3REF: Configure database connections
1534 ** METHOD: sqlite3
1535 **
1536 ** The sqlite3_db_config() interface is used to make configuration
1537 ** changes to a [database connection].  The interface is similar to
1538 ** [sqlite3_config()] except that the changes apply to a single
1539 ** [database connection] (specified in the first argument).
1540 **
1541 ** The second argument to sqlite3_db_config(D,V,...)  is the
1542 ** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code
1543 ** that indicates what aspect of the [database connection] is being configured.
1544 ** Subsequent arguments vary depending on the configuration verb.
1545 **
1546 ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
1547 ** the call is considered successful.
1548 */
1549 int sqlite3_db_config(sqlite3*, int op, ...);
1550 
1551 /*
1552 ** CAPI3REF: Memory Allocation Routines
1553 **
1554 ** An instance of this object defines the interface between SQLite
1555 ** and low-level memory allocation routines.
1556 **
1557 ** This object is used in only one place in the SQLite interface.
1558 ** A pointer to an instance of this object is the argument to
1559 ** [sqlite3_config()] when the configuration option is
1560 ** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC].
1561 ** By creating an instance of this object
1562 ** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC])
1563 ** during configuration, an application can specify an alternative
1564 ** memory allocation subsystem for SQLite to use for all of its
1565 ** dynamic memory needs.
1566 **
1567 ** Note that SQLite comes with several [built-in memory allocators]
1568 ** that are perfectly adequate for the overwhelming majority of applications
1569 ** and that this object is only useful to a tiny minority of applications
1570 ** with specialized memory allocation requirements.  This object is
1571 ** also used during testing of SQLite in order to specify an alternative
1572 ** memory allocator that simulates memory out-of-memory conditions in
1573 ** order to verify that SQLite recovers gracefully from such
1574 ** conditions.
1575 **
1576 ** The xMalloc, xRealloc, and xFree methods must work like the
1577 ** malloc(), realloc() and free() functions from the standard C library.
1578 ** ^SQLite guarantees that the second argument to
1579 ** xRealloc is always a value returned by a prior call to xRoundup.
1580 **
1581 ** xSize should return the allocated size of a memory allocation
1582 ** previously obtained from xMalloc or xRealloc.  The allocated size
1583 ** is always at least as big as the requested size but may be larger.
1584 **
1585 ** The xRoundup method returns what would be the allocated size of
1586 ** a memory allocation given a particular requested size.  Most memory
1587 ** allocators round up memory allocations at least to the next multiple
1588 ** of 8.  Some allocators round up to a larger multiple or to a power of 2.
1589 ** Every memory allocation request coming in through [sqlite3_malloc()]
1590 ** or [sqlite3_realloc()] first calls xRoundup.  If xRoundup returns 0,
1591 ** that causes the corresponding memory allocation to fail.
1592 **
1593 ** The xInit method initializes the memory allocator.  For example,
1594 ** it might allocate any require mutexes or initialize internal data
1595 ** structures.  The xShutdown method is invoked (indirectly) by
1596 ** [sqlite3_shutdown()] and should deallocate any resources acquired
1597 ** by xInit.  The pAppData pointer is used as the only parameter to
1598 ** xInit and xShutdown.
1599 **
1600 ** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes
1601 ** the xInit method, so the xInit method need not be threadsafe.  The
1602 ** xShutdown method is only called from [sqlite3_shutdown()] so it does
1603 ** not need to be threadsafe either.  For all other methods, SQLite
1604 ** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the
1605 ** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which
1606 ** it is by default) and so the methods are automatically serialized.
1607 ** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other
1608 ** methods must be threadsafe or else make their own arrangements for
1609 ** serialization.
1610 **
1611 ** SQLite will never invoke xInit() more than once without an intervening
1612 ** call to xShutdown().
1613 */
1614 struct sqlite3_mem_methods
1615 {
1616     void* function(int) xMalloc; /* Memory allocation function */
1617     void function(void*) xFree; /* Free a prior allocation */
1618     void* function(void*, int) xRealloc; /* Resize an allocation */
1619     int function(void*) xSize; /* Return the size of an allocation */
1620     int function(int) xRoundup; /* Round up request size to allocation size */
1621     int function(void*) xInit; /* Initialize the memory allocator */
1622     void function(void*) xShutdown; /* Deinitialize the memory allocator */
1623     void* pAppData; /* Argument to xInit() and xShutdown() */
1624 }
1625 
1626 /*
1627 ** CAPI3REF: Configuration Options
1628 ** KEYWORDS: {configuration option}
1629 **
1630 ** These constants are the available integer configuration options that
1631 ** can be passed as the first argument to the [sqlite3_config()] interface.
1632 **
1633 ** New configuration options may be added in future releases of SQLite.
1634 ** Existing configuration options might be discontinued.  Applications
1635 ** should check the return code from [sqlite3_config()] to make sure that
1636 ** the call worked.  The [sqlite3_config()] interface will return a
1637 ** non-zero [error code] if a discontinued or unsupported configuration option
1638 ** is invoked.
1639 **
1640 ** <dl>
1641 ** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
1642 ** <dd>There are no arguments to this option.  ^This option sets the
1643 ** [threading mode] to Single-thread.  In other words, it disables
1644 ** all mutexing and puts SQLite into a mode where it can only be used
1645 ** by a single thread.   ^If SQLite is compiled with
1646 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1647 ** it is not possible to change the [threading mode] from its default
1648 ** value of Single-thread and so [sqlite3_config()] will return
1649 ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
1650 ** configuration option.</dd>
1651 **
1652 ** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt>
1653 ** <dd>There are no arguments to this option.  ^This option sets the
1654 ** [threading mode] to Multi-thread.  In other words, it disables
1655 ** mutexing on [database connection] and [prepared statement] objects.
1656 ** The application is responsible for serializing access to
1657 ** [database connections] and [prepared statements].  But other mutexes
1658 ** are enabled so that SQLite will be safe to use in a multi-threaded
1659 ** environment as long as no two threads attempt to use the same
1660 ** [database connection] at the same time.  ^If SQLite is compiled with
1661 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1662 ** it is not possible to set the Multi-thread [threading mode] and
1663 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1664 ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
1665 **
1666 ** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt>
1667 ** <dd>There are no arguments to this option.  ^This option sets the
1668 ** [threading mode] to Serialized. In other words, this option enables
1669 ** all mutexes including the recursive
1670 ** mutexes on [database connection] and [prepared statement] objects.
1671 ** In this mode (which is the default when SQLite is compiled with
1672 ** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access
1673 ** to [database connections] and [prepared statements] so that the
1674 ** application is free to use the same [database connection] or the
1675 ** same [prepared statement] in different threads at the same time.
1676 ** ^If SQLite is compiled with
1677 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1678 ** it is not possible to set the Serialized [threading mode] and
1679 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1680 ** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
1681 **
1682 ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
1683 ** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is
1684 ** a pointer to an instance of the [sqlite3_mem_methods] structure.
1685 ** The argument specifies
1686 ** alternative low-level memory allocation routines to be used in place of
1687 ** the memory allocation routines built into SQLite.)^ ^SQLite makes
1688 ** its own private copy of the content of the [sqlite3_mem_methods] structure
1689 ** before the [sqlite3_config()] call returns.</dd>
1690 **
1691 ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
1692 ** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
1693 ** is a pointer to an instance of the [sqlite3_mem_methods] structure.
1694 ** The [sqlite3_mem_methods]
1695 ** structure is filled with the currently defined memory allocation routines.)^
1696 ** This option can be used to overload the default memory allocation
1697 ** routines with a wrapper that simulations memory allocation failure or
1698 ** tracks memory usage, for example. </dd>
1699 **
1700 ** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt>
1701 ** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes single argument of
1702 ** type int, interpreted as a boolean, which if true provides a hint to
1703 ** SQLite that it should avoid large memory allocations if possible.
1704 ** SQLite will run faster if it is free to make large memory allocations,
1705 ** but some application might prefer to run slower in exchange for
1706 ** guarantees about memory fragmentation that are possible if large
1707 ** allocations are avoided.  This hint is normally off.
1708 ** </dd>
1709 **
1710 ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1711 ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
1712 ** interpreted as a boolean, which enables or disables the collection of
1713 ** memory allocation statistics. ^(When memory allocation statistics are
1714 ** disabled, the following SQLite interfaces become non-operational:
1715 **   <ul>
1716 **   <li> [sqlite3_memory_used()]
1717 **   <li> [sqlite3_memory_highwater()]
1718 **   <li> [sqlite3_soft_heap_limit64()]
1719 **   <li> [sqlite3_status64()]
1720 **   </ul>)^
1721 ** ^Memory allocation statistics are enabled by default unless SQLite is
1722 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1723 ** allocation statistics are disabled by default.
1724 ** </dd>
1725 **
1726 ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
1727 ** <dd> The SQLITE_CONFIG_SCRATCH option is no longer used.
1728 ** </dd>
1729 **
1730 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
1731 ** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool
1732 ** that SQLite can use for the database page cache with the default page
1733 ** cache implementation.
1734 ** This configuration option is a no-op if an application-define page
1735 ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2].
1736 ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
1737 ** 8-byte aligned memory (pMem), the size of each page cache line (sz),
1738 ** and the number of cache lines (N).
1739 ** The sz argument should be the size of the largest database page
1740 ** (a power of two between 512 and 65536) plus some extra bytes for each
1741 ** page header.  ^The number of extra bytes needed by the page header
1742 ** can be determined using [SQLITE_CONFIG_PCACHE_HDRSZ].
1743 ** ^It is harmless, apart from the wasted memory,
1744 ** for the sz parameter to be larger than necessary.  The pMem
1745 ** argument must be either a NULL pointer or a pointer to an 8-byte
1746 ** aligned block of memory of at least sz*N bytes, otherwise
1747 ** subsequent behavior is undefined.
1748 ** ^When pMem is not NULL, SQLite will strive to use the memory provided
1749 ** to satisfy page cache needs, falling back to [sqlite3_malloc()] if
1750 ** a page cache line is larger than sz bytes or if all of the pMem buffer
1751 ** is exhausted.
1752 ** ^If pMem is NULL and N is non-zero, then each database connection
1753 ** does an initial bulk allocation for page cache memory
1754 ** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or
1755 ** of -1024*N bytes if N is negative, . ^If additional
1756 ** page cache memory is needed beyond what is provided by the initial
1757 ** allocation, then SQLite goes to [sqlite3_malloc()] separately for each
1758 ** additional cache line. </dd>
1759 **
1760 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
1761 ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
1762 ** that SQLite will use for all of its dynamic memory allocation needs
1763 ** beyond those provided for by [SQLITE_CONFIG_PAGECACHE].
1764 ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
1765 ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
1766 ** [SQLITE_ERROR] if invoked otherwise.
1767 ** ^There are three arguments to SQLITE_CONFIG_HEAP:
1768 ** An 8-byte aligned pointer to the memory,
1769 ** the number of bytes in the memory buffer, and the minimum allocation size.
1770 ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
1771 ** to using its default memory allocator (the system malloc() implementation),
1772 ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC].  ^If the
1773 ** memory pointer is not NULL then the alternative memory
1774 ** allocator is engaged to handle all of SQLites memory allocation needs.
1775 ** The first pointer (the memory pointer) must be aligned to an 8-byte
1776 ** boundary or subsequent behavior of SQLite will be undefined.
1777 ** The minimum allocation size is capped at 2**12. Reasonable values
1778 ** for the minimum allocation size are 2**5 through 2**8.</dd>
1779 **
1780 ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
1781 ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
1782 ** pointer to an instance of the [sqlite3_mutex_methods] structure.
1783 ** The argument specifies alternative low-level mutex routines to be used
1784 ** in place the mutex routines built into SQLite.)^  ^SQLite makes a copy of
1785 ** the content of the [sqlite3_mutex_methods] structure before the call to
1786 ** [sqlite3_config()] returns. ^If SQLite is compiled with
1787 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1788 ** the entire mutexing subsystem is omitted from the build and hence calls to
1789 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
1790 ** return [SQLITE_ERROR].</dd>
1791 **
1792 ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
1793 ** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which
1794 ** is a pointer to an instance of the [sqlite3_mutex_methods] structure.  The
1795 ** [sqlite3_mutex_methods]
1796 ** structure is filled with the currently defined mutex routines.)^
1797 ** This option can be used to overload the default mutex allocation
1798 ** routines with a wrapper used to track mutex usage for performance
1799 ** profiling or testing, for example.   ^If SQLite is compiled with
1800 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1801 ** the entire mutexing subsystem is omitted from the build and hence calls to
1802 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
1803 ** return [SQLITE_ERROR].</dd>
1804 **
1805 ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1806 ** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
1807 ** the default size of lookaside memory on each [database connection].
1808 ** The first argument is the
1809 ** size of each lookaside buffer slot and the second is the number of
1810 ** slots allocated to each database connection.)^  ^(SQLITE_CONFIG_LOOKASIDE
1811 ** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1812 ** option to [sqlite3_db_config()] can be used to change the lookaside
1813 ** configuration on individual connections.)^ </dd>
1814 **
1815 ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
1816 ** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is
1817 ** a pointer to an [sqlite3_pcache_methods2] object.  This object specifies
1818 ** the interface to a custom page cache implementation.)^
1819 ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
1820 **
1821 ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
1822 ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
1823 ** is a pointer to an [sqlite3_pcache_methods2] object.  SQLite copies of
1824 ** the current page cache implementation into that object.)^ </dd>
1825 **
1826 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
1827 ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
1828 ** global [error log].
1829 ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
1830 ** function with a call signature of void(*)(void*,int,const char*),
1831 ** and a pointer to void. ^If the function pointer is not NULL, it is
1832 ** invoked by [sqlite3_log()] to process each logging event.  ^If the
1833 ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
1834 ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
1835 ** passed through as the first parameter to the application-defined logger
1836 ** function whenever that function is invoked.  ^The second parameter to
1837 ** the logger function is a copy of the first parameter to the corresponding
1838 ** [sqlite3_log()] call and is intended to be a [result code] or an
1839 ** [extended result code].  ^The third parameter passed to the logger is
1840 ** log message after formatting via [sqlite3_snprintf()].
1841 ** The SQLite logging interface is not reentrant; the logger function
1842 ** supplied by the application must not invoke any SQLite interface.
1843 ** In a multi-threaded application, the application-defined logger
1844 ** function must be threadsafe. </dd>
1845 **
1846 ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
1847 ** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int.
1848 ** If non-zero, then URI handling is globally enabled. If the parameter is zero,
1849 ** then URI handling is globally disabled.)^ ^If URI handling is globally
1850 ** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()],
1851 ** [sqlite3_open16()] or
1852 ** specified as part of [ATTACH] commands are interpreted as URIs, regardless
1853 ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
1854 ** connection is opened. ^If it is globally disabled, filenames are
1855 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
1856 ** database connection is opened. ^(By default, URI handling is globally
1857 ** disabled. The default value may be changed by compiling with the
1858 ** [SQLITE_USE_URI] symbol defined.)^
1859 **
1860 ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
1861 ** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer
1862 ** argument which is interpreted as a boolean in order to enable or disable
1863 ** the use of covering indices for full table scans in the query optimizer.
1864 ** ^The default setting is determined
1865 ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
1866 ** if that compile-time option is omitted.
1867 ** The ability to disable the use of covering indices for full table scans
1868 ** is because some incorrectly coded legacy applications might malfunction
1869 ** when the optimization is enabled.  Providing the ability to
1870 ** disable the optimization allows the older, buggy application code to work
1871 ** without change even with newer versions of SQLite.
1872 **
1873 ** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]]
1874 ** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE
1875 ** <dd> These options are obsolete and should not be used by new code.
1876 ** They are retained for backwards compatibility but are now no-ops.
1877 ** </dd>
1878 **
1879 ** [[SQLITE_CONFIG_SQLLOG]]
1880 ** <dt>SQLITE_CONFIG_SQLLOG
1881 ** <dd>This option is only available if sqlite is compiled with the
1882 ** [SQLITE_ENABLE_SQLLOG] pre-processor macro defined. The first argument should
1883 ** be a pointer to a function of type void(*)(void*,sqlite3*,const char*, int).
1884 ** The second should be of type (void*). The callback is invoked by the library
1885 ** in three separate circumstances, identified by the value passed as the
1886 ** fourth parameter. If the fourth parameter is 0, then the database connection
1887 ** passed as the second argument has just been opened. The third argument
1888 ** points to a buffer containing the name of the main database file. If the
1889 ** fourth parameter is 1, then the SQL statement that the third parameter
1890 ** points to has just been executed. Or, if the fourth parameter is 2, then
1891 ** the connection being passed as the second parameter is being closed. The
1892 ** third parameter is passed NULL In this case.  An example of using this
1893 ** configuration option can be seen in the "test_sqllog.c" source file in
1894 ** the canonical SQLite source tree.</dd>
1895 **
1896 ** [[SQLITE_CONFIG_MMAP_SIZE]]
1897 ** <dt>SQLITE_CONFIG_MMAP_SIZE
1898 ** <dd>^SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values
1899 ** that are the default mmap size limit (the default setting for
1900 ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
1901 ** ^The default setting can be overridden by each database connection using
1902 ** either the [PRAGMA mmap_size] command, or by using the
1903 ** [SQLITE_FCNTL_MMAP_SIZE] file control.  ^(The maximum allowed mmap size
1904 ** will be silently truncated if necessary so that it does not exceed the
1905 ** compile-time maximum mmap size set by the
1906 ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
1907 ** ^If either argument to this option is negative, then that argument is
1908 ** changed to its compile-time default.
1909 **
1910 ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
1911 ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
1912 ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
1913 ** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro
1914 ** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
1915 ** that specifies the maximum size of the created heap.
1916 **
1917 ** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
1918 ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
1919 ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
1920 ** is a pointer to an integer and writes into that integer the number of extra
1921 ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
1922 ** The amount of extra space required can change depending on the compiler,
1923 ** target platform, and SQLite version.
1924 **
1925 ** [[SQLITE_CONFIG_PMASZ]]
1926 ** <dt>SQLITE_CONFIG_PMASZ
1927 ** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which
1928 ** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded
1929 ** sorter to that integer.  The default minimum PMA Size is set by the
1930 ** [SQLITE_SORTER_PMASZ] compile-time option.  New threads are launched
1931 ** to help with sort operations when multithreaded sorting
1932 ** is enabled (using the [PRAGMA threads] command) and the amount of content
1933 ** to be sorted exceeds the page size times the minimum of the
1934 ** [PRAGMA cache_size] setting and this value.
1935 **
1936 ** [[SQLITE_CONFIG_STMTJRNL_SPILL]]
1937 ** <dt>SQLITE_CONFIG_STMTJRNL_SPILL
1938 ** <dd>^The SQLITE_CONFIG_STMTJRNL_SPILL option takes a single parameter which
1939 ** becomes the [statement journal] spill-to-disk threshold.
1940 ** [Statement journals] are held in memory until their size (in bytes)
1941 ** exceeds this threshold, at which point they are written to disk.
1942 ** Or if the threshold is -1, statement journals are always held
1943 ** exclusively in memory.
1944 ** Since many statement journals never become large, setting the spill
1945 ** threshold to a value such as 64KiB can greatly reduce the amount of
1946 ** I/O required to support statement rollback.
1947 ** The default value for this setting is controlled by the
1948 ** [SQLITE_STMTJRNL_SPILL] compile-time option.
1949 **
1950 ** [[SQLITE_CONFIG_SORTERREF_SIZE]]
1951 ** <dt>SQLITE_CONFIG_SORTERREF_SIZE
1952 ** <dd>The SQLITE_CONFIG_SORTERREF_SIZE option accepts a single parameter
1953 ** of type (int) - the new value of the sorter-reference size threshold.
1954 ** Usually, when SQLite uses an external sort to order records according
1955 ** to an ORDER BY clause, all fields required by the caller are present in the
1956 ** sorted records. However, if SQLite determines based on the declared type
1957 ** of a table column that its values are likely to be very large - larger
1958 ** than the configured sorter-reference size threshold - then a reference
1959 ** is stored in each sorted record and the required column values loaded
1960 ** from the database as records are returned in sorted order. The default
1961 ** value for this option is to never use this optimization. Specifying a
1962 ** negative value for this option restores the default behaviour.
1963 ** This option is only available if SQLite is compiled with the
1964 ** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option.
1965 ** </dl>
1966 */
1967 enum SQLITE_CONFIG_SINGLETHREAD = 1; /* nil */
1968 enum SQLITE_CONFIG_MULTITHREAD = 2; /* nil */
1969 enum SQLITE_CONFIG_SERIALIZED = 3; /* nil */
1970 enum SQLITE_CONFIG_MALLOC = 4; /* sqlite3_mem_methods* */
1971 enum SQLITE_CONFIG_GETMALLOC = 5; /* sqlite3_mem_methods* */
1972 enum SQLITE_CONFIG_SCRATCH = 6; /* No longer used */
1973 enum SQLITE_CONFIG_PAGECACHE = 7; /* void*, int sz, int N */
1974 enum SQLITE_CONFIG_HEAP = 8; /* void*, int nByte, int min */
1975 enum SQLITE_CONFIG_MEMSTATUS = 9; /* boolean */
1976 enum SQLITE_CONFIG_MUTEX = 10; /* sqlite3_mutex_methods* */
1977 enum SQLITE_CONFIG_GETMUTEX = 11; /* sqlite3_mutex_methods* */
1978 /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
1979 enum SQLITE_CONFIG_LOOKASIDE = 13; /* int int */
1980 enum SQLITE_CONFIG_PCACHE = 14; /* no-op */
1981 enum SQLITE_CONFIG_GETPCACHE = 15; /* no-op */
1982 enum SQLITE_CONFIG_LOG = 16; /* xFunc, void* */
1983 enum SQLITE_CONFIG_URI = 17; /* int */
1984 enum SQLITE_CONFIG_PCACHE2 = 18; /* sqlite3_pcache_methods2* */
1985 enum SQLITE_CONFIG_GETPCACHE2 = 19; /* sqlite3_pcache_methods2* */
1986 enum SQLITE_CONFIG_COVERING_INDEX_SCAN = 20; /* int */
1987 enum SQLITE_CONFIG_SQLLOG = 21; /* xSqllog, void* */
1988 enum SQLITE_CONFIG_MMAP_SIZE = 22; /* sqlite3_int64, sqlite3_int64 */
1989 enum SQLITE_CONFIG_WIN32_HEAPSIZE = 23; /* int nByte */
1990 enum SQLITE_CONFIG_PCACHE_HDRSZ = 24; /* int *psz */
1991 enum SQLITE_CONFIG_PMASZ = 25; /* unsigned int szPma */
1992 enum SQLITE_CONFIG_STMTJRNL_SPILL = 26; /* int nByte */
1993 enum SQLITE_CONFIG_SMALL_MALLOC = 27; /* boolean */
1994 enum SQLITE_CONFIG_SORTERREF_SIZE = 28; /* int nByte */
1995 
1996 /*
1997 ** CAPI3REF: Database Connection Configuration Options
1998 **
1999 ** These constants are the available integer configuration options that
2000 ** can be passed as the second argument to the [sqlite3_db_config()] interface.
2001 **
2002 ** New configuration options may be added in future releases of SQLite.
2003 ** Existing configuration options might be discontinued.  Applications
2004 ** should check the return code from [sqlite3_db_config()] to make sure that
2005 ** the call worked.  ^The [sqlite3_db_config()] interface will return a
2006 ** non-zero [error code] if a discontinued or unsupported configuration option
2007 ** is invoked.
2008 **
2009 ** <dl>
2010 ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
2011 ** <dd> ^This option takes three additional arguments that determine the
2012 ** [lookaside memory allocator] configuration for the [database connection].
2013 ** ^The first argument (the third parameter to [sqlite3_db_config()] is a
2014 ** pointer to a memory buffer to use for lookaside memory.
2015 ** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb
2016 ** may be NULL in which case SQLite will allocate the
2017 ** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the
2018 ** size of each lookaside buffer slot.  ^The third argument is the number of
2019 ** slots.  The size of the buffer in the first argument must be greater than
2020 ** or equal to the product of the second and third arguments.  The buffer
2021 ** must be aligned to an 8-byte boundary.  ^If the second argument to
2022 ** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
2023 ** rounded down to the next smaller multiple of 8.  ^(The lookaside memory
2024 ** configuration for a database connection can only be changed when that
2025 ** connection is not currently using lookaside memory, or in other words
2026 ** when the "current value" returned by
2027 ** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
2028 ** Any attempt to change the lookaside memory configuration when lookaside
2029 ** memory is in use leaves the configuration unchanged and returns
2030 ** [SQLITE_BUSY].)^</dd>
2031 **
2032 ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
2033 ** <dd> ^This option is used to enable or disable the enforcement of
2034 ** [foreign key constraints].  There should be two additional arguments.
2035 ** The first argument is an integer which is 0 to disable FK enforcement,
2036 ** positive to enable FK enforcement or negative to leave FK enforcement
2037 ** unchanged.  The second parameter is a pointer to an integer into which
2038 ** is written 0 or 1 to indicate whether FK enforcement is off or on
2039 ** following this call.  The second parameter may be a NULL pointer, in
2040 ** which case the FK enforcement setting is not reported back. </dd>
2041 **
2042 ** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>
2043 ** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
2044 ** There should be two additional arguments.
2045 ** The first argument is an integer which is 0 to disable triggers,
2046 ** positive to enable triggers or negative to leave the setting unchanged.
2047 ** The second parameter is a pointer to an integer into which
2048 ** is written 0 or 1 to indicate whether triggers are disabled or enabled
2049 ** following this call.  The second parameter may be a NULL pointer, in
2050 ** which case the trigger setting is not reported back. </dd>
2051 **
2052 ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
2053 ** <dd> ^This option is used to enable or disable the two-argument
2054 ** version of the [fts3_tokenizer()] function which is part of the
2055 ** [FTS3] full-text search engine extension.
2056 ** There should be two additional arguments.
2057 ** The first argument is an integer which is 0 to disable fts3_tokenizer() or
2058 ** positive to enable fts3_tokenizer() or negative to leave the setting
2059 ** unchanged.
2060 ** The second parameter is a pointer to an integer into which
2061 ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
2062 ** following this call.  The second parameter may be a NULL pointer, in
2063 ** which case the new setting is not reported back. </dd>
2064 **
2065 ** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
2066 ** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
2067 ** interface independently of the [load_extension()] SQL function.
2068 ** The [sqlite3_enable_load_extension()] API enables or disables both the
2069 ** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
2070 ** There should be two additional arguments.
2071 ** When the first argument to this interface is 1, then only the C-API is
2072 ** enabled and the SQL function remains disabled.  If the first argument to
2073 ** this interface is 0, then both the C-API and the SQL function are disabled.
2074 ** If the first argument is -1, then no changes are made to state of either the
2075 ** C-API or the SQL function.
2076 ** The second parameter is a pointer to an integer into which
2077 ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
2078 ** is disabled or enabled following this call.  The second parameter may
2079 ** be a NULL pointer, in which case the new setting is not reported back.
2080 ** </dd>
2081 **
2082 ** <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
2083 ** <dd> ^This option is used to change the name of the "main" database
2084 ** schema.  ^The sole argument is a pointer to a constant UTF8 string
2085 ** which will become the new schema name in place of "main".  ^SQLite
2086 ** does not make a copy of the new main schema name string, so the application
2087 ** must ensure that the argument passed into this DBCONFIG option is unchanged
2088 ** until after the database connection closes.
2089 ** </dd>
2090 **
2091 ** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>
2092 ** <dd> Usually, when a database in wal mode is closed or detached from a
2093 ** database handle, SQLite checks if this will mean that there are now no
2094 ** connections at all to the database. If so, it performs a checkpoint
2095 ** operation before closing the connection. This option may be used to
2096 ** override this behaviour. The first parameter passed to this operation
2097 ** is an integer - positive to disable checkpoints-on-close, or zero (the
2098 ** default) to enable them, and negative to leave the setting unchanged.
2099 ** The second parameter is a pointer to an integer
2100 ** into which is written 0 or 1 to indicate whether checkpoints-on-close
2101 ** have been disabled - 0 if they are not disabled, 1 if they are.
2102 ** </dd>
2103 **
2104 ** <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
2105 ** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates
2106 ** the [query planner stability guarantee] (QPSG).  When the QPSG is active,
2107 ** a single SQL query statement will always use the same algorithm regardless
2108 ** of values of [bound parameters].)^ The QPSG disables some query optimizations
2109 ** that look at the values of bound parameters, which can make some queries
2110 ** slower.  But the QPSG has the advantage of more predictable behavior.  With
2111 ** the QPSG active, SQLite will always use the same query plan in the field as
2112 ** was used during testing in the lab.
2113 ** The first argument to this setting is an integer which is 0 to disable
2114 ** the QPSG, positive to enable QPSG, or negative to leave the setting
2115 ** unchanged. The second parameter is a pointer to an integer into which
2116 ** is written 0 or 1 to indicate whether the QPSG is disabled or enabled
2117 ** following this call.
2118 ** </dd>
2119 **
2120 ** <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt>
2121 ** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not
2122 ** include output for any operations performed by trigger programs. This
2123 ** option is used to set or clear (the default) a flag that governs this
2124 ** behavior. The first parameter passed to this operation is an integer -
2125 ** positive to enable output for trigger programs, or zero to disable it,
2126 ** or negative to leave the setting unchanged.
2127 ** The second parameter is a pointer to an integer into which is written
2128 ** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if
2129 ** it is not disabled, 1 if it is.
2130 ** </dd>
2131 **
2132 ** <dt>SQLITE_DBCONFIG_RESET_DATABASE</dt>
2133 ** <dd> Set the SQLITE_DBCONFIG_RESET_DATABASE flag and then run
2134 ** [VACUUM] in order to reset a database back to an empty database
2135 ** with no schema and no content. The following process works even for
2136 ** a badly corrupted database file:
2137 ** <ol>
2138 ** <li> If the database connection is newly opened, make sure it has read the
2139 **      database schema by preparing then discarding some query against the
2140 **      database, or calling sqlite3_table_column_metadata(), ignoring any
2141 **      errors.  This step is only necessary if the application desires to keep
2142 **      the database in WAL mode after the reset if it was in WAL mode before
2143 **      the reset.
2144 ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0);
2145 ** <li> [sqlite3_exec](db, "[VACUUM]", 0, 0, 0);
2146 ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
2147 ** </ol>
2148 ** Because resetting a database is destructive and irreversible, the
2149 ** process requires the use of this obscure API and multiple steps to help
2150 ** ensure that it does not happen by accident.
2151 ** </dd>
2152 ** </dl>
2153 */
2154 enum SQLITE_DBCONFIG_MAINDBNAME = 1000; /* const char* */
2155 enum SQLITE_DBCONFIG_LOOKASIDE = 1001; /* void* int int */
2156 enum SQLITE_DBCONFIG_ENABLE_FKEY = 1002; /* int int* */
2157 enum SQLITE_DBCONFIG_ENABLE_TRIGGER = 1003; /* int int* */
2158 enum SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER = 1004; /* int int* */
2159 enum SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION = 1005; /* int int* */
2160 enum SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE = 1006; /* int int* */
2161 enum SQLITE_DBCONFIG_ENABLE_QPSG = 1007; /* int int* */
2162 enum SQLITE_DBCONFIG_TRIGGER_EQP = 1008; /* int int* */
2163 enum SQLITE_DBCONFIG_RESET_DATABASE = 1009; /* int int* */
2164 enum SQLITE_DBCONFIG_MAX = 1009; /* Largest DBCONFIG */
2165 
2166 /*
2167 ** CAPI3REF: Enable Or Disable Extended Result Codes
2168 ** METHOD: sqlite3
2169 **
2170 ** ^The sqlite3_extended_result_codes() routine enables or disables the
2171 ** [extended result codes] feature of SQLite. ^The extended result
2172 ** codes are disabled by default for historical compatibility.
2173 */
2174 int sqlite3_extended_result_codes(sqlite3*, int onoff);
2175 
2176 /*
2177 ** CAPI3REF: Last Insert Rowid
2178 ** METHOD: sqlite3
2179 **
2180 ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
2181 ** has a unique 64-bit signed
2182 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
2183 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
2184 ** names are not also used by explicitly declared columns. ^If
2185 ** the table has a column of type [INTEGER PRIMARY KEY] then that column
2186 ** is another alias for the rowid.
2187 **
2188 ** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of
2189 ** the most recent successful [INSERT] into a rowid table or [virtual table]
2190 ** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not
2191 ** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred
2192 ** on the database connection D, then sqlite3_last_insert_rowid(D) returns
2193 ** zero.
2194 **
2195 ** As well as being set automatically as rows are inserted into database
2196 ** tables, the value returned by this function may be set explicitly by
2197 ** [sqlite3_set_last_insert_rowid()]
2198 **
2199 ** Some virtual table implementations may INSERT rows into rowid tables as
2200 ** part of committing a transaction (e.g. to flush data accumulated in memory
2201 ** to disk). In this case subsequent calls to this function return the rowid
2202 ** associated with these internal INSERT operations, which leads to
2203 ** unintuitive results. Virtual table implementations that do write to rowid
2204 ** tables in this way can avoid this problem by restoring the original
2205 ** rowid value using [sqlite3_set_last_insert_rowid()] before returning
2206 ** control to the user.
2207 **
2208 ** ^(If an [INSERT] occurs within a trigger then this routine will
2209 ** return the [rowid] of the inserted row as long as the trigger is
2210 ** running. Once the trigger program ends, the value returned
2211 ** by this routine reverts to what it was before the trigger was fired.)^
2212 **
2213 ** ^An [INSERT] that fails due to a constraint violation is not a
2214 ** successful [INSERT] and does not change the value returned by this
2215 ** routine.  ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
2216 ** and INSERT OR ABORT make no changes to the return value of this
2217 ** routine when their insertion fails.  ^(When INSERT OR REPLACE
2218 ** encounters a constraint violation, it does not fail.  The
2219 ** INSERT continues to completion after deleting rows that caused
2220 ** the constraint problem so INSERT OR REPLACE will always change
2221 ** the return value of this interface.)^
2222 **
2223 ** ^For the purposes of this routine, an [INSERT] is considered to
2224 ** be successful even if it is subsequently rolled back.
2225 **
2226 ** This function is accessible to SQL statements via the
2227 ** [last_insert_rowid() SQL function].
2228 **
2229 ** If a separate thread performs a new [INSERT] on the same
2230 ** database connection while the [sqlite3_last_insert_rowid()]
2231 ** function is running and thus changes the last insert [rowid],
2232 ** then the value returned by [sqlite3_last_insert_rowid()] is
2233 ** unpredictable and might not equal either the old or the new
2234 ** last insert [rowid].
2235 */
2236 sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
2237 
2238 /*
2239 ** CAPI3REF: Set the Last Insert Rowid value.
2240 ** METHOD: sqlite3
2241 **
2242 ** The sqlite3_set_last_insert_rowid(D, R) method allows the application to
2243 ** set the value returned by calling sqlite3_last_insert_rowid(D) to R
2244 ** without inserting a row into the database.
2245 */
2246 void sqlite3_set_last_insert_rowid(sqlite3*, sqlite3_int64);
2247 
2248 /*
2249 ** CAPI3REF: Count The Number Of Rows Modified
2250 ** METHOD: sqlite3
2251 **
2252 ** ^This function returns the number of rows modified, inserted or
2253 ** deleted by the most recently completed INSERT, UPDATE or DELETE
2254 ** statement on the database connection specified by the only parameter.
2255 ** ^Executing any other type of SQL statement does not modify the value
2256 ** returned by this function.
2257 **
2258 ** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are
2259 ** considered - auxiliary changes caused by [CREATE TRIGGER | triggers],
2260 ** [foreign key actions] or [REPLACE] constraint resolution are not counted.
2261 **
2262 ** Changes to a view that are intercepted by
2263 ** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value
2264 ** returned by sqlite3_changes() immediately after an INSERT, UPDATE or
2265 ** DELETE statement run on a view is always zero. Only changes made to real
2266 ** tables are counted.
2267 **
2268 ** Things are more complicated if the sqlite3_changes() function is
2269 ** executed while a trigger program is running. This may happen if the
2270 ** program uses the [changes() SQL function], or if some other callback
2271 ** function invokes sqlite3_changes() directly. Essentially:
2272 **
2273 ** <ul>
2274 **   <li> ^(Before entering a trigger program the value returned by
2275 **        sqlite3_changes() function is saved. After the trigger program
2276 **        has finished, the original value is restored.)^
2277 **
2278 **   <li> ^(Within a trigger program each INSERT, UPDATE and DELETE
2279 **        statement sets the value returned by sqlite3_changes()
2280 **        upon completion as normal. Of course, this value will not include
2281 **        any changes performed by sub-triggers, as the sqlite3_changes()
2282 **        value will be saved and restored after each sub-trigger has run.)^
2283 ** </ul>
2284 **
2285 ** ^This means that if the changes() SQL function (or similar) is used
2286 ** by the first INSERT, UPDATE or DELETE statement within a trigger, it
2287 ** returns the value as set when the calling statement began executing.
2288 ** ^If it is used by the second or subsequent such statement within a trigger
2289 ** program, the value returned reflects the number of rows modified by the
2290 ** previous INSERT, UPDATE or DELETE statement within the same trigger.
2291 **
2292 ** If a separate thread makes changes on the same database connection
2293 ** while [sqlite3_changes()] is running then the value returned
2294 ** is unpredictable and not meaningful.
2295 **
2296 ** See also:
2297 ** <ul>
2298 ** <li> the [sqlite3_total_changes()] interface
2299 ** <li> the [count_changes pragma]
2300 ** <li> the [changes() SQL function]
2301 ** <li> the [data_version pragma]
2302 ** </ul>
2303 */
2304 int sqlite3_changes(sqlite3*);
2305 
2306 /*
2307 ** CAPI3REF: Total Number Of Rows Modified
2308 ** METHOD: sqlite3
2309 **
2310 ** ^This function returns the total number of rows inserted, modified or
2311 ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
2312 ** since the database connection was opened, including those executed as
2313 ** part of trigger programs. ^Executing any other type of SQL statement
2314 ** does not affect the value returned by sqlite3_total_changes().
2315 **
2316 ** ^Changes made as part of [foreign key actions] are included in the
2317 ** count, but those made as part of REPLACE constraint resolution are
2318 ** not. ^Changes to a view that are intercepted by INSTEAD OF triggers
2319 ** are not counted.
2320 **
2321 ** This the [sqlite3_total_changes(D)] interface only reports the number
2322 ** of rows that changed due to SQL statement run against database
2323 ** connection D.  Any changes by other database connections are ignored.
2324 ** To detect changes against a database file from other database
2325 ** connections use the [PRAGMA data_version] command or the
2326 ** [SQLITE_FCNTL_DATA_VERSION] [file control].
2327 **
2328 ** If a separate thread makes changes on the same database connection
2329 ** while [sqlite3_total_changes()] is running then the value
2330 ** returned is unpredictable and not meaningful.
2331 **
2332 ** See also:
2333 ** <ul>
2334 ** <li> the [sqlite3_changes()] interface
2335 ** <li> the [count_changes pragma]
2336 ** <li> the [changes() SQL function]
2337 ** <li> the [data_version pragma]
2338 ** <li> the [SQLITE_FCNTL_DATA_VERSION] [file control]
2339 ** </ul>
2340 */
2341 int sqlite3_total_changes(sqlite3*);
2342 
2343 /*
2344 ** CAPI3REF: Interrupt A Long-Running Query
2345 ** METHOD: sqlite3
2346 **
2347 ** ^This function causes any pending database operation to abort and
2348 ** return at its earliest opportunity. This routine is typically
2349 ** called in response to a user action such as pressing "Cancel"
2350 ** or Ctrl-C where the user wants a long query operation to halt
2351 ** immediately.
2352 **
2353 ** ^It is safe to call this routine from a thread different from the
2354 ** thread that is currently running the database operation.  But it
2355 ** is not safe to call this routine with a [database connection] that
2356 ** is closed or might close before sqlite3_interrupt() returns.
2357 **
2358 ** ^If an SQL operation is very nearly finished at the time when
2359 ** sqlite3_interrupt() is called, then it might not have an opportunity
2360 ** to be interrupted and might continue to completion.
2361 **
2362 ** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT].
2363 ** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE
2364 ** that is inside an explicit transaction, then the entire transaction
2365 ** will be rolled back automatically.
2366 **
2367 ** ^The sqlite3_interrupt(D) call is in effect until all currently running
2368 ** SQL statements on [database connection] D complete.  ^Any new SQL statements
2369 ** that are started after the sqlite3_interrupt() call and before the
2370 ** running statements reaches zero are interrupted as if they had been
2371 ** running prior to the sqlite3_interrupt() call.  ^New SQL statements
2372 ** that are started after the running statement count reaches zero are
2373 ** not effected by the sqlite3_interrupt().
2374 ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
2375 ** SQL statements is a no-op and has no effect on SQL statements
2376 ** that are started after the sqlite3_interrupt() call returns.
2377 */
2378 void sqlite3_interrupt(sqlite3*);
2379 
2380 /*
2381 ** CAPI3REF: Determine If An SQL Statement Is Complete
2382 **
2383 ** These routines are useful during command-line input to determine if the
2384 ** currently entered text seems to form a complete SQL statement or
2385 ** if additional input is needed before sending the text into
2386 ** SQLite for parsing.  ^These routines return 1 if the input string
2387 ** appears to be a complete SQL statement.  ^A statement is judged to be
2388 ** complete if it ends with a semicolon token and is not a prefix of a
2389 ** well-formed CREATE TRIGGER statement.  ^Semicolons that are embedded within
2390 ** string literals or quoted identifier names or comments are not
2391 ** independent tokens (they are part of the token in which they are
2392 ** embedded) and thus do not count as a statement terminator.  ^Whitespace
2393 ** and comments that follow the final semicolon are ignored.
2394 **
2395 ** ^These routines return 0 if the statement is incomplete.  ^If a
2396 ** memory allocation fails, then SQLITE_NOMEM is returned.
2397 **
2398 ** ^These routines do not parse the SQL statements thus
2399 ** will not detect syntactically incorrect SQL.
2400 **
2401 ** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior
2402 ** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked
2403 ** automatically by sqlite3_complete16().  If that initialization fails,
2404 ** then the return value from sqlite3_complete16() will be non-zero
2405 ** regardless of whether or not the input SQL is complete.)^
2406 **
2407 ** The input to [sqlite3_complete()] must be a zero-terminated
2408 ** UTF-8 string.
2409 **
2410 ** The input to [sqlite3_complete16()] must be a zero-terminated
2411 ** UTF-16 string in native byte order.
2412 */
2413 int sqlite3_complete(const(char)* sql);
2414 int sqlite3_complete16(const(void)* sql);
2415 
2416 /*
2417 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2418 ** KEYWORDS: {busy-handler callback} {busy handler}
2419 ** METHOD: sqlite3
2420 **
2421 ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
2422 ** that might be invoked with argument P whenever
2423 ** an attempt is made to access a database table associated with
2424 ** [database connection] D when another thread
2425 ** or process has the table locked.
2426 ** The sqlite3_busy_handler() interface is used to implement
2427 ** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout].
2428 **
2429 ** ^If the busy callback is NULL, then [SQLITE_BUSY]
2430 ** is returned immediately upon encountering the lock.  ^If the busy callback
2431 ** is not NULL, then the callback might be invoked with two arguments.
2432 **
2433 ** ^The first argument to the busy handler is a copy of the void* pointer which
2434 ** is the third argument to sqlite3_busy_handler().  ^The second argument to
2435 ** the busy handler callback is the number of times that the busy handler has
2436 ** been invoked previously for the same locking event.  ^If the
2437 ** busy callback returns 0, then no additional attempts are made to
2438 ** access the database and [SQLITE_BUSY] is returned
2439 ** to the application.
2440 ** ^If the callback returns non-zero, then another attempt
2441 ** is made to access the database and the cycle repeats.
2442 **
2443 ** The presence of a busy handler does not guarantee that it will be invoked
2444 ** when there is lock contention. ^If SQLite determines that invoking the busy
2445 ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
2446 ** to the application instead of invoking the
2447 ** busy handler.
2448 ** Consider a scenario where one process is holding a read lock that
2449 ** it is trying to promote to a reserved lock and
2450 ** a second process is holding a reserved lock that it is trying
2451 ** to promote to an exclusive lock.  The first process cannot proceed
2452 ** because it is blocked by the second and the second process cannot
2453 ** proceed because it is blocked by the first.  If both processes
2454 ** invoke the busy handlers, neither will make any progress.  Therefore,
2455 ** SQLite returns [SQLITE_BUSY] for the first process, hoping that this
2456 ** will induce the first process to release its read lock and allow
2457 ** the second process to proceed.
2458 **
2459 ** ^The default busy callback is NULL.
2460 **
2461 ** ^(There can only be a single busy handler defined for each
2462 ** [database connection].  Setting a new busy handler clears any
2463 ** previously set handler.)^  ^Note that calling [sqlite3_busy_timeout()]
2464 ** or evaluating [PRAGMA busy_timeout=N] will change the
2465 ** busy handler and thus clear any previously set busy handler.
2466 **
2467 ** The busy callback should not take any actions which modify the
2468 ** database connection that invoked the busy handler.  In other words,
2469 ** the busy handler is not reentrant.  Any such actions
2470 ** result in undefined behavior.
2471 **
2472 ** A busy handler must not close the database connection
2473 ** or [prepared statement] that invoked the busy handler.
2474 */
2475 int sqlite3_busy_handler(sqlite3*, int function(void*, int), void*);
2476 
2477 /*
2478 ** CAPI3REF: Set A Busy Timeout
2479 ** METHOD: sqlite3
2480 **
2481 ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
2482 ** for a specified amount of time when a table is locked.  ^The handler
2483 ** will sleep multiple times until at least "ms" milliseconds of sleeping
2484 ** have accumulated.  ^After at least "ms" milliseconds of sleeping,
2485 ** the handler returns 0 which causes [sqlite3_step()] to return
2486 ** [SQLITE_BUSY].
2487 **
2488 ** ^Calling this routine with an argument less than or equal to zero
2489 ** turns off all busy handlers.
2490 **
2491 ** ^(There can only be a single busy handler for a particular
2492 ** [database connection] at any given moment.  If another busy handler
2493 ** was defined  (using [sqlite3_busy_handler()]) prior to calling
2494 ** this routine, that other busy handler is cleared.)^
2495 **
2496 ** See also:  [PRAGMA busy_timeout]
2497 */
2498 int sqlite3_busy_timeout(sqlite3*, int ms);
2499 
2500 /*
2501 ** CAPI3REF: Convenience Routines For Running Queries
2502 ** METHOD: sqlite3
2503 **
2504 ** This is a legacy interface that is preserved for backwards compatibility.
2505 ** Use of this interface is not recommended.
2506 **
2507 ** Definition: A <b>result table</b> is memory data structure created by the
2508 ** [sqlite3_get_table()] interface.  A result table records the
2509 ** complete query results from one or more queries.
2510 **
2511 ** The table conceptually has a number of rows and columns.  But
2512 ** these numbers are not part of the result table itself.  These
2513 ** numbers are obtained separately.  Let N be the number of rows
2514 ** and M be the number of columns.
2515 **
2516 ** A result table is an array of pointers to zero-terminated UTF-8 strings.
2517 ** There are (N+1)*M elements in the array.  The first M pointers point
2518 ** to zero-terminated strings that  contain the names of the columns.
2519 ** The remaining entries all point to query results.  NULL values result
2520 ** in NULL pointers.  All other values are in their UTF-8 zero-terminated
2521 ** string representation as returned by [sqlite3_column_text()].
2522 **
2523 ** A result table might consist of one or more memory allocations.
2524 ** It is not safe to pass a result table directly to [sqlite3_free()].
2525 ** A result table should be deallocated using [sqlite3_free_table()].
2526 **
2527 ** ^(As an example of the result table format, suppose a query result
2528 ** is as follows:
2529 **
2530 ** <blockquote><pre>
2531 **        Name        | Age
2532 **        -----------------------
2533 **        Alice       | 43
2534 **        Bob         | 28
2535 **        Cindy       | 21
2536 ** </pre></blockquote>
2537 **
2538 ** There are two column (M==2) and three rows (N==3).  Thus the
2539 ** result table has 8 entries.  Suppose the result table is stored
2540 ** in an array names azResult.  Then azResult holds this content:
2541 **
2542 ** <blockquote><pre>
2543 **        azResult&#91;0] = "Name";
2544 **        azResult&#91;1] = "Age";
2545 **        azResult&#91;2] = "Alice";
2546 **        azResult&#91;3] = "43";
2547 **        azResult&#91;4] = "Bob";
2548 **        azResult&#91;5] = "28";
2549 **        azResult&#91;6] = "Cindy";
2550 **        azResult&#91;7] = "21";
2551 ** </pre></blockquote>)^
2552 **
2553 ** ^The sqlite3_get_table() function evaluates one or more
2554 ** semicolon-separated SQL statements in the zero-terminated UTF-8
2555 ** string of its 2nd parameter and returns a result table to the
2556 ** pointer given in its 3rd parameter.
2557 **
2558 ** After the application has finished with the result from sqlite3_get_table(),
2559 ** it must pass the result table pointer to sqlite3_free_table() in order to
2560 ** release the memory that was malloced.  Because of the way the
2561 ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
2562 ** function must not try to call [sqlite3_free()] directly.  Only
2563 ** [sqlite3_free_table()] is able to release the memory properly and safely.
2564 **
2565 ** The sqlite3_get_table() interface is implemented as a wrapper around
2566 ** [sqlite3_exec()].  The sqlite3_get_table() routine does not have access
2567 ** to any internal data structures of SQLite.  It uses only the public
2568 ** interface defined here.  As a consequence, errors that occur in the
2569 ** wrapper layer outside of the internal [sqlite3_exec()] call are not
2570 ** reflected in subsequent calls to [sqlite3_errcode()] or
2571 ** [sqlite3_errmsg()].
2572 */
2573 /* An open database */
2574 /* SQL to be evaluated */
2575 /* Results of the query */
2576 /* Number of result rows written here */
2577 /* Number of result columns written here */
2578 /* Error msg written here */
2579 int sqlite3_get_table(
2580     sqlite3* db,
2581     const(char)* zSql,
2582     char*** pazResult,
2583     int* pnRow,
2584     int* pnColumn,
2585     char** pzErrmsg);
2586 void sqlite3_free_table(char** result);
2587 
2588 /*
2589 ** CAPI3REF: Formatted String Printing Functions
2590 **
2591 ** These routines are work-alikes of the "printf()" family of functions
2592 ** from the standard C library.
2593 ** These routines understand most of the common formatting options from
2594 ** the standard library printf()
2595 ** plus some additional non-standard formats ([%q], [%Q], [%w], and [%z]).
2596 ** See the [built-in printf()] documentation for details.
2597 **
2598 ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
2599 ** results into memory obtained from [sqlite3_malloc64()].
2600 ** The strings returned by these two routines should be
2601 ** released by [sqlite3_free()].  ^Both routines return a
2602 ** NULL pointer if [sqlite3_malloc64()] is unable to allocate enough
2603 ** memory to hold the resulting string.
2604 **
2605 ** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from
2606 ** the standard C library.  The result is written into the
2607 ** buffer supplied as the second parameter whose size is given by
2608 ** the first parameter. Note that the order of the
2609 ** first two parameters is reversed from snprintf().)^  This is an
2610 ** historical accident that cannot be fixed without breaking
2611 ** backwards compatibility.  ^(Note also that sqlite3_snprintf()
2612 ** returns a pointer to its buffer instead of the number of
2613 ** characters actually written into the buffer.)^  We admit that
2614 ** the number of characters written would be a more useful return
2615 ** value but we cannot change the implementation of sqlite3_snprintf()
2616 ** now without breaking compatibility.
2617 **
2618 ** ^As long as the buffer size is greater than zero, sqlite3_snprintf()
2619 ** guarantees that the buffer is always zero-terminated.  ^The first
2620 ** parameter "n" is the total size of the buffer, including space for
2621 ** the zero terminator.  So the longest string that can be completely
2622 ** written will be n-1 characters.
2623 **
2624 ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
2625 **
2626 ** See also:  [built-in printf()], [printf() SQL function]
2627 */
2628 char* sqlite3_mprintf(const(char)*, ...);
2629 char* sqlite3_vmprintf(const(char)*, va_list);
2630 char* sqlite3_snprintf(int, char*, const(char)*, ...);
2631 char* sqlite3_vsnprintf(int, char*, const(char)*, va_list);
2632 
2633 /*
2634 ** CAPI3REF: Memory Allocation Subsystem
2635 **
2636 ** The SQLite core uses these three routines for all of its own
2637 ** internal memory allocation needs. "Core" in the previous sentence
2638 ** does not include operating-system specific VFS implementation.  The
2639 ** Windows VFS uses native malloc() and free() for some operations.
2640 **
2641 ** ^The sqlite3_malloc() routine returns a pointer to a block
2642 ** of memory at least N bytes in length, where N is the parameter.
2643 ** ^If sqlite3_malloc() is unable to obtain sufficient free
2644 ** memory, it returns a NULL pointer.  ^If the parameter N to
2645 ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
2646 ** a NULL pointer.
2647 **
2648 ** ^The sqlite3_malloc64(N) routine works just like
2649 ** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead
2650 ** of a signed 32-bit integer.
2651 **
2652 ** ^Calling sqlite3_free() with a pointer previously returned
2653 ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
2654 ** that it might be reused.  ^The sqlite3_free() routine is
2655 ** a no-op if is called with a NULL pointer.  Passing a NULL pointer
2656 ** to sqlite3_free() is harmless.  After being freed, memory
2657 ** should neither be read nor written.  Even reading previously freed
2658 ** memory might result in a segmentation fault or other severe error.
2659 ** Memory corruption, a segmentation fault, or other severe error
2660 ** might result if sqlite3_free() is called with a non-NULL pointer that
2661 ** was not obtained from sqlite3_malloc() or sqlite3_realloc().
2662 **
2663 ** ^The sqlite3_realloc(X,N) interface attempts to resize a
2664 ** prior memory allocation X to be at least N bytes.
2665 ** ^If the X parameter to sqlite3_realloc(X,N)
2666 ** is a NULL pointer then its behavior is identical to calling
2667 ** sqlite3_malloc(N).
2668 ** ^If the N parameter to sqlite3_realloc(X,N) is zero or
2669 ** negative then the behavior is exactly the same as calling
2670 ** sqlite3_free(X).
2671 ** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation
2672 ** of at least N bytes in size or NULL if insufficient memory is available.
2673 ** ^If M is the size of the prior allocation, then min(N,M) bytes
2674 ** of the prior allocation are copied into the beginning of buffer returned
2675 ** by sqlite3_realloc(X,N) and the prior allocation is freed.
2676 ** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the
2677 ** prior allocation is not freed.
2678 **
2679 ** ^The sqlite3_realloc64(X,N) interfaces works the same as
2680 ** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead
2681 ** of a 32-bit signed integer.
2682 **
2683 ** ^If X is a memory allocation previously obtained from sqlite3_malloc(),
2684 ** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then
2685 ** sqlite3_msize(X) returns the size of that memory allocation in bytes.
2686 ** ^The value returned by sqlite3_msize(X) might be larger than the number
2687 ** of bytes requested when X was allocated.  ^If X is a NULL pointer then
2688 ** sqlite3_msize(X) returns zero.  If X points to something that is not
2689 ** the beginning of memory allocation, or if it points to a formerly
2690 ** valid memory allocation that has now been freed, then the behavior
2691 ** of sqlite3_msize(X) is undefined and possibly harmful.
2692 **
2693 ** ^The memory returned by sqlite3_malloc(), sqlite3_realloc(),
2694 ** sqlite3_malloc64(), and sqlite3_realloc64()
2695 ** is always aligned to at least an 8 byte boundary, or to a
2696 ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
2697 ** option is used.
2698 **
2699 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define
2700 ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
2701 ** implementation of these routines to be omitted.  That capability
2702 ** is no longer provided.  Only built-in memory allocators can be used.
2703 **
2704 ** Prior to SQLite version 3.7.10, the Windows OS interface layer called
2705 ** the system malloc() and free() directly when converting
2706 ** filenames between the UTF-8 encoding used by SQLite
2707 ** and whatever filename encoding is used by the particular Windows
2708 ** installation.  Memory allocation errors were detected, but
2709 ** they were reported back as [SQLITE_CANTOPEN] or
2710 ** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
2711 **
2712 ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
2713 ** must be either NULL or else pointers obtained from a prior
2714 ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
2715 ** not yet been released.
2716 **
2717 ** The application must not read or write any part of
2718 ** a block of memory after it has been released using
2719 ** [sqlite3_free()] or [sqlite3_realloc()].
2720 */
2721 void* sqlite3_malloc(int);
2722 void* sqlite3_malloc64(sqlite3_uint64);
2723 void* sqlite3_realloc(void*, int);
2724 void* sqlite3_realloc64(void*, sqlite3_uint64);
2725 void sqlite3_free(void*);
2726 sqlite3_uint64 sqlite3_msize(void*);
2727 
2728 /*
2729 ** CAPI3REF: Memory Allocator Statistics
2730 **
2731 ** SQLite provides these two interfaces for reporting on the status
2732 ** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()]
2733 ** routines, which form the built-in memory allocation subsystem.
2734 **
2735 ** ^The [sqlite3_memory_used()] routine returns the number of bytes
2736 ** of memory currently outstanding (malloced but not freed).
2737 ** ^The [sqlite3_memory_highwater()] routine returns the maximum
2738 ** value of [sqlite3_memory_used()] since the high-water mark
2739 ** was last reset.  ^The values returned by [sqlite3_memory_used()] and
2740 ** [sqlite3_memory_highwater()] include any overhead
2741 ** added by SQLite in its implementation of [sqlite3_malloc()],
2742 ** but not overhead added by the any underlying system library
2743 ** routines that [sqlite3_malloc()] may call.
2744 **
2745 ** ^The memory high-water mark is reset to the current value of
2746 ** [sqlite3_memory_used()] if and only if the parameter to
2747 ** [sqlite3_memory_highwater()] is true.  ^The value returned
2748 ** by [sqlite3_memory_highwater(1)] is the high-water mark
2749 ** prior to the reset.
2750 */
2751 sqlite3_int64 sqlite3_memory_used();
2752 sqlite3_int64 sqlite3_memory_highwater(int resetFlag);
2753 
2754 /*
2755 ** CAPI3REF: Pseudo-Random Number Generator
2756 **
2757 ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
2758 ** select random [ROWID | ROWIDs] when inserting new records into a table that
2759 ** already uses the largest possible [ROWID].  The PRNG is also used for
2760 ** the build-in random() and randomblob() SQL functions.  This interface allows
2761 ** applications to access the same PRNG for other purposes.
2762 **
2763 ** ^A call to this routine stores N bytes of randomness into buffer P.
2764 ** ^The P parameter can be a NULL pointer.
2765 **
2766 ** ^If this routine has not been previously called or if the previous
2767 ** call had N less than one or a NULL pointer for P, then the PRNG is
2768 ** seeded using randomness obtained from the xRandomness method of
2769 ** the default [sqlite3_vfs] object.
2770 ** ^If the previous call to this routine had an N of 1 or more and a
2771 ** non-NULL P then the pseudo-randomness is generated
2772 ** internally and without recourse to the [sqlite3_vfs] xRandomness
2773 ** method.
2774 */
2775 void sqlite3_randomness(int N, void* P);
2776 
2777 /*
2778 ** CAPI3REF: Compile-Time Authorization Callbacks
2779 ** METHOD: sqlite3
2780 ** KEYWORDS: {authorizer callback}
2781 **
2782 ** ^This routine registers an authorizer callback with a particular
2783 ** [database connection], supplied in the first argument.
2784 ** ^The authorizer callback is invoked as SQL statements are being compiled
2785 ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
2786 ** [sqlite3_prepare_v3()], [sqlite3_prepare16()], [sqlite3_prepare16_v2()],
2787 ** and [sqlite3_prepare16_v3()].  ^At various
2788 ** points during the compilation process, as logic is being created
2789 ** to perform various actions, the authorizer callback is invoked to
2790 ** see if those actions are allowed.  ^The authorizer callback should
2791 ** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the
2792 ** specific action but allow the SQL statement to continue to be
2793 ** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be
2794 ** rejected with an error.  ^If the authorizer callback returns
2795 ** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY]
2796 ** then the [sqlite3_prepare_v2()] or equivalent call that triggered
2797 ** the authorizer will fail with an error message.
2798 **
2799 ** When the callback returns [SQLITE_OK], that means the operation
2800 ** requested is ok.  ^When the callback returns [SQLITE_DENY], the
2801 ** [sqlite3_prepare_v2()] or equivalent call that triggered the
2802 ** authorizer will fail with an error message explaining that
2803 ** access is denied.
2804 **
2805 ** ^The first parameter to the authorizer callback is a copy of the third
2806 ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
2807 ** to the callback is an integer [SQLITE_COPY | action code] that specifies
2808 ** the particular action to be authorized. ^The third through sixth parameters
2809 ** to the callback are either NULL pointers or zero-terminated strings
2810 ** that contain additional details about the action to be authorized.
2811 ** Applications must always be prepared to encounter a NULL pointer in any
2812 ** of the third through the sixth parameters of the authorization callback.
2813 **
2814 ** ^If the action code is [SQLITE_READ]
2815 ** and the callback returns [SQLITE_IGNORE] then the
2816 ** [prepared statement] statement is constructed to substitute
2817 ** a NULL value in place of the table column that would have
2818 ** been read if [SQLITE_OK] had been returned.  The [SQLITE_IGNORE]
2819 ** return can be used to deny an untrusted user access to individual
2820 ** columns of a table.
2821 ** ^When a table is referenced by a [SELECT] but no column values are
2822 ** extracted from that table (for example in a query like
2823 ** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback
2824 ** is invoked once for that table with a column name that is an empty string.
2825 ** ^If the action code is [SQLITE_DELETE] and the callback returns
2826 ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
2827 ** [truncate optimization] is disabled and all rows are deleted individually.
2828 **
2829 ** An authorizer is used when [sqlite3_prepare | preparing]
2830 ** SQL statements from an untrusted source, to ensure that the SQL statements
2831 ** do not try to access data they are not allowed to see, or that they do not
2832 ** try to execute malicious statements that damage the database.  For
2833 ** example, an application may allow a user to enter arbitrary
2834 ** SQL queries for evaluation by a database.  But the application does
2835 ** not want the user to be able to make arbitrary changes to the
2836 ** database.  An authorizer could then be put in place while the
2837 ** user-entered SQL is being [sqlite3_prepare | prepared] that
2838 ** disallows everything except [SELECT] statements.
2839 **
2840 ** Applications that need to process SQL from untrusted sources
2841 ** might also consider lowering resource limits using [sqlite3_limit()]
2842 ** and limiting database size using the [max_page_count] [PRAGMA]
2843 ** in addition to using an authorizer.
2844 **
2845 ** ^(Only a single authorizer can be in place on a database connection
2846 ** at a time.  Each call to sqlite3_set_authorizer overrides the
2847 ** previous call.)^  ^Disable the authorizer by installing a NULL callback.
2848 ** The authorizer is disabled by default.
2849 **
2850 ** The authorizer callback must not do anything that will modify
2851 ** the database connection that invoked the authorizer callback.
2852 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
2853 ** database connections for the meaning of "modify" in this paragraph.
2854 **
2855 ** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the
2856 ** statement might be re-prepared during [sqlite3_step()] due to a
2857 ** schema change.  Hence, the application should ensure that the
2858 ** correct authorizer callback remains in place during the [sqlite3_step()].
2859 **
2860 ** ^Note that the authorizer callback is invoked only during
2861 ** [sqlite3_prepare()] or its variants.  Authorization is not
2862 ** performed during statement evaluation in [sqlite3_step()], unless
2863 ** as stated in the previous paragraph, sqlite3_step() invokes
2864 ** sqlite3_prepare_v2() to reprepare a statement after a schema change.
2865 */
2866 int sqlite3_set_authorizer(
2867     sqlite3*,
2868     int function(void*, int, const(char)*, const(char)*, const(char)*, const(char)*) xAuth,
2869     void* pUserData);
2870 
2871 /*
2872 ** CAPI3REF: Authorizer Return Codes
2873 **
2874 ** The [sqlite3_set_authorizer | authorizer callback function] must
2875 ** return either [SQLITE_OK] or one of these two constants in order
2876 ** to signal SQLite whether or not the action is permitted.  See the
2877 ** [sqlite3_set_authorizer | authorizer documentation] for additional
2878 ** information.
2879 **
2880 ** Note that SQLITE_IGNORE is also used as a [conflict resolution mode]
2881 ** returned from the [sqlite3_vtab_on_conflict()] interface.
2882 */
2883 enum SQLITE_DENY = 1; /* Abort the SQL statement with an error */
2884 enum SQLITE_IGNORE = 2; /* Don't allow access, but don't generate an error */
2885 
2886 /*
2887 ** CAPI3REF: Authorizer Action Codes
2888 **
2889 ** The [sqlite3_set_authorizer()] interface registers a callback function
2890 ** that is invoked to authorize certain SQL statement actions.  The
2891 ** second parameter to the callback is an integer code that specifies
2892 ** what action is being authorized.  These are the integer action codes that
2893 ** the authorizer callback may be passed.
2894 **
2895 ** These action code values signify what kind of operation is to be
2896 ** authorized.  The 3rd and 4th parameters to the authorization
2897 ** callback function will be parameters or NULL depending on which of these
2898 ** codes is used as the second parameter.  ^(The 5th parameter to the
2899 ** authorizer callback is the name of the database ("main", "temp",
2900 ** etc.) if applicable.)^  ^The 6th parameter to the authorizer callback
2901 ** is the name of the inner-most trigger or view that is responsible for
2902 ** the access attempt or NULL if this access attempt is directly from
2903 ** top-level SQL code.
2904 */
2905 /******************************************* 3rd ************ 4th ***********/
2906 enum SQLITE_CREATE_INDEX = 1; /* Index Name      Table Name      */
2907 enum SQLITE_CREATE_TABLE = 2; /* Table Name      NULL            */
2908 enum SQLITE_CREATE_TEMP_INDEX = 3; /* Index Name      Table Name      */
2909 enum SQLITE_CREATE_TEMP_TABLE = 4; /* Table Name      NULL            */
2910 enum SQLITE_CREATE_TEMP_TRIGGER = 5; /* Trigger Name    Table Name      */
2911 enum SQLITE_CREATE_TEMP_VIEW = 6; /* View Name       NULL            */
2912 enum SQLITE_CREATE_TRIGGER = 7; /* Trigger Name    Table Name      */
2913 enum SQLITE_CREATE_VIEW = 8; /* View Name       NULL            */
2914 enum SQLITE_DELETE = 9; /* Table Name      NULL            */
2915 enum SQLITE_DROP_INDEX = 10; /* Index Name      Table Name      */
2916 enum SQLITE_DROP_TABLE = 11; /* Table Name      NULL            */
2917 enum SQLITE_DROP_TEMP_INDEX = 12; /* Index Name      Table Name      */
2918 enum SQLITE_DROP_TEMP_TABLE = 13; /* Table Name      NULL            */
2919 enum SQLITE_DROP_TEMP_TRIGGER = 14; /* Trigger Name    Table Name      */
2920 enum SQLITE_DROP_TEMP_VIEW = 15; /* View Name       NULL            */
2921 enum SQLITE_DROP_TRIGGER = 16; /* Trigger Name    Table Name      */
2922 enum SQLITE_DROP_VIEW = 17; /* View Name       NULL            */
2923 enum SQLITE_INSERT = 18; /* Table Name      NULL            */
2924 enum SQLITE_PRAGMA = 19; /* Pragma Name     1st arg or NULL */
2925 enum SQLITE_READ = 20; /* Table Name      Column Name     */
2926 enum SQLITE_SELECT = 21; /* NULL            NULL            */
2927 enum SQLITE_TRANSACTION = 22; /* Operation       NULL            */
2928 enum SQLITE_UPDATE = 23; /* Table Name      Column Name     */
2929 enum SQLITE_ATTACH = 24; /* Filename        NULL            */
2930 enum SQLITE_DETACH = 25; /* Database Name   NULL            */
2931 enum SQLITE_ALTER_TABLE = 26; /* Database Name   Table Name      */
2932 enum SQLITE_REINDEX = 27; /* Index Name      NULL            */
2933 enum SQLITE_ANALYZE = 28; /* Table Name      NULL            */
2934 enum SQLITE_CREATE_VTABLE = 29; /* Table Name      Module Name     */
2935 enum SQLITE_DROP_VTABLE = 30; /* Table Name      Module Name     */
2936 enum SQLITE_FUNCTION = 31; /* NULL            Function Name   */
2937 enum SQLITE_SAVEPOINT = 32; /* Operation       Savepoint Name  */
2938 enum SQLITE_COPY = 0; /* No longer used */
2939 enum SQLITE_RECURSIVE = 33; /* NULL            NULL            */
2940 
2941 /*
2942 ** CAPI3REF: Tracing And Profiling Functions
2943 ** METHOD: sqlite3
2944 **
2945 ** These routines are deprecated. Use the [sqlite3_trace_v2()] interface
2946 ** instead of the routines described here.
2947 **
2948 ** These routines register callback functions that can be used for
2949 ** tracing and profiling the execution of SQL statements.
2950 **
2951 ** ^The callback function registered by sqlite3_trace() is invoked at
2952 ** various times when an SQL statement is being run by [sqlite3_step()].
2953 ** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the
2954 ** SQL statement text as the statement first begins executing.
2955 ** ^(Additional sqlite3_trace() callbacks might occur
2956 ** as each triggered subprogram is entered.  The callbacks for triggers
2957 ** contain a UTF-8 SQL comment that identifies the trigger.)^
2958 **
2959 ** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit
2960 ** the length of [bound parameter] expansion in the output of sqlite3_trace().
2961 **
2962 ** ^The callback function registered by sqlite3_profile() is invoked
2963 ** as each SQL statement finishes.  ^The profile callback contains
2964 ** the original statement text and an estimate of wall-clock time
2965 ** of how long that statement took to run.  ^The profile callback
2966 ** time is in units of nanoseconds, however the current implementation
2967 ** is only capable of millisecond resolution so the six least significant
2968 ** digits in the time are meaningless.  Future versions of SQLite
2969 ** might provide greater resolution on the profiler callback.  The
2970 ** sqlite3_profile() function is considered experimental and is
2971 ** subject to change in future versions of SQLite.
2972 */
2973 void* sqlite3_trace(sqlite3*, void function(void*, const(char)*) xTrace, void*);
2974 void* sqlite3_profile(
2975     sqlite3*,
2976     void function(void*, const(char)*, sqlite3_uint64) xProfile,
2977     void*);
2978 
2979 /*
2980 ** CAPI3REF: SQL Trace Event Codes
2981 ** KEYWORDS: SQLITE_TRACE
2982 **
2983 ** These constants identify classes of events that can be monitored
2984 ** using the [sqlite3_trace_v2()] tracing logic.  The M argument
2985 ** to [sqlite3_trace_v2(D,M,X,P)] is an OR-ed combination of one or more of
2986 ** the following constants.  ^The first argument to the trace callback
2987 ** is one of the following constants.
2988 **
2989 ** New tracing constants may be added in future releases.
2990 **
2991 ** ^A trace callback has four arguments: xCallback(T,C,P,X).
2992 ** ^The T argument is one of the integer type codes above.
2993 ** ^The C argument is a copy of the context pointer passed in as the
2994 ** fourth argument to [sqlite3_trace_v2()].
2995 ** The P and X arguments are pointers whose meanings depend on T.
2996 **
2997 ** <dl>
2998 ** [[SQLITE_TRACE_STMT]] <dt>SQLITE_TRACE_STMT</dt>
2999 ** <dd>^An SQLITE_TRACE_STMT callback is invoked when a prepared statement
3000 ** first begins running and possibly at other times during the
3001 ** execution of the prepared statement, such as at the start of each
3002 ** trigger subprogram. ^The P argument is a pointer to the
3003 ** [prepared statement]. ^The X argument is a pointer to a string which
3004 ** is the unexpanded SQL text of the prepared statement or an SQL comment
3005 ** that indicates the invocation of a trigger.  ^The callback can compute
3006 ** the same text that would have been returned by the legacy [sqlite3_trace()]
3007 ** interface by using the X argument when X begins with "--" and invoking
3008 ** [sqlite3_expanded_sql(P)] otherwise.
3009 **
3010 ** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt>
3011 ** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same
3012 ** information as is provided by the [sqlite3_profile()] callback.
3013 ** ^The P argument is a pointer to the [prepared statement] and the
3014 ** X argument points to a 64-bit integer which is the estimated of
3015 ** the number of nanosecond that the prepared statement took to run.
3016 ** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.
3017 **
3018 ** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt>
3019 ** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared
3020 ** statement generates a single row of result.
3021 ** ^The P argument is a pointer to the [prepared statement] and the
3022 ** X argument is unused.
3023 **
3024 ** [[SQLITE_TRACE_CLOSE]] <dt>SQLITE_TRACE_CLOSE</dt>
3025 ** <dd>^An SQLITE_TRACE_CLOSE callback is invoked when a database
3026 ** connection closes.
3027 ** ^The P argument is a pointer to the [database connection] object
3028 ** and the X argument is unused.
3029 ** </dl>
3030 */
3031 enum SQLITE_TRACE_STMT = 0x01;
3032 enum SQLITE_TRACE_PROFILE = 0x02;
3033 enum SQLITE_TRACE_ROW = 0x04;
3034 enum SQLITE_TRACE_CLOSE = 0x08;
3035 
3036 /*
3037 ** CAPI3REF: SQL Trace Hook
3038 ** METHOD: sqlite3
3039 **
3040 ** ^The sqlite3_trace_v2(D,M,X,P) interface registers a trace callback
3041 ** function X against [database connection] D, using property mask M
3042 ** and context pointer P.  ^If the X callback is
3043 ** NULL or if the M mask is zero, then tracing is disabled.  The
3044 ** M argument should be the bitwise OR-ed combination of
3045 ** zero or more [SQLITE_TRACE] constants.
3046 **
3047 ** ^Each call to either sqlite3_trace() or sqlite3_trace_v2() overrides
3048 ** (cancels) any prior calls to sqlite3_trace() or sqlite3_trace_v2().
3049 **
3050 ** ^The X callback is invoked whenever any of the events identified by
3051 ** mask M occur.  ^The integer return value from the callback is currently
3052 ** ignored, though this may change in future releases.  Callback
3053 ** implementations should return zero to ensure future compatibility.
3054 **
3055 ** ^A trace callback is invoked with four arguments: callback(T,C,P,X).
3056 ** ^The T argument is one of the [SQLITE_TRACE]
3057 ** constants to indicate why the callback was invoked.
3058 ** ^The C argument is a copy of the context pointer.
3059 ** The P and X arguments are pointers whose meanings depend on T.
3060 **
3061 ** The sqlite3_trace_v2() interface is intended to replace the legacy
3062 ** interfaces [sqlite3_trace()] and [sqlite3_profile()], both of which
3063 ** are deprecated.
3064 */
3065 int sqlite3_trace_v2(
3066     sqlite3*,
3067     uint uMask,
3068     int function(uint, void*, void*, void*) xCallback,
3069     void* pCtx);
3070 
3071 /*
3072 ** CAPI3REF: Query Progress Callbacks
3073 ** METHOD: sqlite3
3074 **
3075 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
3076 ** function X to be invoked periodically during long running calls to
3077 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
3078 ** database connection D.  An example use for this
3079 ** interface is to keep a GUI updated during a large query.
3080 **
3081 ** ^The parameter P is passed through as the only parameter to the
3082 ** callback function X.  ^The parameter N is the approximate number of
3083 ** [virtual machine instructions] that are evaluated between successive
3084 ** invocations of the callback X.  ^If N is less than one then the progress
3085 ** handler is disabled.
3086 **
3087 ** ^Only a single progress handler may be defined at one time per
3088 ** [database connection]; setting a new progress handler cancels the
3089 ** old one.  ^Setting parameter X to NULL disables the progress handler.
3090 ** ^The progress handler is also disabled by setting N to a value less
3091 ** than 1.
3092 **
3093 ** ^If the progress callback returns non-zero, the operation is
3094 ** interrupted.  This feature can be used to implement a
3095 ** "Cancel" button on a GUI progress dialog box.
3096 **
3097 ** The progress handler callback must not do anything that will modify
3098 ** the database connection that invoked the progress handler.
3099 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
3100 ** database connections for the meaning of "modify" in this paragraph.
3101 **
3102 */
3103 void sqlite3_progress_handler(sqlite3*, int, int function(void*), void*);
3104 
3105 /*
3106 ** CAPI3REF: Opening A New Database Connection
3107 ** CONSTRUCTOR: sqlite3
3108 **
3109 ** ^These routines open an SQLite database file as specified by the
3110 ** filename argument. ^The filename argument is interpreted as UTF-8 for
3111 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
3112 ** order for sqlite3_open16(). ^(A [database connection] handle is usually
3113 ** returned in *ppDb, even if an error occurs.  The only exception is that
3114 ** if SQLite is unable to allocate memory to hold the [sqlite3] object,
3115 ** a NULL will be written into *ppDb instead of a pointer to the [sqlite3]
3116 ** object.)^ ^(If the database is opened (and/or created) successfully, then
3117 ** [SQLITE_OK] is returned.  Otherwise an [error code] is returned.)^ ^The
3118 ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
3119 ** an English language description of the error following a failure of any
3120 ** of the sqlite3_open() routines.
3121 **
3122 ** ^The default encoding will be UTF-8 for databases created using
3123 ** sqlite3_open() or sqlite3_open_v2().  ^The default encoding for databases
3124 ** created using sqlite3_open16() will be UTF-16 in the native byte order.
3125 **
3126 ** Whether or not an error occurs when it is opened, resources
3127 ** associated with the [database connection] handle should be released by
3128 ** passing it to [sqlite3_close()] when it is no longer required.
3129 **
3130 ** The sqlite3_open_v2() interface works like sqlite3_open()
3131 ** except that it accepts two additional parameters for additional control
3132 ** over the new database connection.  ^(The flags parameter to
3133 ** sqlite3_open_v2() can take one of
3134 ** the following three values, optionally combined with the
3135 ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE],
3136 ** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^
3137 **
3138 ** <dl>
3139 ** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
3140 ** <dd>The database is opened in read-only mode.  If the database does not
3141 ** already exist, an error is returned.</dd>)^
3142 **
3143 ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
3144 ** <dd>The database is opened for reading and writing if possible, or reading
3145 ** only if the file is write protected by the operating system.  In either
3146 ** case the database must already exist, otherwise an error is returned.</dd>)^
3147 **
3148 ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
3149 ** <dd>The database is opened for reading and writing, and is created if
3150 ** it does not already exist. This is the behavior that is always used for
3151 ** sqlite3_open() and sqlite3_open16().</dd>)^
3152 ** </dl>
3153 **
3154 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
3155 ** combinations shown above optionally combined with other
3156 ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
3157 ** then the behavior is undefined.
3158 **
3159 ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
3160 ** opens in the multi-thread [threading mode] as long as the single-thread
3161 ** mode has not been set at compile-time or start-time.  ^If the
3162 ** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens
3163 ** in the serialized [threading mode] unless single-thread was
3164 ** previously selected at compile-time or start-time.
3165 ** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be
3166 ** eligible to use [shared cache mode], regardless of whether or not shared
3167 ** cache is enabled using [sqlite3_enable_shared_cache()].  ^The
3168 ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not
3169 ** participate in [shared cache mode] even if it is enabled.
3170 **
3171 ** ^The fourth parameter to sqlite3_open_v2() is the name of the
3172 ** [sqlite3_vfs] object that defines the operating system interface that
3173 ** the new database connection should use.  ^If the fourth parameter is
3174 ** a NULL pointer then the default [sqlite3_vfs] object is used.
3175 **
3176 ** ^If the filename is ":memory:", then a private, temporary in-memory database
3177 ** is created for the connection.  ^This in-memory database will vanish when
3178 ** the database connection is closed.  Future versions of SQLite might
3179 ** make use of additional special filenames that begin with the ":" character.
3180 ** It is recommended that when a database filename actually does begin with
3181 ** a ":" character you should prefix the filename with a pathname such as
3182 ** "./" to avoid ambiguity.
3183 **
3184 ** ^If the filename is an empty string, then a private, temporary
3185 ** on-disk database will be created.  ^This private database will be
3186 ** automatically deleted as soon as the database connection is closed.
3187 **
3188 ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
3189 **
3190 ** ^If [URI filename] interpretation is enabled, and the filename argument
3191 ** begins with "file:", then the filename is interpreted as a URI. ^URI
3192 ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
3193 ** set in the third argument to sqlite3_open_v2(), or if it has
3194 ** been enabled globally using the [SQLITE_CONFIG_URI] option with the
3195 ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
3196 ** URI filename interpretation is turned off
3197 ** by default, but future releases of SQLite might enable URI filename
3198 ** interpretation by default.  See "[URI filenames]" for additional
3199 ** information.
3200 **
3201 ** URI filenames are parsed according to RFC 3986. ^If the URI contains an
3202 ** authority, then it must be either an empty string or the string
3203 ** "localhost". ^If the authority is not an empty string or "localhost", an
3204 ** error is returned to the caller. ^The fragment component of a URI, if
3205 ** present, is ignored.
3206 **
3207 ** ^SQLite uses the path component of the URI as the name of the disk file
3208 ** which contains the database. ^If the path begins with a '/' character,
3209 ** then it is interpreted as an absolute path. ^If the path does not begin
3210 ** with a '/' (meaning that the authority section is omitted from the URI)
3211 ** then the path is interpreted as a relative path.
3212 ** ^(On windows, the first component of an absolute path
3213 ** is a drive specification (e.g. "C:").)^
3214 **
3215 ** [[core URI query parameters]]
3216 ** The query component of a URI may contain parameters that are interpreted
3217 ** either by SQLite itself, or by a [VFS | custom VFS implementation].
3218 ** SQLite and its built-in [VFSes] interpret the
3219 ** following query parameters:
3220 **
3221 ** <ul>
3222 **   <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
3223 **     a VFS object that provides the operating system interface that should
3224 **     be used to access the database file on disk. ^If this option is set to
3225 **     an empty string the default VFS object is used. ^Specifying an unknown
3226 **     VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is
3227 **     present, then the VFS specified by the option takes precedence over
3228 **     the value passed as the fourth parameter to sqlite3_open_v2().
3229 **
3230 **   <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",
3231 **     "rwc", or "memory". Attempting to set it to any other value is
3232 **     an error)^.
3233 **     ^If "ro" is specified, then the database is opened for read-only
3234 **     access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
3235 **     third argument to sqlite3_open_v2(). ^If the mode option is set to
3236 **     "rw", then the database is opened for read-write (but not create)
3237 **     access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
3238 **     been set. ^Value "rwc" is equivalent to setting both
3239 **     SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE.  ^If the mode option is
3240 **     set to "memory" then a pure [in-memory database] that never reads
3241 **     or writes from disk is used. ^It is an error to specify a value for
3242 **     the mode parameter that is less restrictive than that specified by
3243 **     the flags passed in the third parameter to sqlite3_open_v2().
3244 **
3245 **   <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or
3246 **     "private". ^Setting it to "shared" is equivalent to setting the
3247 **     SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
3248 **     sqlite3_open_v2(). ^Setting the cache parameter to "private" is
3249 **     equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
3250 **     ^If sqlite3_open_v2() is used and the "cache" parameter is present in
3251 **     a URI filename, its value overrides any behavior requested by setting
3252 **     SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
3253 **
3254 **  <li> <b>psow</b>: ^The psow parameter indicates whether or not the
3255 **     [powersafe overwrite] property does or does not apply to the
3256 **     storage media on which the database file resides.
3257 **
3258 **  <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter
3259 **     which if set disables file locking in rollback journal modes.  This
3260 **     is useful for accessing a database on a filesystem that does not
3261 **     support locking.  Caution:  Database corruption might result if two
3262 **     or more processes write to the same database and any one of those
3263 **     processes uses nolock=1.
3264 **
3265 **  <li> <b>immutable</b>: ^The immutable parameter is a boolean query
3266 **     parameter that indicates that the database file is stored on
3267 **     read-only media.  ^When immutable is set, SQLite assumes that the
3268 **     database file cannot be changed, even by a process with higher
3269 **     privilege, and so the database is opened read-only and all locking
3270 **     and change detection is disabled.  Caution: Setting the immutable
3271 **     property on a database file that does in fact change can result
3272 **     in incorrect query results and/or [SQLITE_CORRUPT] errors.
3273 **     See also: [SQLITE_IOCAP_IMMUTABLE].
3274 **
3275 ** </ul>
3276 **
3277 ** ^Specifying an unknown parameter in the query component of a URI is not an
3278 ** error.  Future versions of SQLite might understand additional query
3279 ** parameters.  See "[query parameters with special meaning to SQLite]" for
3280 ** additional information.
3281 **
3282 ** [[URI filename examples]] <h3>URI filename examples</h3>
3283 **
3284 ** <table border="1" align=center cellpadding=5>
3285 ** <tr><th> URI filenames <th> Results
3286 ** <tr><td> file:data.db <td>
3287 **          Open the file "data.db" in the current directory.
3288 ** <tr><td> file:/home/fred/data.db<br>
3289 **          file:///home/fred/data.db <br>
3290 **          file://localhost/home/fred/data.db <br> <td>
3291 **          Open the database file "/home/fred/data.db".
3292 ** <tr><td> file://darkstar/home/fred/data.db <td>
3293 **          An error. "darkstar" is not a recognized authority.
3294 ** <tr><td style="white-space:nowrap">
3295 **          file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
3296 **     <td> Windows only: Open the file "data.db" on fred's desktop on drive
3297 **          C:. Note that the %20 escaping in this example is not strictly
3298 **          necessary - space characters can be used literally
3299 **          in URI filenames.
3300 ** <tr><td> file:data.db?mode=ro&cache=private <td>
3301 **          Open file "data.db" in the current directory for read-only access.
3302 **          Regardless of whether or not shared-cache mode is enabled by
3303 **          default, use a private cache.
3304 ** <tr><td> file:/home/fred/data.db?vfs=unix-dotfile <td>
3305 **          Open file "/home/fred/data.db". Use the special VFS "unix-dotfile"
3306 **          that uses dot-files in place of posix advisory locking.
3307 ** <tr><td> file:data.db?mode=readonly <td>
3308 **          An error. "readonly" is not a valid option for the "mode" parameter.
3309 ** </table>
3310 **
3311 ** ^URI hexadecimal escape sequences (%HH) are supported within the path and
3312 ** query components of a URI. A hexadecimal escape sequence consists of a
3313 ** percent sign - "%" - followed by exactly two hexadecimal digits
3314 ** specifying an octet value. ^Before the path or query components of a
3315 ** URI filename are interpreted, they are encoded using UTF-8 and all
3316 ** hexadecimal escape sequences replaced by a single byte containing the
3317 ** corresponding octet. If this process generates an invalid UTF-8 encoding,
3318 ** the results are undefined.
3319 **
3320 ** <b>Note to Windows users:</b>  The encoding used for the filename argument
3321 ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
3322 ** codepage is currently defined.  Filenames containing international
3323 ** characters must be converted to UTF-8 prior to passing them into
3324 ** sqlite3_open() or sqlite3_open_v2().
3325 **
3326 ** <b>Note to Windows Runtime users:</b>  The temporary directory must be set
3327 ** prior to calling sqlite3_open() or sqlite3_open_v2().  Otherwise, various
3328 ** features that require the use of temporary files may fail.
3329 **
3330 ** See also: [sqlite3_temp_directory]
3331 */
3332 /* Database filename (UTF-8) */
3333 /* OUT: SQLite db handle */
3334 int sqlite3_open(const(char)* filename, sqlite3** ppDb);
3335 
3336 /* Database filename (UTF-16) */
3337 /* OUT: SQLite db handle */
3338 int sqlite3_open16(const(void)* filename, sqlite3** ppDb);
3339 
3340 /* Database filename (UTF-8) */
3341 /* OUT: SQLite db handle */
3342 /* Flags */
3343 /* Name of VFS module to use */
3344 int sqlite3_open_v2(
3345     const(char)* filename,
3346     sqlite3** ppDb,
3347     int flags,
3348     const(char)* zVfs);
3349 
3350 /*
3351 ** CAPI3REF: Obtain Values For URI Parameters
3352 **
3353 ** These are utility routines, useful to VFS implementations, that check
3354 ** to see if a database file was a URI that contained a specific query
3355 ** parameter, and if so obtains the value of that query parameter.
3356 **
3357 ** If F is the database filename pointer passed into the xOpen() method of
3358 ** a VFS implementation when the flags parameter to xOpen() has one or
3359 ** more of the [SQLITE_OPEN_URI] or [SQLITE_OPEN_MAIN_DB] bits set and
3360 ** P is the name of the query parameter, then
3361 ** sqlite3_uri_parameter(F,P) returns the value of the P
3362 ** parameter if it exists or a NULL pointer if P does not appear as a
3363 ** query parameter on F.  If P is a query parameter of F
3364 ** has no explicit value, then sqlite3_uri_parameter(F,P) returns
3365 ** a pointer to an empty string.
3366 **
3367 ** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean
3368 ** parameter and returns true (1) or false (0) according to the value
3369 ** of P.  The sqlite3_uri_boolean(F,P,B) routine returns true (1) if the
3370 ** value of query parameter P is one of "yes", "true", or "on" in any
3371 ** case or if the value begins with a non-zero number.  The
3372 ** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of
3373 ** query parameter P is one of "no", "false", or "off" in any case or
3374 ** if the value begins with a numeric zero.  If P is not a query
3375 ** parameter on F or if the value of P is does not match any of the
3376 ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
3377 **
3378 ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
3379 ** 64-bit signed integer and returns that integer, or D if P does not
3380 ** exist.  If the value of P is something other than an integer, then
3381 ** zero is returned.
3382 **
3383 ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
3384 ** sqlite3_uri_boolean(F,P,B) returns B.  If F is not a NULL pointer and
3385 ** is not a database file pathname pointer that SQLite passed into the xOpen
3386 ** VFS method, then the behavior of this routine is undefined and probably
3387 ** undesirable.
3388 */
3389 const(char)* sqlite3_uri_parameter(const(char)* zFilename, const(char)* zParam);
3390 int sqlite3_uri_boolean(const(char)* zFile, const(char)* zParam, int bDefault);
3391 sqlite3_int64 sqlite3_uri_int64(const(char)*, const(char)*, sqlite3_int64);
3392 
3393 /*
3394 ** CAPI3REF: Error Codes And Messages
3395 ** METHOD: sqlite3
3396 **
3397 ** ^If the most recent sqlite3_* API call associated with
3398 ** [database connection] D failed, then the sqlite3_errcode(D) interface
3399 ** returns the numeric [result code] or [extended result code] for that
3400 ** API call.
3401 ** ^The sqlite3_extended_errcode()
3402 ** interface is the same except that it always returns the
3403 ** [extended result code] even when extended result codes are
3404 ** disabled.
3405 **
3406 ** The values returned by sqlite3_errcode() and/or
3407 ** sqlite3_extended_errcode() might change with each API call.
3408 ** Except, there are some interfaces that are guaranteed to never
3409 ** change the value of the error code.  The error-code preserving
3410 ** interfaces are:
3411 **
3412 ** <ul>
3413 ** <li> sqlite3_errcode()
3414 ** <li> sqlite3_extended_errcode()
3415 ** <li> sqlite3_errmsg()
3416 ** <li> sqlite3_errmsg16()
3417 ** </ul>
3418 **
3419 ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
3420 ** text that describes the error, as either UTF-8 or UTF-16 respectively.
3421 ** ^(Memory to hold the error message string is managed internally.
3422 ** The application does not need to worry about freeing the result.
3423 ** However, the error string might be overwritten or deallocated by
3424 ** subsequent calls to other SQLite interface functions.)^
3425 **
3426 ** ^The sqlite3_errstr() interface returns the English-language text
3427 ** that describes the [result code], as UTF-8.
3428 ** ^(Memory to hold the error message string is managed internally
3429 ** and must not be freed by the application)^.
3430 **
3431 ** When the serialized [threading mode] is in use, it might be the
3432 ** case that a second error occurs on a separate thread in between
3433 ** the time of the first error and the call to these interfaces.
3434 ** When that happens, the second error will be reported since these
3435 ** interfaces always report the most recent result.  To avoid
3436 ** this, each thread can obtain exclusive use of the [database connection] D
3437 ** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning
3438 ** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after
3439 ** all calls to the interfaces listed here are completed.
3440 **
3441 ** If an interface fails with SQLITE_MISUSE, that means the interface
3442 ** was invoked incorrectly by the application.  In that case, the
3443 ** error code and message may or may not be set.
3444 */
3445 int sqlite3_errcode(sqlite3* db);
3446 int sqlite3_extended_errcode(sqlite3* db);
3447 const(char)* sqlite3_errmsg(sqlite3*);
3448 const(void)* sqlite3_errmsg16(sqlite3*);
3449 const(char)* sqlite3_errstr(int);
3450 
3451 /*
3452 ** CAPI3REF: Prepared Statement Object
3453 ** KEYWORDS: {prepared statement} {prepared statements}
3454 **
3455 ** An instance of this object represents a single SQL statement that
3456 ** has been compiled into binary form and is ready to be evaluated.
3457 **
3458 ** Think of each SQL statement as a separate computer program.  The
3459 ** original SQL text is source code.  A prepared statement object
3460 ** is the compiled object code.  All SQL must be converted into a
3461 ** prepared statement before it can be run.
3462 **
3463 ** The life-cycle of a prepared statement object usually goes like this:
3464 **
3465 ** <ol>
3466 ** <li> Create the prepared statement object using [sqlite3_prepare_v2()].
3467 ** <li> Bind values to [parameters] using the sqlite3_bind_*()
3468 **      interfaces.
3469 ** <li> Run the SQL by calling [sqlite3_step()] one or more times.
3470 ** <li> Reset the prepared statement using [sqlite3_reset()] then go back
3471 **      to step 2.  Do this zero or more times.
3472 ** <li> Destroy the object using [sqlite3_finalize()].
3473 ** </ol>
3474 */
3475 struct sqlite3_stmt;
3476 
3477 /*
3478 ** CAPI3REF: Run-time Limits
3479 ** METHOD: sqlite3
3480 **
3481 ** ^(This interface allows the size of various constructs to be limited
3482 ** on a connection by connection basis.  The first parameter is the
3483 ** [database connection] whose limit is to be set or queried.  The
3484 ** second parameter is one of the [limit categories] that define a
3485 ** class of constructs to be size limited.  The third parameter is the
3486 ** new limit for that construct.)^
3487 **
3488 ** ^If the new limit is a negative number, the limit is unchanged.
3489 ** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a
3490 ** [limits | hard upper bound]
3491 ** set at compile-time by a C preprocessor macro called
3492 ** [limits | SQLITE_MAX_<i>NAME</i>].
3493 ** (The "_LIMIT_" in the name is changed to "_MAX_".))^
3494 ** ^Attempts to increase a limit above its hard upper bound are
3495 ** silently truncated to the hard upper bound.
3496 **
3497 ** ^Regardless of whether or not the limit was changed, the
3498 ** [sqlite3_limit()] interface returns the prior value of the limit.
3499 ** ^Hence, to find the current value of a limit without changing it,
3500 ** simply invoke this interface with the third parameter set to -1.
3501 **
3502 ** Run-time limits are intended for use in applications that manage
3503 ** both their own internal database and also databases that are controlled
3504 ** by untrusted external sources.  An example application might be a
3505 ** web browser that has its own databases for storing history and
3506 ** separate databases controlled by JavaScript applications downloaded
3507 ** off the Internet.  The internal databases can be given the
3508 ** large, default limits.  Databases managed by external sources can
3509 ** be given much smaller limits designed to prevent a denial of service
3510 ** attack.  Developers might also want to use the [sqlite3_set_authorizer()]
3511 ** interface to further control untrusted SQL.  The size of the database
3512 ** created by an untrusted script can be contained using the
3513 ** [max_page_count] [PRAGMA].
3514 **
3515 ** New run-time limit categories may be added in future releases.
3516 */
3517 int sqlite3_limit(sqlite3*, int id, int newVal);
3518 
3519 /*
3520 ** CAPI3REF: Run-Time Limit Categories
3521 ** KEYWORDS: {limit category} {*limit categories}
3522 **
3523 ** These constants define various performance limits
3524 ** that can be lowered at run-time using [sqlite3_limit()].
3525 ** The synopsis of the meanings of the various limits is shown below.
3526 ** Additional information is available at [limits | Limits in SQLite].
3527 **
3528 ** <dl>
3529 ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
3530 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
3531 **
3532 ** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
3533 ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
3534 **
3535 ** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt>
3536 ** <dd>The maximum number of columns in a table definition or in the
3537 ** result set of a [SELECT] or the maximum number of columns in an index
3538 ** or in an ORDER BY or GROUP BY clause.</dd>)^
3539 **
3540 ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
3541 ** <dd>The maximum depth of the parse tree on any expression.</dd>)^
3542 **
3543 ** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
3544 ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
3545 **
3546 ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
3547 ** <dd>The maximum number of instructions in a virtual machine program
3548 ** used to implement an SQL statement.  If [sqlite3_prepare_v2()] or
3549 ** the equivalent tries to allocate space for more than this many opcodes
3550 ** in a single prepared statement, an SQLITE_NOMEM error is returned.</dd>)^
3551 **
3552 ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
3553 ** <dd>The maximum number of arguments on a function.</dd>)^
3554 **
3555 ** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
3556 ** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
3557 **
3558 ** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]]
3559 ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
3560 ** <dd>The maximum length of the pattern argument to the [LIKE] or
3561 ** [GLOB] operators.</dd>)^
3562 **
3563 ** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
3564 ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
3565 ** <dd>The maximum index number of any [parameter] in an SQL statement.)^
3566 **
3567 ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
3568 ** <dd>The maximum depth of recursion for triggers.</dd>)^
3569 **
3570 ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
3571 ** <dd>The maximum number of auxiliary worker threads that a single
3572 ** [prepared statement] may start.</dd>)^
3573 ** </dl>
3574 */
3575 enum SQLITE_LIMIT_LENGTH = 0;
3576 enum SQLITE_LIMIT_SQL_LENGTH = 1;
3577 enum SQLITE_LIMIT_COLUMN = 2;
3578 enum SQLITE_LIMIT_EXPR_DEPTH = 3;
3579 enum SQLITE_LIMIT_COMPOUND_SELECT = 4;
3580 enum SQLITE_LIMIT_VDBE_OP = 5;
3581 enum SQLITE_LIMIT_FUNCTION_ARG = 6;
3582 enum SQLITE_LIMIT_ATTACHED = 7;
3583 enum SQLITE_LIMIT_LIKE_PATTERN_LENGTH = 8;
3584 enum SQLITE_LIMIT_VARIABLE_NUMBER = 9;
3585 enum SQLITE_LIMIT_TRIGGER_DEPTH = 10;
3586 enum SQLITE_LIMIT_WORKER_THREADS = 11;
3587 
3588 /*
3589 ** CAPI3REF: Prepare Flags
3590 **
3591 ** These constants define various flags that can be passed into
3592 ** "prepFlags" parameter of the [sqlite3_prepare_v3()] and
3593 ** [sqlite3_prepare16_v3()] interfaces.
3594 **
3595 ** New flags may be added in future releases of SQLite.
3596 **
3597 ** <dl>
3598 ** [[SQLITE_PREPARE_PERSISTENT]] ^(<dt>SQLITE_PREPARE_PERSISTENT</dt>
3599 ** <dd>The SQLITE_PREPARE_PERSISTENT flag is a hint to the query planner
3600 ** that the prepared statement will be retained for a long time and
3601 ** probably reused many times.)^ ^Without this flag, [sqlite3_prepare_v3()]
3602 ** and [sqlite3_prepare16_v3()] assume that the prepared statement will
3603 ** be used just once or at most a few times and then destroyed using
3604 ** [sqlite3_finalize()] relatively soon. The current implementation acts
3605 ** on this hint by avoiding the use of [lookaside memory] so as not to
3606 ** deplete the limited store of lookaside memory. Future versions of
3607 ** SQLite may act on this hint differently.
3608 ** </dl>
3609 */
3610 enum SQLITE_PREPARE_PERSISTENT = 0x01;
3611 
3612 /*
3613 ** CAPI3REF: Compiling An SQL Statement
3614 ** KEYWORDS: {SQL statement compiler}
3615 ** METHOD: sqlite3
3616 ** CONSTRUCTOR: sqlite3_stmt
3617 **
3618 ** To execute an SQL statement, it must first be compiled into a byte-code
3619 ** program using one of these routines.  Or, in other words, these routines
3620 ** are constructors for the [prepared statement] object.
3621 **
3622 ** The preferred routine to use is [sqlite3_prepare_v2()].  The
3623 ** [sqlite3_prepare()] interface is legacy and should be avoided.
3624 ** [sqlite3_prepare_v3()] has an extra "prepFlags" option that is used
3625 ** for special purposes.
3626 **
3627 ** The use of the UTF-8 interfaces is preferred, as SQLite currently
3628 ** does all parsing using UTF-8.  The UTF-16 interfaces are provided
3629 ** as a convenience.  The UTF-16 interfaces work by converting the
3630 ** input text into UTF-8, then invoking the corresponding UTF-8 interface.
3631 **
3632 ** The first argument, "db", is a [database connection] obtained from a
3633 ** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or
3634 ** [sqlite3_open16()].  The database connection must not have been closed.
3635 **
3636 ** The second argument, "zSql", is the statement to be compiled, encoded
3637 ** as either UTF-8 or UTF-16.  The sqlite3_prepare(), sqlite3_prepare_v2(),
3638 ** and sqlite3_prepare_v3()
3639 ** interfaces use UTF-8, and sqlite3_prepare16(), sqlite3_prepare16_v2(),
3640 ** and sqlite3_prepare16_v3() use UTF-16.
3641 **
3642 ** ^If the nByte argument is negative, then zSql is read up to the
3643 ** first zero terminator. ^If nByte is positive, then it is the
3644 ** number of bytes read from zSql.  ^If nByte is zero, then no prepared
3645 ** statement is generated.
3646 ** If the caller knows that the supplied string is nul-terminated, then
3647 ** there is a small performance advantage to passing an nByte parameter that
3648 ** is the number of bytes in the input string <i>including</i>
3649 ** the nul-terminator.
3650 **
3651 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
3652 ** past the end of the first SQL statement in zSql.  These routines only
3653 ** compile the first statement in zSql, so *pzTail is left pointing to
3654 ** what remains uncompiled.
3655 **
3656 ** ^*ppStmt is left pointing to a compiled [prepared statement] that can be
3657 ** executed using [sqlite3_step()].  ^If there is an error, *ppStmt is set
3658 ** to NULL.  ^If the input text contains no SQL (if the input is an empty
3659 ** string or a comment) then *ppStmt is set to NULL.
3660 ** The calling procedure is responsible for deleting the compiled
3661 ** SQL statement using [sqlite3_finalize()] after it has finished with it.
3662 ** ppStmt may not be NULL.
3663 **
3664 ** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK];
3665 ** otherwise an [error code] is returned.
3666 **
3667 ** The sqlite3_prepare_v2(), sqlite3_prepare_v3(), sqlite3_prepare16_v2(),
3668 ** and sqlite3_prepare16_v3() interfaces are recommended for all new programs.
3669 ** The older interfaces (sqlite3_prepare() and sqlite3_prepare16())
3670 ** are retained for backwards compatibility, but their use is discouraged.
3671 ** ^In the "vX" interfaces, the prepared statement
3672 ** that is returned (the [sqlite3_stmt] object) contains a copy of the
3673 ** original SQL text. This causes the [sqlite3_step()] interface to
3674 ** behave differently in three ways:
3675 **
3676 ** <ol>
3677 ** <li>
3678 ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
3679 ** always used to do, [sqlite3_step()] will automatically recompile the SQL
3680 ** statement and try to run it again. As many as [SQLITE_MAX_SCHEMA_RETRY]
3681 ** retries will occur before sqlite3_step() gives up and returns an error.
3682 ** </li>
3683 **
3684 ** <li>
3685 ** ^When an error occurs, [sqlite3_step()] will return one of the detailed
3686 ** [error codes] or [extended error codes].  ^The legacy behavior was that
3687 ** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code
3688 ** and the application would have to make a second call to [sqlite3_reset()]
3689 ** in order to find the underlying cause of the problem. With the "v2" prepare
3690 ** interfaces, the underlying reason for the error is returned immediately.
3691 ** </li>
3692 **
3693 ** <li>
3694 ** ^If the specific value bound to [parameter | host parameter] in the
3695 ** WHERE clause might influence the choice of query plan for a statement,
3696 ** then the statement will be automatically recompiled, as if there had been
3697 ** a schema change, on the first  [sqlite3_step()] call following any change
3698 ** to the [sqlite3_bind_text | bindings] of that [parameter].
3699 ** ^The specific value of WHERE-clause [parameter] might influence the
3700 ** choice of query plan if the parameter is the left-hand side of a [LIKE]
3701 ** or [GLOB] operator or if the parameter is compared to an indexed column
3702 ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled.
3703 ** </li>
3704 ** </ol>
3705 **
3706 ** <p>^sqlite3_prepare_v3() differs from sqlite3_prepare_v2() only in having
3707 ** the extra prepFlags parameter, which is a bit array consisting of zero or
3708 ** more of the [SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_*] flags.  ^The
3709 ** sqlite3_prepare_v2() interface works exactly the same as
3710 ** sqlite3_prepare_v3() with a zero prepFlags parameter.
3711 */
3712 /* Database handle */
3713 /* SQL statement, UTF-8 encoded */
3714 /* Maximum length of zSql in bytes. */
3715 /* OUT: Statement handle */
3716 /* OUT: Pointer to unused portion of zSql */
3717 int sqlite3_prepare(
3718     sqlite3* db,
3719     const(char)* zSql,
3720     int nByte,
3721     sqlite3_stmt** ppStmt,
3722     const(char*)* pzTail);
3723 
3724 /* Database handle */
3725 /* SQL statement, UTF-8 encoded */
3726 /* Maximum length of zSql in bytes. */
3727 /* OUT: Statement handle */
3728 /* OUT: Pointer to unused portion of zSql */
3729 int sqlite3_prepare_v2(
3730     sqlite3* db,
3731     const(char)* zSql,
3732     int nByte,
3733     sqlite3_stmt** ppStmt,
3734     const(char*)* pzTail);
3735 
3736 /* Database handle */
3737 /* SQL statement, UTF-8 encoded */
3738 /* Maximum length of zSql in bytes. */
3739 /* Zero or more SQLITE_PREPARE_ flags */
3740 /* OUT: Statement handle */
3741 /* OUT: Pointer to unused portion of zSql */
3742 int sqlite3_prepare_v3(
3743     sqlite3* db,
3744     const(char)* zSql,
3745     int nByte,
3746     uint prepFlags,
3747     sqlite3_stmt** ppStmt,
3748     const(char*)* pzTail);
3749 
3750 /* Database handle */
3751 /* SQL statement, UTF-16 encoded */
3752 /* Maximum length of zSql in bytes. */
3753 /* OUT: Statement handle */
3754 /* OUT: Pointer to unused portion of zSql */
3755 int sqlite3_prepare16(
3756     sqlite3* db,
3757     const(void)* zSql,
3758     int nByte,
3759     sqlite3_stmt** ppStmt,
3760     const(void*)* pzTail);
3761 
3762 /* Database handle */
3763 /* SQL statement, UTF-16 encoded */
3764 /* Maximum length of zSql in bytes. */
3765 /* OUT: Statement handle */
3766 /* OUT: Pointer to unused portion of zSql */
3767 int sqlite3_prepare16_v2(
3768     sqlite3* db,
3769     const(void)* zSql,
3770     int nByte,
3771     sqlite3_stmt** ppStmt,
3772     const(void*)* pzTail);
3773 
3774 /* Database handle */
3775 /* SQL statement, UTF-16 encoded */
3776 /* Maximum length of zSql in bytes. */
3777 /* Zero or more SQLITE_PREPARE_ flags */
3778 /* OUT: Statement handle */
3779 /* OUT: Pointer to unused portion of zSql */
3780 int sqlite3_prepare16_v3(
3781     sqlite3* db,
3782     const(void)* zSql,
3783     int nByte,
3784     uint prepFlags,
3785     sqlite3_stmt** ppStmt,
3786     const(void*)* pzTail);
3787 
3788 /*
3789 ** CAPI3REF: Retrieving Statement SQL
3790 ** METHOD: sqlite3_stmt
3791 **
3792 ** ^The sqlite3_sql(P) interface returns a pointer to a copy of the UTF-8
3793 ** SQL text used to create [prepared statement] P if P was
3794 ** created by [sqlite3_prepare_v2()], [sqlite3_prepare_v3()],
3795 ** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()].
3796 ** ^The sqlite3_expanded_sql(P) interface returns a pointer to a UTF-8
3797 ** string containing the SQL text of prepared statement P with
3798 ** [bound parameters] expanded.
3799 **
3800 ** ^(For example, if a prepared statement is created using the SQL
3801 ** text "SELECT $abc,:xyz" and if parameter $abc is bound to integer 2345
3802 ** and parameter :xyz is unbound, then sqlite3_sql() will return
3803 ** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
3804 ** will return "SELECT 2345,NULL".)^
3805 **
3806 ** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
3807 ** is available to hold the result, or if the result would exceed the
3808 ** the maximum string length determined by the [SQLITE_LIMIT_LENGTH].
3809 **
3810 ** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
3811 ** bound parameter expansions.  ^The [SQLITE_OMIT_TRACE] compile-time
3812 ** option causes sqlite3_expanded_sql() to always return NULL.
3813 **
3814 ** ^The string returned by sqlite3_sql(P) is managed by SQLite and is
3815 ** automatically freed when the prepared statement is finalized.
3816 ** ^The string returned by sqlite3_expanded_sql(P), on the other hand,
3817 ** is obtained from [sqlite3_malloc()] and must be free by the application
3818 ** by passing it to [sqlite3_free()].
3819 */
3820 const(char)* sqlite3_sql(sqlite3_stmt* pStmt);
3821 char* sqlite3_expanded_sql(sqlite3_stmt* pStmt);
3822 
3823 /*
3824 ** CAPI3REF: Determine If An SQL Statement Writes The Database
3825 ** METHOD: sqlite3_stmt
3826 **
3827 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
3828 ** and only if the [prepared statement] X makes no direct changes to
3829 ** the content of the database file.
3830 **
3831 ** Note that [application-defined SQL functions] or
3832 ** [virtual tables] might change the database indirectly as a side effect.
3833 ** ^(For example, if an application defines a function "eval()" that
3834 ** calls [sqlite3_exec()], then the following SQL statement would
3835 ** change the database file through side-effects:
3836 **
3837 ** <blockquote><pre>
3838 **    SELECT eval('DELETE FROM t1') FROM t2;
3839 ** </pre></blockquote>
3840 **
3841 ** But because the [SELECT] statement does not change the database file
3842 ** directly, sqlite3_stmt_readonly() would still return true.)^
3843 **
3844 ** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
3845 ** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,
3846 ** since the statements themselves do not actually modify the database but
3847 ** rather they control the timing of when other statements modify the
3848 ** database.  ^The [ATTACH] and [DETACH] statements also cause
3849 ** sqlite3_stmt_readonly() to return true since, while those statements
3850 ** change the configuration of a database connection, they do not make
3851 ** changes to the content of the database files on disk.
3852 ** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
3853 ** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
3854 ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
3855 ** sqlite3_stmt_readonly() returns false for those commands.
3856 */
3857 int sqlite3_stmt_readonly(sqlite3_stmt* pStmt);
3858 
3859 /*
3860 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
3861 ** METHOD: sqlite3_stmt
3862 **
3863 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
3864 ** [prepared statement] S has been stepped at least once using
3865 ** [sqlite3_step(S)] but has neither run to completion (returned
3866 ** [SQLITE_DONE] from [sqlite3_step(S)]) nor
3867 ** been reset using [sqlite3_reset(S)].  ^The sqlite3_stmt_busy(S)
3868 ** interface returns false if S is a NULL pointer.  If S is not a
3869 ** NULL pointer and is not a pointer to a valid [prepared statement]
3870 ** object, then the behavior is undefined and probably undesirable.
3871 **
3872 ** This interface can be used in combination [sqlite3_next_stmt()]
3873 ** to locate all prepared statements associated with a database
3874 ** connection that are in need of being reset.  This can be used,
3875 ** for example, in diagnostic routines to search for prepared
3876 ** statements that are holding a transaction open.
3877 */
3878 int sqlite3_stmt_busy(sqlite3_stmt*);
3879 
3880 /*
3881 ** CAPI3REF: Dynamically Typed Value Object
3882 ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
3883 **
3884 ** SQLite uses the sqlite3_value object to represent all values
3885 ** that can be stored in a database table. SQLite uses dynamic typing
3886 ** for the values it stores.  ^Values stored in sqlite3_value objects
3887 ** can be integers, floating point values, strings, BLOBs, or NULL.
3888 **
3889 ** An sqlite3_value object may be either "protected" or "unprotected".
3890 ** Some interfaces require a protected sqlite3_value.  Other interfaces
3891 ** will accept either a protected or an unprotected sqlite3_value.
3892 ** Every interface that accepts sqlite3_value arguments specifies
3893 ** whether or not it requires a protected sqlite3_value.  The
3894 ** [sqlite3_value_dup()] interface can be used to construct a new
3895 ** protected sqlite3_value from an unprotected sqlite3_value.
3896 **
3897 ** The terms "protected" and "unprotected" refer to whether or not
3898 ** a mutex is held.  An internal mutex is held for a protected
3899 ** sqlite3_value object but no mutex is held for an unprotected
3900 ** sqlite3_value object.  If SQLite is compiled to be single-threaded
3901 ** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)
3902 ** or if SQLite is run in one of reduced mutex modes
3903 ** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
3904 ** then there is no distinction between protected and unprotected
3905 ** sqlite3_value objects and they can be used interchangeably.  However,
3906 ** for maximum code portability it is recommended that applications
3907 ** still make the distinction between protected and unprotected
3908 ** sqlite3_value objects even when not strictly required.
3909 **
3910 ** ^The sqlite3_value objects that are passed as parameters into the
3911 ** implementation of [application-defined SQL functions] are protected.
3912 ** ^The sqlite3_value object returned by
3913 ** [sqlite3_column_value()] is unprotected.
3914 ** Unprotected sqlite3_value objects may only be used as arguments
3915 ** to [sqlite3_result_value()], [sqlite3_bind_value()], and
3916 ** [sqlite3_value_dup()].
3917 ** The [sqlite3_value_blob | sqlite3_value_type()] family of
3918 ** interfaces require protected sqlite3_value objects.
3919 */
3920 struct sqlite3_value;
3921 
3922 /*
3923 ** CAPI3REF: SQL Function Context Object
3924 **
3925 ** The context in which an SQL function executes is stored in an
3926 ** sqlite3_context object.  ^A pointer to an sqlite3_context object
3927 ** is always first parameter to [application-defined SQL functions].
3928 ** The application-defined SQL function implementation will pass this
3929 ** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
3930 ** [sqlite3_aggregate_context()], [sqlite3_user_data()],
3931 ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
3932 ** and/or [sqlite3_set_auxdata()].
3933 */
3934 struct sqlite3_context;
3935 
3936 /*
3937 ** CAPI3REF: Binding Values To Prepared Statements
3938 ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
3939 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
3940 ** METHOD: sqlite3_stmt
3941 **
3942 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
3943 ** literals may be replaced by a [parameter] that matches one of following
3944 ** templates:
3945 **
3946 ** <ul>
3947 ** <li>  ?
3948 ** <li>  ?NNN
3949 ** <li>  :VVV
3950 ** <li>  @VVV
3951 ** <li>  $VVV
3952 ** </ul>
3953 **
3954 ** In the templates above, NNN represents an integer literal,
3955 ** and VVV represents an alphanumeric identifier.)^  ^The values of these
3956 ** parameters (also called "host parameter names" or "SQL parameters")
3957 ** can be set using the sqlite3_bind_*() routines defined here.
3958 **
3959 ** ^The first argument to the sqlite3_bind_*() routines is always
3960 ** a pointer to the [sqlite3_stmt] object returned from
3961 ** [sqlite3_prepare_v2()] or its variants.
3962 **
3963 ** ^The second argument is the index of the SQL parameter to be set.
3964 ** ^The leftmost SQL parameter has an index of 1.  ^When the same named
3965 ** SQL parameter is used more than once, second and subsequent
3966 ** occurrences have the same index as the first occurrence.
3967 ** ^The index for named parameters can be looked up using the
3968 ** [sqlite3_bind_parameter_index()] API if desired.  ^The index
3969 ** for "?NNN" parameters is the value of NNN.
3970 ** ^The NNN value must be between 1 and the [sqlite3_limit()]
3971 ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999).
3972 **
3973 ** ^The third argument is the value to bind to the parameter.
3974 ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16()
3975 ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter
3976 ** is ignored and the end result is the same as sqlite3_bind_null().
3977 **
3978 ** ^(In those routines that have a fourth argument, its value is the
3979 ** number of bytes in the parameter.  To be clear: the value is the
3980 ** number of <u>bytes</u> in the value, not the number of characters.)^
3981 ** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
3982 ** is negative, then the length of the string is
3983 ** the number of bytes up to the first zero terminator.
3984 ** If the fourth parameter to sqlite3_bind_blob() is negative, then
3985 ** the behavior is undefined.
3986 ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
3987 ** or sqlite3_bind_text16() or sqlite3_bind_text64() then
3988 ** that parameter must be the byte offset
3989 ** where the NUL terminator would occur assuming the string were NUL
3990 ** terminated.  If any NUL characters occur at byte offsets less than
3991 ** the value of the fourth parameter then the resulting string value will
3992 ** contain embedded NULs.  The result of expressions involving strings
3993 ** with embedded NULs is undefined.
3994 **
3995 ** ^The fifth argument to the BLOB and string binding interfaces
3996 ** is a destructor used to dispose of the BLOB or
3997 ** string after SQLite has finished with it.  ^The destructor is called
3998 ** to dispose of the BLOB or string even if the call to bind API fails.
3999 ** ^If the fifth argument is
4000 ** the special value [SQLITE_STATIC], then SQLite assumes that the
4001 ** information is in static, unmanaged space and does not need to be freed.
4002 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
4003 ** SQLite makes its own private copy of the data immediately, before
4004 ** the sqlite3_bind_*() routine returns.
4005 **
4006 ** ^The sixth argument to sqlite3_bind_text64() must be one of
4007 ** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
4008 ** to specify the encoding of the text in the third parameter.  If
4009 ** the sixth argument to sqlite3_bind_text64() is not one of the
4010 ** allowed values shown above, or if the text encoding is different
4011 ** from the encoding specified by the sixth parameter, then the behavior
4012 ** is undefined.
4013 **
4014 ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
4015 ** is filled with zeroes.  ^A zeroblob uses a fixed amount of memory
4016 ** (just an integer to hold its size) while it is being processed.
4017 ** Zeroblobs are intended to serve as placeholders for BLOBs whose
4018 ** content is later written using
4019 ** [sqlite3_blob_open | incremental BLOB I/O] routines.
4020 ** ^A negative value for the zeroblob results in a zero-length BLOB.
4021 **
4022 ** ^The sqlite3_bind_pointer(S,I,P,T,D) routine causes the I-th parameter in
4023 ** [prepared statement] S to have an SQL value of NULL, but to also be
4024 ** associated with the pointer P of type T.  ^D is either a NULL pointer or
4025 ** a pointer to a destructor function for P. ^SQLite will invoke the
4026 ** destructor D with a single argument of P when it is finished using
4027 ** P.  The T parameter should be a static string, preferably a string
4028 ** literal. The sqlite3_bind_pointer() routine is part of the
4029 ** [pointer passing interface] added for SQLite 3.20.0.
4030 **
4031 ** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
4032 ** for the [prepared statement] or with a prepared statement for which
4033 ** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
4034 ** then the call will return [SQLITE_MISUSE].  If any sqlite3_bind_()
4035 ** routine is passed a [prepared statement] that has been finalized, the
4036 ** result is undefined and probably harmful.
4037 **
4038 ** ^Bindings are not cleared by the [sqlite3_reset()] routine.
4039 ** ^Unbound parameters are interpreted as NULL.
4040 **
4041 ** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an
4042 ** [error code] if anything goes wrong.
4043 ** ^[SQLITE_TOOBIG] might be returned if the size of a string or BLOB
4044 ** exceeds limits imposed by [sqlite3_limit]([SQLITE_LIMIT_LENGTH]) or
4045 ** [SQLITE_MAX_LENGTH].
4046 ** ^[SQLITE_RANGE] is returned if the parameter
4047 ** index is out of range.  ^[SQLITE_NOMEM] is returned if malloc() fails.
4048 **
4049 ** See also: [sqlite3_bind_parameter_count()],
4050 ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
4051 */
4052 int sqlite3_bind_blob(sqlite3_stmt*, int, const(void)*, int n, void function(void*));
4053 int sqlite3_bind_blob64(
4054     sqlite3_stmt*,
4055     int,
4056     const(void)*,
4057     sqlite3_uint64,
4058     void function(void*));
4059 int sqlite3_bind_double(sqlite3_stmt*, int, double);
4060 int sqlite3_bind_int(sqlite3_stmt*, int, int);
4061 int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
4062 int sqlite3_bind_null(sqlite3_stmt*, int);
4063 int sqlite3_bind_text(sqlite3_stmt*, int, const(char)*, int, void function(void*));
4064 int sqlite3_bind_text16(sqlite3_stmt*, int, const(void)*, int, void function(void*));
4065 int sqlite3_bind_text64(
4066     sqlite3_stmt*,
4067     int,
4068     const(char)*,
4069     sqlite3_uint64,
4070     void function(void*),
4071     ubyte encoding);
4072 int sqlite3_bind_value(sqlite3_stmt*, int, const(sqlite3_value)*);
4073 int sqlite3_bind_pointer(sqlite3_stmt*, int, void*, const(char)*, void function(void*));
4074 int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
4075 int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
4076 
4077 /*
4078 ** CAPI3REF: Number Of SQL Parameters
4079 ** METHOD: sqlite3_stmt
4080 **
4081 ** ^This routine can be used to find the number of [SQL parameters]
4082 ** in a [prepared statement].  SQL parameters are tokens of the
4083 ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
4084 ** placeholders for values that are [sqlite3_bind_blob | bound]
4085 ** to the parameters at a later time.
4086 **
4087 ** ^(This routine actually returns the index of the largest (rightmost)
4088 ** parameter. For all forms except ?NNN, this will correspond to the
4089 ** number of unique parameters.  If parameters of the ?NNN form are used,
4090 ** there may be gaps in the list.)^
4091 **
4092 ** See also: [sqlite3_bind_blob|sqlite3_bind()],
4093 ** [sqlite3_bind_parameter_name()], and
4094 ** [sqlite3_bind_parameter_index()].
4095 */
4096 int sqlite3_bind_parameter_count(sqlite3_stmt*);
4097 
4098 /*
4099 ** CAPI3REF: Name Of A Host Parameter
4100 ** METHOD: sqlite3_stmt
4101 **
4102 ** ^The sqlite3_bind_parameter_name(P,N) interface returns
4103 ** the name of the N-th [SQL parameter] in the [prepared statement] P.
4104 ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
4105 ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
4106 ** respectively.
4107 ** In other words, the initial ":" or "$" or "@" or "?"
4108 ** is included as part of the name.)^
4109 ** ^Parameters of the form "?" without a following integer have no name
4110 ** and are referred to as "nameless" or "anonymous parameters".
4111 **
4112 ** ^The first host parameter has an index of 1, not 0.
4113 **
4114 ** ^If the value N is out of range or if the N-th parameter is
4115 ** nameless, then NULL is returned.  ^The returned string is
4116 ** always in UTF-8 encoding even if the named parameter was
4117 ** originally specified as UTF-16 in [sqlite3_prepare16()],
4118 ** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()].
4119 **
4120 ** See also: [sqlite3_bind_blob|sqlite3_bind()],
4121 ** [sqlite3_bind_parameter_count()], and
4122 ** [sqlite3_bind_parameter_index()].
4123 */
4124 const(char)* sqlite3_bind_parameter_name(sqlite3_stmt*, int);
4125 
4126 /*
4127 ** CAPI3REF: Index Of A Parameter With A Given Name
4128 ** METHOD: sqlite3_stmt
4129 **
4130 ** ^Return the index of an SQL parameter given its name.  ^The
4131 ** index value returned is suitable for use as the second
4132 ** parameter to [sqlite3_bind_blob|sqlite3_bind()].  ^A zero
4133 ** is returned if no matching parameter is found.  ^The parameter
4134 ** name must be given in UTF-8 even if the original statement
4135 ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()] or
4136 ** [sqlite3_prepare16_v3()].
4137 **
4138 ** See also: [sqlite3_bind_blob|sqlite3_bind()],
4139 ** [sqlite3_bind_parameter_count()], and
4140 ** [sqlite3_bind_parameter_name()].
4141 */
4142 int sqlite3_bind_parameter_index(sqlite3_stmt*, const(char)* zName);
4143 
4144 /*
4145 ** CAPI3REF: Reset All Bindings On A Prepared Statement
4146 ** METHOD: sqlite3_stmt
4147 **
4148 ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
4149 ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
4150 ** ^Use this routine to reset all host parameters to NULL.
4151 */
4152 int sqlite3_clear_bindings(sqlite3_stmt*);
4153 
4154 /*
4155 ** CAPI3REF: Number Of Columns In A Result Set
4156 ** METHOD: sqlite3_stmt
4157 **
4158 ** ^Return the number of columns in the result set returned by the
4159 ** [prepared statement]. ^If this routine returns 0, that means the
4160 ** [prepared statement] returns no data (for example an [UPDATE]).
4161 ** ^However, just because this routine returns a positive number does not
4162 ** mean that one or more rows of data will be returned.  ^A SELECT statement
4163 ** will always have a positive sqlite3_column_count() but depending on the
4164 ** WHERE clause constraints and the table content, it might return no rows.
4165 **
4166 ** See also: [sqlite3_data_count()]
4167 */
4168 int sqlite3_column_count(sqlite3_stmt* pStmt);
4169 
4170 /*
4171 ** CAPI3REF: Column Names In A Result Set
4172 ** METHOD: sqlite3_stmt
4173 **
4174 ** ^These routines return the name assigned to a particular column
4175 ** in the result set of a [SELECT] statement.  ^The sqlite3_column_name()
4176 ** interface returns a pointer to a zero-terminated UTF-8 string
4177 ** and sqlite3_column_name16() returns a pointer to a zero-terminated
4178 ** UTF-16 string.  ^The first parameter is the [prepared statement]
4179 ** that implements the [SELECT] statement. ^The second parameter is the
4180 ** column number.  ^The leftmost column is number 0.
4181 **
4182 ** ^The returned string pointer is valid until either the [prepared statement]
4183 ** is destroyed by [sqlite3_finalize()] or until the statement is automatically
4184 ** reprepared by the first call to [sqlite3_step()] for a particular run
4185 ** or until the next call to
4186 ** sqlite3_column_name() or sqlite3_column_name16() on the same column.
4187 **
4188 ** ^If sqlite3_malloc() fails during the processing of either routine
4189 ** (for example during a conversion from UTF-8 to UTF-16) then a
4190 ** NULL pointer is returned.
4191 **
4192 ** ^The name of a result column is the value of the "AS" clause for
4193 ** that column, if there is an AS clause.  If there is no AS clause
4194 ** then the name of the column is unspecified and may change from
4195 ** one release of SQLite to the next.
4196 */
4197 const(char)* sqlite3_column_name(sqlite3_stmt*, int N);
4198 const(void)* sqlite3_column_name16(sqlite3_stmt*, int N);
4199 
4200 /*
4201 ** CAPI3REF: Source Of Data In A Query Result
4202 ** METHOD: sqlite3_stmt
4203 **
4204 ** ^These routines provide a means to determine the database, table, and
4205 ** table column that is the origin of a particular result column in
4206 ** [SELECT] statement.
4207 ** ^The name of the database or table or column can be returned as
4208 ** either a UTF-8 or UTF-16 string.  ^The _database_ routines return
4209 ** the database name, the _table_ routines return the table name, and
4210 ** the origin_ routines return the column name.
4211 ** ^The returned string is valid until the [prepared statement] is destroyed
4212 ** using [sqlite3_finalize()] or until the statement is automatically
4213 ** reprepared by the first call to [sqlite3_step()] for a particular run
4214 ** or until the same information is requested
4215 ** again in a different encoding.
4216 **
4217 ** ^The names returned are the original un-aliased names of the
4218 ** database, table, and column.
4219 **
4220 ** ^The first argument to these interfaces is a [prepared statement].
4221 ** ^These functions return information about the Nth result column returned by
4222 ** the statement, where N is the second function argument.
4223 ** ^The left-most column is column 0 for these routines.
4224 **
4225 ** ^If the Nth column returned by the statement is an expression or
4226 ** subquery and is not a column value, then all of these functions return
4227 ** NULL.  ^These routine might also return NULL if a memory allocation error
4228 ** occurs.  ^Otherwise, they return the name of the attached database, table,
4229 ** or column that query result column was extracted from.
4230 **
4231 ** ^As with all other SQLite APIs, those whose names end with "16" return
4232 ** UTF-16 encoded strings and the other functions return UTF-8.
4233 **
4234 ** ^These APIs are only available if the library was compiled with the
4235 ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
4236 **
4237 ** If two or more threads call one or more of these routines against the same
4238 ** prepared statement and column at the same time then the results are
4239 ** undefined.
4240 **
4241 ** If two or more threads call one or more
4242 ** [sqlite3_column_database_name | column metadata interfaces]
4243 ** for the same [prepared statement] and result column
4244 ** at the same time then the results are undefined.
4245 */
4246 const(char)* sqlite3_column_database_name(sqlite3_stmt*, int);
4247 const(void)* sqlite3_column_database_name16(sqlite3_stmt*, int);
4248 const(char)* sqlite3_column_table_name(sqlite3_stmt*, int);
4249 const(void)* sqlite3_column_table_name16(sqlite3_stmt*, int);
4250 const(char)* sqlite3_column_origin_name(sqlite3_stmt*, int);
4251 const(void)* sqlite3_column_origin_name16(sqlite3_stmt*, int);
4252 
4253 /*
4254 ** CAPI3REF: Declared Datatype Of A Query Result
4255 ** METHOD: sqlite3_stmt
4256 **
4257 ** ^(The first parameter is a [prepared statement].
4258 ** If this statement is a [SELECT] statement and the Nth column of the
4259 ** returned result set of that [SELECT] is a table column (not an
4260 ** expression or subquery) then the declared type of the table
4261 ** column is returned.)^  ^If the Nth column of the result set is an
4262 ** expression or subquery, then a NULL pointer is returned.
4263 ** ^The returned string is always UTF-8 encoded.
4264 **
4265 ** ^(For example, given the database schema:
4266 **
4267 ** CREATE TABLE t1(c1 VARIANT);
4268 **
4269 ** and the following statement to be compiled:
4270 **
4271 ** SELECT c1 + 1, c1 FROM t1;
4272 **
4273 ** this routine would return the string "VARIANT" for the second result
4274 ** column (i==1), and a NULL pointer for the first result column (i==0).)^
4275 **
4276 ** ^SQLite uses dynamic run-time typing.  ^So just because a column
4277 ** is declared to contain a particular type does not mean that the
4278 ** data stored in that column is of the declared type.  SQLite is
4279 ** strongly typed, but the typing is dynamic not static.  ^Type
4280 ** is associated with individual values, not with the containers
4281 ** used to hold those values.
4282 */
4283 const(char)* sqlite3_column_decltype(sqlite3_stmt*, int);
4284 const(void)* sqlite3_column_decltype16(sqlite3_stmt*, int);
4285 
4286 /*
4287 ** CAPI3REF: Evaluate An SQL Statement
4288 ** METHOD: sqlite3_stmt
4289 **
4290 ** After a [prepared statement] has been prepared using any of
4291 ** [sqlite3_prepare_v2()], [sqlite3_prepare_v3()], [sqlite3_prepare16_v2()],
4292 ** or [sqlite3_prepare16_v3()] or one of the legacy
4293 ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
4294 ** must be called one or more times to evaluate the statement.
4295 **
4296 ** The details of the behavior of the sqlite3_step() interface depend
4297 ** on whether the statement was prepared using the newer "vX" interfaces
4298 ** [sqlite3_prepare_v3()], [sqlite3_prepare_v2()], [sqlite3_prepare16_v3()],
4299 ** [sqlite3_prepare16_v2()] or the older legacy
4300 ** interfaces [sqlite3_prepare()] and [sqlite3_prepare16()].  The use of the
4301 ** new "vX" interface is recommended for new applications but the legacy
4302 ** interface will continue to be supported.
4303 **
4304 ** ^In the legacy interface, the return value will be either [SQLITE_BUSY],
4305 ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
4306 ** ^With the "v2" interface, any of the other [result codes] or
4307 ** [extended result codes] might be returned as well.
4308 **
4309 ** ^[SQLITE_BUSY] means that the database engine was unable to acquire the
4310 ** database locks it needs to do its job.  ^If the statement is a [COMMIT]
4311 ** or occurs outside of an explicit transaction, then you can retry the
4312 ** statement.  If the statement is not a [COMMIT] and occurs within an
4313 ** explicit transaction then you should rollback the transaction before
4314 ** continuing.
4315 **
4316 ** ^[SQLITE_DONE] means that the statement has finished executing
4317 ** successfully.  sqlite3_step() should not be called again on this virtual
4318 ** machine without first calling [sqlite3_reset()] to reset the virtual
4319 ** machine back to its initial state.
4320 **
4321 ** ^If the SQL statement being executed returns any data, then [SQLITE_ROW]
4322 ** is returned each time a new row of data is ready for processing by the
4323 ** caller. The values may be accessed using the [column access functions].
4324 ** sqlite3_step() is called again to retrieve the next row of data.
4325 **
4326 ** ^[SQLITE_ERROR] means that a run-time error (such as a constraint
4327 ** violation) has occurred.  sqlite3_step() should not be called again on
4328 ** the VM. More information may be found by calling [sqlite3_errmsg()].
4329 ** ^With the legacy interface, a more specific error code (for example,
4330 ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
4331 ** can be obtained by calling [sqlite3_reset()] on the
4332 ** [prepared statement].  ^In the "v2" interface,
4333 ** the more specific error code is returned directly by sqlite3_step().
4334 **
4335 ** [SQLITE_MISUSE] means that the this routine was called inappropriately.
4336 ** Perhaps it was called on a [prepared statement] that has
4337 ** already been [sqlite3_finalize | finalized] or on one that had
4338 ** previously returned [SQLITE_ERROR] or [SQLITE_DONE].  Or it could
4339 ** be the case that the same database connection is being used by two or
4340 ** more threads at the same moment in time.
4341 **
4342 ** For all versions of SQLite up to and including 3.6.23.1, a call to
4343 ** [sqlite3_reset()] was required after sqlite3_step() returned anything
4344 ** other than [SQLITE_ROW] before any subsequent invocation of
4345 ** sqlite3_step().  Failure to reset the prepared statement using
4346 ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
4347 ** sqlite3_step().  But after [version 3.6.23.1] ([dateof:3.6.23.1],
4348 ** sqlite3_step() began
4349 ** calling [sqlite3_reset()] automatically in this circumstance rather
4350 ** than returning [SQLITE_MISUSE].  This is not considered a compatibility
4351 ** break because any application that ever receives an SQLITE_MISUSE error
4352 ** is broken by definition.  The [SQLITE_OMIT_AUTORESET] compile-time option
4353 ** can be used to restore the legacy behavior.
4354 **
4355 ** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step()
4356 ** API always returns a generic error code, [SQLITE_ERROR], following any
4357 ** error other than [SQLITE_BUSY] and [SQLITE_MISUSE].  You must call
4358 ** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the
4359 ** specific [error codes] that better describes the error.
4360 ** We admit that this is a goofy design.  The problem has been fixed
4361 ** with the "v2" interface.  If you prepare all of your SQL statements
4362 ** using [sqlite3_prepare_v3()] or [sqlite3_prepare_v2()]
4363 ** or [sqlite3_prepare16_v2()] or [sqlite3_prepare16_v3()] instead
4364 ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces,
4365 ** then the more specific [error codes] are returned directly
4366 ** by sqlite3_step().  The use of the "vX" interfaces is recommended.
4367 */
4368 int sqlite3_step(sqlite3_stmt*);
4369 
4370 /*
4371 ** CAPI3REF: Number of columns in a result set
4372 ** METHOD: sqlite3_stmt
4373 **
4374 ** ^The sqlite3_data_count(P) interface returns the number of columns in the
4375 ** current row of the result set of [prepared statement] P.
4376 ** ^If prepared statement P does not have results ready to return
4377 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of
4378 ** interfaces) then sqlite3_data_count(P) returns 0.
4379 ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
4380 ** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
4381 ** [sqlite3_step](P) returned [SQLITE_DONE].  ^The sqlite3_data_count(P)
4382 ** will return non-zero if previous call to [sqlite3_step](P) returned
4383 ** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum]
4384 ** where it always returns zero since each step of that multi-step
4385 ** pragma returns 0 columns of data.
4386 **
4387 ** See also: [sqlite3_column_count()]
4388 */
4389 int sqlite3_data_count(sqlite3_stmt* pStmt);
4390 
4391 /*
4392 ** CAPI3REF: Fundamental Datatypes
4393 ** KEYWORDS: SQLITE_TEXT
4394 **
4395 ** ^(Every value in SQLite has one of five fundamental datatypes:
4396 **
4397 ** <ul>
4398 ** <li> 64-bit signed integer
4399 ** <li> 64-bit IEEE floating point number
4400 ** <li> string
4401 ** <li> BLOB
4402 ** <li> NULL
4403 ** </ul>)^
4404 **
4405 ** These constants are codes for each of those types.
4406 **
4407 ** Note that the SQLITE_TEXT constant was also used in SQLite version 2
4408 ** for a completely different meaning.  Software that links against both
4409 ** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not
4410 ** SQLITE_TEXT.
4411 */
4412 enum SQLITE_INTEGER = 1;
4413 enum SQLITE_FLOAT = 2;
4414 enum SQLITE_BLOB = 4;
4415 enum SQLITE_NULL = 5;
4416 
4417 enum SQLITE_TEXT = 3;
4418 
4419 enum SQLITE3_TEXT = 3;
4420 
4421 /*
4422 ** CAPI3REF: Result Values From A Query
4423 ** KEYWORDS: {column access functions}
4424 ** METHOD: sqlite3_stmt
4425 **
4426 ** <b>Summary:</b>
4427 ** <blockquote><table border=0 cellpadding=0 cellspacing=0>
4428 ** <tr><td><b>sqlite3_column_blob</b><td>&rarr;<td>BLOB result
4429 ** <tr><td><b>sqlite3_column_double</b><td>&rarr;<td>REAL result
4430 ** <tr><td><b>sqlite3_column_int</b><td>&rarr;<td>32-bit INTEGER result
4431 ** <tr><td><b>sqlite3_column_int64</b><td>&rarr;<td>64-bit INTEGER result
4432 ** <tr><td><b>sqlite3_column_text</b><td>&rarr;<td>UTF-8 TEXT result
4433 ** <tr><td><b>sqlite3_column_text16</b><td>&rarr;<td>UTF-16 TEXT result
4434 ** <tr><td><b>sqlite3_column_value</b><td>&rarr;<td>The result as an
4435 ** [sqlite3_value|unprotected sqlite3_value] object.
4436 ** <tr><td>&nbsp;<td>&nbsp;<td>&nbsp;
4437 ** <tr><td><b>sqlite3_column_bytes</b><td>&rarr;<td>Size of a BLOB
4438 ** or a UTF-8 TEXT result in bytes
4439 ** <tr><td><b>sqlite3_column_bytes16&nbsp;&nbsp;</b>
4440 ** <td>&rarr;&nbsp;&nbsp;<td>Size of UTF-16
4441 ** TEXT in bytes
4442 ** <tr><td><b>sqlite3_column_type</b><td>&rarr;<td>Default
4443 ** datatype of the result
4444 ** </table></blockquote>
4445 **
4446 ** <b>Details:</b>
4447 **
4448 ** ^These routines return information about a single column of the current
4449 ** result row of a query.  ^In every case the first argument is a pointer
4450 ** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*]
4451 ** that was returned from [sqlite3_prepare_v2()] or one of its variants)
4452 ** and the second argument is the index of the column for which information
4453 ** should be returned. ^The leftmost column of the result set has the index 0.
4454 ** ^The number of columns in the result can be determined using
4455 ** [sqlite3_column_count()].
4456 **
4457 ** If the SQL statement does not currently point to a valid row, or if the
4458 ** column index is out of range, the result is undefined.
4459 ** These routines may only be called when the most recent call to
4460 ** [sqlite3_step()] has returned [SQLITE_ROW] and neither
4461 ** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently.
4462 ** If any of these routines are called after [sqlite3_reset()] or
4463 ** [sqlite3_finalize()] or after [sqlite3_step()] has returned
4464 ** something other than [SQLITE_ROW], the results are undefined.
4465 ** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()]
4466 ** are called from a different thread while any of these routines
4467 ** are pending, then the results are undefined.
4468 **
4469 ** The first six interfaces (_blob, _double, _int, _int64, _text, and _text16)
4470 ** each return the value of a result column in a specific data format.  If
4471 ** the result column is not initially in the requested format (for example,
4472 ** if the query returns an integer but the sqlite3_column_text() interface
4473 ** is used to extract the value) then an automatic type conversion is performed.
4474 **
4475 ** ^The sqlite3_column_type() routine returns the
4476 ** [SQLITE_INTEGER | datatype code] for the initial data type
4477 ** of the result column.  ^The returned value is one of [SQLITE_INTEGER],
4478 ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].
4479 ** The return value of sqlite3_column_type() can be used to decide which
4480 ** of the first six interface should be used to extract the column value.
4481 ** The value returned by sqlite3_column_type() is only meaningful if no
4482 ** automatic type conversions have occurred for the value in question.
4483 ** After a type conversion, the result of calling sqlite3_column_type()
4484 ** is undefined, though harmless.  Future
4485 ** versions of SQLite may change the behavior of sqlite3_column_type()
4486 ** following a type conversion.
4487 **
4488 ** If the result is a BLOB or a TEXT string, then the sqlite3_column_bytes()
4489 ** or sqlite3_column_bytes16() interfaces can be used to determine the size
4490 ** of that BLOB or string.
4491 **
4492 ** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes()
4493 ** routine returns the number of bytes in that BLOB or string.
4494 ** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts
4495 ** the string to UTF-8 and then returns the number of bytes.
4496 ** ^If the result is a numeric value then sqlite3_column_bytes() uses
4497 ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
4498 ** the number of bytes in that string.
4499 ** ^If the result is NULL, then sqlite3_column_bytes() returns zero.
4500 **
4501 ** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16()
4502 ** routine returns the number of bytes in that BLOB or string.
4503 ** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts
4504 ** the string to UTF-16 and then returns the number of bytes.
4505 ** ^If the result is a numeric value then sqlite3_column_bytes16() uses
4506 ** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns
4507 ** the number of bytes in that string.
4508 ** ^If the result is NULL, then sqlite3_column_bytes16() returns zero.
4509 **
4510 ** ^The values returned by [sqlite3_column_bytes()] and
4511 ** [sqlite3_column_bytes16()] do not include the zero terminators at the end
4512 ** of the string.  ^For clarity: the values returned by
4513 ** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of
4514 ** bytes in the string, not the number of characters.
4515 **
4516 ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
4517 ** even empty strings, are always zero-terminated.  ^The return
4518 ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.
4519 **
4520 ** <b>Warning:</b> ^The object returned by [sqlite3_column_value()] is an
4521 ** [unprotected sqlite3_value] object.  In a multithreaded environment,
4522 ** an unprotected sqlite3_value object may only be used safely with
4523 ** [sqlite3_bind_value()] and [sqlite3_result_value()].
4524 ** If the [unprotected sqlite3_value] object returned by
4525 ** [sqlite3_column_value()] is used in any other way, including calls
4526 ** to routines like [sqlite3_value_int()], [sqlite3_value_text()],
4527 ** or [sqlite3_value_bytes()], the behavior is not threadsafe.
4528 ** Hence, the sqlite3_column_value() interface
4529 ** is normally only useful within the implementation of
4530 ** [application-defined SQL functions] or [virtual tables], not within
4531 ** top-level application code.
4532 **
4533 ** The these routines may attempt to convert the datatype of the result.
4534 ** ^For example, if the internal representation is FLOAT and a text result
4535 ** is requested, [sqlite3_snprintf()] is used internally to perform the
4536 ** conversion automatically.  ^(The following table details the conversions
4537 ** that are applied:
4538 **
4539 ** <blockquote>
4540 ** <table border="1">
4541 ** <tr><th> Internal<br>Type <th> Requested<br>Type <th>  Conversion
4542 **
4543 ** <tr><td>  NULL    <td> INTEGER   <td> Result is 0
4544 ** <tr><td>  NULL    <td>  FLOAT    <td> Result is 0.0
4545 ** <tr><td>  NULL    <td>   TEXT    <td> Result is a NULL pointer
4546 ** <tr><td>  NULL    <td>   BLOB    <td> Result is a NULL pointer
4547 ** <tr><td> INTEGER  <td>  FLOAT    <td> Convert from integer to float
4548 ** <tr><td> INTEGER  <td>   TEXT    <td> ASCII rendering of the integer
4549 ** <tr><td> INTEGER  <td>   BLOB    <td> Same as INTEGER->TEXT
4550 ** <tr><td>  FLOAT   <td> INTEGER   <td> [CAST] to INTEGER
4551 ** <tr><td>  FLOAT   <td>   TEXT    <td> ASCII rendering of the float
4552 ** <tr><td>  FLOAT   <td>   BLOB    <td> [CAST] to BLOB
4553 ** <tr><td>  TEXT    <td> INTEGER   <td> [CAST] to INTEGER
4554 ** <tr><td>  TEXT    <td>  FLOAT    <td> [CAST] to REAL
4555 ** <tr><td>  TEXT    <td>   BLOB    <td> No change
4556 ** <tr><td>  BLOB    <td> INTEGER   <td> [CAST] to INTEGER
4557 ** <tr><td>  BLOB    <td>  FLOAT    <td> [CAST] to REAL
4558 ** <tr><td>  BLOB    <td>   TEXT    <td> Add a zero terminator if needed
4559 ** </table>
4560 ** </blockquote>)^
4561 **
4562 ** Note that when type conversions occur, pointers returned by prior
4563 ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
4564 ** sqlite3_column_text16() may be invalidated.
4565 ** Type conversions and pointer invalidations might occur
4566 ** in the following cases:
4567 **
4568 ** <ul>
4569 ** <li> The initial content is a BLOB and sqlite3_column_text() or
4570 **      sqlite3_column_text16() is called.  A zero-terminator might
4571 **      need to be added to the string.</li>
4572 ** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or
4573 **      sqlite3_column_text16() is called.  The content must be converted
4574 **      to UTF-16.</li>
4575 ** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or
4576 **      sqlite3_column_text() is called.  The content must be converted
4577 **      to UTF-8.</li>
4578 ** </ul>
4579 **
4580 ** ^Conversions between UTF-16be and UTF-16le are always done in place and do
4581 ** not invalidate a prior pointer, though of course the content of the buffer
4582 ** that the prior pointer references will have been modified.  Other kinds
4583 ** of conversion are done in place when it is possible, but sometimes they
4584 ** are not possible and in those cases prior pointers are invalidated.
4585 **
4586 ** The safest policy is to invoke these routines
4587 ** in one of the following ways:
4588 **
4589 ** <ul>
4590 **  <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
4591 **  <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
4592 **  <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
4593 ** </ul>
4594 **
4595 ** In other words, you should call sqlite3_column_text(),
4596 ** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result
4597 ** into the desired format, then invoke sqlite3_column_bytes() or
4598 ** sqlite3_column_bytes16() to find the size of the result.  Do not mix calls
4599 ** to sqlite3_column_text() or sqlite3_column_blob() with calls to
4600 ** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16()
4601 ** with calls to sqlite3_column_bytes().
4602 **
4603 ** ^The pointers returned are valid until a type conversion occurs as
4604 ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
4605 ** [sqlite3_finalize()] is called.  ^The memory space used to hold strings
4606 ** and BLOBs is freed automatically.  Do not pass the pointers returned
4607 ** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
4608 ** [sqlite3_free()].
4609 **
4610 ** As long as the input parameters are correct, these routines will only
4611 ** fail if an out-of-memory error occurs during a format conversion.
4612 ** Only the following subset of interfaces are subject to out-of-memory
4613 ** errors:
4614 **
4615 ** <ul>
4616 ** <li> sqlite3_column_blob()
4617 ** <li> sqlite3_column_text()
4618 ** <li> sqlite3_column_text16()
4619 ** <li> sqlite3_column_bytes()
4620 ** <li> sqlite3_column_bytes16()
4621 ** </ul>
4622 **
4623 ** If an out-of-memory error occurs, then the return value from these
4624 ** routines is the same as if the column had contained an SQL NULL value.
4625 ** Valid SQL NULL returns can be distinguished from out-of-memory errors
4626 ** by invoking the [sqlite3_errcode()] immediately after the suspect
4627 ** return value is obtained and before any
4628 ** other SQLite interface is called on the same [database connection].
4629 */
4630 const(void)* sqlite3_column_blob(sqlite3_stmt*, int iCol);
4631 double sqlite3_column_double(sqlite3_stmt*, int iCol);
4632 int sqlite3_column_int(sqlite3_stmt*, int iCol);
4633 sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
4634 const(ubyte)* sqlite3_column_text(sqlite3_stmt*, int iCol);
4635 const(void)* sqlite3_column_text16(sqlite3_stmt*, int iCol);
4636 sqlite3_value* sqlite3_column_value(sqlite3_stmt*, int iCol);
4637 int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
4638 int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
4639 int sqlite3_column_type(sqlite3_stmt*, int iCol);
4640 
4641 /*
4642 ** CAPI3REF: Destroy A Prepared Statement Object
4643 ** DESTRUCTOR: sqlite3_stmt
4644 **
4645 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
4646 ** ^If the most recent evaluation of the statement encountered no errors
4647 ** or if the statement is never been evaluated, then sqlite3_finalize() returns
4648 ** SQLITE_OK.  ^If the most recent evaluation of statement S failed, then
4649 ** sqlite3_finalize(S) returns the appropriate [error code] or
4650 ** [extended error code].
4651 **
4652 ** ^The sqlite3_finalize(S) routine can be called at any point during
4653 ** the life cycle of [prepared statement] S:
4654 ** before statement S is ever evaluated, after
4655 ** one or more calls to [sqlite3_reset()], or after any call
4656 ** to [sqlite3_step()] regardless of whether or not the statement has
4657 ** completed execution.
4658 **
4659 ** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op.
4660 **
4661 ** The application must finalize every [prepared statement] in order to avoid
4662 ** resource leaks.  It is a grievous error for the application to try to use
4663 ** a prepared statement after it has been finalized.  Any use of a prepared
4664 ** statement after it has been finalized can result in undefined and
4665 ** undesirable behavior such as segfaults and heap corruption.
4666 */
4667 int sqlite3_finalize(sqlite3_stmt* pStmt);
4668 
4669 /*
4670 ** CAPI3REF: Reset A Prepared Statement Object
4671 ** METHOD: sqlite3_stmt
4672 **
4673 ** The sqlite3_reset() function is called to reset a [prepared statement]
4674 ** object back to its initial state, ready to be re-executed.
4675 ** ^Any SQL statement variables that had values bound to them using
4676 ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
4677 ** Use [sqlite3_clear_bindings()] to reset the bindings.
4678 **
4679 ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S
4680 ** back to the beginning of its program.
4681 **
4682 ** ^If the most recent call to [sqlite3_step(S)] for the
4683 ** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE],
4684 ** or if [sqlite3_step(S)] has never before been called on S,
4685 ** then [sqlite3_reset(S)] returns [SQLITE_OK].
4686 **
4687 ** ^If the most recent call to [sqlite3_step(S)] for the
4688 ** [prepared statement] S indicated an error, then
4689 ** [sqlite3_reset(S)] returns an appropriate [error code].
4690 **
4691 ** ^The [sqlite3_reset(S)] interface does not change the values
4692 ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
4693 */
4694 int sqlite3_reset(sqlite3_stmt* pStmt);
4695 
4696 /*
4697 ** CAPI3REF: Create Or Redefine SQL Functions
4698 ** KEYWORDS: {function creation routines}
4699 ** KEYWORDS: {application-defined SQL function}
4700 ** KEYWORDS: {application-defined SQL functions}
4701 ** METHOD: sqlite3
4702 **
4703 ** ^These functions (collectively known as "function creation routines")
4704 ** are used to add SQL functions or aggregates or to redefine the behavior
4705 ** of existing SQL functions or aggregates. The only differences between
4706 ** the three "sqlite3_create_function*" routines are the text encoding
4707 ** expected for the second parameter (the name of the function being
4708 ** created) and the presence or absence of a destructor callback for
4709 ** the application data pointer. Function sqlite3_create_window_function()
4710 ** is similar, but allows the user to supply the extra callback functions
4711 ** needed by [aggregate window functions].
4712 **
4713 ** ^The first parameter is the [database connection] to which the SQL
4714 ** function is to be added.  ^If an application uses more than one database
4715 ** connection then application-defined SQL functions must be added
4716 ** to each database connection separately.
4717 **
4718 ** ^The second parameter is the name of the SQL function to be created or
4719 ** redefined.  ^The length of the name is limited to 255 bytes in a UTF-8
4720 ** representation, exclusive of the zero-terminator.  ^Note that the name
4721 ** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes.
4722 ** ^Any attempt to create a function with a longer name
4723 ** will result in [SQLITE_MISUSE] being returned.
4724 **
4725 ** ^The third parameter (nArg)
4726 ** is the number of arguments that the SQL function or
4727 ** aggregate takes. ^If this parameter is -1, then the SQL function or
4728 ** aggregate may take any number of arguments between 0 and the limit
4729 ** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]).  If the third
4730 ** parameter is less than -1 or greater than 127 then the behavior is
4731 ** undefined.
4732 **
4733 ** ^The fourth parameter, eTextRep, specifies what
4734 ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
4735 ** its parameters.  The application should set this parameter to
4736 ** [SQLITE_UTF16LE] if the function implementation invokes
4737 ** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the
4738 ** implementation invokes [sqlite3_value_text16be()] on an input, or
4739 ** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8]
4740 ** otherwise.  ^The same SQL function may be registered multiple times using
4741 ** different preferred text encodings, with different implementations for
4742 ** each encoding.
4743 ** ^When multiple implementations of the same function are available, SQLite
4744 ** will pick the one that involves the least amount of data conversion.
4745 **
4746 ** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC]
4747 ** to signal that the function will always return the same result given
4748 ** the same inputs within a single SQL statement.  Most SQL functions are
4749 ** deterministic.  The built-in [random()] SQL function is an example of a
4750 ** function that is not deterministic.  The SQLite query planner is able to
4751 ** perform additional optimizations on deterministic functions, so use
4752 ** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
4753 **
4754 ** ^(The fifth parameter is an arbitrary pointer.  The implementation of the
4755 ** function can gain access to this pointer using [sqlite3_user_data()].)^
4756 **
4757 ** ^The sixth, seventh and eighth parameters passed to the three
4758 ** "sqlite3_create_function*" functions, xFunc, xStep and xFinal, are
4759 ** pointers to C-language functions that implement the SQL function or
4760 ** aggregate. ^A scalar SQL function requires an implementation of the xFunc
4761 ** callback only; NULL pointers must be passed as the xStep and xFinal
4762 ** parameters. ^An aggregate SQL function requires an implementation of xStep
4763 ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
4764 ** SQL function or aggregate, pass NULL pointers for all three function
4765 ** callbacks.
4766 **
4767 ** ^The sixth, seventh, eighth and ninth parameters (xStep, xFinal, xValue
4768 ** and xInverse) passed to sqlite3_create_window_function are pointers to
4769 ** C-language callbacks that implement the new function. xStep and xFinal
4770 ** must both be non-NULL. xValue and xInverse may either both be NULL, in
4771 ** which case a regular aggregate function is created, or must both be
4772 ** non-NULL, in which case the new function may be used as either an aggregate
4773 ** or aggregate window function. More details regarding the implementation
4774 ** of aggregate window functions are
4775 ** [user-defined window functions|available here].
4776 **
4777 ** ^(If the final parameter to sqlite3_create_function_v2() or
4778 ** sqlite3_create_window_function() is not NULL, then it is destructor for
4779 ** the application data pointer. The destructor is invoked when the function
4780 ** is deleted, either by being overloaded or when the database connection
4781 ** closes.)^ ^The destructor is also invoked if the call to
4782 ** sqlite3_create_function_v2() fails.  ^When the destructor callback is
4783 ** invoked, it is passed a single argument which is a copy of the application
4784 ** data pointer which was the fifth parameter to sqlite3_create_function_v2().
4785 **
4786 ** ^It is permitted to register multiple implementations of the same
4787 ** functions with the same name but with either differing numbers of
4788 ** arguments or differing preferred text encodings.  ^SQLite will use
4789 ** the implementation that most closely matches the way in which the
4790 ** SQL function is used.  ^A function implementation with a non-negative
4791 ** nArg parameter is a better match than a function implementation with
4792 ** a negative nArg.  ^A function where the preferred text encoding
4793 ** matches the database encoding is a better
4794 ** match than a function where the encoding is different.
4795 ** ^A function where the encoding difference is between UTF16le and UTF16be
4796 ** is a closer match than a function where the encoding difference is
4797 ** between UTF8 and UTF16.
4798 **
4799 ** ^Built-in functions may be overloaded by new application-defined functions.
4800 **
4801 ** ^An application-defined function is permitted to call other
4802 ** SQLite interfaces.  However, such calls must not
4803 ** close the database connection nor finalize or reset the prepared
4804 ** statement in which the function is running.
4805 */
4806 int sqlite3_create_function(
4807     sqlite3* db,
4808     const(char)* zFunctionName,
4809     int nArg,
4810     int eTextRep,
4811     void* pApp,
4812     void function(sqlite3_context*, int, sqlite3_value**) xFunc,
4813     void function(sqlite3_context*, int, sqlite3_value**) xStep,
4814     void function(sqlite3_context*) xFinal);
4815 int sqlite3_create_function16(
4816     sqlite3* db,
4817     const(void)* zFunctionName,
4818     int nArg,
4819     int eTextRep,
4820     void* pApp,
4821     void function(sqlite3_context*, int, sqlite3_value**) xFunc,
4822     void function(sqlite3_context*, int, sqlite3_value**) xStep,
4823     void function(sqlite3_context*) xFinal);
4824 int sqlite3_create_function_v2(
4825     sqlite3* db,
4826     const(char)* zFunctionName,
4827     int nArg,
4828     int eTextRep,
4829     void* pApp,
4830     void function(sqlite3_context*, int, sqlite3_value**) xFunc,
4831     void function(sqlite3_context*, int, sqlite3_value**) xStep,
4832     void function(sqlite3_context*) xFinal,
4833     void function(void*) xDestroy);
4834 int sqlite3_create_window_function(
4835     sqlite3* db,
4836     const(char)* zFunctionName,
4837     int nArg,
4838     int eTextRep,
4839     void* pApp,
4840     void function(sqlite3_context*, int, sqlite3_value**) xStep,
4841     void function(sqlite3_context*) xFinal,
4842     void function(sqlite3_context*) xValue,
4843     void function(sqlite3_context*, int, sqlite3_value**) xInverse,
4844     void function(void*) xDestroy);
4845 
4846 /*
4847 ** CAPI3REF: Text Encodings
4848 **
4849 ** These constant define integer codes that represent the various
4850 ** text encodings supported by SQLite.
4851 */
4852 enum SQLITE_UTF8 = 1; /* IMP: R-37514-35566 */
4853 enum SQLITE_UTF16LE = 2; /* IMP: R-03371-37637 */
4854 enum SQLITE_UTF16BE = 3; /* IMP: R-51971-34154 */
4855 enum SQLITE_UTF16 = 4; /* Use native byte order */
4856 enum SQLITE_ANY = 5; /* Deprecated */
4857 enum SQLITE_UTF16_ALIGNED = 8; /* sqlite3_create_collation only */
4858 
4859 /*
4860 ** CAPI3REF: Function Flags
4861 **
4862 ** These constants may be ORed together with the
4863 ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
4864 ** to [sqlite3_create_function()], [sqlite3_create_function16()], or
4865 ** [sqlite3_create_function_v2()].
4866 */
4867 enum SQLITE_DETERMINISTIC = 0x800;
4868 
4869 /*
4870 ** CAPI3REF: Deprecated Functions
4871 ** DEPRECATED
4872 **
4873 ** These functions are [deprecated].  In order to maintain
4874 ** backwards compatibility with older code, these functions continue
4875 ** to be supported.  However, new applications should avoid
4876 ** the use of these functions.  To encourage programmers to avoid
4877 ** these functions, we will not explain what they do.
4878 */
4879 
4880 int sqlite3_aggregate_count(sqlite3_context*);
4881 int sqlite3_expired(sqlite3_stmt*);
4882 int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
4883 int sqlite3_global_recover();
4884 void sqlite3_thread_cleanup();
4885 int sqlite3_memory_alarm(
4886     void function(void*, sqlite3_int64, int),
4887     void*,
4888     sqlite3_int64);
4889 
4890 /*
4891 ** CAPI3REF: Obtaining SQL Values
4892 ** METHOD: sqlite3_value
4893 **
4894 ** <b>Summary:</b>
4895 ** <blockquote><table border=0 cellpadding=0 cellspacing=0>
4896 ** <tr><td><b>sqlite3_value_blob</b><td>&rarr;<td>BLOB value
4897 ** <tr><td><b>sqlite3_value_double</b><td>&rarr;<td>REAL value
4898 ** <tr><td><b>sqlite3_value_int</b><td>&rarr;<td>32-bit INTEGER value
4899 ** <tr><td><b>sqlite3_value_int64</b><td>&rarr;<td>64-bit INTEGER value
4900 ** <tr><td><b>sqlite3_value_pointer</b><td>&rarr;<td>Pointer value
4901 ** <tr><td><b>sqlite3_value_text</b><td>&rarr;<td>UTF-8 TEXT value
4902 ** <tr><td><b>sqlite3_value_text16</b><td>&rarr;<td>UTF-16 TEXT value in
4903 ** the native byteorder
4904 ** <tr><td><b>sqlite3_value_text16be</b><td>&rarr;<td>UTF-16be TEXT value
4905 ** <tr><td><b>sqlite3_value_text16le</b><td>&rarr;<td>UTF-16le TEXT value
4906 ** <tr><td>&nbsp;<td>&nbsp;<td>&nbsp;
4907 ** <tr><td><b>sqlite3_value_bytes</b><td>&rarr;<td>Size of a BLOB
4908 ** or a UTF-8 TEXT in bytes
4909 ** <tr><td><b>sqlite3_value_bytes16&nbsp;&nbsp;</b>
4910 ** <td>&rarr;&nbsp;&nbsp;<td>Size of UTF-16
4911 ** TEXT in bytes
4912 ** <tr><td><b>sqlite3_value_type</b><td>&rarr;<td>Default
4913 ** datatype of the value
4914 ** <tr><td><b>sqlite3_value_numeric_type&nbsp;&nbsp;</b>
4915 ** <td>&rarr;&nbsp;&nbsp;<td>Best numeric datatype of the value
4916 ** <tr><td><b>sqlite3_value_nochange&nbsp;&nbsp;</b>
4917 ** <td>&rarr;&nbsp;&nbsp;<td>True if the column is unchanged in an UPDATE
4918 ** against a virtual table.
4919 ** </table></blockquote>
4920 **
4921 ** <b>Details:</b>
4922 **
4923 ** These routines extract type, size, and content information from
4924 ** [protected sqlite3_value] objects.  Protected sqlite3_value objects
4925 ** are used to pass parameter information into implementation of
4926 ** [application-defined SQL functions] and [virtual tables].
4927 **
4928 ** These routines work only with [protected sqlite3_value] objects.
4929 ** Any attempt to use these routines on an [unprotected sqlite3_value]
4930 ** is not threadsafe.
4931 **
4932 ** ^These routines work just like the corresponding [column access functions]
4933 ** except that these routines take a single [protected sqlite3_value] object
4934 ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
4935 **
4936 ** ^The sqlite3_value_text16() interface extracts a UTF-16 string
4937 ** in the native byte-order of the host machine.  ^The
4938 ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
4939 ** extract UTF-16 strings as big-endian and little-endian respectively.
4940 **
4941 ** ^If [sqlite3_value] object V was initialized
4942 ** using [sqlite3_bind_pointer(S,I,P,X,D)] or [sqlite3_result_pointer(C,P,X,D)]
4943 ** and if X and Y are strings that compare equal according to strcmp(X,Y),
4944 ** then sqlite3_value_pointer(V,Y) will return the pointer P.  ^Otherwise,
4945 ** sqlite3_value_pointer(V,Y) returns a NULL. The sqlite3_bind_pointer()
4946 ** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
4947 **
4948 ** ^(The sqlite3_value_type(V) interface returns the
4949 ** [SQLITE_INTEGER | datatype code] for the initial datatype of the
4950 ** [sqlite3_value] object V. The returned value is one of [SQLITE_INTEGER],
4951 ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].)^
4952 ** Other interfaces might change the datatype for an sqlite3_value object.
4953 ** For example, if the datatype is initially SQLITE_INTEGER and
4954 ** sqlite3_value_text(V) is called to extract a text value for that
4955 ** integer, then subsequent calls to sqlite3_value_type(V) might return
4956 ** SQLITE_TEXT.  Whether or not a persistent internal datatype conversion
4957 ** occurs is undefined and may change from one release of SQLite to the next.
4958 **
4959 ** ^(The sqlite3_value_numeric_type() interface attempts to apply
4960 ** numeric affinity to the value.  This means that an attempt is
4961 ** made to convert the value to an integer or floating point.  If
4962 ** such a conversion is possible without loss of information (in other
4963 ** words, if the value is a string that looks like a number)
4964 ** then the conversion is performed.  Otherwise no conversion occurs.
4965 ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^
4966 **
4967 ** ^Within the [xUpdate] method of a [virtual table], the
4968 ** sqlite3_value_nochange(X) interface returns true if and only if
4969 ** the column corresponding to X is unchanged by the UPDATE operation
4970 ** that the xUpdate method call was invoked to implement and if
4971 ** and the prior [xColumn] method call that was invoked to extracted
4972 ** the value for that column returned without setting a result (probably
4973 ** because it queried [sqlite3_vtab_nochange()] and found that the column
4974 ** was unchanging).  ^Within an [xUpdate] method, any value for which
4975 ** sqlite3_value_nochange(X) is true will in all other respects appear
4976 ** to be a NULL value.  If sqlite3_value_nochange(X) is invoked anywhere other
4977 ** than within an [xUpdate] method call for an UPDATE statement, then
4978 ** the return value is arbitrary and meaningless.
4979 **
4980 ** Please pay particular attention to the fact that the pointer returned
4981 ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
4982 ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
4983 ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
4984 ** or [sqlite3_value_text16()].
4985 **
4986 ** These routines must be called from the same thread as
4987 ** the SQL function that supplied the [sqlite3_value*] parameters.
4988 **
4989 ** As long as the input parameter is correct, these routines can only
4990 ** fail if an out-of-memory error occurs during a format conversion.
4991 ** Only the following subset of interfaces are subject to out-of-memory
4992 ** errors:
4993 **
4994 ** <ul>
4995 ** <li> sqlite3_value_blob()
4996 ** <li> sqlite3_value_text()
4997 ** <li> sqlite3_value_text16()
4998 ** <li> sqlite3_value_text16le()
4999 ** <li> sqlite3_value_text16be()
5000 ** <li> sqlite3_value_bytes()
5001 ** <li> sqlite3_value_bytes16()
5002 ** </ul>
5003 **
5004 ** If an out-of-memory error occurs, then the return value from these
5005 ** routines is the same as if the column had contained an SQL NULL value.
5006 ** Valid SQL NULL returns can be distinguished from out-of-memory errors
5007 ** by invoking the [sqlite3_errcode()] immediately after the suspect
5008 ** return value is obtained and before any
5009 ** other SQLite interface is called on the same [database connection].
5010 */
5011 const(void)* sqlite3_value_blob(sqlite3_value*);
5012 double sqlite3_value_double(sqlite3_value*);
5013 int sqlite3_value_int(sqlite3_value*);
5014 sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
5015 void* sqlite3_value_pointer(sqlite3_value*, const(char)*);
5016 const(ubyte)* sqlite3_value_text(sqlite3_value*);
5017 const(void)* sqlite3_value_text16(sqlite3_value*);
5018 const(void)* sqlite3_value_text16le(sqlite3_value*);
5019 const(void)* sqlite3_value_text16be(sqlite3_value*);
5020 int sqlite3_value_bytes(sqlite3_value*);
5021 int sqlite3_value_bytes16(sqlite3_value*);
5022 int sqlite3_value_type(sqlite3_value*);
5023 int sqlite3_value_numeric_type(sqlite3_value*);
5024 int sqlite3_value_nochange(sqlite3_value*);
5025 
5026 /*
5027 ** CAPI3REF: Finding The Subtype Of SQL Values
5028 ** METHOD: sqlite3_value
5029 **
5030 ** The sqlite3_value_subtype(V) function returns the subtype for
5031 ** an [application-defined SQL function] argument V.  The subtype
5032 ** information can be used to pass a limited amount of context from
5033 ** one SQL function to another.  Use the [sqlite3_result_subtype()]
5034 ** routine to set the subtype for the return value of an SQL function.
5035 */
5036 uint sqlite3_value_subtype(sqlite3_value*);
5037 
5038 /*
5039 ** CAPI3REF: Copy And Free SQL Values
5040 ** METHOD: sqlite3_value
5041 **
5042 ** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
5043 ** object D and returns a pointer to that copy.  ^The [sqlite3_value] returned
5044 ** is a [protected sqlite3_value] object even if the input is not.
5045 ** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
5046 ** memory allocation fails.
5047 **
5048 ** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object
5049 ** previously obtained from [sqlite3_value_dup()].  ^If V is a NULL pointer
5050 ** then sqlite3_value_free(V) is a harmless no-op.
5051 */
5052 sqlite3_value* sqlite3_value_dup(const(sqlite3_value)*);
5053 void sqlite3_value_free(sqlite3_value*);
5054 
5055 /*
5056 ** CAPI3REF: Obtain Aggregate Function Context
5057 ** METHOD: sqlite3_context
5058 **
5059 ** Implementations of aggregate SQL functions use this
5060 ** routine to allocate memory for storing their state.
5061 **
5062 ** ^The first time the sqlite3_aggregate_context(C,N) routine is called
5063 ** for a particular aggregate function, SQLite
5064 ** allocates N of memory, zeroes out that memory, and returns a pointer
5065 ** to the new memory. ^On second and subsequent calls to
5066 ** sqlite3_aggregate_context() for the same aggregate function instance,
5067 ** the same buffer is returned.  Sqlite3_aggregate_context() is normally
5068 ** called once for each invocation of the xStep callback and then one
5069 ** last time when the xFinal callback is invoked.  ^(When no rows match
5070 ** an aggregate query, the xStep() callback of the aggregate function
5071 ** implementation is never called and xFinal() is called exactly once.
5072 ** In those cases, sqlite3_aggregate_context() might be called for the
5073 ** first time from within xFinal().)^
5074 **
5075 ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer
5076 ** when first called if N is less than or equal to zero or if a memory
5077 ** allocate error occurs.
5078 **
5079 ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
5080 ** determined by the N parameter on first successful call.  Changing the
5081 ** value of N in subsequent call to sqlite3_aggregate_context() within
5082 ** the same aggregate function instance will not resize the memory
5083 ** allocation.)^  Within the xFinal callback, it is customary to set
5084 ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
5085 ** pointless memory allocations occur.
5086 **
5087 ** ^SQLite automatically frees the memory allocated by
5088 ** sqlite3_aggregate_context() when the aggregate query concludes.
5089 **
5090 ** The first parameter must be a copy of the
5091 ** [sqlite3_context | SQL function context] that is the first parameter
5092 ** to the xStep or xFinal callback routine that implements the aggregate
5093 ** function.
5094 **
5095 ** This routine must be called from the same thread in which
5096 ** the aggregate SQL function is running.
5097 */
5098 void* sqlite3_aggregate_context(sqlite3_context*, int nBytes);
5099 
5100 /*
5101 ** CAPI3REF: User Data For Functions
5102 ** METHOD: sqlite3_context
5103 **
5104 ** ^The sqlite3_user_data() interface returns a copy of
5105 ** the pointer that was the pUserData parameter (the 5th parameter)
5106 ** of the [sqlite3_create_function()]
5107 ** and [sqlite3_create_function16()] routines that originally
5108 ** registered the application defined function.
5109 **
5110 ** This routine must be called from the same thread in which
5111 ** the application-defined function is running.
5112 */
5113 void* sqlite3_user_data(sqlite3_context*);
5114 
5115 /*
5116 ** CAPI3REF: Database Connection For Functions
5117 ** METHOD: sqlite3_context
5118 **
5119 ** ^The sqlite3_context_db_handle() interface returns a copy of
5120 ** the pointer to the [database connection] (the 1st parameter)
5121 ** of the [sqlite3_create_function()]
5122 ** and [sqlite3_create_function16()] routines that originally
5123 ** registered the application defined function.
5124 */
5125 sqlite3* sqlite3_context_db_handle(sqlite3_context*);
5126 
5127 /*
5128 ** CAPI3REF: Function Auxiliary Data
5129 ** METHOD: sqlite3_context
5130 **
5131 ** These functions may be used by (non-aggregate) SQL functions to
5132 ** associate metadata with argument values. If the same value is passed to
5133 ** multiple invocations of the same SQL function during query execution, under
5134 ** some circumstances the associated metadata may be preserved.  An example
5135 ** of where this might be useful is in a regular-expression matching
5136 ** function. The compiled version of the regular expression can be stored as
5137 ** metadata associated with the pattern string.
5138 ** Then as long as the pattern string remains the same,
5139 ** the compiled regular expression can be reused on multiple
5140 ** invocations of the same function.
5141 **
5142 ** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the metadata
5143 ** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument
5144 ** value to the application-defined function.  ^N is zero for the left-most
5145 ** function argument.  ^If there is no metadata
5146 ** associated with the function argument, the sqlite3_get_auxdata(C,N) interface
5147 ** returns a NULL pointer.
5148 **
5149 ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
5150 ** argument of the application-defined function.  ^Subsequent
5151 ** calls to sqlite3_get_auxdata(C,N) return P from the most recent
5152 ** sqlite3_set_auxdata(C,N,P,X) call if the metadata is still valid or
5153 ** NULL if the metadata has been discarded.
5154 ** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL,
5155 ** SQLite will invoke the destructor function X with parameter P exactly
5156 ** once, when the metadata is discarded.
5157 ** SQLite is free to discard the metadata at any time, including: <ul>
5158 ** <li> ^(when the corresponding function parameter changes)^, or
5159 ** <li> ^(when [sqlite3_reset()] or [sqlite3_finalize()] is called for the
5160 **      SQL statement)^, or
5161 ** <li> ^(when sqlite3_set_auxdata() is invoked again on the same
5162 **       parameter)^, or
5163 ** <li> ^(during the original sqlite3_set_auxdata() call when a memory
5164 **      allocation error occurs.)^ </ul>
5165 **
5166 ** Note the last bullet in particular.  The destructor X in
5167 ** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the
5168 ** sqlite3_set_auxdata() interface even returns.  Hence sqlite3_set_auxdata()
5169 ** should be called near the end of the function implementation and the
5170 ** function implementation should not make any use of P after
5171 ** sqlite3_set_auxdata() has been called.
5172 **
5173 ** ^(In practice, metadata is preserved between function calls for
5174 ** function parameters that are compile-time constants, including literal
5175 ** values and [parameters] and expressions composed from the same.)^
5176 **
5177 ** The value of the N parameter to these interfaces should be non-negative.
5178 ** Future enhancements may make use of negative N values to define new
5179 ** kinds of function caching behavior.
5180 **
5181 ** These routines must be called from the same thread in which
5182 ** the SQL function is running.
5183 */
5184 void* sqlite3_get_auxdata(sqlite3_context*, int N);
5185 void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void function(void*));
5186 
5187 /*
5188 ** CAPI3REF: Constants Defining Special Destructor Behavior
5189 **
5190 ** These are special values for the destructor that is passed in as the
5191 ** final argument to routines like [sqlite3_result_blob()].  ^If the destructor
5192 ** argument is SQLITE_STATIC, it means that the content pointer is constant
5193 ** and will never change.  It does not need to be destroyed.  ^The
5194 ** SQLITE_TRANSIENT value means that the content will likely change in
5195 ** the near future and that SQLite should make its own private copy of
5196 ** the content before returning.
5197 **
5198 ** The typedef is necessary to work around problems in certain
5199 ** C++ compilers.
5200 */
5201 alias sqlite3_destructor_type = void function(void*);
5202 enum SQLITE_STATIC = cast(sqlite3_destructor_type) 0;
5203 enum SQLITE_TRANSIENT = cast(sqlite3_destructor_type) -1;
5204 
5205 /*
5206 ** CAPI3REF: Setting The Result Of An SQL Function
5207 ** METHOD: sqlite3_context
5208 **
5209 ** These routines are used by the xFunc or xFinal callbacks that
5210 ** implement SQL functions and aggregates.  See
5211 ** [sqlite3_create_function()] and [sqlite3_create_function16()]
5212 ** for additional information.
5213 **
5214 ** These functions work very much like the [parameter binding] family of
5215 ** functions used to bind values to host parameters in prepared statements.
5216 ** Refer to the [SQL parameter] documentation for additional information.
5217 **
5218 ** ^The sqlite3_result_blob() interface sets the result from
5219 ** an application-defined function to be the BLOB whose content is pointed
5220 ** to by the second parameter and which is N bytes long where N is the
5221 ** third parameter.
5222 **
5223 ** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N)
5224 ** interfaces set the result of the application-defined function to be
5225 ** a BLOB containing all zero bytes and N bytes in size.
5226 **
5227 ** ^The sqlite3_result_double() interface sets the result from
5228 ** an application-defined function to be a floating point value specified
5229 ** by its 2nd argument.
5230 **
5231 ** ^The sqlite3_result_error() and sqlite3_result_error16() functions
5232 ** cause the implemented SQL function to throw an exception.
5233 ** ^SQLite uses the string pointed to by the
5234 ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()
5235 ** as the text of an error message.  ^SQLite interprets the error
5236 ** message string from sqlite3_result_error() as UTF-8. ^SQLite
5237 ** interprets the string from sqlite3_result_error16() as UTF-16 in native
5238 ** byte order.  ^If the third parameter to sqlite3_result_error()
5239 ** or sqlite3_result_error16() is negative then SQLite takes as the error
5240 ** message all text up through the first zero character.
5241 ** ^If the third parameter to sqlite3_result_error() or
5242 ** sqlite3_result_error16() is non-negative then SQLite takes that many
5243 ** bytes (not characters) from the 2nd parameter as the error message.
5244 ** ^The sqlite3_result_error() and sqlite3_result_error16()
5245 ** routines make a private copy of the error message text before
5246 ** they return.  Hence, the calling function can deallocate or
5247 ** modify the text after they return without harm.
5248 ** ^The sqlite3_result_error_code() function changes the error code
5249 ** returned by SQLite as a result of an error in a function.  ^By default,
5250 ** the error code is SQLITE_ERROR.  ^A subsequent call to sqlite3_result_error()
5251 ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR.
5252 **
5253 ** ^The sqlite3_result_error_toobig() interface causes SQLite to throw an
5254 ** error indicating that a string or BLOB is too long to represent.
5255 **
5256 ** ^The sqlite3_result_error_nomem() interface causes SQLite to throw an
5257 ** error indicating that a memory allocation failed.
5258 **
5259 ** ^The sqlite3_result_int() interface sets the return value
5260 ** of the application-defined function to be the 32-bit signed integer
5261 ** value given in the 2nd argument.
5262 ** ^The sqlite3_result_int64() interface sets the return value
5263 ** of the application-defined function to be the 64-bit signed integer
5264 ** value given in the 2nd argument.
5265 **
5266 ** ^The sqlite3_result_null() interface sets the return value
5267 ** of the application-defined function to be NULL.
5268 **
5269 ** ^The sqlite3_result_text(), sqlite3_result_text16(),
5270 ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
5271 ** set the return value of the application-defined function to be
5272 ** a text string which is represented as UTF-8, UTF-16 native byte order,
5273 ** UTF-16 little endian, or UTF-16 big endian, respectively.
5274 ** ^The sqlite3_result_text64() interface sets the return value of an
5275 ** application-defined function to be a text string in an encoding
5276 ** specified by the fifth (and last) parameter, which must be one
5277 ** of [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE].
5278 ** ^SQLite takes the text result from the application from
5279 ** the 2nd parameter of the sqlite3_result_text* interfaces.
5280 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
5281 ** is negative, then SQLite takes result text from the 2nd parameter
5282 ** through the first zero character.
5283 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
5284 ** is non-negative, then as many bytes (not characters) of the text
5285 ** pointed to by the 2nd parameter are taken as the application-defined
5286 ** function result.  If the 3rd parameter is non-negative, then it
5287 ** must be the byte offset into the string where the NUL terminator would
5288 ** appear if the string where NUL terminated.  If any NUL characters occur
5289 ** in the string at a byte offset that is less than the value of the 3rd
5290 ** parameter, then the resulting string will contain embedded NULs and the
5291 ** result of expressions operating on strings with embedded NULs is undefined.
5292 ** ^If the 4th parameter to the sqlite3_result_text* interfaces
5293 ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
5294 ** function as the destructor on the text or BLOB result when it has
5295 ** finished using that result.
5296 ** ^If the 4th parameter to the sqlite3_result_text* interfaces or to
5297 ** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite
5298 ** assumes that the text or BLOB result is in constant space and does not
5299 ** copy the content of the parameter nor call a destructor on the content
5300 ** when it has finished using that result.
5301 ** ^If the 4th parameter to the sqlite3_result_text* interfaces
5302 ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
5303 ** then SQLite makes a copy of the result into space obtained
5304 ** from [sqlite3_malloc()] before it returns.
5305 **
5306 ** ^The sqlite3_result_value() interface sets the result of
5307 ** the application-defined function to be a copy of the
5308 ** [unprotected sqlite3_value] object specified by the 2nd parameter.  ^The
5309 ** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
5310 ** so that the [sqlite3_value] specified in the parameter may change or
5311 ** be deallocated after sqlite3_result_value() returns without harm.
5312 ** ^A [protected sqlite3_value] object may always be used where an
5313 ** [unprotected sqlite3_value] object is required, so either
5314 ** kind of [sqlite3_value] object can be used with this interface.
5315 **
5316 ** ^The sqlite3_result_pointer(C,P,T,D) interface sets the result to an
5317 ** SQL NULL value, just like [sqlite3_result_null(C)], except that it
5318 ** also associates the host-language pointer P or type T with that
5319 ** NULL value such that the pointer can be retrieved within an
5320 ** [application-defined SQL function] using [sqlite3_value_pointer()].
5321 ** ^If the D parameter is not NULL, then it is a pointer to a destructor
5322 ** for the P parameter.  ^SQLite invokes D with P as its only argument
5323 ** when SQLite is finished with P.  The T parameter should be a static
5324 ** string and preferably a string literal. The sqlite3_result_pointer()
5325 ** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
5326 **
5327 ** If these routines are called from within the different thread
5328 ** than the one containing the application-defined function that received
5329 ** the [sqlite3_context] pointer, the results are undefined.
5330 */
5331 void sqlite3_result_blob(sqlite3_context*, const(void)*, int, void function(void*));
5332 void sqlite3_result_blob64(
5333     sqlite3_context*,
5334     const(void)*,
5335     sqlite3_uint64,
5336     void function(void*));
5337 void sqlite3_result_double(sqlite3_context*, double);
5338 void sqlite3_result_error(sqlite3_context*, const(char)*, int);
5339 void sqlite3_result_error16(sqlite3_context*, const(void)*, int);
5340 void sqlite3_result_error_toobig(sqlite3_context*);
5341 void sqlite3_result_error_nomem(sqlite3_context*);
5342 void sqlite3_result_error_code(sqlite3_context*, int);
5343 void sqlite3_result_int(sqlite3_context*, int);
5344 void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
5345 void sqlite3_result_null(sqlite3_context*);
5346 void sqlite3_result_text(sqlite3_context*, const(char)*, int, void function(void*));
5347 void sqlite3_result_text64(
5348     sqlite3_context*,
5349     const(char)*,
5350     sqlite3_uint64,
5351     void function(void*),
5352     ubyte encoding);
5353 void sqlite3_result_text16(sqlite3_context*, const(void)*, int, void function(void*));
5354 void sqlite3_result_text16le(sqlite3_context*, const(void)*, int, void function(void*));
5355 void sqlite3_result_text16be(sqlite3_context*, const(void)*, int, void function(void*));
5356 void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
5357 void sqlite3_result_pointer(sqlite3_context*, void*, const(char)*, void function(void*));
5358 void sqlite3_result_zeroblob(sqlite3_context*, int n);
5359 int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
5360 
5361 /*
5362 ** CAPI3REF: Setting The Subtype Of An SQL Function
5363 ** METHOD: sqlite3_context
5364 **
5365 ** The sqlite3_result_subtype(C,T) function causes the subtype of
5366 ** the result from the [application-defined SQL function] with
5367 ** [sqlite3_context] C to be the value T.  Only the lower 8 bits
5368 ** of the subtype T are preserved in current versions of SQLite;
5369 ** higher order bits are discarded.
5370 ** The number of subtype bytes preserved by SQLite might increase
5371 ** in future releases of SQLite.
5372 */
5373 void sqlite3_result_subtype(sqlite3_context*, uint);
5374 
5375 /*
5376 ** CAPI3REF: Define New Collating Sequences
5377 ** METHOD: sqlite3
5378 **
5379 ** ^These functions add, remove, or modify a [collation] associated
5380 ** with the [database connection] specified as the first argument.
5381 **
5382 ** ^The name of the collation is a UTF-8 string
5383 ** for sqlite3_create_collation() and sqlite3_create_collation_v2()
5384 ** and a UTF-16 string in native byte order for sqlite3_create_collation16().
5385 ** ^Collation names that compare equal according to [sqlite3_strnicmp()] are
5386 ** considered to be the same name.
5387 **
5388 ** ^(The third argument (eTextRep) must be one of the constants:
5389 ** <ul>
5390 ** <li> [SQLITE_UTF8],
5391 ** <li> [SQLITE_UTF16LE],
5392 ** <li> [SQLITE_UTF16BE],
5393 ** <li> [SQLITE_UTF16], or
5394 ** <li> [SQLITE_UTF16_ALIGNED].
5395 ** </ul>)^
5396 ** ^The eTextRep argument determines the encoding of strings passed
5397 ** to the collating function callback, xCallback.
5398 ** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep
5399 ** force strings to be UTF16 with native byte order.
5400 ** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin
5401 ** on an even byte address.
5402 **
5403 ** ^The fourth argument, pArg, is an application data pointer that is passed
5404 ** through as the first argument to the collating function callback.
5405 **
5406 ** ^The fifth argument, xCallback, is a pointer to the collating function.
5407 ** ^Multiple collating functions can be registered using the same name but
5408 ** with different eTextRep parameters and SQLite will use whichever
5409 ** function requires the least amount of data transformation.
5410 ** ^If the xCallback argument is NULL then the collating function is
5411 ** deleted.  ^When all collating functions having the same name are deleted,
5412 ** that collation is no longer usable.
5413 **
5414 ** ^The collating function callback is invoked with a copy of the pArg
5415 ** application data pointer and with two strings in the encoding specified
5416 ** by the eTextRep argument.  The collating function must return an
5417 ** integer that is negative, zero, or positive
5418 ** if the first string is less than, equal to, or greater than the second,
5419 ** respectively.  A collating function must always return the same answer
5420 ** given the same inputs.  If two or more collating functions are registered
5421 ** to the same collation name (using different eTextRep values) then all
5422 ** must give an equivalent answer when invoked with equivalent strings.
5423 ** The collating function must obey the following properties for all
5424 ** strings A, B, and C:
5425 **
5426 ** <ol>
5427 ** <li> If A==B then B==A.
5428 ** <li> If A==B and B==C then A==C.
5429 ** <li> If A&lt;B THEN B&gt;A.
5430 ** <li> If A&lt;B and B&lt;C then A&lt;C.
5431 ** </ol>
5432 **
5433 ** If a collating function fails any of the above constraints and that
5434 ** collating function is  registered and used, then the behavior of SQLite
5435 ** is undefined.
5436 **
5437 ** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
5438 ** with the addition that the xDestroy callback is invoked on pArg when
5439 ** the collating function is deleted.
5440 ** ^Collating functions are deleted when they are overridden by later
5441 ** calls to the collation creation functions or when the
5442 ** [database connection] is closed using [sqlite3_close()].
5443 **
5444 ** ^The xDestroy callback is <u>not</u> called if the
5445 ** sqlite3_create_collation_v2() function fails.  Applications that invoke
5446 ** sqlite3_create_collation_v2() with a non-NULL xDestroy argument should
5447 ** check the return code and dispose of the application data pointer
5448 ** themselves rather than expecting SQLite to deal with it for them.
5449 ** This is different from every other SQLite interface.  The inconsistency
5450 ** is unfortunate but cannot be changed without breaking backwards
5451 ** compatibility.
5452 **
5453 ** See also:  [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].
5454 */
5455 int sqlite3_create_collation(
5456     sqlite3*,
5457     const(char)* zName,
5458     int eTextRep,
5459     void* pArg,
5460     int function(void*, int, const(void)*, int, const(void)*) xCompare);
5461 int sqlite3_create_collation_v2(
5462     sqlite3*,
5463     const(char)* zName,
5464     int eTextRep,
5465     void* pArg,
5466     int function(void*, int, const(void)*, int, const(void)*) xCompare,
5467     void function(void*) xDestroy);
5468 int sqlite3_create_collation16(
5469     sqlite3*,
5470     const(void)* zName,
5471     int eTextRep,
5472     void* pArg,
5473     int function(void*, int, const(void)*, int, const(void)*) xCompare);
5474 
5475 /*
5476 ** CAPI3REF: Collation Needed Callbacks
5477 ** METHOD: sqlite3
5478 **
5479 ** ^To avoid having to register all collation sequences before a database
5480 ** can be used, a single callback function may be registered with the
5481 ** [database connection] to be invoked whenever an undefined collation
5482 ** sequence is required.
5483 **
5484 ** ^If the function is registered using the sqlite3_collation_needed() API,
5485 ** then it is passed the names of undefined collation sequences as strings
5486 ** encoded in UTF-8. ^If sqlite3_collation_needed16() is used,
5487 ** the names are passed as UTF-16 in machine native byte order.
5488 ** ^A call to either function replaces the existing collation-needed callback.
5489 **
5490 ** ^(When the callback is invoked, the first argument passed is a copy
5491 ** of the second argument to sqlite3_collation_needed() or
5492 ** sqlite3_collation_needed16().  The second argument is the database
5493 ** connection.  The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE],
5494 ** or [SQLITE_UTF16LE], indicating the most desirable form of the collation
5495 ** sequence function required.  The fourth parameter is the name of the
5496 ** required collation sequence.)^
5497 **
5498 ** The callback function should register the desired collation using
5499 ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
5500 ** [sqlite3_create_collation_v2()].
5501 */
5502 int sqlite3_collation_needed(
5503     sqlite3*,
5504     void*,
5505     void function(void*, sqlite3*, int eTextRep, const(char)*));
5506 int sqlite3_collation_needed16(
5507     sqlite3*,
5508     void*,
5509     void function(void*, sqlite3*, int eTextRep, const(void)*));
5510 
5511 /*
5512 ** Specify the key for an encrypted database.  This routine should be
5513 ** called right after sqlite3_open().
5514 **
5515 ** The code to implement this API is not available in the public release
5516 ** of SQLite.
5517 */
5518 
5519 /* Database to be rekeyed */
5520 /* The key */
5521 
5522 /* Database to be rekeyed */
5523 /* Name of the database */
5524 /* The key */
5525 
5526 /*
5527 ** Change the key on an open database.  If the current database is not
5528 ** encrypted, this routine will encrypt it.  If pNew==0 or nNew==0, the
5529 ** database is decrypted.
5530 **
5531 ** The code to implement this API is not available in the public release
5532 ** of SQLite.
5533 */
5534 
5535 /* Database to be rekeyed */
5536 /* The new key */
5537 
5538 /* Database to be rekeyed */
5539 /* Name of the database */
5540 /* The new key */
5541 
5542 /*
5543 ** Specify the activation key for a SEE database.  Unless
5544 ** activated, none of the SEE routines will work.
5545 */
5546 
5547 /* Activation phrase */
5548 
5549 /*
5550 ** Specify the activation key for a CEROD database.  Unless
5551 ** activated, none of the CEROD routines will work.
5552 */
5553 
5554 /* Activation phrase */
5555 
5556 /*
5557 ** CAPI3REF: Suspend Execution For A Short Time
5558 **
5559 ** The sqlite3_sleep() function causes the current thread to suspend execution
5560 ** for at least a number of milliseconds specified in its parameter.
5561 **
5562 ** If the operating system does not support sleep requests with
5563 ** millisecond time resolution, then the time will be rounded up to
5564 ** the nearest second. The number of milliseconds of sleep actually
5565 ** requested from the operating system is returned.
5566 **
5567 ** ^SQLite implements this interface by calling the xSleep()
5568 ** method of the default [sqlite3_vfs] object.  If the xSleep() method
5569 ** of the default VFS is not implemented correctly, or not implemented at
5570 ** all, then the behavior of sqlite3_sleep() may deviate from the description
5571 ** in the previous paragraphs.
5572 */
5573 int sqlite3_sleep(int);
5574 
5575 /*
5576 ** CAPI3REF: Name Of The Folder Holding Temporary Files
5577 **
5578 ** ^(If this global variable is made to point to a string which is
5579 ** the name of a folder (a.k.a. directory), then all temporary files
5580 ** created by SQLite when using a built-in [sqlite3_vfs | VFS]
5581 ** will be placed in that directory.)^  ^If this variable
5582 ** is a NULL pointer, then SQLite performs a search for an appropriate
5583 ** temporary file directory.
5584 **
5585 ** Applications are strongly discouraged from using this global variable.
5586 ** It is required to set a temporary folder on Windows Runtime (WinRT).
5587 ** But for all other platforms, it is highly recommended that applications
5588 ** neither read nor write this variable.  This global variable is a relic
5589 ** that exists for backwards compatibility of legacy applications and should
5590 ** be avoided in new projects.
5591 **
5592 ** It is not safe to read or modify this variable in more than one
5593 ** thread at a time.  It is not safe to read or modify this variable
5594 ** if a [database connection] is being used at the same time in a separate
5595 ** thread.
5596 ** It is intended that this variable be set once
5597 ** as part of process initialization and before any SQLite interface
5598 ** routines have been called and that this variable remain unchanged
5599 ** thereafter.
5600 **
5601 ** ^The [temp_store_directory pragma] may modify this variable and cause
5602 ** it to point to memory obtained from [sqlite3_malloc].  ^Furthermore,
5603 ** the [temp_store_directory pragma] always assumes that any string
5604 ** that this variable points to is held in memory obtained from
5605 ** [sqlite3_malloc] and the pragma may attempt to free that memory
5606 ** using [sqlite3_free].
5607 ** Hence, if this variable is modified directly, either it should be
5608 ** made NULL or made to point to memory obtained from [sqlite3_malloc]
5609 ** or else the use of the [temp_store_directory pragma] should be avoided.
5610 ** Except when requested by the [temp_store_directory pragma], SQLite
5611 ** does not free the memory that sqlite3_temp_directory points to.  If
5612 ** the application wants that memory to be freed, it must do
5613 ** so itself, taking care to only do so after all [database connection]
5614 ** objects have been destroyed.
5615 **
5616 ** <b>Note to Windows Runtime users:</b>  The temporary directory must be set
5617 ** prior to calling [sqlite3_open] or [sqlite3_open_v2].  Otherwise, various
5618 ** features that require the use of temporary files may fail.  Here is an
5619 ** example of how to do this using C++ with the Windows Runtime:
5620 **
5621 ** <blockquote><pre>
5622 ** LPCWSTR zPath = Windows::Storage::ApplicationData::Current->
5623 ** &nbsp;     TemporaryFolder->Path->Data();
5624 ** char zPathBuf&#91;MAX_PATH + 1&#93;;
5625 ** memset(zPathBuf, 0, sizeof(zPathBuf));
5626 ** WideCharToMultiByte(CP_UTF8, 0, zPath, -1, zPathBuf, sizeof(zPathBuf),
5627 ** &nbsp;     NULL, NULL);
5628 ** sqlite3_temp_directory = sqlite3_mprintf("%s", zPathBuf);
5629 ** </pre></blockquote>
5630 */
5631 extern __gshared char* sqlite3_temp_directory;
5632 
5633 /*
5634 ** CAPI3REF: Name Of The Folder Holding Database Files
5635 **
5636 ** ^(If this global variable is made to point to a string which is
5637 ** the name of a folder (a.k.a. directory), then all database files
5638 ** specified with a relative pathname and created or accessed by
5639 ** SQLite when using a built-in windows [sqlite3_vfs | VFS] will be assumed
5640 ** to be relative to that directory.)^ ^If this variable is a NULL
5641 ** pointer, then SQLite assumes that all database files specified
5642 ** with a relative pathname are relative to the current directory
5643 ** for the process.  Only the windows VFS makes use of this global
5644 ** variable; it is ignored by the unix VFS.
5645 **
5646 ** Changing the value of this variable while a database connection is
5647 ** open can result in a corrupt database.
5648 **
5649 ** It is not safe to read or modify this variable in more than one
5650 ** thread at a time.  It is not safe to read or modify this variable
5651 ** if a [database connection] is being used at the same time in a separate
5652 ** thread.
5653 ** It is intended that this variable be set once
5654 ** as part of process initialization and before any SQLite interface
5655 ** routines have been called and that this variable remain unchanged
5656 ** thereafter.
5657 **
5658 ** ^The [data_store_directory pragma] may modify this variable and cause
5659 ** it to point to memory obtained from [sqlite3_malloc].  ^Furthermore,
5660 ** the [data_store_directory pragma] always assumes that any string
5661 ** that this variable points to is held in memory obtained from
5662 ** [sqlite3_malloc] and the pragma may attempt to free that memory
5663 ** using [sqlite3_free].
5664 ** Hence, if this variable is modified directly, either it should be
5665 ** made NULL or made to point to memory obtained from [sqlite3_malloc]
5666 ** or else the use of the [data_store_directory pragma] should be avoided.
5667 */
5668 extern __gshared char* sqlite3_data_directory;
5669 
5670 /*
5671 ** CAPI3REF: Win32 Specific Interface
5672 **
5673 ** These interfaces are available only on Windows.  The
5674 ** [sqlite3_win32_set_directory] interface is used to set the value associated
5675 ** with the [sqlite3_temp_directory] or [sqlite3_data_directory] variable, to
5676 ** zValue, depending on the value of the type parameter.  The zValue parameter
5677 ** should be NULL to cause the previous value to be freed via [sqlite3_free];
5678 ** a non-NULL value will be copied into memory obtained from [sqlite3_malloc]
5679 ** prior to being used.  The [sqlite3_win32_set_directory] interface returns
5680 ** [SQLITE_OK] to indicate success, [SQLITE_ERROR] if the type is unsupported,
5681 ** or [SQLITE_NOMEM] if memory could not be allocated.  The value of the
5682 ** [sqlite3_data_directory] variable is intended to act as a replacement for
5683 ** the current directory on the sub-platforms of Win32 where that concept is
5684 ** not present, e.g. WinRT and UWP.  The [sqlite3_win32_set_directory8] and
5685 ** [sqlite3_win32_set_directory16] interfaces behave exactly the same as the
5686 ** sqlite3_win32_set_directory interface except the string parameter must be
5687 ** UTF-8 or UTF-16, respectively.
5688 */
5689 /* Identifier for directory being set or reset */
5690 /* New value for directory being set or reset */
5691 int sqlite3_win32_set_directory(c_ulong type, void* zValue);
5692 int sqlite3_win32_set_directory8(c_ulong type, const(char)* zValue);
5693 int sqlite3_win32_set_directory16(c_ulong type, const(void)* zValue);
5694 
5695 /*
5696 ** CAPI3REF: Win32 Directory Types
5697 **
5698 ** These macros are only available on Windows.  They define the allowed values
5699 ** for the type argument to the [sqlite3_win32_set_directory] interface.
5700 */
5701 enum SQLITE_WIN32_DATA_DIRECTORY_TYPE = 1;
5702 enum SQLITE_WIN32_TEMP_DIRECTORY_TYPE = 2;
5703 
5704 /*
5705 ** CAPI3REF: Test For Auto-Commit Mode
5706 ** KEYWORDS: {autocommit mode}
5707 ** METHOD: sqlite3
5708 **
5709 ** ^The sqlite3_get_autocommit() interface returns non-zero or
5710 ** zero if the given database connection is or is not in autocommit mode,
5711 ** respectively.  ^Autocommit mode is on by default.
5712 ** ^Autocommit mode is disabled by a [BEGIN] statement.
5713 ** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK].
5714 **
5715 ** If certain kinds of errors occur on a statement within a multi-statement
5716 ** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR],
5717 ** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the
5718 ** transaction might be rolled back automatically.  The only way to
5719 ** find out whether SQLite automatically rolled back the transaction after
5720 ** an error is to use this function.
5721 **
5722 ** If another thread changes the autocommit status of the database
5723 ** connection while this routine is running, then the return value
5724 ** is undefined.
5725 */
5726 int sqlite3_get_autocommit(sqlite3*);
5727 
5728 /*
5729 ** CAPI3REF: Find The Database Handle Of A Prepared Statement
5730 ** METHOD: sqlite3_stmt
5731 **
5732 ** ^The sqlite3_db_handle interface returns the [database connection] handle
5733 ** to which a [prepared statement] belongs.  ^The [database connection]
5734 ** returned by sqlite3_db_handle is the same [database connection]
5735 ** that was the first argument
5736 ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
5737 ** create the statement in the first place.
5738 */
5739 sqlite3* sqlite3_db_handle(sqlite3_stmt*);
5740 
5741 /*
5742 ** CAPI3REF: Return The Filename For A Database Connection
5743 ** METHOD: sqlite3
5744 **
5745 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
5746 ** associated with database N of connection D.  ^The main database file
5747 ** has the name "main".  If there is no attached database N on the database
5748 ** connection D, or if database N is a temporary or in-memory database, then
5749 ** a NULL pointer is returned.
5750 **
5751 ** ^The filename returned by this function is the output of the
5752 ** xFullPathname method of the [VFS].  ^In other words, the filename
5753 ** will be an absolute pathname, even if the filename used
5754 ** to open the database originally was a URI or relative pathname.
5755 */
5756 const(char)* sqlite3_db_filename(sqlite3* db, const(char)* zDbName);
5757 
5758 /*
5759 ** CAPI3REF: Determine if a database is read-only
5760 ** METHOD: sqlite3
5761 **
5762 ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
5763 ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
5764 ** the name of a database on connection D.
5765 */
5766 int sqlite3_db_readonly(sqlite3* db, const(char)* zDbName);
5767 
5768 /*
5769 ** CAPI3REF: Find the next prepared statement
5770 ** METHOD: sqlite3
5771 **
5772 ** ^This interface returns a pointer to the next [prepared statement] after
5773 ** pStmt associated with the [database connection] pDb.  ^If pStmt is NULL
5774 ** then this interface returns a pointer to the first prepared statement
5775 ** associated with the database connection pDb.  ^If no prepared statement
5776 ** satisfies the conditions of this routine, it returns NULL.
5777 **
5778 ** The [database connection] pointer D in a call to
5779 ** [sqlite3_next_stmt(D,S)] must refer to an open database
5780 ** connection and in particular must not be a NULL pointer.
5781 */
5782 sqlite3_stmt* sqlite3_next_stmt(sqlite3* pDb, sqlite3_stmt* pStmt);
5783 
5784 /*
5785 ** CAPI3REF: Commit And Rollback Notification Callbacks
5786 ** METHOD: sqlite3
5787 **
5788 ** ^The sqlite3_commit_hook() interface registers a callback
5789 ** function to be invoked whenever a transaction is [COMMIT | committed].
5790 ** ^Any callback set by a previous call to sqlite3_commit_hook()
5791 ** for the same database connection is overridden.
5792 ** ^The sqlite3_rollback_hook() interface registers a callback
5793 ** function to be invoked whenever a transaction is [ROLLBACK | rolled back].
5794 ** ^Any callback set by a previous call to sqlite3_rollback_hook()
5795 ** for the same database connection is overridden.
5796 ** ^The pArg argument is passed through to the callback.
5797 ** ^If the callback on a commit hook function returns non-zero,
5798 ** then the commit is converted into a rollback.
5799 **
5800 ** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions
5801 ** return the P argument from the previous call of the same function
5802 ** on the same [database connection] D, or NULL for
5803 ** the first call for each function on D.
5804 **
5805 ** The commit and rollback hook callbacks are not reentrant.
5806 ** The callback implementation must not do anything that will modify
5807 ** the database connection that invoked the callback.  Any actions
5808 ** to modify the database connection must be deferred until after the
5809 ** completion of the [sqlite3_step()] call that triggered the commit
5810 ** or rollback hook in the first place.
5811 ** Note that running any other SQL statements, including SELECT statements,
5812 ** or merely calling [sqlite3_prepare_v2()] and [sqlite3_step()] will modify
5813 ** the database connections for the meaning of "modify" in this paragraph.
5814 **
5815 ** ^Registering a NULL function disables the callback.
5816 **
5817 ** ^When the commit hook callback routine returns zero, the [COMMIT]
5818 ** operation is allowed to continue normally.  ^If the commit hook
5819 ** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK].
5820 ** ^The rollback hook is invoked on a rollback that results from a commit
5821 ** hook returning non-zero, just as it would be with any other rollback.
5822 **
5823 ** ^For the purposes of this API, a transaction is said to have been
5824 ** rolled back if an explicit "ROLLBACK" statement is executed, or
5825 ** an error or constraint causes an implicit rollback to occur.
5826 ** ^The rollback callback is not invoked if a transaction is
5827 ** automatically rolled back because the database connection is closed.
5828 **
5829 ** See also the [sqlite3_update_hook()] interface.
5830 */
5831 void* sqlite3_commit_hook(sqlite3*, int function(void*), void*);
5832 void* sqlite3_rollback_hook(sqlite3*, void function(void*), void*);
5833 
5834 /*
5835 ** CAPI3REF: Data Change Notification Callbacks
5836 ** METHOD: sqlite3
5837 **
5838 ** ^The sqlite3_update_hook() interface registers a callback function
5839 ** with the [database connection] identified by the first argument
5840 ** to be invoked whenever a row is updated, inserted or deleted in
5841 ** a [rowid table].
5842 ** ^Any callback set by a previous call to this function
5843 ** for the same database connection is overridden.
5844 **
5845 ** ^The second argument is a pointer to the function to invoke when a
5846 ** row is updated, inserted or deleted in a rowid table.
5847 ** ^The first argument to the callback is a copy of the third argument
5848 ** to sqlite3_update_hook().
5849 ** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
5850 ** or [SQLITE_UPDATE], depending on the operation that caused the callback
5851 ** to be invoked.
5852 ** ^The third and fourth arguments to the callback contain pointers to the
5853 ** database and table name containing the affected row.
5854 ** ^The final callback parameter is the [rowid] of the row.
5855 ** ^In the case of an update, this is the [rowid] after the update takes place.
5856 **
5857 ** ^(The update hook is not invoked when internal system tables are
5858 ** modified (i.e. sqlite_master and sqlite_sequence).)^
5859 ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
5860 **
5861 ** ^In the current implementation, the update hook
5862 ** is not invoked when conflicting rows are deleted because of an
5863 ** [ON CONFLICT | ON CONFLICT REPLACE] clause.  ^Nor is the update hook
5864 ** invoked when rows are deleted using the [truncate optimization].
5865 ** The exceptions defined in this paragraph might change in a future
5866 ** release of SQLite.
5867 **
5868 ** The update hook implementation must not do anything that will modify
5869 ** the database connection that invoked the update hook.  Any actions
5870 ** to modify the database connection must be deferred until after the
5871 ** completion of the [sqlite3_step()] call that triggered the update hook.
5872 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
5873 ** database connections for the meaning of "modify" in this paragraph.
5874 **
5875 ** ^The sqlite3_update_hook(D,C,P) function
5876 ** returns the P argument from the previous call
5877 ** on the same [database connection] D, or NULL for
5878 ** the first call on D.
5879 **
5880 ** See also the [sqlite3_commit_hook()], [sqlite3_rollback_hook()],
5881 ** and [sqlite3_preupdate_hook()] interfaces.
5882 */
5883 void* sqlite3_update_hook(
5884     sqlite3*,
5885     void function(void*, int, const(char)*, const(char)*, sqlite3_int64),
5886     void*);
5887 
5888 /*
5889 ** CAPI3REF: Enable Or Disable Shared Pager Cache
5890 **
5891 ** ^(This routine enables or disables the sharing of the database cache
5892 ** and schema data structures between [database connection | connections]
5893 ** to the same database. Sharing is enabled if the argument is true
5894 ** and disabled if the argument is false.)^
5895 **
5896 ** ^Cache sharing is enabled and disabled for an entire process.
5897 ** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]).
5898 ** In prior versions of SQLite,
5899 ** sharing was enabled or disabled for each thread separately.
5900 **
5901 ** ^(The cache sharing mode set by this interface effects all subsequent
5902 ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
5903 ** Existing database connections continue use the sharing mode
5904 ** that was in effect at the time they were opened.)^
5905 **
5906 ** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled
5907 ** successfully.  An [error code] is returned otherwise.)^
5908 **
5909 ** ^Shared cache is disabled by default. But this might change in
5910 ** future releases of SQLite.  Applications that care about shared
5911 ** cache setting should set it explicitly.
5912 **
5913 ** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0
5914 ** and will always return SQLITE_MISUSE. On those systems,
5915 ** shared cache mode should be enabled per-database connection via
5916 ** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE].
5917 **
5918 ** This interface is threadsafe on processors where writing a
5919 ** 32-bit integer is atomic.
5920 **
5921 ** See Also:  [SQLite Shared-Cache Mode]
5922 */
5923 int sqlite3_enable_shared_cache(int);
5924 
5925 /*
5926 ** CAPI3REF: Attempt To Free Heap Memory
5927 **
5928 ** ^The sqlite3_release_memory() interface attempts to free N bytes
5929 ** of heap memory by deallocating non-essential memory allocations
5930 ** held by the database library.   Memory used to cache database
5931 ** pages to improve performance is an example of non-essential memory.
5932 ** ^sqlite3_release_memory() returns the number of bytes actually freed,
5933 ** which might be more or less than the amount requested.
5934 ** ^The sqlite3_release_memory() routine is a no-op returning zero
5935 ** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT].
5936 **
5937 ** See also: [sqlite3_db_release_memory()]
5938 */
5939 int sqlite3_release_memory(int);
5940 
5941 /*
5942 ** CAPI3REF: Free Memory Used By A Database Connection
5943 ** METHOD: sqlite3
5944 **
5945 ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
5946 ** memory as possible from database connection D. Unlike the
5947 ** [sqlite3_release_memory()] interface, this interface is in effect even
5948 ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
5949 ** omitted.
5950 **
5951 ** See also: [sqlite3_release_memory()]
5952 */
5953 int sqlite3_db_release_memory(sqlite3*);
5954 
5955 /*
5956 ** CAPI3REF: Impose A Limit On Heap Size
5957 **
5958 ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
5959 ** soft limit on the amount of heap memory that may be allocated by SQLite.
5960 ** ^SQLite strives to keep heap memory utilization below the soft heap
5961 ** limit by reducing the number of pages held in the page cache
5962 ** as heap memory usages approaches the limit.
5963 ** ^The soft heap limit is "soft" because even though SQLite strives to stay
5964 ** below the limit, it will exceed the limit rather than generate
5965 ** an [SQLITE_NOMEM] error.  In other words, the soft heap limit
5966 ** is advisory only.
5967 **
5968 ** ^The return value from sqlite3_soft_heap_limit64() is the size of
5969 ** the soft heap limit prior to the call, or negative in the case of an
5970 ** error.  ^If the argument N is negative
5971 ** then no change is made to the soft heap limit.  Hence, the current
5972 ** size of the soft heap limit can be determined by invoking
5973 ** sqlite3_soft_heap_limit64() with a negative argument.
5974 **
5975 ** ^If the argument N is zero then the soft heap limit is disabled.
5976 **
5977 ** ^(The soft heap limit is not enforced in the current implementation
5978 ** if one or more of following conditions are true:
5979 **
5980 ** <ul>
5981 ** <li> The soft heap limit is set to zero.
5982 ** <li> Memory accounting is disabled using a combination of the
5983 **      [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and
5984 **      the [SQLITE_DEFAULT_MEMSTATUS] compile-time option.
5985 ** <li> An alternative page cache implementation is specified using
5986 **      [sqlite3_config]([SQLITE_CONFIG_PCACHE2],...).
5987 ** <li> The page cache allocates from its own memory pool supplied
5988 **      by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
5989 **      from the heap.
5990 ** </ul>)^
5991 **
5992 ** Beginning with SQLite [version 3.7.3] ([dateof:3.7.3]),
5993 ** the soft heap limit is enforced
5994 ** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT]
5995 ** compile-time option is invoked.  With [SQLITE_ENABLE_MEMORY_MANAGEMENT],
5996 ** the soft heap limit is enforced on every memory allocation.  Without
5997 ** [SQLITE_ENABLE_MEMORY_MANAGEMENT], the soft heap limit is only enforced
5998 ** when memory is allocated by the page cache.  Testing suggests that because
5999 ** the page cache is the predominate memory user in SQLite, most
6000 ** applications will achieve adequate soft heap limit enforcement without
6001 ** the use of [SQLITE_ENABLE_MEMORY_MANAGEMENT].
6002 **
6003 ** The circumstances under which SQLite will enforce the soft heap limit may
6004 ** changes in future releases of SQLite.
6005 */
6006 sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);
6007 
6008 /*
6009 ** CAPI3REF: Deprecated Soft Heap Limit Interface
6010 ** DEPRECATED
6011 **
6012 ** This is a deprecated version of the [sqlite3_soft_heap_limit64()]
6013 ** interface.  This routine is provided for historical compatibility
6014 ** only.  All new applications should use the
6015 ** [sqlite3_soft_heap_limit64()] interface rather than this one.
6016 */
6017 void sqlite3_soft_heap_limit(int N);
6018 
6019 /*
6020 ** CAPI3REF: Extract Metadata About A Column Of A Table
6021 ** METHOD: sqlite3
6022 **
6023 ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
6024 ** information about column C of table T in database D
6025 ** on [database connection] X.)^  ^The sqlite3_table_column_metadata()
6026 ** interface returns SQLITE_OK and fills in the non-NULL pointers in
6027 ** the final five arguments with appropriate values if the specified
6028 ** column exists.  ^The sqlite3_table_column_metadata() interface returns
6029 ** SQLITE_ERROR and if the specified column does not exist.
6030 ** ^If the column-name parameter to sqlite3_table_column_metadata() is a
6031 ** NULL pointer, then this routine simply checks for the existence of the
6032 ** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
6033 ** does not.  If the table name parameter T in a call to
6034 ** sqlite3_table_column_metadata(X,D,T,C,...) is NULL then the result is
6035 ** undefined behavior.
6036 **
6037 ** ^The column is identified by the second, third and fourth parameters to
6038 ** this function. ^(The second parameter is either the name of the database
6039 ** (i.e. "main", "temp", or an attached database) containing the specified
6040 ** table or NULL.)^ ^If it is NULL, then all attached databases are searched
6041 ** for the table using the same algorithm used by the database engine to
6042 ** resolve unqualified table references.
6043 **
6044 ** ^The third and fourth parameters to this function are the table and column
6045 ** name of the desired column, respectively.
6046 **
6047 ** ^Metadata is returned by writing to the memory locations passed as the 5th
6048 ** and subsequent parameters to this function. ^Any of these arguments may be
6049 ** NULL, in which case the corresponding element of metadata is omitted.
6050 **
6051 ** ^(<blockquote>
6052 ** <table border="1">
6053 ** <tr><th> Parameter <th> Output<br>Type <th>  Description
6054 **
6055 ** <tr><td> 5th <td> const char* <td> Data type
6056 ** <tr><td> 6th <td> const char* <td> Name of default collation sequence
6057 ** <tr><td> 7th <td> int         <td> True if column has a NOT NULL constraint
6058 ** <tr><td> 8th <td> int         <td> True if column is part of the PRIMARY KEY
6059 ** <tr><td> 9th <td> int         <td> True if column is [AUTOINCREMENT]
6060 ** </table>
6061 ** </blockquote>)^
6062 **
6063 ** ^The memory pointed to by the character pointers returned for the
6064 ** declaration type and collation sequence is valid until the next
6065 ** call to any SQLite API function.
6066 **
6067 ** ^If the specified table is actually a view, an [error code] is returned.
6068 **
6069 ** ^If the specified column is "rowid", "oid" or "_rowid_" and the table
6070 ** is not a [WITHOUT ROWID] table and an
6071 ** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
6072 ** parameters are set for the explicitly declared column. ^(If there is no
6073 ** [INTEGER PRIMARY KEY] column, then the outputs
6074 ** for the [rowid] are set as follows:
6075 **
6076 ** <pre>
6077 **     data type: "INTEGER"
6078 **     collation sequence: "BINARY"
6079 **     not null: 0
6080 **     primary key: 1
6081 **     auto increment: 0
6082 ** </pre>)^
6083 **
6084 ** ^This function causes all database schemas to be read from disk and
6085 ** parsed, if that has not already been done, and returns an error if
6086 ** any errors are encountered while loading the schema.
6087 */
6088 /* Connection handle */
6089 /* Database name or NULL */
6090 /* Table name */
6091 /* Column name */
6092 /* OUTPUT: Declared data type */
6093 /* OUTPUT: Collation sequence name */
6094 /* OUTPUT: True if NOT NULL constraint exists */
6095 /* OUTPUT: True if column part of PK */
6096 /* OUTPUT: True if column is auto-increment */
6097 int sqlite3_table_column_metadata(
6098     sqlite3* db,
6099     const(char)* zDbName,
6100     const(char)* zTableName,
6101     const(char)* zColumnName,
6102     const(char*)* pzDataType,
6103     const(char*)* pzCollSeq,
6104     int* pNotNull,
6105     int* pPrimaryKey,
6106     int* pAutoinc);
6107 
6108 /*
6109 ** CAPI3REF: Load An Extension
6110 ** METHOD: sqlite3
6111 **
6112 ** ^This interface loads an SQLite extension library from the named file.
6113 **
6114 ** ^The sqlite3_load_extension() interface attempts to load an
6115 ** [SQLite extension] library contained in the file zFile.  If
6116 ** the file cannot be loaded directly, attempts are made to load
6117 ** with various operating-system specific extensions added.
6118 ** So for example, if "samplelib" cannot be loaded, then names like
6119 ** "samplelib.so" or "samplelib.dylib" or "samplelib.dll" might
6120 ** be tried also.
6121 **
6122 ** ^The entry point is zProc.
6123 ** ^(zProc may be 0, in which case SQLite will try to come up with an
6124 ** entry point name on its own.  It first tries "sqlite3_extension_init".
6125 ** If that does not work, it constructs a name "sqlite3_X_init" where the
6126 ** X is consists of the lower-case equivalent of all ASCII alphabetic
6127 ** characters in the filename from the last "/" to the first following
6128 ** "." and omitting any initial "lib".)^
6129 ** ^The sqlite3_load_extension() interface returns
6130 ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
6131 ** ^If an error occurs and pzErrMsg is not 0, then the
6132 ** [sqlite3_load_extension()] interface shall attempt to
6133 ** fill *pzErrMsg with error message text stored in memory
6134 ** obtained from [sqlite3_malloc()]. The calling function
6135 ** should free this memory by calling [sqlite3_free()].
6136 **
6137 ** ^Extension loading must be enabled using
6138 ** [sqlite3_enable_load_extension()] or
6139 ** [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],1,NULL)
6140 ** prior to calling this API,
6141 ** otherwise an error will be returned.
6142 **
6143 ** <b>Security warning:</b> It is recommended that the
6144 ** [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method be used to enable only this
6145 ** interface.  The use of the [sqlite3_enable_load_extension()] interface
6146 ** should be avoided.  This will keep the SQL function [load_extension()]
6147 ** disabled and prevent SQL injections from giving attackers
6148 ** access to extension loading capabilities.
6149 **
6150 ** See also the [load_extension() SQL function].
6151 */
6152 /* Load the extension into this database connection */
6153 /* Name of the shared library containing extension */
6154 /* Entry point.  Derived from zFile if 0 */
6155 /* Put error message here if not 0 */
6156 int sqlite3_load_extension(
6157     sqlite3* db,
6158     const(char)* zFile,
6159     const(char)* zProc,
6160     char** pzErrMsg);
6161 
6162 /*
6163 ** CAPI3REF: Enable Or Disable Extension Loading
6164 ** METHOD: sqlite3
6165 **
6166 ** ^So as not to open security holes in older applications that are
6167 ** unprepared to deal with [extension loading], and as a means of disabling
6168 ** [extension loading] while evaluating user-entered SQL, the following API
6169 ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
6170 **
6171 ** ^Extension loading is off by default.
6172 ** ^Call the sqlite3_enable_load_extension() routine with onoff==1
6173 ** to turn extension loading on and call it with onoff==0 to turn
6174 ** it back off again.
6175 **
6176 ** ^This interface enables or disables both the C-API
6177 ** [sqlite3_load_extension()] and the SQL function [load_extension()].
6178 ** ^(Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
6179 ** to enable or disable only the C-API.)^
6180 **
6181 ** <b>Security warning:</b> It is recommended that extension loading
6182 ** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
6183 ** rather than this interface, so the [load_extension()] SQL function
6184 ** remains disabled. This will prevent SQL injections from giving attackers
6185 ** access to extension loading capabilities.
6186 */
6187 int sqlite3_enable_load_extension(sqlite3* db, int onoff);
6188 
6189 /*
6190 ** CAPI3REF: Automatically Load Statically Linked Extensions
6191 **
6192 ** ^This interface causes the xEntryPoint() function to be invoked for
6193 ** each new [database connection] that is created.  The idea here is that
6194 ** xEntryPoint() is the entry point for a statically linked [SQLite extension]
6195 ** that is to be automatically loaded into all new database connections.
6196 **
6197 ** ^(Even though the function prototype shows that xEntryPoint() takes
6198 ** no arguments and returns void, SQLite invokes xEntryPoint() with three
6199 ** arguments and expects an integer result as if the signature of the
6200 ** entry point where as follows:
6201 **
6202 ** <blockquote><pre>
6203 ** &nbsp;  int xEntryPoint(
6204 ** &nbsp;    sqlite3 *db,
6205 ** &nbsp;    const char **pzErrMsg,
6206 ** &nbsp;    const struct sqlite3_api_routines *pThunk
6207 ** &nbsp;  );
6208 ** </pre></blockquote>)^
6209 **
6210 ** If the xEntryPoint routine encounters an error, it should make *pzErrMsg
6211 ** point to an appropriate error message (obtained from [sqlite3_mprintf()])
6212 ** and return an appropriate [error code].  ^SQLite ensures that *pzErrMsg
6213 ** is NULL before calling the xEntryPoint().  ^SQLite will invoke
6214 ** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns.  ^If any
6215 ** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()],
6216 ** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail.
6217 **
6218 ** ^Calling sqlite3_auto_extension(X) with an entry point X that is already
6219 ** on the list of automatic extensions is a harmless no-op. ^No entry point
6220 ** will be called more than once for each database connection that is opened.
6221 **
6222 ** See also: [sqlite3_reset_auto_extension()]
6223 ** and [sqlite3_cancel_auto_extension()]
6224 */
6225 int sqlite3_auto_extension(void function() xEntryPoint);
6226 
6227 /*
6228 ** CAPI3REF: Cancel Automatic Extension Loading
6229 **
6230 ** ^The [sqlite3_cancel_auto_extension(X)] interface unregisters the
6231 ** initialization routine X that was registered using a prior call to
6232 ** [sqlite3_auto_extension(X)].  ^The [sqlite3_cancel_auto_extension(X)]
6233 ** routine returns 1 if initialization routine X was successfully
6234 ** unregistered and it returns 0 if X was not on the list of initialization
6235 ** routines.
6236 */
6237 int sqlite3_cancel_auto_extension(void function() xEntryPoint);
6238 
6239 /*
6240 ** CAPI3REF: Reset Automatic Extension Loading
6241 **
6242 ** ^This interface disables all automatic extensions previously
6243 ** registered using [sqlite3_auto_extension()].
6244 */
6245 void sqlite3_reset_auto_extension();
6246 
6247 /*
6248 ** The interface to the virtual-table mechanism is currently considered
6249 ** to be experimental.  The interface might change in incompatible ways.
6250 ** If this is a problem for you, do not use the interface at this time.
6251 **
6252 ** When the virtual-table mechanism stabilizes, we will declare the
6253 ** interface fixed, support it indefinitely, and remove this comment.
6254 */
6255 
6256 /*
6257 ** Structures used by the virtual table interface
6258 */
6259 
6260 /*
6261 ** CAPI3REF: Virtual Table Object
6262 ** KEYWORDS: sqlite3_module {virtual table module}
6263 **
6264 ** This structure, sometimes called a "virtual table module",
6265 ** defines the implementation of a [virtual tables].
6266 ** This structure consists mostly of methods for the module.
6267 **
6268 ** ^A virtual table module is created by filling in a persistent
6269 ** instance of this structure and passing a pointer to that instance
6270 ** to [sqlite3_create_module()] or [sqlite3_create_module_v2()].
6271 ** ^The registration remains valid until it is replaced by a different
6272 ** module or until the [database connection] closes.  The content
6273 ** of this structure must not change while it is registered with
6274 ** any database connection.
6275 */
6276 struct sqlite3_module
6277 {
6278     int iVersion;
6279     int function(sqlite3*, void* pAux, int argc, const(char*)* argv, sqlite3_vtab** ppVTab, char**) xCreate;
6280     int function(sqlite3*, void* pAux, int argc, const(char*)* argv, sqlite3_vtab** ppVTab, char**) xConnect;
6281     int function(sqlite3_vtab* pVTab, sqlite3_index_info*) xBestIndex;
6282     int function(sqlite3_vtab* pVTab) xDisconnect;
6283     int function(sqlite3_vtab* pVTab) xDestroy;
6284     int function(sqlite3_vtab* pVTab, sqlite3_vtab_cursor** ppCursor) xOpen;
6285     int function(sqlite3_vtab_cursor*) xClose;
6286     int function(sqlite3_vtab_cursor*, int idxNum, const(char)* idxStr, int argc, sqlite3_value** argv) xFilter;
6287     int function(sqlite3_vtab_cursor*) xNext;
6288     int function(sqlite3_vtab_cursor*) xEof;
6289     int function(sqlite3_vtab_cursor*, sqlite3_context*, int) xColumn;
6290     int function(sqlite3_vtab_cursor*, sqlite3_int64* pRowid) xRowid;
6291     int function(sqlite3_vtab*, int, sqlite3_value**, sqlite3_int64*) xUpdate;
6292     int function(sqlite3_vtab* pVTab) xBegin;
6293     int function(sqlite3_vtab* pVTab) xSync;
6294     int function(sqlite3_vtab* pVTab) xCommit;
6295     int function(sqlite3_vtab* pVTab) xRollback;
6296     int function(sqlite3_vtab* pVtab, int nArg, const(char)* zName, void function(sqlite3_context*, int, sqlite3_value**)* pxFunc, void** ppArg) xFindFunction;
6297     int function(sqlite3_vtab* pVtab, const(char)* zNew) xRename;
6298     /* The methods above are in version 1 of the sqlite_module object. Those
6299     ** below are for version 2 and greater. */
6300     int function(sqlite3_vtab* pVTab, int) xSavepoint;
6301     int function(sqlite3_vtab* pVTab, int) xRelease;
6302     int function(sqlite3_vtab* pVTab, int) xRollbackTo;
6303 }
6304 
6305 /*
6306 ** CAPI3REF: Virtual Table Indexing Information
6307 ** KEYWORDS: sqlite3_index_info
6308 **
6309 ** The sqlite3_index_info structure and its substructures is used as part
6310 ** of the [virtual table] interface to
6311 ** pass information into and receive the reply from the [xBestIndex]
6312 ** method of a [virtual table module].  The fields under **Inputs** are the
6313 ** inputs to xBestIndex and are read-only.  xBestIndex inserts its
6314 ** results into the **Outputs** fields.
6315 **
6316 ** ^(The aConstraint[] array records WHERE clause constraints of the form:
6317 **
6318 ** <blockquote>column OP expr</blockquote>
6319 **
6320 ** where OP is =, &lt;, &lt;=, &gt;, or &gt;=.)^  ^(The particular operator is
6321 ** stored in aConstraint[].op using one of the
6322 ** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^
6323 ** ^(The index of the column is stored in
6324 ** aConstraint[].iColumn.)^  ^(aConstraint[].usable is TRUE if the
6325 ** expr on the right-hand side can be evaluated (and thus the constraint
6326 ** is usable) and false if it cannot.)^
6327 **
6328 ** ^The optimizer automatically inverts terms of the form "expr OP column"
6329 ** and makes other simplifications to the WHERE clause in an attempt to
6330 ** get as many WHERE clause terms into the form shown above as possible.
6331 ** ^The aConstraint[] array only reports WHERE clause terms that are
6332 ** relevant to the particular virtual table being queried.
6333 **
6334 ** ^Information about the ORDER BY clause is stored in aOrderBy[].
6335 ** ^Each term of aOrderBy records a column of the ORDER BY clause.
6336 **
6337 ** The colUsed field indicates which columns of the virtual table may be
6338 ** required by the current scan. Virtual table columns are numbered from
6339 ** zero in the order in which they appear within the CREATE TABLE statement
6340 ** passed to sqlite3_declare_vtab(). For the first 63 columns (columns 0-62),
6341 ** the corresponding bit is set within the colUsed mask if the column may be
6342 ** required by SQLite. If the table has at least 64 columns and any column
6343 ** to the right of the first 63 is required, then bit 63 of colUsed is also
6344 ** set. In other words, column iCol may be required if the expression
6345 ** (colUsed & ((sqlite3_uint64)1 << (iCol>=63 ? 63 : iCol))) evaluates to
6346 ** non-zero.
6347 **
6348 ** The [xBestIndex] method must fill aConstraintUsage[] with information
6349 ** about what parameters to pass to xFilter.  ^If argvIndex>0 then
6350 ** the right-hand side of the corresponding aConstraint[] is evaluated
6351 ** and becomes the argvIndex-th entry in argv.  ^(If aConstraintUsage[].omit
6352 ** is true, then the constraint is assumed to be fully handled by the
6353 ** virtual table and is not checked again by SQLite.)^
6354 **
6355 ** ^The idxNum and idxPtr values are recorded and passed into the
6356 ** [xFilter] method.
6357 ** ^[sqlite3_free()] is used to free idxPtr if and only if
6358 ** needToFreeIdxPtr is true.
6359 **
6360 ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
6361 ** the correct order to satisfy the ORDER BY clause so that no separate
6362 ** sorting step is required.
6363 **
6364 ** ^The estimatedCost value is an estimate of the cost of a particular
6365 ** strategy. A cost of N indicates that the cost of the strategy is similar
6366 ** to a linear scan of an SQLite table with N rows. A cost of log(N)
6367 ** indicates that the expense of the operation is similar to that of a
6368 ** binary search on a unique indexed field of an SQLite table with N rows.
6369 **
6370 ** ^The estimatedRows value is an estimate of the number of rows that
6371 ** will be returned by the strategy.
6372 **
6373 ** The xBestIndex method may optionally populate the idxFlags field with a
6374 ** mask of SQLITE_INDEX_SCAN_* flags. Currently there is only one such flag -
6375 ** SQLITE_INDEX_SCAN_UNIQUE. If the xBestIndex method sets this flag, SQLite
6376 ** assumes that the strategy may visit at most one row.
6377 **
6378 ** Additionally, if xBestIndex sets the SQLITE_INDEX_SCAN_UNIQUE flag, then
6379 ** SQLite also assumes that if a call to the xUpdate() method is made as
6380 ** part of the same statement to delete or update a virtual table row and the
6381 ** implementation returns SQLITE_CONSTRAINT, then there is no need to rollback
6382 ** any database changes. In other words, if the xUpdate() returns
6383 ** SQLITE_CONSTRAINT, the database contents must be exactly as they were
6384 ** before xUpdate was called. By contrast, if SQLITE_INDEX_SCAN_UNIQUE is not
6385 ** set and xUpdate returns SQLITE_CONSTRAINT, any database changes made by
6386 ** the xUpdate method are automatically rolled back by SQLite.
6387 **
6388 ** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
6389 ** structure for SQLite [version 3.8.2] ([dateof:3.8.2]).
6390 ** If a virtual table extension is
6391 ** used with an SQLite version earlier than 3.8.2, the results of attempting
6392 ** to read or write the estimatedRows field are undefined (but are likely
6393 ** to included crashing the application). The estimatedRows field should
6394 ** therefore only be used if [sqlite3_libversion_number()] returns a
6395 ** value greater than or equal to 3008002. Similarly, the idxFlags field
6396 ** was added for [version 3.9.0] ([dateof:3.9.0]).
6397 ** It may therefore only be used if
6398 ** sqlite3_libversion_number() returns a value greater than or equal to
6399 ** 3009000.
6400 */
6401 struct sqlite3_index_info
6402 {
6403     /* Inputs */
6404     int nConstraint; /* Number of entries in aConstraint */
6405 
6406     /* Column constrained.  -1 for ROWID */
6407     /* Constraint operator */
6408     /* True if this constraint is usable */
6409     /* Used internally - xBestIndex should ignore */
6410     struct sqlite3_index_constraint
6411     {
6412         int iColumn;
6413         ubyte op;
6414         ubyte usable;
6415         int iTermOffset;
6416     }
6417 
6418     sqlite3_index_constraint* aConstraint; /* Table of WHERE clause constraints */
6419     int nOrderBy; /* Number of terms in the ORDER BY clause */
6420 
6421     /* Column number */
6422     /* True for DESC.  False for ASC. */
6423     struct sqlite3_index_orderby
6424     {
6425         int iColumn;
6426         ubyte desc;
6427     }
6428 
6429     sqlite3_index_orderby* aOrderBy; /* The ORDER BY clause */
6430     /* Outputs */
6431 
6432     /* if >0, constraint is part of argv to xFilter */
6433     /* Do not code a test for this constraint */
6434     struct sqlite3_index_constraint_usage
6435     {
6436         int argvIndex;
6437         ubyte omit;
6438     }
6439 
6440     sqlite3_index_constraint_usage* aConstraintUsage;
6441     int idxNum; /* Number used to identify the index */
6442     char* idxStr; /* String, possibly obtained from sqlite3_malloc */
6443     int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
6444     int orderByConsumed; /* True if output is already ordered */
6445     double estimatedCost; /* Estimated cost of using this index */
6446     /* Fields below are only available in SQLite 3.8.2 and later */
6447     sqlite3_int64 estimatedRows; /* Estimated number of rows returned */
6448     /* Fields below are only available in SQLite 3.9.0 and later */
6449     int idxFlags; /* Mask of SQLITE_INDEX_SCAN_* flags */
6450     /* Fields below are only available in SQLite 3.10.0 and later */
6451     sqlite3_uint64 colUsed; /* Input: Mask of columns used by statement */
6452 }
6453 
6454 /*
6455 ** CAPI3REF: Virtual Table Scan Flags
6456 **
6457 ** Virtual table implementations are allowed to set the
6458 ** [sqlite3_index_info].idxFlags field to some combination of
6459 ** these bits.
6460 */
6461 enum SQLITE_INDEX_SCAN_UNIQUE = 1; /* Scan visits at most 1 row */
6462 
6463 /*
6464 ** CAPI3REF: Virtual Table Constraint Operator Codes
6465 **
6466 ** These macros defined the allowed values for the
6467 ** [sqlite3_index_info].aConstraint[].op field.  Each value represents
6468 ** an operator that is part of a constraint term in the wHERE clause of
6469 ** a query that uses a [virtual table].
6470 */
6471 enum SQLITE_INDEX_CONSTRAINT_EQ = 2;
6472 enum SQLITE_INDEX_CONSTRAINT_GT = 4;
6473 enum SQLITE_INDEX_CONSTRAINT_LE = 8;
6474 enum SQLITE_INDEX_CONSTRAINT_LT = 16;
6475 enum SQLITE_INDEX_CONSTRAINT_GE = 32;
6476 enum SQLITE_INDEX_CONSTRAINT_MATCH = 64;
6477 enum SQLITE_INDEX_CONSTRAINT_LIKE = 65;
6478 enum SQLITE_INDEX_CONSTRAINT_GLOB = 66;
6479 enum SQLITE_INDEX_CONSTRAINT_REGEXP = 67;
6480 enum SQLITE_INDEX_CONSTRAINT_NE = 68;
6481 enum SQLITE_INDEX_CONSTRAINT_ISNOT = 69;
6482 enum SQLITE_INDEX_CONSTRAINT_ISNOTNULL = 70;
6483 enum SQLITE_INDEX_CONSTRAINT_ISNULL = 71;
6484 enum SQLITE_INDEX_CONSTRAINT_IS = 72;
6485 enum SQLITE_INDEX_CONSTRAINT_FUNCTION = 150;
6486 
6487 /*
6488 ** CAPI3REF: Register A Virtual Table Implementation
6489 ** METHOD: sqlite3
6490 **
6491 ** ^These routines are used to register a new [virtual table module] name.
6492 ** ^Module names must be registered before
6493 ** creating a new [virtual table] using the module and before using a
6494 ** preexisting [virtual table] for the module.
6495 **
6496 ** ^The module name is registered on the [database connection] specified
6497 ** by the first parameter.  ^The name of the module is given by the
6498 ** second parameter.  ^The third parameter is a pointer to
6499 ** the implementation of the [virtual table module].   ^The fourth
6500 ** parameter is an arbitrary client data pointer that is passed through
6501 ** into the [xCreate] and [xConnect] methods of the virtual table module
6502 ** when a new virtual table is be being created or reinitialized.
6503 **
6504 ** ^The sqlite3_create_module_v2() interface has a fifth parameter which
6505 ** is a pointer to a destructor for the pClientData.  ^SQLite will
6506 ** invoke the destructor function (if it is not NULL) when SQLite
6507 ** no longer needs the pClientData pointer.  ^The destructor will also
6508 ** be invoked if the call to sqlite3_create_module_v2() fails.
6509 ** ^The sqlite3_create_module()
6510 ** interface is equivalent to sqlite3_create_module_v2() with a NULL
6511 ** destructor.
6512 */
6513 /* SQLite connection to register module with */
6514 /* Name of the module */
6515 /* Methods for the module */
6516 /* Client data for xCreate/xConnect */
6517 int sqlite3_create_module(
6518     sqlite3* db,
6519     const(char)* zName,
6520     const(sqlite3_module)* p,
6521     void* pClientData);
6522 
6523 /* SQLite connection to register module with */
6524 /* Name of the module */
6525 /* Methods for the module */
6526 /* Client data for xCreate/xConnect */
6527 /* Module destructor function */
6528 int sqlite3_create_module_v2(
6529     sqlite3* db,
6530     const(char)* zName,
6531     const(sqlite3_module)* p,
6532     void* pClientData,
6533     void function(void*) xDestroy);
6534 
6535 /*
6536 ** CAPI3REF: Virtual Table Instance Object
6537 ** KEYWORDS: sqlite3_vtab
6538 **
6539 ** Every [virtual table module] implementation uses a subclass
6540 ** of this object to describe a particular instance
6541 ** of the [virtual table].  Each subclass will
6542 ** be tailored to the specific needs of the module implementation.
6543 ** The purpose of this superclass is to define certain fields that are
6544 ** common to all module implementations.
6545 **
6546 ** ^Virtual tables methods can set an error message by assigning a
6547 ** string obtained from [sqlite3_mprintf()] to zErrMsg.  The method should
6548 ** take care that any prior string is freed by a call to [sqlite3_free()]
6549 ** prior to assigning a new string to zErrMsg.  ^After the error message
6550 ** is delivered up to the client application, the string will be automatically
6551 ** freed by sqlite3_free() and the zErrMsg field will be zeroed.
6552 */
6553 struct sqlite3_vtab
6554 {
6555     const(sqlite3_module)* pModule; /* The module for this virtual table */
6556     int nRef; /* Number of open cursors */
6557     char* zErrMsg; /* Error message from sqlite3_mprintf() */
6558     /* Virtual table implementations will typically add additional fields */
6559 }
6560 
6561 /*
6562 ** CAPI3REF: Virtual Table Cursor Object
6563 ** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
6564 **
6565 ** Every [virtual table module] implementation uses a subclass of the
6566 ** following structure to describe cursors that point into the
6567 ** [virtual table] and are used
6568 ** to loop through the virtual table.  Cursors are created using the
6569 ** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed
6570 ** by the [sqlite3_module.xClose | xClose] method.  Cursors are used
6571 ** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods
6572 ** of the module.  Each module implementation will define
6573 ** the content of a cursor structure to suit its own needs.
6574 **
6575 ** This superclass exists in order to define fields of the cursor that
6576 ** are common to all implementations.
6577 */
6578 struct sqlite3_vtab_cursor
6579 {
6580     sqlite3_vtab* pVtab; /* Virtual table of this cursor */
6581     /* Virtual table implementations will typically add additional fields */
6582 }
6583 
6584 /*
6585 ** CAPI3REF: Declare The Schema Of A Virtual Table
6586 **
6587 ** ^The [xCreate] and [xConnect] methods of a
6588 ** [virtual table module] call this interface
6589 ** to declare the format (the names and datatypes of the columns) of
6590 ** the virtual tables they implement.
6591 */
6592 int sqlite3_declare_vtab(sqlite3*, const(char)* zSQL);
6593 
6594 /*
6595 ** CAPI3REF: Overload A Function For A Virtual Table
6596 ** METHOD: sqlite3
6597 **
6598 ** ^(Virtual tables can provide alternative implementations of functions
6599 ** using the [xFindFunction] method of the [virtual table module].
6600 ** But global versions of those functions
6601 ** must exist in order to be overloaded.)^
6602 **
6603 ** ^(This API makes sure a global version of a function with a particular
6604 ** name and number of parameters exists.  If no such function exists
6605 ** before this API is called, a new function is created.)^  ^The implementation
6606 ** of the new function always causes an exception to be thrown.  So
6607 ** the new function is not good for anything by itself.  Its only
6608 ** purpose is to be a placeholder function that can be overloaded
6609 ** by a [virtual table].
6610 */
6611 int sqlite3_overload_function(sqlite3*, const(char)* zFuncName, int nArg);
6612 
6613 /*
6614 ** The interface to the virtual-table mechanism defined above (back up
6615 ** to a comment remarkably similar to this one) is currently considered
6616 ** to be experimental.  The interface might change in incompatible ways.
6617 ** If this is a problem for you, do not use the interface at this time.
6618 **
6619 ** When the virtual-table mechanism stabilizes, we will declare the
6620 ** interface fixed, support it indefinitely, and remove this comment.
6621 */
6622 
6623 /*
6624 ** CAPI3REF: A Handle To An Open BLOB
6625 ** KEYWORDS: {BLOB handle} {BLOB handles}
6626 **
6627 ** An instance of this object represents an open BLOB on which
6628 ** [sqlite3_blob_open | incremental BLOB I/O] can be performed.
6629 ** ^Objects of this type are created by [sqlite3_blob_open()]
6630 ** and destroyed by [sqlite3_blob_close()].
6631 ** ^The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces
6632 ** can be used to read or write small subsections of the BLOB.
6633 ** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes.
6634 */
6635 struct sqlite3_blob;
6636 
6637 /*
6638 ** CAPI3REF: Open A BLOB For Incremental I/O
6639 ** METHOD: sqlite3
6640 ** CONSTRUCTOR: sqlite3_blob
6641 **
6642 ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
6643 ** in row iRow, column zColumn, table zTable in database zDb;
6644 ** in other words, the same BLOB that would be selected by:
6645 **
6646 ** <pre>
6647 **     SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
6648 ** </pre>)^
6649 **
6650 ** ^(Parameter zDb is not the filename that contains the database, but
6651 ** rather the symbolic name of the database. For attached databases, this is
6652 ** the name that appears after the AS keyword in the [ATTACH] statement.
6653 ** For the main database file, the database name is "main". For TEMP
6654 ** tables, the database name is "temp".)^
6655 **
6656 ** ^If the flags parameter is non-zero, then the BLOB is opened for read
6657 ** and write access. ^If the flags parameter is zero, the BLOB is opened for
6658 ** read-only access.
6659 **
6660 ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
6661 ** in *ppBlob. Otherwise an [error code] is returned and, unless the error
6662 ** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
6663 ** the API is not misused, it is always safe to call [sqlite3_blob_close()]
6664 ** on *ppBlob after this function it returns.
6665 **
6666 ** This function fails with SQLITE_ERROR if any of the following are true:
6667 ** <ul>
6668 **   <li> ^(Database zDb does not exist)^,
6669 **   <li> ^(Table zTable does not exist within database zDb)^,
6670 **   <li> ^(Table zTable is a WITHOUT ROWID table)^,
6671 **   <li> ^(Column zColumn does not exist)^,
6672 **   <li> ^(Row iRow is not present in the table)^,
6673 **   <li> ^(The specified column of row iRow contains a value that is not
6674 **         a TEXT or BLOB value)^,
6675 **   <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE
6676 **         constraint and the blob is being opened for read/write access)^,
6677 **   <li> ^([foreign key constraints | Foreign key constraints] are enabled,
6678 **         column zColumn is part of a [child key] definition and the blob is
6679 **         being opened for read/write access)^.
6680 ** </ul>
6681 **
6682 ** ^Unless it returns SQLITE_MISUSE, this function sets the
6683 ** [database connection] error code and message accessible via
6684 ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
6685 **
6686 ** A BLOB referenced by sqlite3_blob_open() may be read using the
6687 ** [sqlite3_blob_read()] interface and modified by using
6688 ** [sqlite3_blob_write()].  The [BLOB handle] can be moved to a
6689 ** different row of the same table using the [sqlite3_blob_reopen()]
6690 ** interface.  However, the column, table, or database of a [BLOB handle]
6691 ** cannot be changed after the [BLOB handle] is opened.
6692 **
6693 ** ^(If the row that a BLOB handle points to is modified by an
6694 ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
6695 ** then the BLOB handle is marked as "expired".
6696 ** This is true if any column of the row is changed, even a column
6697 ** other than the one the BLOB handle is open on.)^
6698 ** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for
6699 ** an expired BLOB handle fail with a return code of [SQLITE_ABORT].
6700 ** ^(Changes written into a BLOB prior to the BLOB expiring are not
6701 ** rolled back by the expiration of the BLOB.  Such changes will eventually
6702 ** commit if the transaction continues to completion.)^
6703 **
6704 ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
6705 ** the opened blob.  ^The size of a blob may not be changed by this
6706 ** interface.  Use the [UPDATE] SQL command to change the size of a
6707 ** blob.
6708 **
6709 ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
6710 ** and the built-in [zeroblob] SQL function may be used to create a
6711 ** zero-filled blob to read or write using the incremental-blob interface.
6712 **
6713 ** To avoid a resource leak, every open [BLOB handle] should eventually
6714 ** be released by a call to [sqlite3_blob_close()].
6715 **
6716 ** See also: [sqlite3_blob_close()],
6717 ** [sqlite3_blob_reopen()], [sqlite3_blob_read()],
6718 ** [sqlite3_blob_bytes()], [sqlite3_blob_write()].
6719 */
6720 int sqlite3_blob_open(
6721     sqlite3*,
6722     const(char)* zDb,
6723     const(char)* zTable,
6724     const(char)* zColumn,
6725     sqlite3_int64 iRow,
6726     int flags,
6727     sqlite3_blob** ppBlob);
6728 
6729 /*
6730 ** CAPI3REF: Move a BLOB Handle to a New Row
6731 ** METHOD: sqlite3_blob
6732 **
6733 ** ^This function is used to move an existing [BLOB handle] so that it points
6734 ** to a different row of the same database table. ^The new row is identified
6735 ** by the rowid value passed as the second argument. Only the row can be
6736 ** changed. ^The database, table and column on which the blob handle is open
6737 ** remain the same. Moving an existing [BLOB handle] to a new row is
6738 ** faster than closing the existing handle and opening a new one.
6739 **
6740 ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] -
6741 ** it must exist and there must be either a blob or text value stored in
6742 ** the nominated column.)^ ^If the new row is not present in the table, or if
6743 ** it does not contain a blob or text value, or if another error occurs, an
6744 ** SQLite error code is returned and the blob handle is considered aborted.
6745 ** ^All subsequent calls to [sqlite3_blob_read()], [sqlite3_blob_write()] or
6746 ** [sqlite3_blob_reopen()] on an aborted blob handle immediately return
6747 ** SQLITE_ABORT. ^Calling [sqlite3_blob_bytes()] on an aborted blob handle
6748 ** always returns zero.
6749 **
6750 ** ^This function sets the database handle error code and message.
6751 */
6752 int sqlite3_blob_reopen(sqlite3_blob*, sqlite3_int64);
6753 
6754 /*
6755 ** CAPI3REF: Close A BLOB Handle
6756 ** DESTRUCTOR: sqlite3_blob
6757 **
6758 ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
6759 ** unconditionally.  Even if this routine returns an error code, the
6760 ** handle is still closed.)^
6761 **
6762 ** ^If the blob handle being closed was opened for read-write access, and if
6763 ** the database is in auto-commit mode and there are no other open read-write
6764 ** blob handles or active write statements, the current transaction is
6765 ** committed. ^If an error occurs while committing the transaction, an error
6766 ** code is returned and the transaction rolled back.
6767 **
6768 ** Calling this function with an argument that is not a NULL pointer or an
6769 ** open blob handle results in undefined behaviour. ^Calling this routine
6770 ** with a null pointer (such as would be returned by a failed call to
6771 ** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function
6772 ** is passed a valid open blob handle, the values returned by the
6773 ** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
6774 */
6775 int sqlite3_blob_close(sqlite3_blob*);
6776 
6777 /*
6778 ** CAPI3REF: Return The Size Of An Open BLOB
6779 ** METHOD: sqlite3_blob
6780 **
6781 ** ^Returns the size in bytes of the BLOB accessible via the
6782 ** successfully opened [BLOB handle] in its only argument.  ^The
6783 ** incremental blob I/O routines can only read or overwriting existing
6784 ** blob content; they cannot change the size of a blob.
6785 **
6786 ** This routine only works on a [BLOB handle] which has been created
6787 ** by a prior successful call to [sqlite3_blob_open()] and which has not
6788 ** been closed by [sqlite3_blob_close()].  Passing any other pointer in
6789 ** to this routine results in undefined and probably undesirable behavior.
6790 */
6791 int sqlite3_blob_bytes(sqlite3_blob*);
6792 
6793 /*
6794 ** CAPI3REF: Read Data From A BLOB Incrementally
6795 ** METHOD: sqlite3_blob
6796 **
6797 ** ^(This function is used to read data from an open [BLOB handle] into a
6798 ** caller-supplied buffer. N bytes of data are copied into buffer Z
6799 ** from the open BLOB, starting at offset iOffset.)^
6800 **
6801 ** ^If offset iOffset is less than N bytes from the end of the BLOB,
6802 ** [SQLITE_ERROR] is returned and no data is read.  ^If N or iOffset is
6803 ** less than zero, [SQLITE_ERROR] is returned and no data is read.
6804 ** ^The size of the blob (and hence the maximum value of N+iOffset)
6805 ** can be determined using the [sqlite3_blob_bytes()] interface.
6806 **
6807 ** ^An attempt to read from an expired [BLOB handle] fails with an
6808 ** error code of [SQLITE_ABORT].
6809 **
6810 ** ^(On success, sqlite3_blob_read() returns SQLITE_OK.
6811 ** Otherwise, an [error code] or an [extended error code] is returned.)^
6812 **
6813 ** This routine only works on a [BLOB handle] which has been created
6814 ** by a prior successful call to [sqlite3_blob_open()] and which has not
6815 ** been closed by [sqlite3_blob_close()].  Passing any other pointer in
6816 ** to this routine results in undefined and probably undesirable behavior.
6817 **
6818 ** See also: [sqlite3_blob_write()].
6819 */
6820 int sqlite3_blob_read(sqlite3_blob*, void* Z, int N, int iOffset);
6821 
6822 /*
6823 ** CAPI3REF: Write Data Into A BLOB Incrementally
6824 ** METHOD: sqlite3_blob
6825 **
6826 ** ^(This function is used to write data into an open [BLOB handle] from a
6827 ** caller-supplied buffer. N bytes of data are copied from the buffer Z
6828 ** into the open BLOB, starting at offset iOffset.)^
6829 **
6830 ** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
6831 ** Otherwise, an  [error code] or an [extended error code] is returned.)^
6832 ** ^Unless SQLITE_MISUSE is returned, this function sets the
6833 ** [database connection] error code and message accessible via
6834 ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
6835 **
6836 ** ^If the [BLOB handle] passed as the first argument was not opened for
6837 ** writing (the flags parameter to [sqlite3_blob_open()] was zero),
6838 ** this function returns [SQLITE_READONLY].
6839 **
6840 ** This function may only modify the contents of the BLOB; it is
6841 ** not possible to increase the size of a BLOB using this API.
6842 ** ^If offset iOffset is less than N bytes from the end of the BLOB,
6843 ** [SQLITE_ERROR] is returned and no data is written. The size of the
6844 ** BLOB (and hence the maximum value of N+iOffset) can be determined
6845 ** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less
6846 ** than zero [SQLITE_ERROR] is returned and no data is written.
6847 **
6848 ** ^An attempt to write to an expired [BLOB handle] fails with an
6849 ** error code of [SQLITE_ABORT].  ^Writes to the BLOB that occurred
6850 ** before the [BLOB handle] expired are not rolled back by the
6851 ** expiration of the handle, though of course those changes might
6852 ** have been overwritten by the statement that expired the BLOB handle
6853 ** or by other independent statements.
6854 **
6855 ** This routine only works on a [BLOB handle] which has been created
6856 ** by a prior successful call to [sqlite3_blob_open()] and which has not
6857 ** been closed by [sqlite3_blob_close()].  Passing any other pointer in
6858 ** to this routine results in undefined and probably undesirable behavior.
6859 **
6860 ** See also: [sqlite3_blob_read()].
6861 */
6862 int sqlite3_blob_write(sqlite3_blob*, const(void)* z, int n, int iOffset);
6863 
6864 /*
6865 ** CAPI3REF: Virtual File System Objects
6866 **
6867 ** A virtual filesystem (VFS) is an [sqlite3_vfs] object
6868 ** that SQLite uses to interact
6869 ** with the underlying operating system.  Most SQLite builds come with a
6870 ** single default VFS that is appropriate for the host computer.
6871 ** New VFSes can be registered and existing VFSes can be unregistered.
6872 ** The following interfaces are provided.
6873 **
6874 ** ^The sqlite3_vfs_find() interface returns a pointer to a VFS given its name.
6875 ** ^Names are case sensitive.
6876 ** ^Names are zero-terminated UTF-8 strings.
6877 ** ^If there is no match, a NULL pointer is returned.
6878 ** ^If zVfsName is NULL then the default VFS is returned.
6879 **
6880 ** ^New VFSes are registered with sqlite3_vfs_register().
6881 ** ^Each new VFS becomes the default VFS if the makeDflt flag is set.
6882 ** ^The same VFS can be registered multiple times without injury.
6883 ** ^To make an existing VFS into the default VFS, register it again
6884 ** with the makeDflt flag set.  If two different VFSes with the
6885 ** same name are registered, the behavior is undefined.  If a
6886 ** VFS is registered with a name that is NULL or an empty string,
6887 ** then the behavior is undefined.
6888 **
6889 ** ^Unregister a VFS with the sqlite3_vfs_unregister() interface.
6890 ** ^(If the default VFS is unregistered, another VFS is chosen as
6891 ** the default.  The choice for the new VFS is arbitrary.)^
6892 */
6893 sqlite3_vfs* sqlite3_vfs_find(const(char)* zVfsName);
6894 int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
6895 int sqlite3_vfs_unregister(sqlite3_vfs*);
6896 
6897 /*
6898 ** CAPI3REF: Mutexes
6899 **
6900 ** The SQLite core uses these routines for thread
6901 ** synchronization. Though they are intended for internal
6902 ** use by SQLite, code that links against SQLite is
6903 ** permitted to use any of these routines.
6904 **
6905 ** The SQLite source code contains multiple implementations
6906 ** of these mutex routines.  An appropriate implementation
6907 ** is selected automatically at compile-time.  The following
6908 ** implementations are available in the SQLite core:
6909 **
6910 ** <ul>
6911 ** <li>   SQLITE_MUTEX_PTHREADS
6912 ** <li>   SQLITE_MUTEX_W32
6913 ** <li>   SQLITE_MUTEX_NOOP
6914 ** </ul>
6915 **
6916 ** The SQLITE_MUTEX_NOOP implementation is a set of routines
6917 ** that does no real locking and is appropriate for use in
6918 ** a single-threaded application.  The SQLITE_MUTEX_PTHREADS and
6919 ** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix
6920 ** and Windows.
6921 **
6922 ** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
6923 ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
6924 ** implementation is included with the library. In this case the
6925 ** application must supply a custom mutex implementation using the
6926 ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
6927 ** before calling sqlite3_initialize() or any other public sqlite3_
6928 ** function that calls sqlite3_initialize().
6929 **
6930 ** ^The sqlite3_mutex_alloc() routine allocates a new
6931 ** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()
6932 ** routine returns NULL if it is unable to allocate the requested
6933 ** mutex.  The argument to sqlite3_mutex_alloc() must one of these
6934 ** integer constants:
6935 **
6936 ** <ul>
6937 ** <li>  SQLITE_MUTEX_FAST
6938 ** <li>  SQLITE_MUTEX_RECURSIVE
6939 ** <li>  SQLITE_MUTEX_STATIC_MASTER
6940 ** <li>  SQLITE_MUTEX_STATIC_MEM
6941 ** <li>  SQLITE_MUTEX_STATIC_OPEN
6942 ** <li>  SQLITE_MUTEX_STATIC_PRNG
6943 ** <li>  SQLITE_MUTEX_STATIC_LRU
6944 ** <li>  SQLITE_MUTEX_STATIC_PMEM
6945 ** <li>  SQLITE_MUTEX_STATIC_APP1
6946 ** <li>  SQLITE_MUTEX_STATIC_APP2
6947 ** <li>  SQLITE_MUTEX_STATIC_APP3
6948 ** <li>  SQLITE_MUTEX_STATIC_VFS1
6949 ** <li>  SQLITE_MUTEX_STATIC_VFS2
6950 ** <li>  SQLITE_MUTEX_STATIC_VFS3
6951 ** </ul>
6952 **
6953 ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
6954 ** cause sqlite3_mutex_alloc() to create
6955 ** a new mutex.  ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
6956 ** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
6957 ** The mutex implementation does not need to make a distinction
6958 ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
6959 ** not want to.  SQLite will only request a recursive mutex in
6960 ** cases where it really needs one.  If a faster non-recursive mutex
6961 ** implementation is available on the host platform, the mutex subsystem
6962 ** might return such a mutex in response to SQLITE_MUTEX_FAST.
6963 **
6964 ** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other
6965 ** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return
6966 ** a pointer to a static preexisting mutex.  ^Nine static mutexes are
6967 ** used by the current version of SQLite.  Future versions of SQLite
6968 ** may add additional static mutexes.  Static mutexes are for internal
6969 ** use by SQLite only.  Applications that use SQLite mutexes should
6970 ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
6971 ** SQLITE_MUTEX_RECURSIVE.
6972 **
6973 ** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
6974 ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
6975 ** returns a different mutex on every call.  ^For the static
6976 ** mutex types, the same mutex is returned on every call that has
6977 ** the same type number.
6978 **
6979 ** ^The sqlite3_mutex_free() routine deallocates a previously
6980 ** allocated dynamic mutex.  Attempting to deallocate a static
6981 ** mutex results in undefined behavior.
6982 **
6983 ** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
6984 ** to enter a mutex.  ^If another thread is already within the mutex,
6985 ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
6986 ** SQLITE_BUSY.  ^The sqlite3_mutex_try() interface returns [SQLITE_OK]
6987 ** upon successful entry.  ^(Mutexes created using
6988 ** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.
6989 ** In such cases, the
6990 ** mutex must be exited an equal number of times before another thread
6991 ** can enter.)^  If the same thread tries to enter any mutex other
6992 ** than an SQLITE_MUTEX_RECURSIVE more than once, the behavior is undefined.
6993 **
6994 ** ^(Some systems (for example, Windows 95) do not support the operation
6995 ** implemented by sqlite3_mutex_try().  On those systems, sqlite3_mutex_try()
6996 ** will always return SQLITE_BUSY. The SQLite core only ever uses
6997 ** sqlite3_mutex_try() as an optimization so this is acceptable
6998 ** behavior.)^
6999 **
7000 ** ^The sqlite3_mutex_leave() routine exits a mutex that was
7001 ** previously entered by the same thread.   The behavior
7002 ** is undefined if the mutex is not currently entered by the
7003 ** calling thread or is not currently allocated.
7004 **
7005 ** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or
7006 ** sqlite3_mutex_leave() is a NULL pointer, then all three routines
7007 ** behave as no-ops.
7008 **
7009 ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()].
7010 */
7011 sqlite3_mutex* sqlite3_mutex_alloc(int);
7012 void sqlite3_mutex_free(sqlite3_mutex*);
7013 void sqlite3_mutex_enter(sqlite3_mutex*);
7014 int sqlite3_mutex_try(sqlite3_mutex*);
7015 void sqlite3_mutex_leave(sqlite3_mutex*);
7016 
7017 /*
7018 ** CAPI3REF: Mutex Methods Object
7019 **
7020 ** An instance of this structure defines the low-level routines
7021 ** used to allocate and use mutexes.
7022 **
7023 ** Usually, the default mutex implementations provided by SQLite are
7024 ** sufficient, however the application has the option of substituting a custom
7025 ** implementation for specialized deployments or systems for which SQLite
7026 ** does not provide a suitable implementation. In this case, the application
7027 ** creates and populates an instance of this structure to pass
7028 ** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option.
7029 ** Additionally, an instance of this structure can be used as an
7030 ** output variable when querying the system for the current mutex
7031 ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
7032 **
7033 ** ^The xMutexInit method defined by this structure is invoked as
7034 ** part of system initialization by the sqlite3_initialize() function.
7035 ** ^The xMutexInit routine is called by SQLite exactly once for each
7036 ** effective call to [sqlite3_initialize()].
7037 **
7038 ** ^The xMutexEnd method defined by this structure is invoked as
7039 ** part of system shutdown by the sqlite3_shutdown() function. The
7040 ** implementation of this method is expected to release all outstanding
7041 ** resources obtained by the mutex methods implementation, especially
7042 ** those obtained by the xMutexInit method.  ^The xMutexEnd()
7043 ** interface is invoked exactly once for each call to [sqlite3_shutdown()].
7044 **
7045 ** ^(The remaining seven methods defined by this structure (xMutexAlloc,
7046 ** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and
7047 ** xMutexNotheld) implement the following interfaces (respectively):
7048 **
7049 ** <ul>
7050 **   <li>  [sqlite3_mutex_alloc()] </li>
7051 **   <li>  [sqlite3_mutex_free()] </li>
7052 **   <li>  [sqlite3_mutex_enter()] </li>
7053 **   <li>  [sqlite3_mutex_try()] </li>
7054 **   <li>  [sqlite3_mutex_leave()] </li>
7055 **   <li>  [sqlite3_mutex_held()] </li>
7056 **   <li>  [sqlite3_mutex_notheld()] </li>
7057 ** </ul>)^
7058 **
7059 ** The only difference is that the public sqlite3_XXX functions enumerated
7060 ** above silently ignore any invocations that pass a NULL pointer instead
7061 ** of a valid mutex handle. The implementations of the methods defined
7062 ** by this structure are not required to handle this case, the results
7063 ** of passing a NULL pointer instead of a valid mutex handle are undefined
7064 ** (i.e. it is acceptable to provide an implementation that segfaults if
7065 ** it is passed a NULL pointer).
7066 **
7067 ** The xMutexInit() method must be threadsafe.  It must be harmless to
7068 ** invoke xMutexInit() multiple times within the same process and without
7069 ** intervening calls to xMutexEnd().  Second and subsequent calls to
7070 ** xMutexInit() must be no-ops.
7071 **
7072 ** xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()]
7073 ** and its associates).  Similarly, xMutexAlloc() must not use SQLite memory
7074 ** allocation for a static mutex.  ^However xMutexAlloc() may use SQLite
7075 ** memory allocation for a fast or recursive mutex.
7076 **
7077 ** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is
7078 ** called, but only if the prior call to xMutexInit returned SQLITE_OK.
7079 ** If xMutexInit fails in any way, it is expected to clean up after itself
7080 ** prior to returning.
7081 */
7082 struct sqlite3_mutex_methods
7083 {
7084     int function() xMutexInit;
7085     int function() xMutexEnd;
7086     sqlite3_mutex* function(int) xMutexAlloc;
7087     void function(sqlite3_mutex*) xMutexFree;
7088     void function(sqlite3_mutex*) xMutexEnter;
7089     int function(sqlite3_mutex*) xMutexTry;
7090     void function(sqlite3_mutex*) xMutexLeave;
7091     int function(sqlite3_mutex*) xMutexHeld;
7092     int function(sqlite3_mutex*) xMutexNotheld;
7093 }
7094 
7095 /*
7096 ** CAPI3REF: Mutex Verification Routines
7097 **
7098 ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
7099 ** are intended for use inside assert() statements.  The SQLite core
7100 ** never uses these routines except inside an assert() and applications
7101 ** are advised to follow the lead of the core.  The SQLite core only
7102 ** provides implementations for these routines when it is compiled
7103 ** with the SQLITE_DEBUG flag.  External mutex implementations
7104 ** are only required to provide these routines if SQLITE_DEBUG is
7105 ** defined and if NDEBUG is not defined.
7106 **
7107 ** These routines should return true if the mutex in their argument
7108 ** is held or not held, respectively, by the calling thread.
7109 **
7110 ** The implementation is not required to provide versions of these
7111 ** routines that actually work. If the implementation does not provide working
7112 ** versions of these routines, it should at least provide stubs that always
7113 ** return true so that one does not get spurious assertion failures.
7114 **
7115 ** If the argument to sqlite3_mutex_held() is a NULL pointer then
7116 ** the routine should return 1.   This seems counter-intuitive since
7117 ** clearly the mutex cannot be held if it does not exist.  But
7118 ** the reason the mutex does not exist is because the build is not
7119 ** using mutexes.  And we do not want the assert() containing the
7120 ** call to sqlite3_mutex_held() to fail, so a non-zero return is
7121 ** the appropriate thing to do.  The sqlite3_mutex_notheld()
7122 ** interface should also return 1 when given a NULL pointer.
7123 */
7124 
7125 int sqlite3_mutex_held(sqlite3_mutex*);
7126 int sqlite3_mutex_notheld(sqlite3_mutex*);
7127 
7128 /*
7129 ** CAPI3REF: Mutex Types
7130 **
7131 ** The [sqlite3_mutex_alloc()] interface takes a single argument
7132 ** which is one of these integer constants.
7133 **
7134 ** The set of static mutexes may change from one SQLite release to the
7135 ** next.  Applications that override the built-in mutex logic must be
7136 ** prepared to accommodate additional static mutexes.
7137 */
7138 enum SQLITE_MUTEX_FAST = 0;
7139 enum SQLITE_MUTEX_RECURSIVE = 1;
7140 enum SQLITE_MUTEX_STATIC_MASTER = 2;
7141 enum SQLITE_MUTEX_STATIC_MEM = 3; /* sqlite3_malloc() */
7142 enum SQLITE_MUTEX_STATIC_MEM2 = 4; /* NOT USED */
7143 enum SQLITE_MUTEX_STATIC_OPEN = 4; /* sqlite3BtreeOpen() */
7144 enum SQLITE_MUTEX_STATIC_PRNG = 5; /* sqlite3_randomness() */
7145 enum SQLITE_MUTEX_STATIC_LRU = 6; /* lru page list */
7146 enum SQLITE_MUTEX_STATIC_LRU2 = 7; /* NOT USED */
7147 enum SQLITE_MUTEX_STATIC_PMEM = 7; /* sqlite3PageMalloc() */
7148 enum SQLITE_MUTEX_STATIC_APP1 = 8; /* For use by application */
7149 enum SQLITE_MUTEX_STATIC_APP2 = 9; /* For use by application */
7150 enum SQLITE_MUTEX_STATIC_APP3 = 10; /* For use by application */
7151 enum SQLITE_MUTEX_STATIC_VFS1 = 11; /* For use by built-in VFS */
7152 enum SQLITE_MUTEX_STATIC_VFS2 = 12; /* For use by extension VFS */
7153 enum SQLITE_MUTEX_STATIC_VFS3 = 13; /* For use by application VFS */
7154 
7155 /*
7156 ** CAPI3REF: Retrieve the mutex for a database connection
7157 ** METHOD: sqlite3
7158 **
7159 ** ^This interface returns a pointer the [sqlite3_mutex] object that
7160 ** serializes access to the [database connection] given in the argument
7161 ** when the [threading mode] is Serialized.
7162 ** ^If the [threading mode] is Single-thread or Multi-thread then this
7163 ** routine returns a NULL pointer.
7164 */
7165 sqlite3_mutex* sqlite3_db_mutex(sqlite3*);
7166 
7167 /*
7168 ** CAPI3REF: Low-Level Control Of Database Files
7169 ** METHOD: sqlite3
7170 ** KEYWORDS: {file control}
7171 **
7172 ** ^The [sqlite3_file_control()] interface makes a direct call to the
7173 ** xFileControl method for the [sqlite3_io_methods] object associated
7174 ** with a particular database identified by the second argument. ^The
7175 ** name of the database is "main" for the main database or "temp" for the
7176 ** TEMP database, or the name that appears after the AS keyword for
7177 ** databases that are added using the [ATTACH] SQL command.
7178 ** ^A NULL pointer can be used in place of "main" to refer to the
7179 ** main database file.
7180 ** ^The third and fourth parameters to this routine
7181 ** are passed directly through to the second and third parameters of
7182 ** the xFileControl method.  ^The return value of the xFileControl
7183 ** method becomes the return value of this routine.
7184 **
7185 ** A few opcodes for [sqlite3_file_control()] are handled directly
7186 ** by the SQLite core and never invoke the
7187 ** sqlite3_io_methods.xFileControl method.
7188 ** ^The [SQLITE_FCNTL_FILE_POINTER] value for the op parameter causes
7189 ** a pointer to the underlying [sqlite3_file] object to be written into
7190 ** the space pointed to by the 4th parameter.  The
7191 ** [SQLITE_FCNTL_JOURNAL_POINTER] works similarly except that it returns
7192 ** the [sqlite3_file] object associated with the journal file instead of
7193 ** the main database.  The [SQLITE_FCNTL_VFS_POINTER] opcode returns
7194 ** a pointer to the underlying [sqlite3_vfs] object for the file.
7195 ** The [SQLITE_FCNTL_DATA_VERSION] returns the data version counter
7196 ** from the pager.
7197 **
7198 ** ^If the second parameter (zDbName) does not match the name of any
7199 ** open database file, then SQLITE_ERROR is returned.  ^This error
7200 ** code is not remembered and will not be recalled by [sqlite3_errcode()]
7201 ** or [sqlite3_errmsg()].  The underlying xFileControl method might
7202 ** also return SQLITE_ERROR.  There is no way to distinguish between
7203 ** an incorrect zDbName and an SQLITE_ERROR return from the underlying
7204 ** xFileControl method.
7205 **
7206 ** See also: [file control opcodes]
7207 */
7208 int sqlite3_file_control(sqlite3*, const(char)* zDbName, int op, void*);
7209 
7210 /*
7211 ** CAPI3REF: Testing Interface
7212 **
7213 ** ^The sqlite3_test_control() interface is used to read out internal
7214 ** state of SQLite and to inject faults into SQLite for testing
7215 ** purposes.  ^The first parameter is an operation code that determines
7216 ** the number, meaning, and operation of all subsequent parameters.
7217 **
7218 ** This interface is not for use by applications.  It exists solely
7219 ** for verifying the correct operation of the SQLite library.  Depending
7220 ** on how the SQLite library is compiled, this interface might not exist.
7221 **
7222 ** The details of the operation codes, their meanings, the parameters
7223 ** they take, and what they do are all subject to change without notice.
7224 ** Unlike most of the SQLite API, this function is not guaranteed to
7225 ** operate consistently from one release to the next.
7226 */
7227 int sqlite3_test_control(int op, ...);
7228 
7229 /*
7230 ** CAPI3REF: Testing Interface Operation Codes
7231 **
7232 ** These constants are the valid operation code parameters used
7233 ** as the first argument to [sqlite3_test_control()].
7234 **
7235 ** These parameters and their meanings are subject to change
7236 ** without notice.  These values are for testing purposes only.
7237 ** Applications should not use any of these parameters or the
7238 ** [sqlite3_test_control()] interface.
7239 */
7240 enum SQLITE_TESTCTRL_FIRST = 5;
7241 enum SQLITE_TESTCTRL_PRNG_SAVE = 5;
7242 enum SQLITE_TESTCTRL_PRNG_RESTORE = 6;
7243 enum SQLITE_TESTCTRL_PRNG_RESET = 7;
7244 enum SQLITE_TESTCTRL_BITVEC_TEST = 8;
7245 enum SQLITE_TESTCTRL_FAULT_INSTALL = 9;
7246 enum SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS = 10;
7247 enum SQLITE_TESTCTRL_PENDING_BYTE = 11;
7248 enum SQLITE_TESTCTRL_ASSERT = 12;
7249 enum SQLITE_TESTCTRL_ALWAYS = 13;
7250 enum SQLITE_TESTCTRL_RESERVE = 14;
7251 enum SQLITE_TESTCTRL_OPTIMIZATIONS = 15;
7252 enum SQLITE_TESTCTRL_ISKEYWORD = 16; /* NOT USED */
7253 enum SQLITE_TESTCTRL_SCRATCHMALLOC = 17; /* NOT USED */
7254 enum SQLITE_TESTCTRL_LOCALTIME_FAULT = 18;
7255 enum SQLITE_TESTCTRL_EXPLAIN_STMT = 19; /* NOT USED */
7256 enum SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD = 19;
7257 enum SQLITE_TESTCTRL_NEVER_CORRUPT = 20;
7258 enum SQLITE_TESTCTRL_VDBE_COVERAGE = 21;
7259 enum SQLITE_TESTCTRL_BYTEORDER = 22;
7260 enum SQLITE_TESTCTRL_ISINIT = 23;
7261 enum SQLITE_TESTCTRL_SORTER_MMAP = 24;
7262 enum SQLITE_TESTCTRL_IMPOSTER = 25;
7263 enum SQLITE_TESTCTRL_PARSER_COVERAGE = 26;
7264 enum SQLITE_TESTCTRL_LAST = 26; /* Largest TESTCTRL */
7265 
7266 /*
7267 ** CAPI3REF: SQL Keyword Checking
7268 **
7269 ** These routines provide access to the set of SQL language keywords
7270 ** recognized by SQLite.  Applications can uses these routines to determine
7271 ** whether or not a specific identifier needs to be escaped (for example,
7272 ** by enclosing in double-quotes) so as not to confuse the parser.
7273 **
7274 ** The sqlite3_keyword_count() interface returns the number of distinct
7275 ** keywords understood by SQLite.
7276 **
7277 ** The sqlite3_keyword_name(N,Z,L) interface finds the N-th keyword and
7278 ** makes *Z point to that keyword expressed as UTF8 and writes the number
7279 ** of bytes in the keyword into *L.  The string that *Z points to is not
7280 ** zero-terminated.  The sqlite3_keyword_name(N,Z,L) routine returns
7281 ** SQLITE_OK if N is within bounds and SQLITE_ERROR if not. If either Z
7282 ** or L are NULL or invalid pointers then calls to
7283 ** sqlite3_keyword_name(N,Z,L) result in undefined behavior.
7284 **
7285 ** The sqlite3_keyword_check(Z,L) interface checks to see whether or not
7286 ** the L-byte UTF8 identifier that Z points to is a keyword, returning non-zero
7287 ** if it is and zero if not.
7288 **
7289 ** The parser used by SQLite is forgiving.  It is often possible to use
7290 ** a keyword as an identifier as long as such use does not result in a
7291 ** parsing ambiguity.  For example, the statement
7292 ** "CREATE TABLE BEGIN(REPLACE,PRAGMA,END);" is accepted by SQLite, and
7293 ** creates a new table named "BEGIN" with three columns named
7294 ** "REPLACE", "PRAGMA", and "END".  Nevertheless, best practice is to avoid
7295 ** using keywords as identifiers.  Common techniques used to avoid keyword
7296 ** name collisions include:
7297 ** <ul>
7298 ** <li> Put all identifier names inside double-quotes.  This is the official
7299 **      SQL way to escape identifier names.
7300 ** <li> Put identifier names inside &#91;...&#93;.  This is not standard SQL,
7301 **      but it is what SQL Server does and so lots of programmers use this
7302 **      technique.
7303 ** <li> Begin every identifier with the letter "Z" as no SQL keywords start
7304 **      with "Z".
7305 ** <li> Include a digit somewhere in every identifier name.
7306 ** </ul>
7307 **
7308 ** Note that the number of keywords understood by SQLite can depend on
7309 ** compile-time options.  For example, "VACUUM" is not a keyword if
7310 ** SQLite is compiled with the [-DSQLITE_OMIT_VACUUM] option.  Also,
7311 ** new keywords may be added to future releases of SQLite.
7312 */
7313 int sqlite3_keyword_count();
7314 int sqlite3_keyword_name(int, const(char*)*, int*);
7315 int sqlite3_keyword_check(const(char)*, int);
7316 
7317 /*
7318 ** CAPI3REF: Dynamic String Object
7319 ** KEYWORDS: {dynamic string}
7320 **
7321 ** An instance of the sqlite3_str object contains a dynamically-sized
7322 ** string under construction.
7323 **
7324 ** The lifecycle of an sqlite3_str object is as follows:
7325 ** <ol>
7326 ** <li> ^The sqlite3_str object is created using [sqlite3_str_new()].
7327 ** <li> ^Text is appended to the sqlite3_str object using various
7328 ** methods, such as [sqlite3_str_appendf()].
7329 ** <li> ^The sqlite3_str object is destroyed and the string it created
7330 ** is returned using the [sqlite3_str_finish()] interface.
7331 ** </ol>
7332 */
7333 struct sqlite3_str;
7334 
7335 /*
7336 ** CAPI3REF: Create A New Dynamic String Object
7337 ** CONSTRUCTOR: sqlite3_str
7338 **
7339 ** ^The [sqlite3_str_new(D)] interface allocates and initializes
7340 ** a new [sqlite3_str] object.  To avoid memory leaks, the object returned by
7341 ** [sqlite3_str_new()] must be freed by a subsequent call to
7342 ** [sqlite3_str_finish(X)].
7343 **
7344 ** ^The [sqlite3_str_new(D)] interface always returns a pointer to a
7345 ** valid [sqlite3_str] object, though in the event of an out-of-memory
7346 ** error the returned object might be a special singleton that will
7347 ** silently reject new text, always return SQLITE_NOMEM from
7348 ** [sqlite3_str_errcode()], always return 0 for
7349 ** [sqlite3_str_length()], and always return NULL from
7350 ** [sqlite3_str_finish(X)].  It is always safe to use the value
7351 ** returned by [sqlite3_str_new(D)] as the sqlite3_str parameter
7352 ** to any of the other [sqlite3_str] methods.
7353 **
7354 ** The D parameter to [sqlite3_str_new(D)] may be NULL.  If the
7355 ** D parameter in [sqlite3_str_new(D)] is not NULL, then the maximum
7356 ** length of the string contained in the [sqlite3_str] object will be
7357 ** the value set for [sqlite3_limit](D,[SQLITE_LIMIT_LENGTH]) instead
7358 ** of [SQLITE_MAX_LENGTH].
7359 */
7360 sqlite3_str* sqlite3_str_new(sqlite3*);
7361 
7362 /*
7363 ** CAPI3REF: Finalize A Dynamic String
7364 ** DESTRUCTOR: sqlite3_str
7365 **
7366 ** ^The [sqlite3_str_finish(X)] interface destroys the sqlite3_str object X
7367 ** and returns a pointer to a memory buffer obtained from [sqlite3_malloc64()]
7368 ** that contains the constructed string.  The calling application should
7369 ** pass the returned value to [sqlite3_free()] to avoid a memory leak.
7370 ** ^The [sqlite3_str_finish(X)] interface may return a NULL pointer if any
7371 ** errors were encountered during construction of the string.  ^The
7372 ** [sqlite3_str_finish(X)] interface will also return a NULL pointer if the
7373 ** string in [sqlite3_str] object X is zero bytes long.
7374 */
7375 char* sqlite3_str_finish(sqlite3_str*);
7376 
7377 /*
7378 ** CAPI3REF: Add Content To A Dynamic String
7379 ** METHOD: sqlite3_str
7380 **
7381 ** These interfaces add content to an sqlite3_str object previously obtained
7382 ** from [sqlite3_str_new()].
7383 **
7384 ** ^The [sqlite3_str_appendf(X,F,...)] and
7385 ** [sqlite3_str_vappendf(X,F,V)] interfaces uses the [built-in printf]
7386 ** functionality of SQLite to append formatted text onto the end of
7387 ** [sqlite3_str] object X.
7388 **
7389 ** ^The [sqlite3_str_append(X,S,N)] method appends exactly N bytes from string S
7390 ** onto the end of the [sqlite3_str] object X.  N must be non-negative.
7391 ** S must contain at least N non-zero bytes of content.  To append a
7392 ** zero-terminated string in its entirety, use the [sqlite3_str_appendall()]
7393 ** method instead.
7394 **
7395 ** ^The [sqlite3_str_appendall(X,S)] method appends the complete content of
7396 ** zero-terminated string S onto the end of [sqlite3_str] object X.
7397 **
7398 ** ^The [sqlite3_str_appendchar(X,N,C)] method appends N copies of the
7399 ** single-byte character C onto the end of [sqlite3_str] object X.
7400 ** ^This method can be used, for example, to add whitespace indentation.
7401 **
7402 ** ^The [sqlite3_str_reset(X)] method resets the string under construction
7403 ** inside [sqlite3_str] object X back to zero bytes in length.
7404 **
7405 ** These methods do not return a result code.  ^If an error occurs, that fact
7406 ** is recorded in the [sqlite3_str] object and can be recovered by a
7407 ** subsequent call to [sqlite3_str_errcode(X)].
7408 */
7409 void sqlite3_str_appendf(sqlite3_str*, const(char)* zFormat, ...);
7410 void sqlite3_str_vappendf(sqlite3_str*, const(char)* zFormat, va_list);
7411 void sqlite3_str_append(sqlite3_str*, const(char)* zIn, int N);
7412 void sqlite3_str_appendall(sqlite3_str*, const(char)* zIn);
7413 void sqlite3_str_appendchar(sqlite3_str*, int N, char C);
7414 void sqlite3_str_reset(sqlite3_str*);
7415 
7416 /*
7417 ** CAPI3REF: Status Of A Dynamic String
7418 ** METHOD: sqlite3_str
7419 **
7420 ** These interfaces return the current status of an [sqlite3_str] object.
7421 **
7422 ** ^If any prior errors have occurred while constructing the dynamic string
7423 ** in sqlite3_str X, then the [sqlite3_str_errcode(X)] method will return
7424 ** an appropriate error code.  ^The [sqlite3_str_errcode(X)] method returns
7425 ** [SQLITE_NOMEM] following any out-of-memory error, or
7426 ** [SQLITE_TOOBIG] if the size of the dynamic string exceeds
7427 ** [SQLITE_MAX_LENGTH], or [SQLITE_OK] if there have been no errors.
7428 **
7429 ** ^The [sqlite3_str_length(X)] method returns the current length, in bytes,
7430 ** of the dynamic string under construction in [sqlite3_str] object X.
7431 ** ^The length returned by [sqlite3_str_length(X)] does not include the
7432 ** zero-termination byte.
7433 **
7434 ** ^The [sqlite3_str_value(X)] method returns a pointer to the current
7435 ** content of the dynamic string under construction in X.  The value
7436 ** returned by [sqlite3_str_value(X)] is managed by the sqlite3_str object X
7437 ** and might be freed or altered by any subsequent method on the same
7438 ** [sqlite3_str] object.  Applications must not used the pointer returned
7439 ** [sqlite3_str_value(X)] after any subsequent method call on the same
7440 ** object.  ^Applications may change the content of the string returned
7441 ** by [sqlite3_str_value(X)] as long as they do not write into any bytes
7442 ** outside the range of 0 to [sqlite3_str_length(X)] and do not read or
7443 ** write any byte after any subsequent sqlite3_str method call.
7444 */
7445 int sqlite3_str_errcode(sqlite3_str*);
7446 int sqlite3_str_length(sqlite3_str*);
7447 char* sqlite3_str_value(sqlite3_str*);
7448 
7449 /*
7450 ** CAPI3REF: SQLite Runtime Status
7451 **
7452 ** ^These interfaces are used to retrieve runtime status information
7453 ** about the performance of SQLite, and optionally to reset various
7454 ** highwater marks.  ^The first argument is an integer code for
7455 ** the specific parameter to measure.  ^(Recognized integer codes
7456 ** are of the form [status parameters | SQLITE_STATUS_...].)^
7457 ** ^The current value of the parameter is returned into *pCurrent.
7458 ** ^The highest recorded value is returned in *pHighwater.  ^If the
7459 ** resetFlag is true, then the highest record value is reset after
7460 ** *pHighwater is written.  ^(Some parameters do not record the highest
7461 ** value.  For those parameters
7462 ** nothing is written into *pHighwater and the resetFlag is ignored.)^
7463 ** ^(Other parameters record only the highwater mark and not the current
7464 ** value.  For these latter parameters nothing is written into *pCurrent.)^
7465 **
7466 ** ^The sqlite3_status() and sqlite3_status64() routines return
7467 ** SQLITE_OK on success and a non-zero [error code] on failure.
7468 **
7469 ** If either the current value or the highwater mark is too large to
7470 ** be represented by a 32-bit integer, then the values returned by
7471 ** sqlite3_status() are undefined.
7472 **
7473 ** See also: [sqlite3_db_status()]
7474 */
7475 int sqlite3_status(int op, int* pCurrent, int* pHighwater, int resetFlag);
7476 int sqlite3_status64(
7477     int op,
7478     sqlite3_int64* pCurrent,
7479     sqlite3_int64* pHighwater,
7480     int resetFlag);
7481 
7482 /*
7483 ** CAPI3REF: Status Parameters
7484 ** KEYWORDS: {status parameters}
7485 **
7486 ** These integer constants designate various run-time status parameters
7487 ** that can be returned by [sqlite3_status()].
7488 **
7489 ** <dl>
7490 ** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
7491 ** <dd>This parameter is the current amount of memory checked out
7492 ** using [sqlite3_malloc()], either directly or indirectly.  The
7493 ** figure includes calls made to [sqlite3_malloc()] by the application
7494 ** and internal memory usage by the SQLite library.  Auxiliary page-cache
7495 ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
7496 ** this parameter.  The amount returned is the sum of the allocation
7497 ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
7498 **
7499 ** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
7500 ** <dd>This parameter records the largest memory allocation request
7501 ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
7502 ** internal equivalents).  Only the value returned in the
7503 ** *pHighwater parameter to [sqlite3_status()] is of interest.
7504 ** The value written into the *pCurrent parameter is undefined.</dd>)^
7505 **
7506 ** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
7507 ** <dd>This parameter records the number of separate memory allocations
7508 ** currently checked out.</dd>)^
7509 **
7510 ** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
7511 ** <dd>This parameter returns the number of pages used out of the
7512 ** [pagecache memory allocator] that was configured using
7513 ** [SQLITE_CONFIG_PAGECACHE].  The
7514 ** value returned is in pages, not in bytes.</dd>)^
7515 **
7516 ** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]]
7517 ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
7518 ** <dd>This parameter returns the number of bytes of page cache
7519 ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
7520 ** buffer and where forced to overflow to [sqlite3_malloc()].  The
7521 ** returned value includes allocations that overflowed because they
7522 ** where too large (they were larger than the "sz" parameter to
7523 ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
7524 ** no space was left in the page cache.</dd>)^
7525 **
7526 ** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
7527 ** <dd>This parameter records the largest memory allocation request
7528 ** handed to [pagecache memory allocator].  Only the value returned in the
7529 ** *pHighwater parameter to [sqlite3_status()] is of interest.
7530 ** The value written into the *pCurrent parameter is undefined.</dd>)^
7531 **
7532 ** [[SQLITE_STATUS_SCRATCH_USED]] <dt>SQLITE_STATUS_SCRATCH_USED</dt>
7533 ** <dd>No longer used.</dd>
7534 **
7535 ** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
7536 ** <dd>No longer used.</dd>
7537 **
7538 ** [[SQLITE_STATUS_SCRATCH_SIZE]] <dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
7539 ** <dd>No longer used.</dd>
7540 **
7541 ** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
7542 ** <dd>The *pHighwater parameter records the deepest parser stack.
7543 ** The *pCurrent value is undefined.  The *pHighwater value is only
7544 ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
7545 ** </dl>
7546 **
7547 ** New status parameters may be added from time to time.
7548 */
7549 enum SQLITE_STATUS_MEMORY_USED = 0;
7550 enum SQLITE_STATUS_PAGECACHE_USED = 1;
7551 enum SQLITE_STATUS_PAGECACHE_OVERFLOW = 2;
7552 enum SQLITE_STATUS_SCRATCH_USED = 3; /* NOT USED */
7553 enum SQLITE_STATUS_SCRATCH_OVERFLOW = 4; /* NOT USED */
7554 enum SQLITE_STATUS_MALLOC_SIZE = 5;
7555 enum SQLITE_STATUS_PARSER_STACK = 6;
7556 enum SQLITE_STATUS_PAGECACHE_SIZE = 7;
7557 enum SQLITE_STATUS_SCRATCH_SIZE = 8; /* NOT USED */
7558 enum SQLITE_STATUS_MALLOC_COUNT = 9;
7559 
7560 /*
7561 ** CAPI3REF: Database Connection Status
7562 ** METHOD: sqlite3
7563 **
7564 ** ^This interface is used to retrieve runtime status information
7565 ** about a single [database connection].  ^The first argument is the
7566 ** database connection object to be interrogated.  ^The second argument
7567 ** is an integer constant, taken from the set of
7568 ** [SQLITE_DBSTATUS options], that
7569 ** determines the parameter to interrogate.  The set of
7570 ** [SQLITE_DBSTATUS options] is likely
7571 ** to grow in future releases of SQLite.
7572 **
7573 ** ^The current value of the requested parameter is written into *pCur
7574 ** and the highest instantaneous value is written into *pHiwtr.  ^If
7575 ** the resetFlg is true, then the highest instantaneous value is
7576 ** reset back down to the current value.
7577 **
7578 ** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a
7579 ** non-zero [error code] on failure.
7580 **
7581 ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
7582 */
7583 int sqlite3_db_status(sqlite3*, int op, int* pCur, int* pHiwtr, int resetFlg);
7584 
7585 /*
7586 ** CAPI3REF: Status Parameters for database connections
7587 ** KEYWORDS: {SQLITE_DBSTATUS options}
7588 **
7589 ** These constants are the available integer "verbs" that can be passed as
7590 ** the second argument to the [sqlite3_db_status()] interface.
7591 **
7592 ** New verbs may be added in future releases of SQLite. Existing verbs
7593 ** might be discontinued. Applications should check the return code from
7594 ** [sqlite3_db_status()] to make sure that the call worked.
7595 ** The [sqlite3_db_status()] interface will return a non-zero error code
7596 ** if a discontinued or unsupported verb is invoked.
7597 **
7598 ** <dl>
7599 ** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
7600 ** <dd>This parameter returns the number of lookaside memory slots currently
7601 ** checked out.</dd>)^
7602 **
7603 ** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
7604 ** <dd>This parameter returns the number malloc attempts that were
7605 ** satisfied using lookaside memory. Only the high-water value is meaningful;
7606 ** the current value is always zero.)^
7607 **
7608 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
7609 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
7610 ** <dd>This parameter returns the number malloc attempts that might have
7611 ** been satisfied using lookaside memory but failed due to the amount of
7612 ** memory requested being larger than the lookaside slot size.
7613 ** Only the high-water value is meaningful;
7614 ** the current value is always zero.)^
7615 **
7616 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]]
7617 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
7618 ** <dd>This parameter returns the number malloc attempts that might have
7619 ** been satisfied using lookaside memory but failed due to all lookaside
7620 ** memory already being in use.
7621 ** Only the high-water value is meaningful;
7622 ** the current value is always zero.)^
7623 **
7624 ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
7625 ** <dd>This parameter returns the approximate number of bytes of heap
7626 ** memory used by all pager caches associated with the database connection.)^
7627 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
7628 **
7629 ** [[SQLITE_DBSTATUS_CACHE_USED_SHARED]]
7630 ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED_SHARED</dt>
7631 ** <dd>This parameter is similar to DBSTATUS_CACHE_USED, except that if a
7632 ** pager cache is shared between two or more connections the bytes of heap
7633 ** memory used by that pager cache is divided evenly between the attached
7634 ** connections.)^  In other words, if none of the pager caches associated
7635 ** with the database connection are shared, this request returns the same
7636 ** value as DBSTATUS_CACHE_USED. Or, if one or more or the pager caches are
7637 ** shared, the value returned by this call will be smaller than that returned
7638 ** by DBSTATUS_CACHE_USED. ^The highwater mark associated with
7639 ** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0.
7640 **
7641 ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
7642 ** <dd>This parameter returns the approximate number of bytes of heap
7643 ** memory used to store the schema for all databases associated
7644 ** with the connection - main, temp, and any [ATTACH]-ed databases.)^
7645 ** ^The full amount of memory used by the schemas is reported, even if the
7646 ** schema memory is shared with other database connections due to
7647 ** [shared cache mode] being enabled.
7648 ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
7649 **
7650 ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
7651 ** <dd>This parameter returns the approximate number of bytes of heap
7652 ** and lookaside memory used by all prepared statements associated with
7653 ** the database connection.)^
7654 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
7655 ** </dd>
7656 **
7657 ** [[SQLITE_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE_DBSTATUS_CACHE_HIT</dt>
7658 ** <dd>This parameter returns the number of pager cache hits that have
7659 ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_HIT
7660 ** is always 0.
7661 ** </dd>
7662 **
7663 ** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt>
7664 ** <dd>This parameter returns the number of pager cache misses that have
7665 ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS
7666 ** is always 0.
7667 ** </dd>
7668 **
7669 ** [[SQLITE_DBSTATUS_CACHE_WRITE]] ^(<dt>SQLITE_DBSTATUS_CACHE_WRITE</dt>
7670 ** <dd>This parameter returns the number of dirty cache entries that have
7671 ** been written to disk. Specifically, the number of pages written to the
7672 ** wal file in wal mode databases, or the number of pages written to the
7673 ** database file in rollback mode databases. Any pages written as part of
7674 ** transaction rollback or database recovery operations are not included.
7675 ** If an IO or other error occurs while writing a page to disk, the effect
7676 ** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The
7677 ** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0.
7678 ** </dd>
7679 **
7680 ** [[SQLITE_DBSTATUS_CACHE_SPILL]] ^(<dt>SQLITE_DBSTATUS_CACHE_SPILL</dt>
7681 ** <dd>This parameter returns the number of dirty cache entries that have
7682 ** been written to disk in the middle of a transaction due to the page
7683 ** cache overflowing. Transactions are more efficient if they are written
7684 ** to disk all at once. When pages spill mid-transaction, that introduces
7685 ** additional overhead. This parameter can be used help identify
7686 ** inefficiencies that can be resolve by increasing the cache size.
7687 ** </dd>
7688 **
7689 ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
7690 ** <dd>This parameter returns zero for the current value if and only if
7691 ** all foreign key constraints (deferred or immediate) have been
7692 ** resolved.)^  ^The highwater mark is always 0.
7693 ** </dd>
7694 ** </dl>
7695 */
7696 enum SQLITE_DBSTATUS_LOOKASIDE_USED = 0;
7697 enum SQLITE_DBSTATUS_CACHE_USED = 1;
7698 enum SQLITE_DBSTATUS_SCHEMA_USED = 2;
7699 enum SQLITE_DBSTATUS_STMT_USED = 3;
7700 enum SQLITE_DBSTATUS_LOOKASIDE_HIT = 4;
7701 enum SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE = 5;
7702 enum SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL = 6;
7703 enum SQLITE_DBSTATUS_CACHE_HIT = 7;
7704 enum SQLITE_DBSTATUS_CACHE_MISS = 8;
7705 enum SQLITE_DBSTATUS_CACHE_WRITE = 9;
7706 enum SQLITE_DBSTATUS_DEFERRED_FKS = 10;
7707 enum SQLITE_DBSTATUS_CACHE_USED_SHARED = 11;
7708 enum SQLITE_DBSTATUS_CACHE_SPILL = 12;
7709 enum SQLITE_DBSTATUS_MAX = 12; /* Largest defined DBSTATUS */
7710 
7711 /*
7712 ** CAPI3REF: Prepared Statement Status
7713 ** METHOD: sqlite3_stmt
7714 **
7715 ** ^(Each prepared statement maintains various
7716 ** [SQLITE_STMTSTATUS counters] that measure the number
7717 ** of times it has performed specific operations.)^  These counters can
7718 ** be used to monitor the performance characteristics of the prepared
7719 ** statements.  For example, if the number of table steps greatly exceeds
7720 ** the number of table searches or result rows, that would tend to indicate
7721 ** that the prepared statement is using a full table scan rather than
7722 ** an index.
7723 **
7724 ** ^(This interface is used to retrieve and reset counter values from
7725 ** a [prepared statement].  The first argument is the prepared statement
7726 ** object to be interrogated.  The second argument
7727 ** is an integer code for a specific [SQLITE_STMTSTATUS counter]
7728 ** to be interrogated.)^
7729 ** ^The current value of the requested counter is returned.
7730 ** ^If the resetFlg is true, then the counter is reset to zero after this
7731 ** interface call returns.
7732 **
7733 ** See also: [sqlite3_status()] and [sqlite3_db_status()].
7734 */
7735 int sqlite3_stmt_status(sqlite3_stmt*, int op, int resetFlg);
7736 
7737 /*
7738 ** CAPI3REF: Status Parameters for prepared statements
7739 ** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters}
7740 **
7741 ** These preprocessor macros define integer codes that name counter
7742 ** values associated with the [sqlite3_stmt_status()] interface.
7743 ** The meanings of the various counters are as follows:
7744 **
7745 ** <dl>
7746 ** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
7747 ** <dd>^This is the number of times that SQLite has stepped forward in
7748 ** a table as part of a full table scan.  Large numbers for this counter
7749 ** may indicate opportunities for performance improvement through
7750 ** careful use of indices.</dd>
7751 **
7752 ** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt>
7753 ** <dd>^This is the number of sort operations that have occurred.
7754 ** A non-zero value in this counter may indicate an opportunity to
7755 ** improvement performance through careful use of indices.</dd>
7756 **
7757 ** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
7758 ** <dd>^This is the number of rows inserted into transient indices that
7759 ** were created automatically in order to help joins run faster.
7760 ** A non-zero value in this counter may indicate an opportunity to
7761 ** improvement performance by adding permanent indices that do not
7762 ** need to be reinitialized each time the statement is run.</dd>
7763 **
7764 ** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>
7765 ** <dd>^This is the number of virtual machine operations executed
7766 ** by the prepared statement if that number is less than or equal
7767 ** to 2147483647.  The number of virtual machine operations can be
7768 ** used as a proxy for the total work done by the prepared statement.
7769 ** If the number of virtual machine operations exceeds 2147483647
7770 ** then the value returned by this statement status code is undefined.
7771 **
7772 ** [[SQLITE_STMTSTATUS_REPREPARE]] <dt>SQLITE_STMTSTATUS_REPREPARE</dt>
7773 ** <dd>^This is the number of times that the prepare statement has been
7774 ** automatically regenerated due to schema changes or change to
7775 ** [bound parameters] that might affect the query plan.
7776 **
7777 ** [[SQLITE_STMTSTATUS_RUN]] <dt>SQLITE_STMTSTATUS_RUN</dt>
7778 ** <dd>^This is the number of times that the prepared statement has
7779 ** been run.  A single "run" for the purposes of this counter is one
7780 ** or more calls to [sqlite3_step()] followed by a call to [sqlite3_reset()].
7781 ** The counter is incremented on the first [sqlite3_step()] call of each
7782 ** cycle.
7783 **
7784 ** [[SQLITE_STMTSTATUS_MEMUSED]] <dt>SQLITE_STMTSTATUS_MEMUSED</dt>
7785 ** <dd>^This is the approximate number of bytes of heap memory
7786 ** used to store the prepared statement.  ^This value is not actually
7787 ** a counter, and so the resetFlg parameter to sqlite3_stmt_status()
7788 ** is ignored when the opcode is SQLITE_STMTSTATUS_MEMUSED.
7789 ** </dd>
7790 ** </dl>
7791 */
7792 enum SQLITE_STMTSTATUS_FULLSCAN_STEP = 1;
7793 enum SQLITE_STMTSTATUS_SORT = 2;
7794 enum SQLITE_STMTSTATUS_AUTOINDEX = 3;
7795 enum SQLITE_STMTSTATUS_VM_STEP = 4;
7796 enum SQLITE_STMTSTATUS_REPREPARE = 5;
7797 enum SQLITE_STMTSTATUS_RUN = 6;
7798 enum SQLITE_STMTSTATUS_MEMUSED = 99;
7799 
7800 /*
7801 ** CAPI3REF: Custom Page Cache Object
7802 **
7803 ** The sqlite3_pcache type is opaque.  It is implemented by
7804 ** the pluggable module.  The SQLite core has no knowledge of
7805 ** its size or internal structure and never deals with the
7806 ** sqlite3_pcache object except by holding and passing pointers
7807 ** to the object.
7808 **
7809 ** See [sqlite3_pcache_methods2] for additional information.
7810 */
7811 struct sqlite3_pcache;
7812 
7813 /*
7814 ** CAPI3REF: Custom Page Cache Object
7815 **
7816 ** The sqlite3_pcache_page object represents a single page in the
7817 ** page cache.  The page cache will allocate instances of this
7818 ** object.  Various methods of the page cache use pointers to instances
7819 ** of this object as parameters or as their return value.
7820 **
7821 ** See [sqlite3_pcache_methods2] for additional information.
7822 */
7823 struct sqlite3_pcache_page
7824 {
7825     void* pBuf; /* The content of the page */
7826     void* pExtra; /* Extra information associated with the page */
7827 }
7828 
7829 /*
7830 ** CAPI3REF: Application Defined Page Cache.
7831 ** KEYWORDS: {page cache}
7832 **
7833 ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE2], ...) interface can
7834 ** register an alternative page cache implementation by passing in an
7835 ** instance of the sqlite3_pcache_methods2 structure.)^
7836 ** In many applications, most of the heap memory allocated by
7837 ** SQLite is used for the page cache.
7838 ** By implementing a
7839 ** custom page cache using this API, an application can better control
7840 ** the amount of memory consumed by SQLite, the way in which
7841 ** that memory is allocated and released, and the policies used to
7842 ** determine exactly which parts of a database file are cached and for
7843 ** how long.
7844 **
7845 ** The alternative page cache mechanism is an
7846 ** extreme measure that is only needed by the most demanding applications.
7847 ** The built-in page cache is recommended for most uses.
7848 **
7849 ** ^(The contents of the sqlite3_pcache_methods2 structure are copied to an
7850 ** internal buffer by SQLite within the call to [sqlite3_config].  Hence
7851 ** the application may discard the parameter after the call to
7852 ** [sqlite3_config()] returns.)^
7853 **
7854 ** [[the xInit() page cache method]]
7855 ** ^(The xInit() method is called once for each effective
7856 ** call to [sqlite3_initialize()])^
7857 ** (usually only once during the lifetime of the process). ^(The xInit()
7858 ** method is passed a copy of the sqlite3_pcache_methods2.pArg value.)^
7859 ** The intent of the xInit() method is to set up global data structures
7860 ** required by the custom page cache implementation.
7861 ** ^(If the xInit() method is NULL, then the
7862 ** built-in default page cache is used instead of the application defined
7863 ** page cache.)^
7864 **
7865 ** [[the xShutdown() page cache method]]
7866 ** ^The xShutdown() method is called by [sqlite3_shutdown()].
7867 ** It can be used to clean up
7868 ** any outstanding resources before process shutdown, if required.
7869 ** ^The xShutdown() method may be NULL.
7870 **
7871 ** ^SQLite automatically serializes calls to the xInit method,
7872 ** so the xInit method need not be threadsafe.  ^The
7873 ** xShutdown method is only called from [sqlite3_shutdown()] so it does
7874 ** not need to be threadsafe either.  All other methods must be threadsafe
7875 ** in multithreaded applications.
7876 **
7877 ** ^SQLite will never invoke xInit() more than once without an intervening
7878 ** call to xShutdown().
7879 **
7880 ** [[the xCreate() page cache methods]]
7881 ** ^SQLite invokes the xCreate() method to construct a new cache instance.
7882 ** SQLite will typically create one cache instance for each open database file,
7883 ** though this is not guaranteed. ^The
7884 ** first parameter, szPage, is the size in bytes of the pages that must
7885 ** be allocated by the cache.  ^szPage will always a power of two.  ^The
7886 ** second parameter szExtra is a number of bytes of extra storage
7887 ** associated with each page cache entry.  ^The szExtra parameter will
7888 ** a number less than 250.  SQLite will use the
7889 ** extra szExtra bytes on each page to store metadata about the underlying
7890 ** database page on disk.  The value passed into szExtra depends
7891 ** on the SQLite version, the target platform, and how SQLite was compiled.
7892 ** ^The third argument to xCreate(), bPurgeable, is true if the cache being
7893 ** created will be used to cache database pages of a file stored on disk, or
7894 ** false if it is used for an in-memory database. The cache implementation
7895 ** does not have to do anything special based with the value of bPurgeable;
7896 ** it is purely advisory.  ^On a cache where bPurgeable is false, SQLite will
7897 ** never invoke xUnpin() except to deliberately delete a page.
7898 ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
7899 ** false will always have the "discard" flag set to true.
7900 ** ^Hence, a cache created with bPurgeable false will
7901 ** never contain any unpinned pages.
7902 **
7903 ** [[the xCachesize() page cache method]]
7904 ** ^(The xCachesize() method may be called at any time by SQLite to set the
7905 ** suggested maximum cache-size (number of pages stored by) the cache
7906 ** instance passed as the first argument. This is the value configured using
7907 ** the SQLite "[PRAGMA cache_size]" command.)^  As with the bPurgeable
7908 ** parameter, the implementation is not required to do anything with this
7909 ** value; it is advisory only.
7910 **
7911 ** [[the xPagecount() page cache methods]]
7912 ** The xPagecount() method must return the number of pages currently
7913 ** stored in the cache, both pinned and unpinned.
7914 **
7915 ** [[the xFetch() page cache methods]]
7916 ** The xFetch() method locates a page in the cache and returns a pointer to
7917 ** an sqlite3_pcache_page object associated with that page, or a NULL pointer.
7918 ** The pBuf element of the returned sqlite3_pcache_page object will be a
7919 ** pointer to a buffer of szPage bytes used to store the content of a
7920 ** single database page.  The pExtra element of sqlite3_pcache_page will be
7921 ** a pointer to the szExtra bytes of extra storage that SQLite has requested
7922 ** for each entry in the page cache.
7923 **
7924 ** The page to be fetched is determined by the key. ^The minimum key value
7925 ** is 1.  After it has been retrieved using xFetch, the page is considered
7926 ** to be "pinned".
7927 **
7928 ** If the requested page is already in the page cache, then the page cache
7929 ** implementation must return a pointer to the page buffer with its content
7930 ** intact.  If the requested page is not already in the cache, then the
7931 ** cache implementation should use the value of the createFlag
7932 ** parameter to help it determined what action to take:
7933 **
7934 ** <table border=1 width=85% align=center>
7935 ** <tr><th> createFlag <th> Behavior when page is not already in cache
7936 ** <tr><td> 0 <td> Do not allocate a new page.  Return NULL.
7937 ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
7938 **                 Otherwise return NULL.
7939 ** <tr><td> 2 <td> Make every effort to allocate a new page.  Only return
7940 **                 NULL if allocating a new page is effectively impossible.
7941 ** </table>
7942 **
7943 ** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1.  SQLite
7944 ** will only use a createFlag of 2 after a prior call with a createFlag of 1
7945 ** failed.)^  In between the to xFetch() calls, SQLite may
7946 ** attempt to unpin one or more cache pages by spilling the content of
7947 ** pinned pages to disk and synching the operating system disk cache.
7948 **
7949 ** [[the xUnpin() page cache method]]
7950 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
7951 ** as its second argument.  If the third parameter, discard, is non-zero,
7952 ** then the page must be evicted from the cache.
7953 ** ^If the discard parameter is
7954 ** zero, then the page may be discarded or retained at the discretion of
7955 ** page cache implementation. ^The page cache implementation
7956 ** may choose to evict unpinned pages at any time.
7957 **
7958 ** The cache must not perform any reference counting. A single
7959 ** call to xUnpin() unpins the page regardless of the number of prior calls
7960 ** to xFetch().
7961 **
7962 ** [[the xRekey() page cache methods]]
7963 ** The xRekey() method is used to change the key value associated with the
7964 ** page passed as the second argument. If the cache
7965 ** previously contains an entry associated with newKey, it must be
7966 ** discarded. ^Any prior cache entry associated with newKey is guaranteed not
7967 ** to be pinned.
7968 **
7969 ** When SQLite calls the xTruncate() method, the cache must discard all
7970 ** existing cache entries with page numbers (keys) greater than or equal
7971 ** to the value of the iLimit parameter passed to xTruncate(). If any
7972 ** of these pages are pinned, they are implicitly unpinned, meaning that
7973 ** they can be safely discarded.
7974 **
7975 ** [[the xDestroy() page cache method]]
7976 ** ^The xDestroy() method is used to delete a cache allocated by xCreate().
7977 ** All resources associated with the specified cache should be freed. ^After
7978 ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
7979 ** handle invalid, and will not use it with any other sqlite3_pcache_methods2
7980 ** functions.
7981 **
7982 ** [[the xShrink() page cache method]]
7983 ** ^SQLite invokes the xShrink() method when it wants the page cache to
7984 ** free up as much of heap memory as possible.  The page cache implementation
7985 ** is not obligated to free any memory, but well-behaved implementations should
7986 ** do their best.
7987 */
7988 struct sqlite3_pcache_methods2
7989 {
7990     int iVersion;
7991     void* pArg;
7992     int function(void*) xInit;
7993     void function(void*) xShutdown;
7994     sqlite3_pcache* function(int szPage, int szExtra, int bPurgeable) xCreate;
7995     void function(sqlite3_pcache*, int nCachesize) xCachesize;
7996     int function(sqlite3_pcache*) xPagecount;
7997     sqlite3_pcache_page* function(sqlite3_pcache*, uint key, int createFlag) xFetch;
7998     void function(sqlite3_pcache*, sqlite3_pcache_page*, int discard) xUnpin;
7999     void function(sqlite3_pcache*, sqlite3_pcache_page*, uint oldKey, uint newKey) xRekey;
8000     void function(sqlite3_pcache*, uint iLimit) xTruncate;
8001     void function(sqlite3_pcache*) xDestroy;
8002     void function(sqlite3_pcache*) xShrink;
8003 }
8004 
8005 /*
8006 ** This is the obsolete pcache_methods object that has now been replaced
8007 ** by sqlite3_pcache_methods2.  This object is not used by SQLite.  It is
8008 ** retained in the header file for backwards compatibility only.
8009 */
8010 struct sqlite3_pcache_methods
8011 {
8012     void* pArg;
8013     int function(void*) xInit;
8014     void function(void*) xShutdown;
8015     sqlite3_pcache* function(int szPage, int bPurgeable) xCreate;
8016     void function(sqlite3_pcache*, int nCachesize) xCachesize;
8017     int function(sqlite3_pcache*) xPagecount;
8018     void* function(sqlite3_pcache*, uint key, int createFlag) xFetch;
8019     void function(sqlite3_pcache*, void*, int discard) xUnpin;
8020     void function(sqlite3_pcache*, void*, uint oldKey, uint newKey) xRekey;
8021     void function(sqlite3_pcache*, uint iLimit) xTruncate;
8022     void function(sqlite3_pcache*) xDestroy;
8023 }
8024 
8025 /*
8026 ** CAPI3REF: Online Backup Object
8027 **
8028 ** The sqlite3_backup object records state information about an ongoing
8029 ** online backup operation.  ^The sqlite3_backup object is created by
8030 ** a call to [sqlite3_backup_init()] and is destroyed by a call to
8031 ** [sqlite3_backup_finish()].
8032 **
8033 ** See Also: [Using the SQLite Online Backup API]
8034 */
8035 struct sqlite3_backup;
8036 
8037 /*
8038 ** CAPI3REF: Online Backup API.
8039 **
8040 ** The backup API copies the content of one database into another.
8041 ** It is useful either for creating backups of databases or
8042 ** for copying in-memory databases to or from persistent files.
8043 **
8044 ** See Also: [Using the SQLite Online Backup API]
8045 **
8046 ** ^SQLite holds a write transaction open on the destination database file
8047 ** for the duration of the backup operation.
8048 ** ^The source database is read-locked only while it is being read;
8049 ** it is not locked continuously for the entire backup operation.
8050 ** ^Thus, the backup may be performed on a live source database without
8051 ** preventing other database connections from
8052 ** reading or writing to the source database while the backup is underway.
8053 **
8054 ** ^(To perform a backup operation:
8055 **   <ol>
8056 **     <li><b>sqlite3_backup_init()</b> is called once to initialize the
8057 **         backup,
8058 **     <li><b>sqlite3_backup_step()</b> is called one or more times to transfer
8059 **         the data between the two databases, and finally
8060 **     <li><b>sqlite3_backup_finish()</b> is called to release all resources
8061 **         associated with the backup operation.
8062 **   </ol>)^
8063 ** There should be exactly one call to sqlite3_backup_finish() for each
8064 ** successful call to sqlite3_backup_init().
8065 **
8066 ** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b>
8067 **
8068 ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the
8069 ** [database connection] associated with the destination database
8070 ** and the database name, respectively.
8071 ** ^The database name is "main" for the main database, "temp" for the
8072 ** temporary database, or the name specified after the AS keyword in
8073 ** an [ATTACH] statement for an attached database.
8074 ** ^The S and M arguments passed to
8075 ** sqlite3_backup_init(D,N,S,M) identify the [database connection]
8076 ** and database name of the source database, respectively.
8077 ** ^The source and destination [database connections] (parameters S and D)
8078 ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
8079 ** an error.
8080 **
8081 ** ^A call to sqlite3_backup_init() will fail, returning NULL, if
8082 ** there is already a read or read-write transaction open on the
8083 ** destination database.
8084 **
8085 ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
8086 ** returned and an error code and error message are stored in the
8087 ** destination [database connection] D.
8088 ** ^The error code and message for the failed call to sqlite3_backup_init()
8089 ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
8090 ** [sqlite3_errmsg16()] functions.
8091 ** ^A successful call to sqlite3_backup_init() returns a pointer to an
8092 ** [sqlite3_backup] object.
8093 ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and
8094 ** sqlite3_backup_finish() functions to perform the specified backup
8095 ** operation.
8096 **
8097 ** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b>
8098 **
8099 ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
8100 ** the source and destination databases specified by [sqlite3_backup] object B.
8101 ** ^If N is negative, all remaining source pages are copied.
8102 ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
8103 ** are still more pages to be copied, then the function returns [SQLITE_OK].
8104 ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
8105 ** from source to destination, then it returns [SQLITE_DONE].
8106 ** ^If an error occurs while running sqlite3_backup_step(B,N),
8107 ** then an [error code] is returned. ^As well as [SQLITE_OK] and
8108 ** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
8109 ** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an
8110 ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code.
8111 **
8112 ** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
8113 ** <ol>
8114 ** <li> the destination database was opened read-only, or
8115 ** <li> the destination database is using write-ahead-log journaling
8116 ** and the destination and source page sizes differ, or
8117 ** <li> the destination database is an in-memory database and the
8118 ** destination and source page sizes differ.
8119 ** </ol>)^
8120 **
8121 ** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
8122 ** the [sqlite3_busy_handler | busy-handler function]
8123 ** is invoked (if one is specified). ^If the
8124 ** busy-handler returns non-zero before the lock is available, then
8125 ** [SQLITE_BUSY] is returned to the caller. ^In this case the call to
8126 ** sqlite3_backup_step() can be retried later. ^If the source
8127 ** [database connection]
8128 ** is being used to write to the source database when sqlite3_backup_step()
8129 ** is called, then [SQLITE_LOCKED] is returned immediately. ^Again, in this
8130 ** case the call to sqlite3_backup_step() can be retried later on. ^(If
8131 ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or
8132 ** [SQLITE_READONLY] is returned, then
8133 ** there is no point in retrying the call to sqlite3_backup_step(). These
8134 ** errors are considered fatal.)^  The application must accept
8135 ** that the backup operation has failed and pass the backup operation handle
8136 ** to the sqlite3_backup_finish() to release associated resources.
8137 **
8138 ** ^The first call to sqlite3_backup_step() obtains an exclusive lock
8139 ** on the destination file. ^The exclusive lock is not released until either
8140 ** sqlite3_backup_finish() is called or the backup operation is complete
8141 ** and sqlite3_backup_step() returns [SQLITE_DONE].  ^Every call to
8142 ** sqlite3_backup_step() obtains a [shared lock] on the source database that
8143 ** lasts for the duration of the sqlite3_backup_step() call.
8144 ** ^Because the source database is not locked between calls to
8145 ** sqlite3_backup_step(), the source database may be modified mid-way
8146 ** through the backup process.  ^If the source database is modified by an
8147 ** external process or via a database connection other than the one being
8148 ** used by the backup operation, then the backup will be automatically
8149 ** restarted by the next call to sqlite3_backup_step(). ^If the source
8150 ** database is modified by the using the same database connection as is used
8151 ** by the backup operation, then the backup database is automatically
8152 ** updated at the same time.
8153 **
8154 ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
8155 **
8156 ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the
8157 ** application wishes to abandon the backup operation, the application
8158 ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish().
8159 ** ^The sqlite3_backup_finish() interfaces releases all
8160 ** resources associated with the [sqlite3_backup] object.
8161 ** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any
8162 ** active write-transaction on the destination database is rolled back.
8163 ** The [sqlite3_backup] object is invalid
8164 ** and may not be used following a call to sqlite3_backup_finish().
8165 **
8166 ** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
8167 ** sqlite3_backup_step() errors occurred, regardless or whether or not
8168 ** sqlite3_backup_step() completed.
8169 ** ^If an out-of-memory condition or IO error occurred during any prior
8170 ** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
8171 ** sqlite3_backup_finish() returns the corresponding [error code].
8172 **
8173 ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
8174 ** is not a permanent error and does not affect the return value of
8175 ** sqlite3_backup_finish().
8176 **
8177 ** [[sqlite3_backup_remaining()]] [[sqlite3_backup_pagecount()]]
8178 ** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b>
8179 **
8180 ** ^The sqlite3_backup_remaining() routine returns the number of pages still
8181 ** to be backed up at the conclusion of the most recent sqlite3_backup_step().
8182 ** ^The sqlite3_backup_pagecount() routine returns the total number of pages
8183 ** in the source database at the conclusion of the most recent
8184 ** sqlite3_backup_step().
8185 ** ^(The values returned by these functions are only updated by
8186 ** sqlite3_backup_step(). If the source database is modified in a way that
8187 ** changes the size of the source database or the number of pages remaining,
8188 ** those changes are not reflected in the output of sqlite3_backup_pagecount()
8189 ** and sqlite3_backup_remaining() until after the next
8190 ** sqlite3_backup_step().)^
8191 **
8192 ** <b>Concurrent Usage of Database Handles</b>
8193 **
8194 ** ^The source [database connection] may be used by the application for other
8195 ** purposes while a backup operation is underway or being initialized.
8196 ** ^If SQLite is compiled and configured to support threadsafe database
8197 ** connections, then the source database connection may be used concurrently
8198 ** from within other threads.
8199 **
8200 ** However, the application must guarantee that the destination
8201 ** [database connection] is not passed to any other API (by any thread) after
8202 ** sqlite3_backup_init() is called and before the corresponding call to
8203 ** sqlite3_backup_finish().  SQLite does not currently check to see
8204 ** if the application incorrectly accesses the destination [database connection]
8205 ** and so no error code is reported, but the operations may malfunction
8206 ** nevertheless.  Use of the destination database connection while a
8207 ** backup is in progress might also also cause a mutex deadlock.
8208 **
8209 ** If running in [shared cache mode], the application must
8210 ** guarantee that the shared cache used by the destination database
8211 ** is not accessed while the backup is running. In practice this means
8212 ** that the application must guarantee that the disk file being
8213 ** backed up to is not accessed by any connection within the process,
8214 ** not just the specific connection that was passed to sqlite3_backup_init().
8215 **
8216 ** The [sqlite3_backup] object itself is partially threadsafe. Multiple
8217 ** threads may safely make multiple concurrent calls to sqlite3_backup_step().
8218 ** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount()
8219 ** APIs are not strictly speaking threadsafe. If they are invoked at the
8220 ** same time as another thread is invoking sqlite3_backup_step() it is
8221 ** possible that they return invalid values.
8222 */
8223 /* Destination database handle */
8224 /* Destination database name */
8225 /* Source database handle */
8226 /* Source database name */
8227 sqlite3_backup* sqlite3_backup_init(
8228     sqlite3* pDest,
8229     const(char)* zDestName,
8230     sqlite3* pSource,
8231     const(char)* zSourceName);
8232 int sqlite3_backup_step(sqlite3_backup* p, int nPage);
8233 int sqlite3_backup_finish(sqlite3_backup* p);
8234 int sqlite3_backup_remaining(sqlite3_backup* p);
8235 int sqlite3_backup_pagecount(sqlite3_backup* p);
8236 
8237 /*
8238 ** CAPI3REF: Unlock Notification
8239 ** METHOD: sqlite3
8240 **
8241 ** ^When running in shared-cache mode, a database operation may fail with
8242 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
8243 ** individual tables within the shared-cache cannot be obtained. See
8244 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
8245 ** ^This API may be used to register a callback that SQLite will invoke
8246 ** when the connection currently holding the required lock relinquishes it.
8247 ** ^This API is only available if the library was compiled with the
8248 ** [SQLITE_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined.
8249 **
8250 ** See Also: [Using the SQLite Unlock Notification Feature].
8251 **
8252 ** ^Shared-cache locks are released when a database connection concludes
8253 ** its current transaction, either by committing it or rolling it back.
8254 **
8255 ** ^When a connection (known as the blocked connection) fails to obtain a
8256 ** shared-cache lock and SQLITE_LOCKED is returned to the caller, the
8257 ** identity of the database connection (the blocking connection) that
8258 ** has locked the required resource is stored internally. ^After an
8259 ** application receives an SQLITE_LOCKED error, it may call the
8260 ** sqlite3_unlock_notify() method with the blocked connection handle as
8261 ** the first argument to register for a callback that will be invoked
8262 ** when the blocking connections current transaction is concluded. ^The
8263 ** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
8264 ** call that concludes the blocking connections transaction.
8265 **
8266 ** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
8267 ** there is a chance that the blocking connection will have already
8268 ** concluded its transaction by the time sqlite3_unlock_notify() is invoked.
8269 ** If this happens, then the specified callback is invoked immediately,
8270 ** from within the call to sqlite3_unlock_notify().)^
8271 **
8272 ** ^If the blocked connection is attempting to obtain a write-lock on a
8273 ** shared-cache table, and more than one other connection currently holds
8274 ** a read-lock on the same table, then SQLite arbitrarily selects one of
8275 ** the other connections to use as the blocking connection.
8276 **
8277 ** ^(There may be at most one unlock-notify callback registered by a
8278 ** blocked connection. If sqlite3_unlock_notify() is called when the
8279 ** blocked connection already has a registered unlock-notify callback,
8280 ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
8281 ** called with a NULL pointer as its second argument, then any existing
8282 ** unlock-notify callback is canceled. ^The blocked connections
8283 ** unlock-notify callback may also be canceled by closing the blocked
8284 ** connection using [sqlite3_close()].
8285 **
8286 ** The unlock-notify callback is not reentrant. If an application invokes
8287 ** any sqlite3_xxx API functions from within an unlock-notify callback, a
8288 ** crash or deadlock may be the result.
8289 **
8290 ** ^Unless deadlock is detected (see below), sqlite3_unlock_notify() always
8291 ** returns SQLITE_OK.
8292 **
8293 ** <b>Callback Invocation Details</b>
8294 **
8295 ** When an unlock-notify callback is registered, the application provides a
8296 ** single void* pointer that is passed to the callback when it is invoked.
8297 ** However, the signature of the callback function allows SQLite to pass
8298 ** it an array of void* context pointers. The first argument passed to
8299 ** an unlock-notify callback is a pointer to an array of void* pointers,
8300 ** and the second is the number of entries in the array.
8301 **
8302 ** When a blocking connections transaction is concluded, there may be
8303 ** more than one blocked connection that has registered for an unlock-notify
8304 ** callback. ^If two or more such blocked connections have specified the
8305 ** same callback function, then instead of invoking the callback function
8306 ** multiple times, it is invoked once with the set of void* context pointers
8307 ** specified by the blocked connections bundled together into an array.
8308 ** This gives the application an opportunity to prioritize any actions
8309 ** related to the set of unblocked database connections.
8310 **
8311 ** <b>Deadlock Detection</b>
8312 **
8313 ** Assuming that after registering for an unlock-notify callback a
8314 ** database waits for the callback to be issued before taking any further
8315 ** action (a reasonable assumption), then using this API may cause the
8316 ** application to deadlock. For example, if connection X is waiting for
8317 ** connection Y's transaction to be concluded, and similarly connection
8318 ** Y is waiting on connection X's transaction, then neither connection
8319 ** will proceed and the system may remain deadlocked indefinitely.
8320 **
8321 ** To avoid this scenario, the sqlite3_unlock_notify() performs deadlock
8322 ** detection. ^If a given call to sqlite3_unlock_notify() would put the
8323 ** system in a deadlocked state, then SQLITE_LOCKED is returned and no
8324 ** unlock-notify callback is registered. The system is said to be in
8325 ** a deadlocked state if connection A has registered for an unlock-notify
8326 ** callback on the conclusion of connection B's transaction, and connection
8327 ** B has itself registered for an unlock-notify callback when connection
8328 ** A's transaction is concluded. ^Indirect deadlock is also detected, so
8329 ** the system is also considered to be deadlocked if connection B has
8330 ** registered for an unlock-notify callback on the conclusion of connection
8331 ** C's transaction, where connection C is waiting on connection A. ^Any
8332 ** number of levels of indirection are allowed.
8333 **
8334 ** <b>The "DROP TABLE" Exception</b>
8335 **
8336 ** When a call to [sqlite3_step()] returns SQLITE_LOCKED, it is almost
8337 ** always appropriate to call sqlite3_unlock_notify(). There is however,
8338 ** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement,
8339 ** SQLite checks if there are any currently executing SELECT statements
8340 ** that belong to the same connection. If there are, SQLITE_LOCKED is
8341 ** returned. In this case there is no "blocking connection", so invoking
8342 ** sqlite3_unlock_notify() results in the unlock-notify callback being
8343 ** invoked immediately. If the application then re-attempts the "DROP TABLE"
8344 ** or "DROP INDEX" query, an infinite loop might be the result.
8345 **
8346 ** One way around this problem is to check the extended error code returned
8347 ** by an sqlite3_step() call. ^(If there is a blocking connection, then the
8348 ** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in
8349 ** the special "DROP TABLE/INDEX" case, the extended error code is just
8350 ** SQLITE_LOCKED.)^
8351 */
8352 /* Waiting connection */
8353 /* Callback function to invoke */
8354 /* Argument to pass to xNotify */
8355 int sqlite3_unlock_notify(
8356     sqlite3* pBlocked,
8357     void function(void** apArg, int nArg) xNotify,
8358     void* pNotifyArg);
8359 
8360 /*
8361 ** CAPI3REF: String Comparison
8362 **
8363 ** ^The [sqlite3_stricmp()] and [sqlite3_strnicmp()] APIs allow applications
8364 ** and extensions to compare the contents of two buffers containing UTF-8
8365 ** strings in a case-independent fashion, using the same definition of "case
8366 ** independence" that SQLite uses internally when comparing identifiers.
8367 */
8368 int sqlite3_stricmp(const(char)*, const(char)*);
8369 int sqlite3_strnicmp(const(char)*, const(char)*, int);
8370 
8371 /*
8372 ** CAPI3REF: String Globbing
8373 *
8374 ** ^The [sqlite3_strglob(P,X)] interface returns zero if and only if
8375 ** string X matches the [GLOB] pattern P.
8376 ** ^The definition of [GLOB] pattern matching used in
8377 ** [sqlite3_strglob(P,X)] is the same as for the "X GLOB P" operator in the
8378 ** SQL dialect understood by SQLite.  ^The [sqlite3_strglob(P,X)] function
8379 ** is case sensitive.
8380 **
8381 ** Note that this routine returns zero on a match and non-zero if the strings
8382 ** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()].
8383 **
8384 ** See also: [sqlite3_strlike()].
8385 */
8386 int sqlite3_strglob(const(char)* zGlob, const(char)* zStr);
8387 
8388 /*
8389 ** CAPI3REF: String LIKE Matching
8390 *
8391 ** ^The [sqlite3_strlike(P,X,E)] interface returns zero if and only if
8392 ** string X matches the [LIKE] pattern P with escape character E.
8393 ** ^The definition of [LIKE] pattern matching used in
8394 ** [sqlite3_strlike(P,X,E)] is the same as for the "X LIKE P ESCAPE E"
8395 ** operator in the SQL dialect understood by SQLite.  ^For "X LIKE P" without
8396 ** the ESCAPE clause, set the E parameter of [sqlite3_strlike(P,X,E)] to 0.
8397 ** ^As with the LIKE operator, the [sqlite3_strlike(P,X,E)] function is case
8398 ** insensitive - equivalent upper and lower case ASCII characters match
8399 ** one another.
8400 **
8401 ** ^The [sqlite3_strlike(P,X,E)] function matches Unicode characters, though
8402 ** only ASCII characters are case folded.
8403 **
8404 ** Note that this routine returns zero on a match and non-zero if the strings
8405 ** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()].
8406 **
8407 ** See also: [sqlite3_strglob()].
8408 */
8409 int sqlite3_strlike(const(char)* zGlob, const(char)* zStr, uint cEsc);
8410 
8411 /*
8412 ** CAPI3REF: Error Logging Interface
8413 **
8414 ** ^The [sqlite3_log()] interface writes a message into the [error log]
8415 ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
8416 ** ^If logging is enabled, the zFormat string and subsequent arguments are
8417 ** used with [sqlite3_snprintf()] to generate the final output string.
8418 **
8419 ** The sqlite3_log() interface is intended for use by extensions such as
8420 ** virtual tables, collating functions, and SQL functions.  While there is
8421 ** nothing to prevent an application from calling sqlite3_log(), doing so
8422 ** is considered bad form.
8423 **
8424 ** The zFormat string must not be NULL.
8425 **
8426 ** To avoid deadlocks and other threading problems, the sqlite3_log() routine
8427 ** will not use dynamically allocated memory.  The log message is stored in
8428 ** a fixed-length buffer on the stack.  If the log message is longer than
8429 ** a few hundred characters, it will be truncated to the length of the
8430 ** buffer.
8431 */
8432 void sqlite3_log(int iErrCode, const(char)* zFormat, ...);
8433 
8434 /*
8435 ** CAPI3REF: Write-Ahead Log Commit Hook
8436 ** METHOD: sqlite3
8437 **
8438 ** ^The [sqlite3_wal_hook()] function is used to register a callback that
8439 ** is invoked each time data is committed to a database in wal mode.
8440 **
8441 ** ^(The callback is invoked by SQLite after the commit has taken place and
8442 ** the associated write-lock on the database released)^, so the implementation
8443 ** may read, write or [checkpoint] the database as required.
8444 **
8445 ** ^The first parameter passed to the callback function when it is invoked
8446 ** is a copy of the third parameter passed to sqlite3_wal_hook() when
8447 ** registering the callback. ^The second is a copy of the database handle.
8448 ** ^The third parameter is the name of the database that was written to -
8449 ** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter
8450 ** is the number of pages currently in the write-ahead log file,
8451 ** including those that were just committed.
8452 **
8453 ** The callback function should normally return [SQLITE_OK].  ^If an error
8454 ** code is returned, that error will propagate back up through the
8455 ** SQLite code base to cause the statement that provoked the callback
8456 ** to report an error, though the commit will have still occurred. If the
8457 ** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value
8458 ** that does not correspond to any valid SQLite error code, the results
8459 ** are undefined.
8460 **
8461 ** A single database handle may have at most a single write-ahead log callback
8462 ** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any
8463 ** previously registered write-ahead log callback. ^Note that the
8464 ** [sqlite3_wal_autocheckpoint()] interface and the
8465 ** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will
8466 ** overwrite any prior [sqlite3_wal_hook()] settings.
8467 */
8468 void* sqlite3_wal_hook(
8469     sqlite3*,
8470     int function(void*, sqlite3*, const(char)*, int),
8471     void*);
8472 
8473 /*
8474 ** CAPI3REF: Configure an auto-checkpoint
8475 ** METHOD: sqlite3
8476 **
8477 ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
8478 ** [sqlite3_wal_hook()] that causes any database on [database connection] D
8479 ** to automatically [checkpoint]
8480 ** after committing a transaction if there are N or
8481 ** more frames in the [write-ahead log] file.  ^Passing zero or
8482 ** a negative value as the nFrame parameter disables automatic
8483 ** checkpoints entirely.
8484 **
8485 ** ^The callback registered by this function replaces any existing callback
8486 ** registered using [sqlite3_wal_hook()].  ^Likewise, registering a callback
8487 ** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
8488 ** configured by this function.
8489 **
8490 ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
8491 ** from SQL.
8492 **
8493 ** ^Checkpoints initiated by this mechanism are
8494 ** [sqlite3_wal_checkpoint_v2|PASSIVE].
8495 **
8496 ** ^Every new [database connection] defaults to having the auto-checkpoint
8497 ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
8498 ** pages.  The use of this interface
8499 ** is only necessary if the default setting is found to be suboptimal
8500 ** for a particular application.
8501 */
8502 int sqlite3_wal_autocheckpoint(sqlite3* db, int N);
8503 
8504 /*
8505 ** CAPI3REF: Checkpoint a database
8506 ** METHOD: sqlite3
8507 **
8508 ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
8509 ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
8510 **
8511 ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
8512 ** [write-ahead log] for database X on [database connection] D to be
8513 ** transferred into the database file and for the write-ahead log to
8514 ** be reset.  See the [checkpointing] documentation for addition
8515 ** information.
8516 **
8517 ** This interface used to be the only way to cause a checkpoint to
8518 ** occur.  But then the newer and more powerful [sqlite3_wal_checkpoint_v2()]
8519 ** interface was added.  This interface is retained for backwards
8520 ** compatibility and as a convenience for applications that need to manually
8521 ** start a callback but which do not need the full power (and corresponding
8522 ** complication) of [sqlite3_wal_checkpoint_v2()].
8523 */
8524 int sqlite3_wal_checkpoint(sqlite3* db, const(char)* zDb);
8525 
8526 /*
8527 ** CAPI3REF: Checkpoint a database
8528 ** METHOD: sqlite3
8529 **
8530 ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
8531 ** operation on database X of [database connection] D in mode M.  Status
8532 ** information is written back into integers pointed to by L and C.)^
8533 ** ^(The M parameter must be a valid [checkpoint mode]:)^
8534 **
8535 ** <dl>
8536 ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>
8537 **   ^Checkpoint as many frames as possible without waiting for any database
8538 **   readers or writers to finish, then sync the database file if all frames
8539 **   in the log were checkpointed. ^The [busy-handler callback]
8540 **   is never invoked in the SQLITE_CHECKPOINT_PASSIVE mode.
8541 **   ^On the other hand, passive mode might leave the checkpoint unfinished
8542 **   if there are concurrent readers or writers.
8543 **
8544 ** <dt>SQLITE_CHECKPOINT_FULL<dd>
8545 **   ^This mode blocks (it invokes the
8546 **   [sqlite3_busy_handler|busy-handler callback]) until there is no
8547 **   database writer and all readers are reading from the most recent database
8548 **   snapshot. ^It then checkpoints all frames in the log file and syncs the
8549 **   database file. ^This mode blocks new database writers while it is pending,
8550 **   but new database readers are allowed to continue unimpeded.
8551 **
8552 ** <dt>SQLITE_CHECKPOINT_RESTART<dd>
8553 **   ^This mode works the same way as SQLITE_CHECKPOINT_FULL with the addition
8554 **   that after checkpointing the log file it blocks (calls the
8555 **   [busy-handler callback])
8556 **   until all readers are reading from the database file only. ^This ensures
8557 **   that the next writer will restart the log file from the beginning.
8558 **   ^Like SQLITE_CHECKPOINT_FULL, this mode blocks new
8559 **   database writer attempts while it is pending, but does not impede readers.
8560 **
8561 ** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd>
8562 **   ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the
8563 **   addition that it also truncates the log file to zero bytes just prior
8564 **   to a successful return.
8565 ** </dl>
8566 **
8567 ** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in
8568 ** the log file or to -1 if the checkpoint could not run because
8569 ** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not
8570 ** NULL,then *pnCkpt is set to the total number of checkpointed frames in the
8571 ** log file (including any that were already checkpointed before the function
8572 ** was called) or to -1 if the checkpoint could not run due to an error or
8573 ** because the database is not in WAL mode. ^Note that upon successful
8574 ** completion of an SQLITE_CHECKPOINT_TRUNCATE, the log file will have been
8575 ** truncated to zero bytes and so both *pnLog and *pnCkpt will be set to zero.
8576 **
8577 ** ^All calls obtain an exclusive "checkpoint" lock on the database file. ^If
8578 ** any other process is running a checkpoint operation at the same time, the
8579 ** lock cannot be obtained and SQLITE_BUSY is returned. ^Even if there is a
8580 ** busy-handler configured, it will not be invoked in this case.
8581 **
8582 ** ^The SQLITE_CHECKPOINT_FULL, RESTART and TRUNCATE modes also obtain the
8583 ** exclusive "writer" lock on the database file. ^If the writer lock cannot be
8584 ** obtained immediately, and a busy-handler is configured, it is invoked and
8585 ** the writer lock retried until either the busy-handler returns 0 or the lock
8586 ** is successfully obtained. ^The busy-handler is also invoked while waiting for
8587 ** database readers as described above. ^If the busy-handler returns 0 before
8588 ** the writer lock is obtained or while waiting for database readers, the
8589 ** checkpoint operation proceeds from that point in the same way as
8590 ** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible
8591 ** without blocking any further. ^SQLITE_BUSY is returned in this case.
8592 **
8593 ** ^If parameter zDb is NULL or points to a zero length string, then the
8594 ** specified operation is attempted on all WAL databases [attached] to
8595 ** [database connection] db.  In this case the
8596 ** values written to output parameters *pnLog and *pnCkpt are undefined. ^If
8597 ** an SQLITE_BUSY error is encountered when processing one or more of the
8598 ** attached WAL databases, the operation is still attempted on any remaining
8599 ** attached databases and SQLITE_BUSY is returned at the end. ^If any other
8600 ** error occurs while processing an attached database, processing is abandoned
8601 ** and the error code is returned to the caller immediately. ^If no error
8602 ** (SQLITE_BUSY or otherwise) is encountered while processing the attached
8603 ** databases, SQLITE_OK is returned.
8604 **
8605 ** ^If database zDb is the name of an attached database that is not in WAL
8606 ** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. ^If
8607 ** zDb is not NULL (or a zero length string) and is not the name of any
8608 ** attached database, SQLITE_ERROR is returned to the caller.
8609 **
8610 ** ^Unless it returns SQLITE_MISUSE,
8611 ** the sqlite3_wal_checkpoint_v2() interface
8612 ** sets the error information that is queried by
8613 ** [sqlite3_errcode()] and [sqlite3_errmsg()].
8614 **
8615 ** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface
8616 ** from SQL.
8617 */
8618 /* Database handle */
8619 /* Name of attached database (or NULL) */
8620 /* SQLITE_CHECKPOINT_* value */
8621 /* OUT: Size of WAL log in frames */
8622 /* OUT: Total number of frames checkpointed */
8623 int sqlite3_wal_checkpoint_v2(
8624     sqlite3* db,
8625     const(char)* zDb,
8626     int eMode,
8627     int* pnLog,
8628     int* pnCkpt);
8629 
8630 /*
8631 ** CAPI3REF: Checkpoint Mode Values
8632 ** KEYWORDS: {checkpoint mode}
8633 **
8634 ** These constants define all valid values for the "checkpoint mode" passed
8635 ** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface.
8636 ** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the
8637 ** meaning of each of these checkpoint modes.
8638 */
8639 enum SQLITE_CHECKPOINT_PASSIVE = 0; /* Do as much as possible w/o blocking */
8640 enum SQLITE_CHECKPOINT_FULL = 1; /* Wait for writers, then checkpoint */
8641 enum SQLITE_CHECKPOINT_RESTART = 2; /* Like FULL but wait for for readers */
8642 enum SQLITE_CHECKPOINT_TRUNCATE = 3; /* Like RESTART but also truncate WAL */
8643 
8644 /*
8645 ** CAPI3REF: Virtual Table Interface Configuration
8646 **
8647 ** This function may be called by either the [xConnect] or [xCreate] method
8648 ** of a [virtual table] implementation to configure
8649 ** various facets of the virtual table interface.
8650 **
8651 ** If this interface is invoked outside the context of an xConnect or
8652 ** xCreate virtual table method then the behavior is undefined.
8653 **
8654 ** At present, there is only one option that may be configured using
8655 ** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].)  Further options
8656 ** may be added in the future.
8657 */
8658 int sqlite3_vtab_config(sqlite3*, int op, ...);
8659 
8660 /*
8661 ** CAPI3REF: Virtual Table Configuration Options
8662 **
8663 ** These macros define the various options to the
8664 ** [sqlite3_vtab_config()] interface that [virtual table] implementations
8665 ** can use to customize and optimize their behavior.
8666 **
8667 ** <dl>
8668 ** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT
8669 ** <dd>Calls of the form
8670 ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
8671 ** where X is an integer.  If X is zero, then the [virtual table] whose
8672 ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
8673 ** support constraints.  In this configuration (which is the default) if
8674 ** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire
8675 ** statement is rolled back as if [ON CONFLICT | OR ABORT] had been
8676 ** specified as part of the users SQL statement, regardless of the actual
8677 ** ON CONFLICT mode specified.
8678 **
8679 ** If X is non-zero, then the virtual table implementation guarantees
8680 ** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before
8681 ** any modifications to internal or persistent data structures have been made.
8682 ** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite
8683 ** is able to roll back a statement or database transaction, and abandon
8684 ** or continue processing the current SQL statement as appropriate.
8685 ** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns
8686 ** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode
8687 ** had been ABORT.
8688 **
8689 ** Virtual table implementations that are required to handle OR REPLACE
8690 ** must do so within the [xUpdate] method. If a call to the
8691 ** [sqlite3_vtab_on_conflict()] function indicates that the current ON
8692 ** CONFLICT policy is REPLACE, the virtual table implementation should
8693 ** silently replace the appropriate rows within the xUpdate callback and
8694 ** return SQLITE_OK. Or, if this is not possible, it may return
8695 ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
8696 ** constraint handling.
8697 ** </dl>
8698 */
8699 enum SQLITE_VTAB_CONSTRAINT_SUPPORT = 1;
8700 
8701 /*
8702 ** CAPI3REF: Determine The Virtual Table Conflict Policy
8703 **
8704 ** This function may only be called from within a call to the [xUpdate] method
8705 ** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The
8706 ** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL],
8707 ** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode
8708 ** of the SQL statement that triggered the call to the [xUpdate] method of the
8709 ** [virtual table].
8710 */
8711 int sqlite3_vtab_on_conflict(sqlite3*);
8712 
8713 /*
8714 ** CAPI3REF: Determine If Virtual Table Column Access Is For UPDATE
8715 **
8716 ** If the sqlite3_vtab_nochange(X) routine is called within the [xColumn]
8717 ** method of a [virtual table], then it returns true if and only if the
8718 ** column is being fetched as part of an UPDATE operation during which the
8719 ** column value will not change.  Applications might use this to substitute
8720 ** a return value that is less expensive to compute and that the corresponding
8721 ** [xUpdate] method understands as a "no-change" value.
8722 **
8723 ** If the [xColumn] method calls sqlite3_vtab_nochange() and finds that
8724 ** the column is not changed by the UPDATE statement, then the xColumn
8725 ** method can optionally return without setting a result, without calling
8726 ** any of the [sqlite3_result_int|sqlite3_result_xxxxx() interfaces].
8727 ** In that case, [sqlite3_value_nochange(X)] will return true for the
8728 ** same column in the [xUpdate] method.
8729 */
8730 int sqlite3_vtab_nochange(sqlite3_context*);
8731 
8732 /*
8733 ** CAPI3REF: Determine The Collation For a Virtual Table Constraint
8734 **
8735 ** This function may only be called from within a call to the [xBestIndex]
8736 ** method of a [virtual table].
8737 **
8738 ** The first argument must be the sqlite3_index_info object that is the
8739 ** first parameter to the xBestIndex() method. The second argument must be
8740 ** an index into the aConstraint[] array belonging to the sqlite3_index_info
8741 ** structure passed to xBestIndex. This function returns a pointer to a buffer
8742 ** containing the name of the collation sequence for the corresponding
8743 ** constraint.
8744 */
8745 const(char)* sqlite3_vtab_collation(sqlite3_index_info*, int);
8746 
8747 /*
8748 ** CAPI3REF: Conflict resolution modes
8749 ** KEYWORDS: {conflict resolution mode}
8750 **
8751 ** These constants are returned by [sqlite3_vtab_on_conflict()] to
8752 ** inform a [virtual table] implementation what the [ON CONFLICT] mode
8753 ** is for the SQL statement being evaluated.
8754 **
8755 ** Note that the [SQLITE_IGNORE] constant is also used as a potential
8756 ** return value from the [sqlite3_set_authorizer()] callback and that
8757 ** [SQLITE_ABORT] is also a [result code].
8758 */
8759 enum SQLITE_ROLLBACK = 1;
8760 /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */
8761 enum SQLITE_FAIL = 3;
8762 /* #define SQLITE_ABORT 4  // Also an error code */
8763 enum SQLITE_REPLACE = 5;
8764 
8765 /*
8766 ** CAPI3REF: Prepared Statement Scan Status Opcodes
8767 ** KEYWORDS: {scanstatus options}
8768 **
8769 ** The following constants can be used for the T parameter to the
8770 ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface.  Each constant designates a
8771 ** different metric for sqlite3_stmt_scanstatus() to return.
8772 **
8773 ** When the value returned to V is a string, space to hold that string is
8774 ** managed by the prepared statement S and will be automatically freed when
8775 ** S is finalized.
8776 **
8777 ** <dl>
8778 ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
8779 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
8780 ** set to the total number of times that the X-th loop has run.</dd>
8781 **
8782 ** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>
8783 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set
8784 ** to the total number of rows examined by all iterations of the X-th loop.</dd>
8785 **
8786 ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
8787 ** <dd>^The "double" variable pointed to by the T parameter will be set to the
8788 ** query planner's estimate for the average number of rows output from each
8789 ** iteration of the X-th loop.  If the query planner's estimates was accurate,
8790 ** then this value will approximate the quotient NVISIT/NLOOP and the
8791 ** product of this value for all prior loops with the same SELECTID will
8792 ** be the NLOOP value for the current loop.
8793 **
8794 ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
8795 ** <dd>^The "const char *" variable pointed to by the T parameter will be set
8796 ** to a zero-terminated UTF-8 string containing the name of the index or table
8797 ** used for the X-th loop.
8798 **
8799 ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
8800 ** <dd>^The "const char *" variable pointed to by the T parameter will be set
8801 ** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
8802 ** description for the X-th loop.
8803 **
8804 ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
8805 ** <dd>^The "int" variable pointed to by the T parameter will be set to the
8806 ** "select-id" for the X-th loop.  The select-id identifies which query or
8807 ** subquery the loop is part of.  The main query has a select-id of zero.
8808 ** The select-id is the same value as is output in the first column
8809 ** of an [EXPLAIN QUERY PLAN] query.
8810 ** </dl>
8811 */
8812 enum SQLITE_SCANSTAT_NLOOP = 0;
8813 enum SQLITE_SCANSTAT_NVISIT = 1;
8814 enum SQLITE_SCANSTAT_EST = 2;
8815 enum SQLITE_SCANSTAT_NAME = 3;
8816 enum SQLITE_SCANSTAT_EXPLAIN = 4;
8817 enum SQLITE_SCANSTAT_SELECTID = 5;
8818 
8819 /*
8820 ** CAPI3REF: Prepared Statement Scan Status
8821 ** METHOD: sqlite3_stmt
8822 **
8823 ** This interface returns information about the predicted and measured
8824 ** performance for pStmt.  Advanced applications can use this
8825 ** interface to compare the predicted and the measured performance and
8826 ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
8827 **
8828 ** Since this interface is expected to be rarely used, it is only
8829 ** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS]
8830 ** compile-time option.
8831 **
8832 ** The "iScanStatusOp" parameter determines which status information to return.
8833 ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
8834 ** of this interface is undefined.
8835 ** ^The requested measurement is written into a variable pointed to by
8836 ** the "pOut" parameter.
8837 ** Parameter "idx" identifies the specific loop to retrieve statistics for.
8838 ** Loops are numbered starting from zero. ^If idx is out of range - less than
8839 ** zero or greater than or equal to the total number of loops used to implement
8840 ** the statement - a non-zero value is returned and the variable that pOut
8841 ** points to is unchanged.
8842 **
8843 ** ^Statistics might not be available for all loops in all statements. ^In cases
8844 ** where there exist loops with no available statistics, this function behaves
8845 ** as if the loop did not exist - it returns non-zero and leave the variable
8846 ** that pOut points to unchanged.
8847 **
8848 ** See also: [sqlite3_stmt_scanstatus_reset()]
8849 */
8850 /* Prepared statement for which info desired */
8851 /* Index of loop to report on */
8852 /* Information desired.  SQLITE_SCANSTAT_* */
8853 /* Result written here */
8854 int sqlite3_stmt_scanstatus(
8855     sqlite3_stmt* pStmt,
8856     int idx,
8857     int iScanStatusOp,
8858     void* pOut);
8859 
8860 /*
8861 ** CAPI3REF: Zero Scan-Status Counters
8862 ** METHOD: sqlite3_stmt
8863 **
8864 ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
8865 **
8866 ** This API is only available if the library is built with pre-processor
8867 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
8868 */
8869 void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
8870 
8871 /*
8872 ** CAPI3REF: Flush caches to disk mid-transaction
8873 **
8874 ** ^If a write-transaction is open on [database connection] D when the
8875 ** [sqlite3_db_cacheflush(D)] interface invoked, any dirty
8876 ** pages in the pager-cache that are not currently in use are written out
8877 ** to disk. A dirty page may be in use if a database cursor created by an
8878 ** active SQL statement is reading from it, or if it is page 1 of a database
8879 ** file (page 1 is always "in use").  ^The [sqlite3_db_cacheflush(D)]
8880 ** interface flushes caches for all schemas - "main", "temp", and
8881 ** any [attached] databases.
8882 **
8883 ** ^If this function needs to obtain extra database locks before dirty pages
8884 ** can be flushed to disk, it does so. ^If those locks cannot be obtained
8885 ** immediately and there is a busy-handler callback configured, it is invoked
8886 ** in the usual manner. ^If the required lock still cannot be obtained, then
8887 ** the database is skipped and an attempt made to flush any dirty pages
8888 ** belonging to the next (if any) database. ^If any databases are skipped
8889 ** because locks cannot be obtained, but no other error occurs, this
8890 ** function returns SQLITE_BUSY.
8891 **
8892 ** ^If any other error occurs while flushing dirty pages to disk (for
8893 ** example an IO error or out-of-memory condition), then processing is
8894 ** abandoned and an SQLite [error code] is returned to the caller immediately.
8895 **
8896 ** ^Otherwise, if no error occurs, [sqlite3_db_cacheflush()] returns SQLITE_OK.
8897 **
8898 ** ^This function does not set the database handle error code or message
8899 ** returned by the [sqlite3_errcode()] and [sqlite3_errmsg()] functions.
8900 */
8901 int sqlite3_db_cacheflush(sqlite3*);
8902 
8903 /*
8904 ** CAPI3REF: The pre-update hook.
8905 **
8906 ** ^These interfaces are only available if SQLite is compiled using the
8907 ** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option.
8908 **
8909 ** ^The [sqlite3_preupdate_hook()] interface registers a callback function
8910 ** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation
8911 ** on a database table.
8912 ** ^At most one preupdate hook may be registered at a time on a single
8913 ** [database connection]; each call to [sqlite3_preupdate_hook()] overrides
8914 ** the previous setting.
8915 ** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()]
8916 ** with a NULL pointer as the second parameter.
8917 ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as
8918 ** the first parameter to callbacks.
8919 **
8920 ** ^The preupdate hook only fires for changes to real database tables; the
8921 ** preupdate hook is not invoked for changes to [virtual tables] or to
8922 ** system tables like sqlite_master or sqlite_stat1.
8923 **
8924 ** ^The second parameter to the preupdate callback is a pointer to
8925 ** the [database connection] that registered the preupdate hook.
8926 ** ^The third parameter to the preupdate callback is one of the constants
8927 ** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the
8928 ** kind of update operation that is about to occur.
8929 ** ^(The fourth parameter to the preupdate callback is the name of the
8930 ** database within the database connection that is being modified.  This
8931 ** will be "main" for the main database or "temp" for TEMP tables or
8932 ** the name given after the AS keyword in the [ATTACH] statement for attached
8933 ** databases.)^
8934 ** ^The fifth parameter to the preupdate callback is the name of the
8935 ** table that is being modified.
8936 **
8937 ** For an UPDATE or DELETE operation on a [rowid table], the sixth
8938 ** parameter passed to the preupdate callback is the initial [rowid] of the
8939 ** row being modified or deleted. For an INSERT operation on a rowid table,
8940 ** or any operation on a WITHOUT ROWID table, the value of the sixth
8941 ** parameter is undefined. For an INSERT or UPDATE on a rowid table the
8942 ** seventh parameter is the final rowid value of the row being inserted
8943 ** or updated. The value of the seventh parameter passed to the callback
8944 ** function is not defined for operations on WITHOUT ROWID tables, or for
8945 ** INSERT operations on rowid tables.
8946 **
8947 ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
8948 ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
8949 ** provide additional information about a preupdate event. These routines
8950 ** may only be called from within a preupdate callback.  Invoking any of
8951 ** these routines from outside of a preupdate callback or with a
8952 ** [database connection] pointer that is different from the one supplied
8953 ** to the preupdate callback results in undefined and probably undesirable
8954 ** behavior.
8955 **
8956 ** ^The [sqlite3_preupdate_count(D)] interface returns the number of columns
8957 ** in the row that is being inserted, updated, or deleted.
8958 **
8959 ** ^The [sqlite3_preupdate_old(D,N,P)] interface writes into P a pointer to
8960 ** a [protected sqlite3_value] that contains the value of the Nth column of
8961 ** the table row before it is updated.  The N parameter must be between 0
8962 ** and one less than the number of columns or the behavior will be
8963 ** undefined. This must only be used within SQLITE_UPDATE and SQLITE_DELETE
8964 ** preupdate callbacks; if it is used by an SQLITE_INSERT callback then the
8965 ** behavior is undefined.  The [sqlite3_value] that P points to
8966 ** will be destroyed when the preupdate callback returns.
8967 **
8968 ** ^The [sqlite3_preupdate_new(D,N,P)] interface writes into P a pointer to
8969 ** a [protected sqlite3_value] that contains the value of the Nth column of
8970 ** the table row after it is updated.  The N parameter must be between 0
8971 ** and one less than the number of columns or the behavior will be
8972 ** undefined. This must only be used within SQLITE_INSERT and SQLITE_UPDATE
8973 ** preupdate callbacks; if it is used by an SQLITE_DELETE callback then the
8974 ** behavior is undefined.  The [sqlite3_value] that P points to
8975 ** will be destroyed when the preupdate callback returns.
8976 **
8977 ** ^The [sqlite3_preupdate_depth(D)] interface returns 0 if the preupdate
8978 ** callback was invoked as a result of a direct insert, update, or delete
8979 ** operation; or 1 for inserts, updates, or deletes invoked by top-level
8980 ** triggers; or 2 for changes resulting from triggers called by top-level
8981 ** triggers; and so forth.
8982 **
8983 ** See also:  [sqlite3_update_hook()]
8984 */
8985 
8986 /* Copy of third arg to preupdate_hook() */
8987 /* Database handle */
8988 /* SQLITE_UPDATE, DELETE or INSERT */
8989 /* Database name */
8990 /* Table name */
8991 /* Rowid of row about to be deleted/updated */
8992 /* New rowid value (for a rowid UPDATE) */
8993 
8994 /*
8995 ** CAPI3REF: Low-level system error code
8996 **
8997 ** ^Attempt to return the underlying operating system error code or error
8998 ** number that caused the most recent I/O error or failure to open a file.
8999 ** The return value is OS-dependent.  For example, on unix systems, after
9000 ** [sqlite3_open_v2()] returns [SQLITE_CANTOPEN], this interface could be
9001 ** called to get back the underlying "errno" that caused the problem, such
9002 ** as ENOSPC, EAUTH, EISDIR, and so forth.
9003 */
9004 int sqlite3_system_errno(sqlite3*);
9005 
9006 /*
9007 ** CAPI3REF: Database Snapshot
9008 ** KEYWORDS: {snapshot} {sqlite3_snapshot}
9009 **
9010 ** An instance of the snapshot object records the state of a [WAL mode]
9011 ** database for some specific point in history.
9012 **
9013 ** In [WAL mode], multiple [database connections] that are open on the
9014 ** same database file can each be reading a different historical version
9015 ** of the database file.  When a [database connection] begins a read
9016 ** transaction, that connection sees an unchanging copy of the database
9017 ** as it existed for the point in time when the transaction first started.
9018 ** Subsequent changes to the database from other connections are not seen
9019 ** by the reader until a new read transaction is started.
9020 **
9021 ** The sqlite3_snapshot object records state information about an historical
9022 ** version of the database file so that it is possible to later open a new read
9023 ** transaction that sees that historical version of the database rather than
9024 ** the most recent version.
9025 */
9026 struct sqlite3_snapshot
9027 {
9028     ubyte[48] hidden;
9029 }
9030 
9031 /*
9032 ** CAPI3REF: Record A Database Snapshot
9033 ** CONSTRUCTOR: sqlite3_snapshot
9034 **
9035 ** ^The [sqlite3_snapshot_get(D,S,P)] interface attempts to make a
9036 ** new [sqlite3_snapshot] object that records the current state of
9037 ** schema S in database connection D.  ^On success, the
9038 ** [sqlite3_snapshot_get(D,S,P)] interface writes a pointer to the newly
9039 ** created [sqlite3_snapshot] object into *P and returns SQLITE_OK.
9040 ** If there is not already a read-transaction open on schema S when
9041 ** this function is called, one is opened automatically.
9042 **
9043 ** The following must be true for this function to succeed. If any of
9044 ** the following statements are false when sqlite3_snapshot_get() is
9045 ** called, SQLITE_ERROR is returned. The final value of *P is undefined
9046 ** in this case.
9047 **
9048 ** <ul>
9049 **   <li> The database handle must not be in [autocommit mode].
9050 **
9051 **   <li> Schema S of [database connection] D must be a [WAL mode] database.
9052 **
9053 **   <li> There must not be a write transaction open on schema S of database
9054 **        connection D.
9055 **
9056 **   <li> One or more transactions must have been written to the current wal
9057 **        file since it was created on disk (by any connection). This means
9058 **        that a snapshot cannot be taken on a wal mode database with no wal
9059 **        file immediately after it is first opened. At least one transaction
9060 **        must be written to it first.
9061 ** </ul>
9062 **
9063 ** This function may also return SQLITE_NOMEM.  If it is called with the
9064 ** database handle in autocommit mode but fails for some other reason,
9065 ** whether or not a read transaction is opened on schema S is undefined.
9066 **
9067 ** The [sqlite3_snapshot] object returned from a successful call to
9068 ** [sqlite3_snapshot_get()] must be freed using [sqlite3_snapshot_free()]
9069 ** to avoid a memory leak.
9070 **
9071 ** The [sqlite3_snapshot_get()] interface is only available when the
9072 ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
9073 */
9074 int sqlite3_snapshot_get(
9075     sqlite3* db,
9076     const(char)* zSchema,
9077     sqlite3_snapshot** ppSnapshot);
9078 
9079 /*
9080 ** CAPI3REF: Start a read transaction on an historical snapshot
9081 ** METHOD: sqlite3_snapshot
9082 **
9083 ** ^The [sqlite3_snapshot_open(D,S,P)] interface either starts a new read
9084 ** transaction or upgrades an existing one for schema S of
9085 ** [database connection] D such that the read transaction refers to
9086 ** historical [snapshot] P, rather than the most recent change to the
9087 ** database. ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK
9088 ** on success or an appropriate [error code] if it fails.
9089 **
9090 ** ^In order to succeed, the database connection must not be in
9091 ** [autocommit mode] when [sqlite3_snapshot_open(D,S,P)] is called. If there
9092 ** is already a read transaction open on schema S, then the database handle
9093 ** must have no active statements (SELECT statements that have been passed
9094 ** to sqlite3_step() but not sqlite3_reset() or sqlite3_finalize()).
9095 ** SQLITE_ERROR is returned if either of these conditions is violated, or
9096 ** if schema S does not exist, or if the snapshot object is invalid.
9097 **
9098 ** ^A call to sqlite3_snapshot_open() will fail to open if the specified
9099 ** snapshot has been overwritten by a [checkpoint]. In this case
9100 ** SQLITE_ERROR_SNAPSHOT is returned.
9101 **
9102 ** If there is already a read transaction open when this function is
9103 ** invoked, then the same read transaction remains open (on the same
9104 ** database snapshot) if SQLITE_ERROR, SQLITE_BUSY or SQLITE_ERROR_SNAPSHOT
9105 ** is returned. If another error code - for example SQLITE_PROTOCOL or an
9106 ** SQLITE_IOERR error code - is returned, then the final state of the
9107 ** read transaction is undefined. If SQLITE_OK is returned, then the
9108 ** read transaction is now open on database snapshot P.
9109 **
9110 ** ^(A call to [sqlite3_snapshot_open(D,S,P)] will fail if the
9111 ** database connection D does not know that the database file for
9112 ** schema S is in [WAL mode].  A database connection might not know
9113 ** that the database file is in [WAL mode] if there has been no prior
9114 ** I/O on that database connection, or if the database entered [WAL mode]
9115 ** after the most recent I/O on the database connection.)^
9116 ** (Hint: Run "[PRAGMA application_id]" against a newly opened
9117 ** database connection in order to make it ready to use snapshots.)
9118 **
9119 ** The [sqlite3_snapshot_open()] interface is only available when the
9120 ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
9121 */
9122 int sqlite3_snapshot_open(
9123     sqlite3* db,
9124     const(char)* zSchema,
9125     sqlite3_snapshot* pSnapshot);
9126 
9127 /*
9128 ** CAPI3REF: Destroy a snapshot
9129 ** DESTRUCTOR: sqlite3_snapshot
9130 **
9131 ** ^The [sqlite3_snapshot_free(P)] interface destroys [sqlite3_snapshot] P.
9132 ** The application must eventually free every [sqlite3_snapshot] object
9133 ** using this routine to avoid a memory leak.
9134 **
9135 ** The [sqlite3_snapshot_free()] interface is only available when the
9136 ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
9137 */
9138 void sqlite3_snapshot_free(sqlite3_snapshot*);
9139 
9140 /*
9141 ** CAPI3REF: Compare the ages of two snapshot handles.
9142 ** METHOD: sqlite3_snapshot
9143 **
9144 ** The sqlite3_snapshot_cmp(P1, P2) interface is used to compare the ages
9145 ** of two valid snapshot handles.
9146 **
9147 ** If the two snapshot handles are not associated with the same database
9148 ** file, the result of the comparison is undefined.
9149 **
9150 ** Additionally, the result of the comparison is only valid if both of the
9151 ** snapshot handles were obtained by calling sqlite3_snapshot_get() since the
9152 ** last time the wal file was deleted. The wal file is deleted when the
9153 ** database is changed back to rollback mode or when the number of database
9154 ** clients drops to zero. If either snapshot handle was obtained before the
9155 ** wal file was last deleted, the value returned by this function
9156 ** is undefined.
9157 **
9158 ** Otherwise, this API returns a negative value if P1 refers to an older
9159 ** snapshot than P2, zero if the two handles refer to the same database
9160 ** snapshot, and a positive value if P1 is a newer snapshot than P2.
9161 **
9162 ** This interface is only available if SQLite is compiled with the
9163 ** [SQLITE_ENABLE_SNAPSHOT] option.
9164 */
9165 int sqlite3_snapshot_cmp(sqlite3_snapshot* p1, sqlite3_snapshot* p2);
9166 
9167 /*
9168 ** CAPI3REF: Recover snapshots from a wal file
9169 ** METHOD: sqlite3_snapshot
9170 **
9171 ** If a [WAL file] remains on disk after all database connections close
9172 ** (either through the use of the [SQLITE_FCNTL_PERSIST_WAL] [file control]
9173 ** or because the last process to have the database opened exited without
9174 ** calling [sqlite3_close()]) and a new connection is subsequently opened
9175 ** on that database and [WAL file], the [sqlite3_snapshot_open()] interface
9176 ** will only be able to open the last transaction added to the WAL file
9177 ** even though the WAL file contains other valid transactions.
9178 **
9179 ** This function attempts to scan the WAL file associated with database zDb
9180 ** of database handle db and make all valid snapshots available to
9181 ** sqlite3_snapshot_open(). It is an error if there is already a read
9182 ** transaction open on the database, or if the database is not a WAL mode
9183 ** database.
9184 **
9185 ** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
9186 **
9187 ** This interface is only available if SQLite is compiled with the
9188 ** [SQLITE_ENABLE_SNAPSHOT] option.
9189 */
9190 int sqlite3_snapshot_recover(sqlite3* db, const(char)* zDb);
9191 
9192 /*
9193 ** CAPI3REF: Serialize a database
9194 **
9195 ** The sqlite3_serialize(D,S,P,F) interface returns a pointer to memory
9196 ** that is a serialization of the S database on [database connection] D.
9197 ** If P is not a NULL pointer, then the size of the database in bytes
9198 ** is written into *P.
9199 **
9200 ** For an ordinary on-disk database file, the serialization is just a
9201 ** copy of the disk file.  For an in-memory database or a "TEMP" database,
9202 ** the serialization is the same sequence of bytes which would be written
9203 ** to disk if that database where backed up to disk.
9204 **
9205 ** The usual case is that sqlite3_serialize() copies the serialization of
9206 ** the database into memory obtained from [sqlite3_malloc64()] and returns
9207 ** a pointer to that memory.  The caller is responsible for freeing the
9208 ** returned value to avoid a memory leak.  However, if the F argument
9209 ** contains the SQLITE_SERIALIZE_NOCOPY bit, then no memory allocations
9210 ** are made, and the sqlite3_serialize() function will return a pointer
9211 ** to the contiguous memory representation of the database that SQLite
9212 ** is currently using for that database, or NULL if the no such contiguous
9213 ** memory representation of the database exists.  A contiguous memory
9214 ** representation of the database will usually only exist if there has
9215 ** been a prior call to [sqlite3_deserialize(D,S,...)] with the same
9216 ** values of D and S.
9217 ** The size of the database is written into *P even if the
9218 ** SQLITE_SERIALIZE_NOCOPY bit is set but no contiguous copy
9219 ** of the database exists.
9220 **
9221 ** A call to sqlite3_serialize(D,S,P,F) might return NULL even if the
9222 ** SQLITE_SERIALIZE_NOCOPY bit is omitted from argument F if a memory
9223 ** allocation error occurs.
9224 **
9225 ** This interface is only available if SQLite is compiled with the
9226 ** [SQLITE_ENABLE_DESERIALIZE] option.
9227 */
9228 /* The database connection */
9229 /* Which DB to serialize. ex: "main", "temp", ... */
9230 /* Write size of the DB here, if not NULL */
9231 /* Zero or more SQLITE_SERIALIZE_* flags */
9232 ubyte* sqlite3_serialize(
9233     sqlite3* db,
9234     const(char)* zSchema,
9235     sqlite3_int64* piSize,
9236     uint mFlags);
9237 
9238 /*
9239 ** CAPI3REF: Flags for sqlite3_serialize
9240 **
9241 ** Zero or more of the following constants can be OR-ed together for
9242 ** the F argument to [sqlite3_serialize(D,S,P,F)].
9243 **
9244 ** SQLITE_SERIALIZE_NOCOPY means that [sqlite3_serialize()] will return
9245 ** a pointer to contiguous in-memory database that it is currently using,
9246 ** without making a copy of the database.  If SQLite is not currently using
9247 ** a contiguous in-memory database, then this option causes
9248 ** [sqlite3_serialize()] to return a NULL pointer.  SQLite will only be
9249 ** using a contiguous in-memory database if it has been initialized by a
9250 ** prior call to [sqlite3_deserialize()].
9251 */
9252 enum SQLITE_SERIALIZE_NOCOPY = 0x001; /* Do no memory allocations */
9253 
9254 /*
9255 ** CAPI3REF: Deserialize a database
9256 **
9257 ** The sqlite3_deserialize(D,S,P,N,M,F) interface causes the
9258 ** [database connection] D to disconnect from database S and then
9259 ** reopen S as an in-memory database based on the serialization contained
9260 ** in P.  The serialized database P is N bytes in size.  M is the size of
9261 ** the buffer P, which might be larger than N.  If M is larger than N, and
9262 ** the SQLITE_DESERIALIZE_READONLY bit is not set in F, then SQLite is
9263 ** permitted to add content to the in-memory database as long as the total
9264 ** size does not exceed M bytes.
9265 **
9266 ** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will
9267 ** invoke sqlite3_free() on the serialization buffer when the database
9268 ** connection closes.  If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then
9269 ** SQLite will try to increase the buffer size using sqlite3_realloc64()
9270 ** if writes on the database cause it to grow larger than M bytes.
9271 **
9272 ** The sqlite3_deserialize() interface will fail with SQLITE_BUSY if the
9273 ** database is currently in a read transaction or is involved in a backup
9274 ** operation.
9275 **
9276 ** If sqlite3_deserialize(D,S,P,N,M,F) fails for any reason and if the
9277 ** SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then
9278 ** [sqlite3_free()] is invoked on argument P prior to returning.
9279 **
9280 ** This interface is only available if SQLite is compiled with the
9281 ** [SQLITE_ENABLE_DESERIALIZE] option.
9282 */
9283 /* The database connection */
9284 /* Which DB to reopen with the deserialization */
9285 /* The serialized database content */
9286 /* Number bytes in the deserialization */
9287 /* Total size of buffer pData[] */
9288 /* Zero or more SQLITE_DESERIALIZE_* flags */
9289 int sqlite3_deserialize(
9290     sqlite3* db,
9291     const(char)* zSchema,
9292     ubyte* pData,
9293     sqlite3_int64 szDb,
9294     sqlite3_int64 szBuf,
9295     uint mFlags);
9296 
9297 /*
9298 ** CAPI3REF: Flags for sqlite3_deserialize()
9299 **
9300 ** The following are allowed values for 6th argument (the F argument) to
9301 ** the [sqlite3_deserialize(D,S,P,N,M,F)] interface.
9302 **
9303 ** The SQLITE_DESERIALIZE_FREEONCLOSE means that the database serialization
9304 ** in the P argument is held in memory obtained from [sqlite3_malloc64()]
9305 ** and that SQLite should take ownership of this memory and automatically
9306 ** free it when it has finished using it.  Without this flag, the caller
9307 ** is responsible for freeing any dynamically allocated memory.
9308 **
9309 ** The SQLITE_DESERIALIZE_RESIZEABLE flag means that SQLite is allowed to
9310 ** grow the size of the database using calls to [sqlite3_realloc64()].  This
9311 ** flag should only be used if SQLITE_DESERIALIZE_FREEONCLOSE is also used.
9312 ** Without this flag, the deserialized database cannot increase in size beyond
9313 ** the number of bytes specified by the M parameter.
9314 **
9315 ** The SQLITE_DESERIALIZE_READONLY flag means that the deserialized database
9316 ** should be treated as read-only.
9317 */
9318 enum SQLITE_DESERIALIZE_FREEONCLOSE = 1; /* Call sqlite3_free() on close */
9319 enum SQLITE_DESERIALIZE_RESIZEABLE = 2; /* Resize using sqlite3_realloc64() */
9320 enum SQLITE_DESERIALIZE_READONLY = 4; /* Database is read-only */
9321 
9322 /*
9323 ** Undo the hack that converts floating point types to integer for
9324 ** builds on processors without floating point support.
9325 */
9326 
9327 /* End of the 'extern "C"' block */
9328 
9329 /* SQLITE3_H */
9330 
9331 /******** Begin file sqlite3rtree.h *********/
9332 /*
9333 ** 2010 August 30
9334 **
9335 ** The author disclaims copyright to this source code.  In place of
9336 ** a legal notice, here is a blessing:
9337 **
9338 **    May you do good and not evil.
9339 **    May you find forgiveness for yourself and forgive others.
9340 **    May you share freely, never taking more than you give.
9341 **
9342 *************************************************************************
9343 */
9344 
9345 /* The double-precision datatype used by RTree depends on the
9346 ** SQLITE_RTREE_INT_ONLY compile-time option.
9347 */
9348 
9349 alias sqlite3_rtree_dbl = double;
9350 
9351 /*
9352 ** Register a geometry callback named zGeom that can be used as part of an
9353 ** R-Tree geometry query as follows:
9354 **
9355 **   SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...)
9356 */
9357 int sqlite3_rtree_geometry_callback(
9358     sqlite3* db,
9359     const(char)* zGeom,
9360     int function(sqlite3_rtree_geometry*, int, sqlite3_rtree_dbl*, int*) xGeom,
9361     void* pContext);
9362 
9363 /*
9364 ** A pointer to a structure of the following type is passed as the first
9365 ** argument to callbacks registered using rtree_geometry_callback().
9366 */
9367 struct sqlite3_rtree_geometry
9368 {
9369     void* pContext; /* Copy of pContext passed to s_r_g_c() */
9370     int nParam; /* Size of array aParam[] */
9371     sqlite3_rtree_dbl* aParam; /* Parameters passed to SQL geom function */
9372     void* pUser; /* Callback implementation user data */
9373     void function(void*) xDelUser; /* Called by SQLite to clean up pUser */
9374 }
9375 
9376 /*
9377 ** Register a 2nd-generation geometry callback named zScore that can be
9378 ** used as part of an R-Tree geometry query as follows:
9379 **
9380 **   SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zQueryFunc(... params ...)
9381 */
9382 int sqlite3_rtree_query_callback(
9383     sqlite3* db,
9384     const(char)* zQueryFunc,
9385     int function(sqlite3_rtree_query_info*) xQueryFunc,
9386     void* pContext,
9387     void function(void*) xDestructor);
9388 
9389 /*
9390 ** A pointer to a structure of the following type is passed as the
9391 ** argument to scored geometry callback registered using
9392 ** sqlite3_rtree_query_callback().
9393 **
9394 ** Note that the first 5 fields of this structure are identical to
9395 ** sqlite3_rtree_geometry.  This structure is a subclass of
9396 ** sqlite3_rtree_geometry.
9397 */
9398 struct sqlite3_rtree_query_info
9399 {
9400     void* pContext; /* pContext from when function registered */
9401     int nParam; /* Number of function parameters */
9402     sqlite3_rtree_dbl* aParam; /* value of function parameters */
9403     void* pUser; /* callback can use this, if desired */
9404     void function(void*) xDelUser; /* function to free pUser */
9405     sqlite3_rtree_dbl* aCoord; /* Coordinates of node or entry to check */
9406     uint* anQueue; /* Number of pending entries in the queue */
9407     int nCoord; /* Number of coordinates */
9408     int iLevel; /* Level of current node or entry */
9409     int mxLevel; /* The largest iLevel value in the tree */
9410     sqlite3_int64 iRowid; /* Rowid for current entry */
9411     sqlite3_rtree_dbl rParentScore; /* Score of parent node */
9412     int eParentWithin; /* Visibility of parent node */
9413     int eWithin; /* OUT: Visiblity */
9414     sqlite3_rtree_dbl rScore; /* OUT: Write the score here */
9415     /* The following fields are only available in 3.8.11 and later */
9416     sqlite3_value** apSqlParam; /* Original SQL values of parameters */
9417 }
9418 
9419 /*
9420 ** Allowed values for sqlite3_rtree_query.eWithin and .eParentWithin.
9421 */
9422 enum NOT_WITHIN = 0; /* Object completely outside of query region */
9423 enum PARTLY_WITHIN = 1; /* Object partially overlaps query region */
9424 enum FULLY_WITHIN = 2; /* Object fully contained within query region */
9425 
9426 /* end of the 'extern "C"' block */
9427 
9428 /* ifndef _SQLITE3RTREE_H_ */
9429 
9430 /******** End of sqlite3rtree.h *********/
9431 /******** Begin file sqlite3session.h *********/
9432 
9433 /*
9434 ** Make sure we can call this stuff from C++.
9435 */
9436 
9437 /*
9438 ** CAPI3REF: Session Object Handle
9439 **
9440 ** An instance of this object is a [session] that can be used to
9441 ** record changes to a database.
9442 */
9443 
9444 /*
9445 ** CAPI3REF: Changeset Iterator Handle
9446 **
9447 ** An instance of this object acts as a cursor for iterating
9448 ** over the elements of a [changeset] or [patchset].
9449 */
9450 
9451 /*
9452 ** CAPI3REF: Create A New Session Object
9453 ** CONSTRUCTOR: sqlite3_session
9454 **
9455 ** Create a new session object attached to database handle db. If successful,
9456 ** a pointer to the new object is written to *ppSession and SQLITE_OK is
9457 ** returned. If an error occurs, *ppSession is set to NULL and an SQLite
9458 ** error code (e.g. SQLITE_NOMEM) is returned.
9459 **
9460 ** It is possible to create multiple session objects attached to a single
9461 ** database handle.
9462 **
9463 ** Session objects created using this function should be deleted using the
9464 ** [sqlite3session_delete()] function before the database handle that they
9465 ** are attached to is itself closed. If the database handle is closed before
9466 ** the session object is deleted, then the results of calling any session
9467 ** module function, including [sqlite3session_delete()] on the session object
9468 ** are undefined.
9469 **
9470 ** Because the session module uses the [sqlite3_preupdate_hook()] API, it
9471 ** is not possible for an application to register a pre-update hook on a
9472 ** database handle that has one or more session objects attached. Nor is
9473 ** it possible to create a session object attached to a database handle for
9474 ** which a pre-update hook is already defined. The results of attempting
9475 ** either of these things are undefined.
9476 **
9477 ** The session object will be used to create changesets for tables in
9478 ** database zDb, where zDb is either "main", or "temp", or the name of an
9479 ** attached database. It is not an error if database zDb is not attached
9480 ** to the database when the session object is created.
9481 */
9482 
9483 /* Database handle */
9484 /* Name of db (e.g. "main") */
9485 /* OUT: New session object */
9486 
9487 /*
9488 ** CAPI3REF: Delete A Session Object
9489 ** DESTRUCTOR: sqlite3_session
9490 **
9491 ** Delete a session object previously allocated using
9492 ** [sqlite3session_create()]. Once a session object has been deleted, the
9493 ** results of attempting to use pSession with any other session module
9494 ** function are undefined.
9495 **
9496 ** Session objects must be deleted before the database handle to which they
9497 ** are attached is closed. Refer to the documentation for
9498 ** [sqlite3session_create()] for details.
9499 */
9500 
9501 /*
9502 ** CAPI3REF: Enable Or Disable A Session Object
9503 ** METHOD: sqlite3_session
9504 **
9505 ** Enable or disable the recording of changes by a session object. When
9506 ** enabled, a session object records changes made to the database. When
9507 ** disabled - it does not. A newly created session object is enabled.
9508 ** Refer to the documentation for [sqlite3session_changeset()] for further
9509 ** details regarding how enabling and disabling a session object affects
9510 ** the eventual changesets.
9511 **
9512 ** Passing zero to this function disables the session. Passing a value
9513 ** greater than zero enables it. Passing a value less than zero is a
9514 ** no-op, and may be used to query the current state of the session.
9515 **
9516 ** The return value indicates the final state of the session object: 0 if
9517 ** the session is disabled, or 1 if it is enabled.
9518 */
9519 
9520 /*
9521 ** CAPI3REF: Set Or Clear the Indirect Change Flag
9522 ** METHOD: sqlite3_session
9523 **
9524 ** Each change recorded by a session object is marked as either direct or
9525 ** indirect. A change is marked as indirect if either:
9526 **
9527 ** <ul>
9528 **   <li> The session object "indirect" flag is set when the change is
9529 **        made, or
9530 **   <li> The change is made by an SQL trigger or foreign key action
9531 **        instead of directly as a result of a users SQL statement.
9532 ** </ul>
9533 **
9534 ** If a single row is affected by more than one operation within a session,
9535 ** then the change is considered indirect if all operations meet the criteria
9536 ** for an indirect change above, or direct otherwise.
9537 **
9538 ** This function is used to set, clear or query the session object indirect
9539 ** flag.  If the second argument passed to this function is zero, then the
9540 ** indirect flag is cleared. If it is greater than zero, the indirect flag
9541 ** is set. Passing a value less than zero does not modify the current value
9542 ** of the indirect flag, and may be used to query the current state of the
9543 ** indirect flag for the specified session object.
9544 **
9545 ** The return value indicates the final state of the indirect flag: 0 if
9546 ** it is clear, or 1 if it is set.
9547 */
9548 
9549 /*
9550 ** CAPI3REF: Attach A Table To A Session Object
9551 ** METHOD: sqlite3_session
9552 **
9553 ** If argument zTab is not NULL, then it is the name of a table to attach
9554 ** to the session object passed as the first argument. All subsequent changes
9555 ** made to the table while the session object is enabled will be recorded. See
9556 ** documentation for [sqlite3session_changeset()] for further details.
9557 **
9558 ** Or, if argument zTab is NULL, then changes are recorded for all tables
9559 ** in the database. If additional tables are added to the database (by
9560 ** executing "CREATE TABLE" statements) after this call is made, changes for
9561 ** the new tables are also recorded.
9562 **
9563 ** Changes can only be recorded for tables that have a PRIMARY KEY explicitly
9564 ** defined as part of their CREATE TABLE statement. It does not matter if the
9565 ** PRIMARY KEY is an "INTEGER PRIMARY KEY" (rowid alias) or not. The PRIMARY
9566 ** KEY may consist of a single column, or may be a composite key.
9567 **
9568 ** It is not an error if the named table does not exist in the database. Nor
9569 ** is it an error if the named table does not have a PRIMARY KEY. However,
9570 ** no changes will be recorded in either of these scenarios.
9571 **
9572 ** Changes are not recorded for individual rows that have NULL values stored
9573 ** in one or more of their PRIMARY KEY columns.
9574 **
9575 ** SQLITE_OK is returned if the call completes without error. Or, if an error
9576 ** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
9577 **
9578 ** <h3>Special sqlite_stat1 Handling</h3>
9579 **
9580 ** As of SQLite version 3.22.0, the "sqlite_stat1" table is an exception to
9581 ** some of the rules above. In SQLite, the schema of sqlite_stat1 is:
9582 **  <pre>
9583 **  &nbsp;     CREATE TABLE sqlite_stat1(tbl,idx,stat)
9584 **  </pre>
9585 **
9586 ** Even though sqlite_stat1 does not have a PRIMARY KEY, changes are
9587 ** recorded for it as if the PRIMARY KEY is (tbl,idx). Additionally, changes
9588 ** are recorded for rows for which (idx IS NULL) is true. However, for such
9589 ** rows a zero-length blob (SQL value X'') is stored in the changeset or
9590 ** patchset instead of a NULL value. This allows such changesets to be
9591 ** manipulated by legacy implementations of sqlite3changeset_invert(),
9592 ** concat() and similar.
9593 **
9594 ** The sqlite3changeset_apply() function automatically converts the
9595 ** zero-length blob back to a NULL value when updating the sqlite_stat1
9596 ** table. However, if the application calls sqlite3changeset_new(),
9597 ** sqlite3changeset_old() or sqlite3changeset_conflict on a changeset
9598 ** iterator directly (including on a changeset iterator passed to a
9599 ** conflict-handler callback) then the X'' value is returned. The application
9600 ** must translate X'' to NULL itself if required.
9601 **
9602 ** Legacy (older than 3.22.0) versions of the sessions module cannot capture
9603 ** changes made to the sqlite_stat1 table. Legacy versions of the
9604 ** sqlite3changeset_apply() function silently ignore any modifications to the
9605 ** sqlite_stat1 table that are part of a changeset or patchset.
9606 */
9607 
9608 /* Session object */
9609 /* Table name */
9610 
9611 /*
9612 ** CAPI3REF: Set a table filter on a Session Object.
9613 ** METHOD: sqlite3_session
9614 **
9615 ** The second argument (xFilter) is the "filter callback". For changes to rows
9616 ** in tables that are not attached to the Session object, the filter is called
9617 ** to determine whether changes to the table's rows should be tracked or not.
9618 ** If xFilter returns 0, changes is not tracked. Note that once a table is
9619 ** attached, xFilter will not be called again.
9620 */
9621 
9622 /* Session object */
9623 
9624 /* Copy of third arg to _filter_table() */
9625 /* Table name */
9626 
9627 /* First argument passed to xFilter */
9628 
9629 /*
9630 ** CAPI3REF: Generate A Changeset From A Session Object
9631 ** METHOD: sqlite3_session
9632 **
9633 ** Obtain a changeset containing changes to the tables attached to the
9634 ** session object passed as the first argument. If successful,
9635 ** set *ppChangeset to point to a buffer containing the changeset
9636 ** and *pnChangeset to the size of the changeset in bytes before returning
9637 ** SQLITE_OK. If an error occurs, set both *ppChangeset and *pnChangeset to
9638 ** zero and return an SQLite error code.
9639 **
9640 ** A changeset consists of zero or more INSERT, UPDATE and/or DELETE changes,
9641 ** each representing a change to a single row of an attached table. An INSERT
9642 ** change contains the values of each field of a new database row. A DELETE
9643 ** contains the original values of each field of a deleted database row. An
9644 ** UPDATE change contains the original values of each field of an updated
9645 ** database row along with the updated values for each updated non-primary-key
9646 ** column. It is not possible for an UPDATE change to represent a change that
9647 ** modifies the values of primary key columns. If such a change is made, it
9648 ** is represented in a changeset as a DELETE followed by an INSERT.
9649 **
9650 ** Changes are not recorded for rows that have NULL values stored in one or
9651 ** more of their PRIMARY KEY columns. If such a row is inserted or deleted,
9652 ** no corresponding change is present in the changesets returned by this
9653 ** function. If an existing row with one or more NULL values stored in
9654 ** PRIMARY KEY columns is updated so that all PRIMARY KEY columns are non-NULL,
9655 ** only an INSERT is appears in the changeset. Similarly, if an existing row
9656 ** with non-NULL PRIMARY KEY values is updated so that one or more of its
9657 ** PRIMARY KEY columns are set to NULL, the resulting changeset contains a
9658 ** DELETE change only.
9659 **
9660 ** The contents of a changeset may be traversed using an iterator created
9661 ** using the [sqlite3changeset_start()] API. A changeset may be applied to
9662 ** a database with a compatible schema using the [sqlite3changeset_apply()]
9663 ** API.
9664 **
9665 ** Within a changeset generated by this function, all changes related to a
9666 ** single table are grouped together. In other words, when iterating through
9667 ** a changeset or when applying a changeset to a database, all changes related
9668 ** to a single table are processed before moving on to the next table. Tables
9669 ** are sorted in the same order in which they were attached (or auto-attached)
9670 ** to the sqlite3_session object. The order in which the changes related to
9671 ** a single table are stored is undefined.
9672 **
9673 ** Following a successful call to this function, it is the responsibility of
9674 ** the caller to eventually free the buffer that *ppChangeset points to using
9675 ** [sqlite3_free()].
9676 **
9677 ** <h3>Changeset Generation</h3>
9678 **
9679 ** Once a table has been attached to a session object, the session object
9680 ** records the primary key values of all new rows inserted into the table.
9681 ** It also records the original primary key and other column values of any
9682 ** deleted or updated rows. For each unique primary key value, data is only
9683 ** recorded once - the first time a row with said primary key is inserted,
9684 ** updated or deleted in the lifetime of the session.
9685 **
9686 ** There is one exception to the previous paragraph: when a row is inserted,
9687 ** updated or deleted, if one or more of its primary key columns contain a
9688 ** NULL value, no record of the change is made.
9689 **
9690 ** The session object therefore accumulates two types of records - those
9691 ** that consist of primary key values only (created when the user inserts
9692 ** a new record) and those that consist of the primary key values and the
9693 ** original values of other table columns (created when the users deletes
9694 ** or updates a record).
9695 **
9696 ** When this function is called, the requested changeset is created using
9697 ** both the accumulated records and the current contents of the database
9698 ** file. Specifically:
9699 **
9700 ** <ul>
9701 **   <li> For each record generated by an insert, the database is queried
9702 **        for a row with a matching primary key. If one is found, an INSERT
9703 **        change is added to the changeset. If no such row is found, no change
9704 **        is added to the changeset.
9705 **
9706 **   <li> For each record generated by an update or delete, the database is
9707 **        queried for a row with a matching primary key. If such a row is
9708 **        found and one or more of the non-primary key fields have been
9709 **        modified from their original values, an UPDATE change is added to
9710 **        the changeset. Or, if no such row is found in the table, a DELETE
9711 **        change is added to the changeset. If there is a row with a matching
9712 **        primary key in the database, but all fields contain their original
9713 **        values, no change is added to the changeset.
9714 ** </ul>
9715 **
9716 ** This means, amongst other things, that if a row is inserted and then later
9717 ** deleted while a session object is active, neither the insert nor the delete
9718 ** will be present in the changeset. Or if a row is deleted and then later a
9719 ** row with the same primary key values inserted while a session object is
9720 ** active, the resulting changeset will contain an UPDATE change instead of
9721 ** a DELETE and an INSERT.
9722 **
9723 ** When a session object is disabled (see the [sqlite3session_enable()] API),
9724 ** it does not accumulate records when rows are inserted, updated or deleted.
9725 ** This may appear to have some counter-intuitive effects if a single row
9726 ** is written to more than once during a session. For example, if a row
9727 ** is inserted while a session object is enabled, then later deleted while
9728 ** the same session object is disabled, no INSERT record will appear in the
9729 ** changeset, even though the delete took place while the session was disabled.
9730 ** Or, if one field of a row is updated while a session is disabled, and
9731 ** another field of the same row is updated while the session is enabled, the
9732 ** resulting changeset will contain an UPDATE change that updates both fields.
9733 */
9734 
9735 /* Session object */
9736 /* OUT: Size of buffer at *ppChangeset */
9737 /* OUT: Buffer containing changeset */
9738 
9739 /*
9740 ** CAPI3REF: Load The Difference Between Tables Into A Session
9741 ** METHOD: sqlite3_session
9742 **
9743 ** If it is not already attached to the session object passed as the first
9744 ** argument, this function attaches table zTbl in the same manner as the
9745 ** [sqlite3session_attach()] function. If zTbl does not exist, or if it
9746 ** does not have a primary key, this function is a no-op (but does not return
9747 ** an error).
9748 **
9749 ** Argument zFromDb must be the name of a database ("main", "temp" etc.)
9750 ** attached to the same database handle as the session object that contains
9751 ** a table compatible with the table attached to the session by this function.
9752 ** A table is considered compatible if it:
9753 **
9754 ** <ul>
9755 **   <li> Has the same name,
9756 **   <li> Has the same set of columns declared in the same order, and
9757 **   <li> Has the same PRIMARY KEY definition.
9758 ** </ul>
9759 **
9760 ** If the tables are not compatible, SQLITE_SCHEMA is returned. If the tables
9761 ** are compatible but do not have any PRIMARY KEY columns, it is not an error
9762 ** but no changes are added to the session object. As with other session
9763 ** APIs, tables without PRIMARY KEYs are simply ignored.
9764 **
9765 ** This function adds a set of changes to the session object that could be
9766 ** used to update the table in database zFrom (call this the "from-table")
9767 ** so that its content is the same as the table attached to the session
9768 ** object (call this the "to-table"). Specifically:
9769 **
9770 ** <ul>
9771 **   <li> For each row (primary key) that exists in the to-table but not in
9772 **     the from-table, an INSERT record is added to the session object.
9773 **
9774 **   <li> For each row (primary key) that exists in the to-table but not in
9775 **     the from-table, a DELETE record is added to the session object.
9776 **
9777 **   <li> For each row (primary key) that exists in both tables, but features
9778 **     different non-PK values in each, an UPDATE record is added to the
9779 **     session.
9780 ** </ul>
9781 **
9782 ** To clarify, if this function is called and then a changeset constructed
9783 ** using [sqlite3session_changeset()], then after applying that changeset to
9784 ** database zFrom the contents of the two compatible tables would be
9785 ** identical.
9786 **
9787 ** It an error if database zFrom does not exist or does not contain the
9788 ** required compatible table.
9789 **
9790 ** If the operation successful, SQLITE_OK is returned. Otherwise, an SQLite
9791 ** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
9792 ** may be set to point to a buffer containing an English language error
9793 ** message. It is the responsibility of the caller to free this buffer using
9794 ** sqlite3_free().
9795 */
9796 
9797 /*
9798 ** CAPI3REF: Generate A Patchset From A Session Object
9799 ** METHOD: sqlite3_session
9800 **
9801 ** The differences between a patchset and a changeset are that:
9802 **
9803 ** <ul>
9804 **   <li> DELETE records consist of the primary key fields only. The
9805 **        original values of other fields are omitted.
9806 **   <li> The original values of any modified fields are omitted from
9807 **        UPDATE records.
9808 ** </ul>
9809 **
9810 ** A patchset blob may be used with up to date versions of all
9811 ** sqlite3changeset_xxx API functions except for sqlite3changeset_invert(),
9812 ** which returns SQLITE_CORRUPT if it is passed a patchset. Similarly,
9813 ** attempting to use a patchset blob with old versions of the
9814 ** sqlite3changeset_xxx APIs also provokes an SQLITE_CORRUPT error.
9815 **
9816 ** Because the non-primary key "old.*" fields are omitted, no
9817 ** SQLITE_CHANGESET_DATA conflicts can be detected or reported if a patchset
9818 ** is passed to the sqlite3changeset_apply() API. Other conflict types work
9819 ** in the same way as for changesets.
9820 **
9821 ** Changes within a patchset are ordered in the same way as for changesets
9822 ** generated by the sqlite3session_changeset() function (i.e. all changes for
9823 ** a single table are grouped together, tables appear in the order in which
9824 ** they were attached to the session object).
9825 */
9826 
9827 /* Session object */
9828 /* OUT: Size of buffer at *ppPatchset */
9829 /* OUT: Buffer containing patchset */
9830 
9831 /*
9832 ** CAPI3REF: Test if a changeset has recorded any changes.
9833 **
9834 ** Return non-zero if no changes to attached tables have been recorded by
9835 ** the session object passed as the first argument. Otherwise, if one or
9836 ** more changes have been recorded, return zero.
9837 **
9838 ** Even if this function returns zero, it is possible that calling
9839 ** [sqlite3session_changeset()] on the session handle may still return a
9840 ** changeset that contains no changes. This can happen when a row in
9841 ** an attached table is modified and then later on the original values
9842 ** are restored. However, if this function returns non-zero, then it is
9843 ** guaranteed that a call to sqlite3session_changeset() will return a
9844 ** changeset containing zero changes.
9845 */
9846 
9847 /*
9848 ** CAPI3REF: Create An Iterator To Traverse A Changeset
9849 ** CONSTRUCTOR: sqlite3_changeset_iter
9850 **
9851 ** Create an iterator used to iterate through the contents of a changeset.
9852 ** If successful, *pp is set to point to the iterator handle and SQLITE_OK
9853 ** is returned. Otherwise, if an error occurs, *pp is set to zero and an
9854 ** SQLite error code is returned.
9855 **
9856 ** The following functions can be used to advance and query a changeset
9857 ** iterator created by this function:
9858 **
9859 ** <ul>
9860 **   <li> [sqlite3changeset_next()]
9861 **   <li> [sqlite3changeset_op()]
9862 **   <li> [sqlite3changeset_new()]
9863 **   <li> [sqlite3changeset_old()]
9864 ** </ul>
9865 **
9866 ** It is the responsibility of the caller to eventually destroy the iterator
9867 ** by passing it to [sqlite3changeset_finalize()]. The buffer containing the
9868 ** changeset (pChangeset) must remain valid until after the iterator is
9869 ** destroyed.
9870 **
9871 ** Assuming the changeset blob was created by one of the
9872 ** [sqlite3session_changeset()], [sqlite3changeset_concat()] or
9873 ** [sqlite3changeset_invert()] functions, all changes within the changeset
9874 ** that apply to a single table are grouped together. This means that when
9875 ** an application iterates through a changeset using an iterator created by
9876 ** this function, all changes that relate to a single table are visited
9877 ** consecutively. There is no chance that the iterator will visit a change
9878 ** the applies to table X, then one for table Y, and then later on visit
9879 ** another change for table X.
9880 */
9881 
9882 /* OUT: New changeset iterator handle */
9883 /* Size of changeset blob in bytes */
9884 /* Pointer to blob containing changeset */
9885 
9886 /*
9887 ** CAPI3REF: Advance A Changeset Iterator
9888 ** METHOD: sqlite3_changeset_iter
9889 **
9890 ** This function may only be used with iterators created by function
9891 ** [sqlite3changeset_start()]. If it is called on an iterator passed to
9892 ** a conflict-handler callback by [sqlite3changeset_apply()], SQLITE_MISUSE
9893 ** is returned and the call has no effect.
9894 **
9895 ** Immediately after an iterator is created by sqlite3changeset_start(), it
9896 ** does not point to any change in the changeset. Assuming the changeset
9897 ** is not empty, the first call to this function advances the iterator to
9898 ** point to the first change in the changeset. Each subsequent call advances
9899 ** the iterator to point to the next change in the changeset (if any). If
9900 ** no error occurs and the iterator points to a valid change after a call
9901 ** to sqlite3changeset_next() has advanced it, SQLITE_ROW is returned.
9902 ** Otherwise, if all changes in the changeset have already been visited,
9903 ** SQLITE_DONE is returned.
9904 **
9905 ** If an error occurs, an SQLite error code is returned. Possible error
9906 ** codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or
9907 ** SQLITE_NOMEM.
9908 */
9909 
9910 /*
9911 ** CAPI3REF: Obtain The Current Operation From A Changeset Iterator
9912 ** METHOD: sqlite3_changeset_iter
9913 **
9914 ** The pIter argument passed to this function may either be an iterator
9915 ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
9916 ** created by [sqlite3changeset_start()]. In the latter case, the most recent
9917 ** call to [sqlite3changeset_next()] must have returned [SQLITE_ROW]. If this
9918 ** is not the case, this function returns [SQLITE_MISUSE].
9919 **
9920 ** If argument pzTab is not NULL, then *pzTab is set to point to a
9921 ** nul-terminated utf-8 encoded string containing the name of the table
9922 ** affected by the current change. The buffer remains valid until either
9923 ** sqlite3changeset_next() is called on the iterator or until the
9924 ** conflict-handler function returns. If pnCol is not NULL, then *pnCol is
9925 ** set to the number of columns in the table affected by the change. If
9926 ** pbIncorrect is not NULL, then *pbIndirect is set to true (1) if the change
9927 ** is an indirect change, or false (0) otherwise. See the documentation for
9928 ** [sqlite3session_indirect()] for a description of direct and indirect
9929 ** changes. Finally, if pOp is not NULL, then *pOp is set to one of
9930 ** [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE], depending on the
9931 ** type of change that the iterator currently points to.
9932 **
9933 ** If no error occurs, SQLITE_OK is returned. If an error does occur, an
9934 ** SQLite error code is returned. The values of the output variables may not
9935 ** be trusted in this case.
9936 */
9937 
9938 /* Iterator object */
9939 /* OUT: Pointer to table name */
9940 /* OUT: Number of columns in table */
9941 /* OUT: SQLITE_INSERT, DELETE or UPDATE */
9942 /* OUT: True for an 'indirect' change */
9943 
9944 /*
9945 ** CAPI3REF: Obtain The Primary Key Definition Of A Table
9946 ** METHOD: sqlite3_changeset_iter
9947 **
9948 ** For each modified table, a changeset includes the following:
9949 **
9950 ** <ul>
9951 **   <li> The number of columns in the table, and
9952 **   <li> Which of those columns make up the tables PRIMARY KEY.
9953 ** </ul>
9954 **
9955 ** This function is used to find which columns comprise the PRIMARY KEY of
9956 ** the table modified by the change that iterator pIter currently points to.
9957 ** If successful, *pabPK is set to point to an array of nCol entries, where
9958 ** nCol is the number of columns in the table. Elements of *pabPK are set to
9959 ** 0x01 if the corresponding column is part of the tables primary key, or
9960 ** 0x00 if it is not.
9961 **
9962 ** If argument pnCol is not NULL, then *pnCol is set to the number of columns
9963 ** in the table.
9964 **
9965 ** If this function is called when the iterator does not point to a valid
9966 ** entry, SQLITE_MISUSE is returned and the output variables zeroed. Otherwise,
9967 ** SQLITE_OK is returned and the output variables populated as described
9968 ** above.
9969 */
9970 
9971 /* Iterator object */
9972 /* OUT: Array of boolean - true for PK cols */
9973 /* OUT: Number of entries in output array */
9974 
9975 /*
9976 ** CAPI3REF: Obtain old.* Values From A Changeset Iterator
9977 ** METHOD: sqlite3_changeset_iter
9978 **
9979 ** The pIter argument passed to this function may either be an iterator
9980 ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
9981 ** created by [sqlite3changeset_start()]. In the latter case, the most recent
9982 ** call to [sqlite3changeset_next()] must have returned SQLITE_ROW.
9983 ** Furthermore, it may only be called if the type of change that the iterator
9984 ** currently points to is either [SQLITE_DELETE] or [SQLITE_UPDATE]. Otherwise,
9985 ** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL.
9986 **
9987 ** Argument iVal must be greater than or equal to 0, and less than the number
9988 ** of columns in the table affected by the current change. Otherwise,
9989 ** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
9990 **
9991 ** If successful, this function sets *ppValue to point to a protected
9992 ** sqlite3_value object containing the iVal'th value from the vector of
9993 ** original row values stored as part of the UPDATE or DELETE change and
9994 ** returns SQLITE_OK. The name of the function comes from the fact that this
9995 ** is similar to the "old.*" columns available to update or delete triggers.
9996 **
9997 ** If some other error occurs (e.g. an OOM condition), an SQLite error code
9998 ** is returned and *ppValue is set to NULL.
9999 */
10000 
10001 /* Changeset iterator */
10002 /* Column number */
10003 /* OUT: Old value (or NULL pointer) */
10004 
10005 /*
10006 ** CAPI3REF: Obtain new.* Values From A Changeset Iterator
10007 ** METHOD: sqlite3_changeset_iter
10008 **
10009 ** The pIter argument passed to this function may either be an iterator
10010 ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
10011 ** created by [sqlite3changeset_start()]. In the latter case, the most recent
10012 ** call to [sqlite3changeset_next()] must have returned SQLITE_ROW.
10013 ** Furthermore, it may only be called if the type of change that the iterator
10014 ** currently points to is either [SQLITE_UPDATE] or [SQLITE_INSERT]. Otherwise,
10015 ** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL.
10016 **
10017 ** Argument iVal must be greater than or equal to 0, and less than the number
10018 ** of columns in the table affected by the current change. Otherwise,
10019 ** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
10020 **
10021 ** If successful, this function sets *ppValue to point to a protected
10022 ** sqlite3_value object containing the iVal'th value from the vector of
10023 ** new row values stored as part of the UPDATE or INSERT change and
10024 ** returns SQLITE_OK. If the change is an UPDATE and does not include
10025 ** a new value for the requested column, *ppValue is set to NULL and
10026 ** SQLITE_OK returned. The name of the function comes from the fact that
10027 ** this is similar to the "new.*" columns available to update or delete
10028 ** triggers.
10029 **
10030 ** If some other error occurs (e.g. an OOM condition), an SQLite error code
10031 ** is returned and *ppValue is set to NULL.
10032 */
10033 
10034 /* Changeset iterator */
10035 /* Column number */
10036 /* OUT: New value (or NULL pointer) */
10037 
10038 /*
10039 ** CAPI3REF: Obtain Conflicting Row Values From A Changeset Iterator
10040 ** METHOD: sqlite3_changeset_iter
10041 **
10042 ** This function should only be used with iterator objects passed to a
10043 ** conflict-handler callback by [sqlite3changeset_apply()] with either
10044 ** [SQLITE_CHANGESET_DATA] or [SQLITE_CHANGESET_CONFLICT]. If this function
10045 ** is called on any other iterator, [SQLITE_MISUSE] is returned and *ppValue
10046 ** is set to NULL.
10047 **
10048 ** Argument iVal must be greater than or equal to 0, and less than the number
10049 ** of columns in the table affected by the current change. Otherwise,
10050 ** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
10051 **
10052 ** If successful, this function sets *ppValue to point to a protected
10053 ** sqlite3_value object containing the iVal'th value from the
10054 ** "conflicting row" associated with the current conflict-handler callback
10055 ** and returns SQLITE_OK.
10056 **
10057 ** If some other error occurs (e.g. an OOM condition), an SQLite error code
10058 ** is returned and *ppValue is set to NULL.
10059 */
10060 
10061 /* Changeset iterator */
10062 /* Column number */
10063 /* OUT: Value from conflicting row */
10064 
10065 /*
10066 ** CAPI3REF: Determine The Number Of Foreign Key Constraint Violations
10067 ** METHOD: sqlite3_changeset_iter
10068 **
10069 ** This function may only be called with an iterator passed to an
10070 ** SQLITE_CHANGESET_FOREIGN_KEY conflict handler callback. In this case
10071 ** it sets the output variable to the total number of known foreign key
10072 ** violations in the destination database and returns SQLITE_OK.
10073 **
10074 ** In all other cases this function returns SQLITE_MISUSE.
10075 */
10076 
10077 /* Changeset iterator */
10078 /* OUT: Number of FK violations */
10079 
10080 /*
10081 ** CAPI3REF: Finalize A Changeset Iterator
10082 ** METHOD: sqlite3_changeset_iter
10083 **
10084 ** This function is used to finalize an iterator allocated with
10085 ** [sqlite3changeset_start()].
10086 **
10087 ** This function should only be called on iterators created using the
10088 ** [sqlite3changeset_start()] function. If an application calls this
10089 ** function with an iterator passed to a conflict-handler by
10090 ** [sqlite3changeset_apply()], [SQLITE_MISUSE] is immediately returned and the
10091 ** call has no effect.
10092 **
10093 ** If an error was encountered within a call to an sqlite3changeset_xxx()
10094 ** function (for example an [SQLITE_CORRUPT] in [sqlite3changeset_next()] or an
10095 ** [SQLITE_NOMEM] in [sqlite3changeset_new()]) then an error code corresponding
10096 ** to that error is returned by this function. Otherwise, SQLITE_OK is
10097 ** returned. This is to allow the following pattern (pseudo-code):
10098 **
10099 ** <pre>
10100 **   sqlite3changeset_start();
10101 **   while( SQLITE_ROW==sqlite3changeset_next() ){
10102 **     // Do something with change.
10103 **   }
10104 **   rc = sqlite3changeset_finalize();
10105 **   if( rc!=SQLITE_OK ){
10106 **     // An error has occurred
10107 **   }
10108 ** </pre>
10109 */
10110 
10111 /*
10112 ** CAPI3REF: Invert A Changeset
10113 **
10114 ** This function is used to "invert" a changeset object. Applying an inverted
10115 ** changeset to a database reverses the effects of applying the uninverted
10116 ** changeset. Specifically:
10117 **
10118 ** <ul>
10119 **   <li> Each DELETE change is changed to an INSERT, and
10120 **   <li> Each INSERT change is changed to a DELETE, and
10121 **   <li> For each UPDATE change, the old.* and new.* values are exchanged.
10122 ** </ul>
10123 **
10124 ** This function does not change the order in which changes appear within
10125 ** the changeset. It merely reverses the sense of each individual change.
10126 **
10127 ** If successful, a pointer to a buffer containing the inverted changeset
10128 ** is stored in *ppOut, the size of the same buffer is stored in *pnOut, and
10129 ** SQLITE_OK is returned. If an error occurs, both *pnOut and *ppOut are
10130 ** zeroed and an SQLite error code returned.
10131 **
10132 ** It is the responsibility of the caller to eventually call sqlite3_free()
10133 ** on the *ppOut pointer to free the buffer allocation following a successful
10134 ** call to this function.
10135 **
10136 ** WARNING/TODO: This function currently assumes that the input is a valid
10137 ** changeset. If it is not, the results are undefined.
10138 */
10139 
10140 /* Input changeset */
10141 /* OUT: Inverse of input */
10142 
10143 /*
10144 ** CAPI3REF: Concatenate Two Changeset Objects
10145 **
10146 ** This function is used to concatenate two changesets, A and B, into a
10147 ** single changeset. The result is a changeset equivalent to applying
10148 ** changeset A followed by changeset B.
10149 **
10150 ** This function combines the two input changesets using an
10151 ** sqlite3_changegroup object. Calling it produces similar results as the
10152 ** following code fragment:
10153 **
10154 ** <pre>
10155 **   sqlite3_changegroup *pGrp;
10156 **   rc = sqlite3_changegroup_new(&pGrp);
10157 **   if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nA, pA);
10158 **   if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nB, pB);
10159 **   if( rc==SQLITE_OK ){
10160 **     rc = sqlite3changegroup_output(pGrp, pnOut, ppOut);
10161 **   }else{
10162 **     *ppOut = 0;
10163 **     *pnOut = 0;
10164 **   }
10165 ** </pre>
10166 **
10167 ** Refer to the sqlite3_changegroup documentation below for details.
10168 */
10169 
10170 /* Number of bytes in buffer pA */
10171 /* Pointer to buffer containing changeset A */
10172 /* Number of bytes in buffer pB */
10173 /* Pointer to buffer containing changeset B */
10174 /* OUT: Number of bytes in output changeset */
10175 /* OUT: Buffer containing output changeset */
10176 
10177 /*
10178 ** CAPI3REF: Changegroup Handle
10179 **
10180 ** A changegroup is an object used to combine two or more
10181 ** [changesets] or [patchsets]
10182 */
10183 
10184 /*
10185 ** CAPI3REF: Create A New Changegroup Object
10186 ** CONSTRUCTOR: sqlite3_changegroup
10187 **
10188 ** An sqlite3_changegroup object is used to combine two or more changesets
10189 ** (or patchsets) into a single changeset (or patchset). A single changegroup
10190 ** object may combine changesets or patchsets, but not both. The output is
10191 ** always in the same format as the input.
10192 **
10193 ** If successful, this function returns SQLITE_OK and populates (*pp) with
10194 ** a pointer to a new sqlite3_changegroup object before returning. The caller
10195 ** should eventually free the returned object using a call to
10196 ** sqlite3changegroup_delete(). If an error occurs, an SQLite error code
10197 ** (i.e. SQLITE_NOMEM) is returned and *pp is set to NULL.
10198 **
10199 ** The usual usage pattern for an sqlite3_changegroup object is as follows:
10200 **
10201 ** <ul>
10202 **   <li> It is created using a call to sqlite3changegroup_new().
10203 **
10204 **   <li> Zero or more changesets (or patchsets) are added to the object
10205 **        by calling sqlite3changegroup_add().
10206 **
10207 **   <li> The result of combining all input changesets together is obtained
10208 **        by the application via a call to sqlite3changegroup_output().
10209 **
10210 **   <li> The object is deleted using a call to sqlite3changegroup_delete().
10211 ** </ul>
10212 **
10213 ** Any number of calls to add() and output() may be made between the calls to
10214 ** new() and delete(), and in any order.
10215 **
10216 ** As well as the regular sqlite3changegroup_add() and
10217 ** sqlite3changegroup_output() functions, also available are the streaming
10218 ** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm().
10219 */
10220 
10221 /*
10222 ** CAPI3REF: Add A Changeset To A Changegroup
10223 ** METHOD: sqlite3_changegroup
10224 **
10225 ** Add all changes within the changeset (or patchset) in buffer pData (size
10226 ** nData bytes) to the changegroup.
10227 **
10228 ** If the buffer contains a patchset, then all prior calls to this function
10229 ** on the same changegroup object must also have specified patchsets. Or, if
10230 ** the buffer contains a changeset, so must have the earlier calls to this
10231 ** function. Otherwise, SQLITE_ERROR is returned and no changes are added
10232 ** to the changegroup.
10233 **
10234 ** Rows within the changeset and changegroup are identified by the values in
10235 ** their PRIMARY KEY columns. A change in the changeset is considered to
10236 ** apply to the same row as a change already present in the changegroup if
10237 ** the two rows have the same primary key.
10238 **
10239 ** Changes to rows that do not already appear in the changegroup are
10240 ** simply copied into it. Or, if both the new changeset and the changegroup
10241 ** contain changes that apply to a single row, the final contents of the
10242 ** changegroup depends on the type of each change, as follows:
10243 **
10244 ** <table border=1 style="margin-left:8ex;margin-right:8ex">
10245 **   <tr><th style="white-space:pre">Existing Change  </th>
10246 **       <th style="white-space:pre">New Change       </th>
10247 **       <th>Output Change
10248 **   <tr><td>INSERT <td>INSERT <td>
10249 **       The new change is ignored. This case does not occur if the new
10250 **       changeset was recorded immediately after the changesets already
10251 **       added to the changegroup.
10252 **   <tr><td>INSERT <td>UPDATE <td>
10253 **       The INSERT change remains in the changegroup. The values in the
10254 **       INSERT change are modified as if the row was inserted by the
10255 **       existing change and then updated according to the new change.
10256 **   <tr><td>INSERT <td>DELETE <td>
10257 **       The existing INSERT is removed from the changegroup. The DELETE is
10258 **       not added.
10259 **   <tr><td>UPDATE <td>INSERT <td>
10260 **       The new change is ignored. This case does not occur if the new
10261 **       changeset was recorded immediately after the changesets already
10262 **       added to the changegroup.
10263 **   <tr><td>UPDATE <td>UPDATE <td>
10264 **       The existing UPDATE remains within the changegroup. It is amended
10265 **       so that the accompanying values are as if the row was updated once
10266 **       by the existing change and then again by the new change.
10267 **   <tr><td>UPDATE <td>DELETE <td>
10268 **       The existing UPDATE is replaced by the new DELETE within the
10269 **       changegroup.
10270 **   <tr><td>DELETE <td>INSERT <td>
10271 **       If one or more of the column values in the row inserted by the
10272 **       new change differ from those in the row deleted by the existing
10273 **       change, the existing DELETE is replaced by an UPDATE within the
10274 **       changegroup. Otherwise, if the inserted row is exactly the same
10275 **       as the deleted row, the existing DELETE is simply discarded.
10276 **   <tr><td>DELETE <td>UPDATE <td>
10277 **       The new change is ignored. This case does not occur if the new
10278 **       changeset was recorded immediately after the changesets already
10279 **       added to the changegroup.
10280 **   <tr><td>DELETE <td>DELETE <td>
10281 **       The new change is ignored. This case does not occur if the new
10282 **       changeset was recorded immediately after the changesets already
10283 **       added to the changegroup.
10284 ** </table>
10285 **
10286 ** If the new changeset contains changes to a table that is already present
10287 ** in the changegroup, then the number of columns and the position of the
10288 ** primary key columns for the table must be consistent. If this is not the
10289 ** case, this function fails with SQLITE_SCHEMA. If the input changeset
10290 ** appears to be corrupt and the corruption is detected, SQLITE_CORRUPT is
10291 ** returned. Or, if an out-of-memory condition occurs during processing, this
10292 ** function returns SQLITE_NOMEM. In all cases, if an error occurs the
10293 ** final contents of the changegroup is undefined.
10294 **
10295 ** If no error occurs, SQLITE_OK is returned.
10296 */
10297 
10298 /*
10299 ** CAPI3REF: Obtain A Composite Changeset From A Changegroup
10300 ** METHOD: sqlite3_changegroup
10301 **
10302 ** Obtain a buffer containing a changeset (or patchset) representing the
10303 ** current contents of the changegroup. If the inputs to the changegroup
10304 ** were themselves changesets, the output is a changeset. Or, if the
10305 ** inputs were patchsets, the output is also a patchset.
10306 **
10307 ** As with the output of the sqlite3session_changeset() and
10308 ** sqlite3session_patchset() functions, all changes related to a single
10309 ** table are grouped together in the output of this function. Tables appear
10310 ** in the same order as for the very first changeset added to the changegroup.
10311 ** If the second or subsequent changesets added to the changegroup contain
10312 ** changes for tables that do not appear in the first changeset, they are
10313 ** appended onto the end of the output changeset, again in the order in
10314 ** which they are first encountered.
10315 **
10316 ** If an error occurs, an SQLite error code is returned and the output
10317 ** variables (*pnData) and (*ppData) are set to 0. Otherwise, SQLITE_OK
10318 ** is returned and the output variables are set to the size of and a
10319 ** pointer to the output buffer, respectively. In this case it is the
10320 ** responsibility of the caller to eventually free the buffer using a
10321 ** call to sqlite3_free().
10322 */
10323 
10324 /* OUT: Size of output buffer in bytes */
10325 /* OUT: Pointer to output buffer */
10326 
10327 /*
10328 ** CAPI3REF: Delete A Changegroup Object
10329 ** DESTRUCTOR: sqlite3_changegroup
10330 */
10331 
10332 /*
10333 ** CAPI3REF: Apply A Changeset To A Database
10334 **
10335 ** Apply a changeset or patchset to a database. These functions attempt to
10336 ** update the "main" database attached to handle db with the changes found in
10337 ** the changeset passed via the second and third arguments.
10338 **
10339 ** The fourth argument (xFilter) passed to these functions is the "filter
10340 ** callback". If it is not NULL, then for each table affected by at least one
10341 ** change in the changeset, the filter callback is invoked with
10342 ** the table name as the second argument, and a copy of the context pointer
10343 ** passed as the sixth argument as the first. If the "filter callback"
10344 ** returns zero, then no attempt is made to apply any changes to the table.
10345 ** Otherwise, if the return value is non-zero or the xFilter argument to
10346 ** is NULL, all changes related to the table are attempted.
10347 **
10348 ** For each table that is not excluded by the filter callback, this function
10349 ** tests that the target database contains a compatible table. A table is
10350 ** considered compatible if all of the following are true:
10351 **
10352 ** <ul>
10353 **   <li> The table has the same name as the name recorded in the
10354 **        changeset, and
10355 **   <li> The table has at least as many columns as recorded in the
10356 **        changeset, and
10357 **   <li> The table has primary key columns in the same position as
10358 **        recorded in the changeset.
10359 ** </ul>
10360 **
10361 ** If there is no compatible table, it is not an error, but none of the
10362 ** changes associated with the table are applied. A warning message is issued
10363 ** via the sqlite3_log() mechanism with the error code SQLITE_SCHEMA. At most
10364 ** one such warning is issued for each table in the changeset.
10365 **
10366 ** For each change for which there is a compatible table, an attempt is made
10367 ** to modify the table contents according to the UPDATE, INSERT or DELETE
10368 ** change. If a change cannot be applied cleanly, the conflict handler
10369 ** function passed as the fifth argument to sqlite3changeset_apply() may be
10370 ** invoked. A description of exactly when the conflict handler is invoked for
10371 ** each type of change is below.
10372 **
10373 ** Unlike the xFilter argument, xConflict may not be passed NULL. The results
10374 ** of passing anything other than a valid function pointer as the xConflict
10375 ** argument are undefined.
10376 **
10377 ** Each time the conflict handler function is invoked, it must return one
10378 ** of [SQLITE_CHANGESET_OMIT], [SQLITE_CHANGESET_ABORT] or
10379 ** [SQLITE_CHANGESET_REPLACE]. SQLITE_CHANGESET_REPLACE may only be returned
10380 ** if the second argument passed to the conflict handler is either
10381 ** SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If the conflict-handler
10382 ** returns an illegal value, any changes already made are rolled back and
10383 ** the call to sqlite3changeset_apply() returns SQLITE_MISUSE. Different
10384 ** actions are taken by sqlite3changeset_apply() depending on the value
10385 ** returned by each invocation of the conflict-handler function. Refer to
10386 ** the documentation for the three
10387 ** [SQLITE_CHANGESET_OMIT|available return values] for details.
10388 **
10389 ** <dl>
10390 ** <dt>DELETE Changes<dd>
10391 **   For each DELETE change, the function checks if the target database
10392 **   contains a row with the same primary key value (or values) as the
10393 **   original row values stored in the changeset. If it does, and the values
10394 **   stored in all non-primary key columns also match the values stored in
10395 **   the changeset the row is deleted from the target database.
10396 **
10397 **   If a row with matching primary key values is found, but one or more of
10398 **   the non-primary key fields contains a value different from the original
10399 **   row value stored in the changeset, the conflict-handler function is
10400 **   invoked with [SQLITE_CHANGESET_DATA] as the second argument. If the
10401 **   database table has more columns than are recorded in the changeset,
10402 **   only the values of those non-primary key fields are compared against
10403 **   the current database contents - any trailing database table columns
10404 **   are ignored.
10405 **
10406 **   If no row with matching primary key values is found in the database,
10407 **   the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
10408 **   passed as the second argument.
10409 **
10410 **   If the DELETE operation is attempted, but SQLite returns SQLITE_CONSTRAINT
10411 **   (which can only happen if a foreign key constraint is violated), the
10412 **   conflict-handler function is invoked with [SQLITE_CHANGESET_CONSTRAINT]
10413 **   passed as the second argument. This includes the case where the DELETE
10414 **   operation is attempted because an earlier call to the conflict handler
10415 **   function returned [SQLITE_CHANGESET_REPLACE].
10416 **
10417 ** <dt>INSERT Changes<dd>
10418 **   For each INSERT change, an attempt is made to insert the new row into
10419 **   the database. If the changeset row contains fewer fields than the
10420 **   database table, the trailing fields are populated with their default
10421 **   values.
10422 **
10423 **   If the attempt to insert the row fails because the database already
10424 **   contains a row with the same primary key values, the conflict handler
10425 **   function is invoked with the second argument set to
10426 **   [SQLITE_CHANGESET_CONFLICT].
10427 **
10428 **   If the attempt to insert the row fails because of some other constraint
10429 **   violation (e.g. NOT NULL or UNIQUE), the conflict handler function is
10430 **   invoked with the second argument set to [SQLITE_CHANGESET_CONSTRAINT].
10431 **   This includes the case where the INSERT operation is re-attempted because
10432 **   an earlier call to the conflict handler function returned
10433 **   [SQLITE_CHANGESET_REPLACE].
10434 **
10435 ** <dt>UPDATE Changes<dd>
10436 **   For each UPDATE change, the function checks if the target database
10437 **   contains a row with the same primary key value (or values) as the
10438 **   original row values stored in the changeset. If it does, and the values
10439 **   stored in all modified non-primary key columns also match the values
10440 **   stored in the changeset the row is updated within the target database.
10441 **
10442 **   If a row with matching primary key values is found, but one or more of
10443 **   the modified non-primary key fields contains a value different from an
10444 **   original row value stored in the changeset, the conflict-handler function
10445 **   is invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since
10446 **   UPDATE changes only contain values for non-primary key fields that are
10447 **   to be modified, only those fields need to match the original values to
10448 **   avoid the SQLITE_CHANGESET_DATA conflict-handler callback.
10449 **
10450 **   If no row with matching primary key values is found in the database,
10451 **   the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
10452 **   passed as the second argument.
10453 **
10454 **   If the UPDATE operation is attempted, but SQLite returns
10455 **   SQLITE_CONSTRAINT, the conflict-handler function is invoked with
10456 **   [SQLITE_CHANGESET_CONSTRAINT] passed as the second argument.
10457 **   This includes the case where the UPDATE operation is attempted after
10458 **   an earlier call to the conflict handler function returned
10459 **   [SQLITE_CHANGESET_REPLACE].
10460 ** </dl>
10461 **
10462 ** It is safe to execute SQL statements, including those that write to the
10463 ** table that the callback related to, from within the xConflict callback.
10464 ** This can be used to further customize the applications conflict
10465 ** resolution strategy.
10466 **
10467 ** All changes made by these functions are enclosed in a savepoint transaction.
10468 ** If any other error (aside from a constraint failure when attempting to
10469 ** write to the target database) occurs, then the savepoint transaction is
10470 ** rolled back, restoring the target database to its original state, and an
10471 ** SQLite error code returned.
10472 **
10473 ** If the output parameters (ppRebase) and (pnRebase) are non-NULL and
10474 ** the input is a changeset (not a patchset), then sqlite3changeset_apply_v2()
10475 ** may set (*ppRebase) to point to a "rebase" that may be used with the
10476 ** sqlite3_rebaser APIs buffer before returning. In this case (*pnRebase)
10477 ** is set to the size of the buffer in bytes. It is the responsibility of the
10478 ** caller to eventually free any such buffer using sqlite3_free(). The buffer
10479 ** is only allocated and populated if one or more conflicts were encountered
10480 ** while applying the patchset. See comments surrounding the sqlite3_rebaser
10481 ** APIs for further details.
10482 **
10483 ** The behavior of sqlite3changeset_apply_v2() and its streaming equivalent
10484 ** may be modified by passing a combination of
10485 ** [SQLITE_CHANGESETAPPLY_NOSAVEPOINT | supported flags] as the 9th parameter.
10486 **
10487 ** Note that the sqlite3changeset_apply_v2() API is still <b>experimental</b>
10488 ** and therefore subject to change.
10489 */
10490 
10491 /* Apply change to "main" db of this handle */
10492 /* Size of changeset in bytes */
10493 /* Changeset blob */
10494 
10495 /* Copy of sixth arg to _apply() */
10496 /* Table name */
10497 
10498 /* Copy of sixth arg to _apply() */
10499 /* DATA, MISSING, CONFLICT, CONSTRAINT */
10500 /* Handle describing change and conflict */
10501 
10502 /* First argument passed to xConflict */
10503 
10504 /* Apply change to "main" db of this handle */
10505 /* Size of changeset in bytes */
10506 /* Changeset blob */
10507 
10508 /* Copy of sixth arg to _apply() */
10509 /* Table name */
10510 
10511 /* Copy of sixth arg to _apply() */
10512 /* DATA, MISSING, CONFLICT, CONSTRAINT */
10513 /* Handle describing change and conflict */
10514 
10515 /* First argument passed to xConflict */
10516 /* OUT: Rebase data */
10517 /* Combination of SESSION_APPLY_* flags */
10518 
10519 /*
10520 ** CAPI3REF: Flags for sqlite3changeset_apply_v2
10521 **
10522 ** The following flags may passed via the 9th parameter to
10523 ** [sqlite3changeset_apply_v2] and [sqlite3changeset_apply_v2_strm]:
10524 **
10525 ** <dl>
10526 ** <dt>SQLITE_CHANGESETAPPLY_NOSAVEPOINT <dd>
10527 **   Usually, the sessions module encloses all operations performed by
10528 **   a single call to apply_v2() or apply_v2_strm() in a [SAVEPOINT]. The
10529 **   SAVEPOINT is committed if the changeset or patchset is successfully
10530 **   applied, or rolled back if an error occurs. Specifying this flag
10531 **   causes the sessions module to omit this savepoint. In this case, if the
10532 **   caller has an open transaction or savepoint when apply_v2() is called,
10533 **   it may revert the partially applied changeset by rolling it back.
10534 */
10535 
10536 /*
10537 ** CAPI3REF: Constants Passed To The Conflict Handler
10538 **
10539 ** Values that may be passed as the second argument to a conflict-handler.
10540 **
10541 ** <dl>
10542 ** <dt>SQLITE_CHANGESET_DATA<dd>
10543 **   The conflict handler is invoked with CHANGESET_DATA as the second argument
10544 **   when processing a DELETE or UPDATE change if a row with the required
10545 **   PRIMARY KEY fields is present in the database, but one or more other
10546 **   (non primary-key) fields modified by the update do not contain the
10547 **   expected "before" values.
10548 **
10549 **   The conflicting row, in this case, is the database row with the matching
10550 **   primary key.
10551 **
10552 ** <dt>SQLITE_CHANGESET_NOTFOUND<dd>
10553 **   The conflict handler is invoked with CHANGESET_NOTFOUND as the second
10554 **   argument when processing a DELETE or UPDATE change if a row with the
10555 **   required PRIMARY KEY fields is not present in the database.
10556 **
10557 **   There is no conflicting row in this case. The results of invoking the
10558 **   sqlite3changeset_conflict() API are undefined.
10559 **
10560 ** <dt>SQLITE_CHANGESET_CONFLICT<dd>
10561 **   CHANGESET_CONFLICT is passed as the second argument to the conflict
10562 **   handler while processing an INSERT change if the operation would result
10563 **   in duplicate primary key values.
10564 **
10565 **   The conflicting row in this case is the database row with the matching
10566 **   primary key.
10567 **
10568 ** <dt>SQLITE_CHANGESET_FOREIGN_KEY<dd>
10569 **   If foreign key handling is enabled, and applying a changeset leaves the
10570 **   database in a state containing foreign key violations, the conflict
10571 **   handler is invoked with CHANGESET_FOREIGN_KEY as the second argument
10572 **   exactly once before the changeset is committed. If the conflict handler
10573 **   returns CHANGESET_OMIT, the changes, including those that caused the
10574 **   foreign key constraint violation, are committed. Or, if it returns
10575 **   CHANGESET_ABORT, the changeset is rolled back.
10576 **
10577 **   No current or conflicting row information is provided. The only function
10578 **   it is possible to call on the supplied sqlite3_changeset_iter handle
10579 **   is sqlite3changeset_fk_conflicts().
10580 **
10581 ** <dt>SQLITE_CHANGESET_CONSTRAINT<dd>
10582 **   If any other constraint violation occurs while applying a change (i.e.
10583 **   a UNIQUE, CHECK or NOT NULL constraint), the conflict handler is
10584 **   invoked with CHANGESET_CONSTRAINT as the second argument.
10585 **
10586 **   There is no conflicting row in this case. The results of invoking the
10587 **   sqlite3changeset_conflict() API are undefined.
10588 **
10589 ** </dl>
10590 */
10591 
10592 /*
10593 ** CAPI3REF: Constants Returned By The Conflict Handler
10594 **
10595 ** A conflict handler callback must return one of the following three values.
10596 **
10597 ** <dl>
10598 ** <dt>SQLITE_CHANGESET_OMIT<dd>
10599 **   If a conflict handler returns this value no special action is taken. The
10600 **   change that caused the conflict is not applied. The session module
10601 **   continues to the next change in the changeset.
10602 **
10603 ** <dt>SQLITE_CHANGESET_REPLACE<dd>
10604 **   This value may only be returned if the second argument to the conflict
10605 **   handler was SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If this
10606 **   is not the case, any changes applied so far are rolled back and the
10607 **   call to sqlite3changeset_apply() returns SQLITE_MISUSE.
10608 **
10609 **   If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_DATA conflict
10610 **   handler, then the conflicting row is either updated or deleted, depending
10611 **   on the type of change.
10612 **
10613 **   If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_CONFLICT conflict
10614 **   handler, then the conflicting row is removed from the database and a
10615 **   second attempt to apply the change is made. If this second attempt fails,
10616 **   the original row is restored to the database before continuing.
10617 **
10618 ** <dt>SQLITE_CHANGESET_ABORT<dd>
10619 **   If this value is returned, any changes applied so far are rolled back
10620 **   and the call to sqlite3changeset_apply() returns SQLITE_ABORT.
10621 ** </dl>
10622 */
10623 
10624 /*
10625 ** CAPI3REF: Rebasing changesets
10626 ** EXPERIMENTAL
10627 **
10628 ** Suppose there is a site hosting a database in state S0. And that
10629 ** modifications are made that move that database to state S1 and a
10630 ** changeset recorded (the "local" changeset). Then, a changeset based
10631 ** on S0 is received from another site (the "remote" changeset) and
10632 ** applied to the database. The database is then in state
10633 ** (S1+"remote"), where the exact state depends on any conflict
10634 ** resolution decisions (OMIT or REPLACE) made while applying "remote".
10635 ** Rebasing a changeset is to update it to take those conflict
10636 ** resolution decisions into account, so that the same conflicts
10637 ** do not have to be resolved elsewhere in the network.
10638 **
10639 ** For example, if both the local and remote changesets contain an
10640 ** INSERT of the same key on "CREATE TABLE t1(a PRIMARY KEY, b)":
10641 **
10642 **   local:  INSERT INTO t1 VALUES(1, 'v1');
10643 **   remote: INSERT INTO t1 VALUES(1, 'v2');
10644 **
10645 ** and the conflict resolution is REPLACE, then the INSERT change is
10646 ** removed from the local changeset (it was overridden). Or, if the
10647 ** conflict resolution was "OMIT", then the local changeset is modified
10648 ** to instead contain:
10649 **
10650 **           UPDATE t1 SET b = 'v2' WHERE a=1;
10651 **
10652 ** Changes within the local changeset are rebased as follows:
10653 **
10654 ** <dl>
10655 ** <dt>Local INSERT<dd>
10656 **   This may only conflict with a remote INSERT. If the conflict
10657 **   resolution was OMIT, then add an UPDATE change to the rebased
10658 **   changeset. Or, if the conflict resolution was REPLACE, add
10659 **   nothing to the rebased changeset.
10660 **
10661 ** <dt>Local DELETE<dd>
10662 **   This may conflict with a remote UPDATE or DELETE. In both cases the
10663 **   only possible resolution is OMIT. If the remote operation was a
10664 **   DELETE, then add no change to the rebased changeset. If the remote
10665 **   operation was an UPDATE, then the old.* fields of change are updated
10666 **   to reflect the new.* values in the UPDATE.
10667 **
10668 ** <dt>Local UPDATE<dd>
10669 **   This may conflict with a remote UPDATE or DELETE. If it conflicts
10670 **   with a DELETE, and the conflict resolution was OMIT, then the update
10671 **   is changed into an INSERT. Any undefined values in the new.* record
10672 **   from the update change are filled in using the old.* values from
10673 **   the conflicting DELETE. Or, if the conflict resolution was REPLACE,
10674 **   the UPDATE change is simply omitted from the rebased changeset.
10675 **
10676 **   If conflict is with a remote UPDATE and the resolution is OMIT, then
10677 **   the old.* values are rebased using the new.* values in the remote
10678 **   change. Or, if the resolution is REPLACE, then the change is copied
10679 **   into the rebased changeset with updates to columns also updated by
10680 **   the conflicting remote UPDATE removed. If this means no columns would
10681 **   be updated, the change is omitted.
10682 ** </dl>
10683 **
10684 ** A local change may be rebased against multiple remote changes
10685 ** simultaneously. If a single key is modified by multiple remote
10686 ** changesets, they are combined as follows before the local changeset
10687 ** is rebased:
10688 **
10689 ** <ul>
10690 **    <li> If there has been one or more REPLACE resolutions on a
10691 **         key, it is rebased according to a REPLACE.
10692 **
10693 **    <li> If there have been no REPLACE resolutions on a key, then
10694 **         the local changeset is rebased according to the most recent
10695 **         of the OMIT resolutions.
10696 ** </ul>
10697 **
10698 ** Note that conflict resolutions from multiple remote changesets are
10699 ** combined on a per-field basis, not per-row. This means that in the
10700 ** case of multiple remote UPDATE operations, some fields of a single
10701 ** local change may be rebased for REPLACE while others are rebased for
10702 ** OMIT.
10703 **
10704 ** In order to rebase a local changeset, the remote changeset must first
10705 ** be applied to the local database using sqlite3changeset_apply_v2() and
10706 ** the buffer of rebase information captured. Then:
10707 **
10708 ** <ol>
10709 **   <li> An sqlite3_rebaser object is created by calling
10710 **        sqlite3rebaser_create().
10711 **   <li> The new object is configured with the rebase buffer obtained from
10712 **        sqlite3changeset_apply_v2() by calling sqlite3rebaser_configure().
10713 **        If the local changeset is to be rebased against multiple remote
10714 **        changesets, then sqlite3rebaser_configure() should be called
10715 **        multiple times, in the same order that the multiple
10716 **        sqlite3changeset_apply_v2() calls were made.
10717 **   <li> Each local changeset is rebased by calling sqlite3rebaser_rebase().
10718 **   <li> The sqlite3_rebaser object is deleted by calling
10719 **        sqlite3rebaser_delete().
10720 ** </ol>
10721 */
10722 
10723 /*
10724 ** CAPI3REF: Create a changeset rebaser object.
10725 ** EXPERIMENTAL
10726 **
10727 ** Allocate a new changeset rebaser object. If successful, set (*ppNew) to
10728 ** point to the new object and return SQLITE_OK. Otherwise, if an error
10729 ** occurs, return an SQLite error code (e.g. SQLITE_NOMEM) and set (*ppNew)
10730 ** to NULL.
10731 */
10732 
10733 /*
10734 ** CAPI3REF: Configure a changeset rebaser object.
10735 ** EXPERIMENTAL
10736 **
10737 ** Configure the changeset rebaser object to rebase changesets according
10738 ** to the conflict resolutions described by buffer pRebase (size nRebase
10739 ** bytes), which must have been obtained from a previous call to
10740 ** sqlite3changeset_apply_v2().
10741 */
10742 
10743 /*
10744 ** CAPI3REF: Rebase a changeset
10745 ** EXPERIMENTAL
10746 **
10747 ** Argument pIn must point to a buffer containing a changeset nIn bytes
10748 ** in size. This function allocates and populates a buffer with a copy
10749 ** of the changeset rebased rebased according to the configuration of the
10750 ** rebaser object passed as the first argument. If successful, (*ppOut)
10751 ** is set to point to the new buffer containing the rebased changset and
10752 ** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the
10753 ** responsibility of the caller to eventually free the new buffer using
10754 ** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut)
10755 ** are set to zero and an SQLite error code returned.
10756 */
10757 
10758 /*
10759 ** CAPI3REF: Delete a changeset rebaser object.
10760 ** EXPERIMENTAL
10761 **
10762 ** Delete the changeset rebaser object and all associated resources. There
10763 ** should be one call to this function for each successful invocation
10764 ** of sqlite3rebaser_create().
10765 */
10766 
10767 /*
10768 ** CAPI3REF: Streaming Versions of API functions.
10769 **
10770 ** The six streaming API xxx_strm() functions serve similar purposes to the
10771 ** corresponding non-streaming API functions:
10772 **
10773 ** <table border=1 style="margin-left:8ex;margin-right:8ex">
10774 **   <tr><th>Streaming function<th>Non-streaming equivalent</th>
10775 **   <tr><td>sqlite3changeset_apply_strm<td>[sqlite3changeset_apply]
10776 **   <tr><td>sqlite3changeset_apply_strm_v2<td>[sqlite3changeset_apply_v2]
10777 **   <tr><td>sqlite3changeset_concat_strm<td>[sqlite3changeset_concat]
10778 **   <tr><td>sqlite3changeset_invert_strm<td>[sqlite3changeset_invert]
10779 **   <tr><td>sqlite3changeset_start_strm<td>[sqlite3changeset_start]
10780 **   <tr><td>sqlite3session_changeset_strm<td>[sqlite3session_changeset]
10781 **   <tr><td>sqlite3session_patchset_strm<td>[sqlite3session_patchset]
10782 ** </table>
10783 **
10784 ** Non-streaming functions that accept changesets (or patchsets) as input
10785 ** require that the entire changeset be stored in a single buffer in memory.
10786 ** Similarly, those that return a changeset or patchset do so by returning
10787 ** a pointer to a single large buffer allocated using sqlite3_malloc().
10788 ** Normally this is convenient. However, if an application running in a
10789 ** low-memory environment is required to handle very large changesets, the
10790 ** large contiguous memory allocations required can become onerous.
10791 **
10792 ** In order to avoid this problem, instead of a single large buffer, input
10793 ** is passed to a streaming API functions by way of a callback function that
10794 ** the sessions module invokes to incrementally request input data as it is
10795 ** required. In all cases, a pair of API function parameters such as
10796 **
10797 **  <pre>
10798 **  &nbsp;     int nChangeset,
10799 **  &nbsp;     void *pChangeset,
10800 **  </pre>
10801 **
10802 ** Is replaced by:
10803 **
10804 **  <pre>
10805 **  &nbsp;     int (*xInput)(void *pIn, void *pData, int *pnData),
10806 **  &nbsp;     void *pIn,
10807 **  </pre>
10808 **
10809 ** Each time the xInput callback is invoked by the sessions module, the first
10810 ** argument passed is a copy of the supplied pIn context pointer. The second
10811 ** argument, pData, points to a buffer (*pnData) bytes in size. Assuming no
10812 ** error occurs the xInput method should copy up to (*pnData) bytes of data
10813 ** into the buffer and set (*pnData) to the actual number of bytes copied
10814 ** before returning SQLITE_OK. If the input is completely exhausted, (*pnData)
10815 ** should be set to zero to indicate this. Or, if an error occurs, an SQLite
10816 ** error code should be returned. In all cases, if an xInput callback returns
10817 ** an error, all processing is abandoned and the streaming API function
10818 ** returns a copy of the error code to the caller.
10819 **
10820 ** In the case of sqlite3changeset_start_strm(), the xInput callback may be
10821 ** invoked by the sessions module at any point during the lifetime of the
10822 ** iterator. If such an xInput callback returns an error, the iterator enters
10823 ** an error state, whereby all subsequent calls to iterator functions
10824 ** immediately fail with the same error code as returned by xInput.
10825 **
10826 ** Similarly, streaming API functions that return changesets (or patchsets)
10827 ** return them in chunks by way of a callback function instead of via a
10828 ** pointer to a single large buffer. In this case, a pair of parameters such
10829 ** as:
10830 **
10831 **  <pre>
10832 **  &nbsp;     int *pnChangeset,
10833 **  &nbsp;     void **ppChangeset,
10834 **  </pre>
10835 **
10836 ** Is replaced by:
10837 **
10838 **  <pre>
10839 **  &nbsp;     int (*xOutput)(void *pOut, const void *pData, int nData),
10840 **  &nbsp;     void *pOut
10841 **  </pre>
10842 **
10843 ** The xOutput callback is invoked zero or more times to return data to
10844 ** the application. The first parameter passed to each call is a copy of the
10845 ** pOut pointer supplied by the application. The second parameter, pData,
10846 ** points to a buffer nData bytes in size containing the chunk of output
10847 ** data being returned. If the xOutput callback successfully processes the
10848 ** supplied data, it should return SQLITE_OK to indicate success. Otherwise,
10849 ** it should return some other SQLite error code. In this case processing
10850 ** is immediately abandoned and the streaming API function returns a copy
10851 ** of the xOutput error code to the application.
10852 **
10853 ** The sessions module never invokes an xOutput callback with the third
10854 ** parameter set to a value less than or equal to zero. Other than this,
10855 ** no guarantees are made as to the size of the chunks of data returned.
10856 */
10857 
10858 /* Apply change to "main" db of this handle */
10859 /* Input function */
10860 /* First arg for xInput */
10861 
10862 /* Copy of sixth arg to _apply() */
10863 /* Table name */
10864 
10865 /* Copy of sixth arg to _apply() */
10866 /* DATA, MISSING, CONFLICT, CONSTRAINT */
10867 /* Handle describing change and conflict */
10868 
10869 /* First argument passed to xConflict */
10870 
10871 /* Apply change to "main" db of this handle */
10872 /* Input function */
10873 /* First arg for xInput */
10874 
10875 /* Copy of sixth arg to _apply() */
10876 /* Table name */
10877 
10878 /* Copy of sixth arg to _apply() */
10879 /* DATA, MISSING, CONFLICT, CONSTRAINT */
10880 /* Handle describing change and conflict */
10881 
10882 /* First argument passed to xConflict */
10883 
10884 /*
10885 ** Make sure we can call this stuff from C++.
10886 */
10887 
10888 /* !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION) */
10889 
10890 /******** End of sqlite3session.h *********/
10891 /******** Begin file fts5.h *********/
10892 /*
10893 ** 2014 May 31
10894 **
10895 ** The author disclaims copyright to this source code.  In place of
10896 ** a legal notice, here is a blessing:
10897 **
10898 **    May you do good and not evil.
10899 **    May you find forgiveness for yourself and forgive others.
10900 **    May you share freely, never taking more than you give.
10901 **
10902 ******************************************************************************
10903 **
10904 ** Interfaces to extend FTS5. Using the interfaces defined in this file,
10905 ** FTS5 may be extended with:
10906 **
10907 **     * custom tokenizers, and
10908 **     * custom auxiliary functions.
10909 */
10910 
10911 /*************************************************************************
10912 ** CUSTOM AUXILIARY FUNCTIONS
10913 **
10914 ** Virtual table implementations may overload SQL functions by implementing
10915 ** the sqlite3_module.xFindFunction() method.
10916 */
10917 
10918 struct Fts5Context;
10919 
10920 /* API offered by current FTS version */
10921 /* First arg to pass to pApi functions */
10922 /* Context for returning result/error */
10923 /* Number of values in apVal[] array */
10924 /* Array of trailing arguments */
10925 alias fts5_extension_function = void function(const(Fts5ExtensionApi)* pApi, Fts5Context* pFts, sqlite3_context* pCtx, int nVal, sqlite3_value** apVal);
10926 
10927 struct Fts5PhraseIter
10928 {
10929     const(ubyte)* a;
10930     const(ubyte)* b;
10931 }
10932 
10933 /*
10934 ** EXTENSION API FUNCTIONS
10935 **
10936 ** xUserData(pFts):
10937 **   Return a copy of the context pointer the extension function was
10938 **   registered with.
10939 **
10940 ** xColumnTotalSize(pFts, iCol, pnToken):
10941 **   If parameter iCol is less than zero, set output variable *pnToken
10942 **   to the total number of tokens in the FTS5 table. Or, if iCol is
10943 **   non-negative but less than the number of columns in the table, return
10944 **   the total number of tokens in column iCol, considering all rows in
10945 **   the FTS5 table.
10946 **
10947 **   If parameter iCol is greater than or equal to the number of columns
10948 **   in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.
10949 **   an OOM condition or IO error), an appropriate SQLite error code is
10950 **   returned.
10951 **
10952 ** xColumnCount(pFts):
10953 **   Return the number of columns in the table.
10954 **
10955 ** xColumnSize(pFts, iCol, pnToken):
10956 **   If parameter iCol is less than zero, set output variable *pnToken
10957 **   to the total number of tokens in the current row. Or, if iCol is
10958 **   non-negative but less than the number of columns in the table, set
10959 **   *pnToken to the number of tokens in column iCol of the current row.
10960 **
10961 **   If parameter iCol is greater than or equal to the number of columns
10962 **   in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.
10963 **   an OOM condition or IO error), an appropriate SQLite error code is
10964 **   returned.
10965 **
10966 **   This function may be quite inefficient if used with an FTS5 table
10967 **   created with the "columnsize=0" option.
10968 **
10969 ** xColumnText:
10970 **   This function attempts to retrieve the text of column iCol of the
10971 **   current document. If successful, (*pz) is set to point to a buffer
10972 **   containing the text in utf-8 encoding, (*pn) is set to the size in bytes
10973 **   (not characters) of the buffer and SQLITE_OK is returned. Otherwise,
10974 **   if an error occurs, an SQLite error code is returned and the final values
10975 **   of (*pz) and (*pn) are undefined.
10976 **
10977 ** xPhraseCount:
10978 **   Returns the number of phrases in the current query expression.
10979 **
10980 ** xPhraseSize:
10981 **   Returns the number of tokens in phrase iPhrase of the query. Phrases
10982 **   are numbered starting from zero.
10983 **
10984 ** xInstCount:
10985 **   Set *pnInst to the total number of occurrences of all phrases within
10986 **   the query within the current row. Return SQLITE_OK if successful, or
10987 **   an error code (i.e. SQLITE_NOMEM) if an error occurs.
10988 **
10989 **   This API can be quite slow if used with an FTS5 table created with the
10990 **   "detail=none" or "detail=column" option. If the FTS5 table is created
10991 **   with either "detail=none" or "detail=column" and "content=" option
10992 **   (i.e. if it is a contentless table), then this API always returns 0.
10993 **
10994 ** xInst:
10995 **   Query for the details of phrase match iIdx within the current row.
10996 **   Phrase matches are numbered starting from zero, so the iIdx argument
10997 **   should be greater than or equal to zero and smaller than the value
10998 **   output by xInstCount().
10999 **
11000 **   Usually, output parameter *piPhrase is set to the phrase number, *piCol
11001 **   to the column in which it occurs and *piOff the token offset of the
11002 **   first token of the phrase. The exception is if the table was created
11003 **   with the offsets=0 option specified. In this case *piOff is always
11004 **   set to -1.
11005 **
11006 **   Returns SQLITE_OK if successful, or an error code (i.e. SQLITE_NOMEM)
11007 **   if an error occurs.
11008 **
11009 **   This API can be quite slow if used with an FTS5 table created with the
11010 **   "detail=none" or "detail=column" option.
11011 **
11012 ** xRowid:
11013 **   Returns the rowid of the current row.
11014 **
11015 ** xTokenize:
11016 **   Tokenize text using the tokenizer belonging to the FTS5 table.
11017 **
11018 ** xQueryPhrase(pFts5, iPhrase, pUserData, xCallback):
11019 **   This API function is used to query the FTS table for phrase iPhrase
11020 **   of the current query. Specifically, a query equivalent to:
11021 **
11022 **       ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid
11023 **
11024 **   with $p set to a phrase equivalent to the phrase iPhrase of the
11025 **   current query is executed. Any column filter that applies to
11026 **   phrase iPhrase of the current query is included in $p. For each
11027 **   row visited, the callback function passed as the fourth argument
11028 **   is invoked. The context and API objects passed to the callback
11029 **   function may be used to access the properties of each matched row.
11030 **   Invoking Api.xUserData() returns a copy of the pointer passed as
11031 **   the third argument to pUserData.
11032 **
11033 **   If the callback function returns any value other than SQLITE_OK, the
11034 **   query is abandoned and the xQueryPhrase function returns immediately.
11035 **   If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK.
11036 **   Otherwise, the error code is propagated upwards.
11037 **
11038 **   If the query runs to completion without incident, SQLITE_OK is returned.
11039 **   Or, if some error occurs before the query completes or is aborted by
11040 **   the callback, an SQLite error code is returned.
11041 **
11042 **
11043 ** xSetAuxdata(pFts5, pAux, xDelete)
11044 **
11045 **   Save the pointer passed as the second argument as the extension functions
11046 **   "auxiliary data". The pointer may then be retrieved by the current or any
11047 **   future invocation of the same fts5 extension function made as part of
11048 **   of the same MATCH query using the xGetAuxdata() API.
11049 **
11050 **   Each extension function is allocated a single auxiliary data slot for
11051 **   each FTS query (MATCH expression). If the extension function is invoked
11052 **   more than once for a single FTS query, then all invocations share a
11053 **   single auxiliary data context.
11054 **
11055 **   If there is already an auxiliary data pointer when this function is
11056 **   invoked, then it is replaced by the new pointer. If an xDelete callback
11057 **   was specified along with the original pointer, it is invoked at this
11058 **   point.
11059 **
11060 **   The xDelete callback, if one is specified, is also invoked on the
11061 **   auxiliary data pointer after the FTS5 query has finished.
11062 **
11063 **   If an error (e.g. an OOM condition) occurs within this function, an
11064 **   the auxiliary data is set to NULL and an error code returned. If the
11065 **   xDelete parameter was not NULL, it is invoked on the auxiliary data
11066 **   pointer before returning.
11067 **
11068 **
11069 ** xGetAuxdata(pFts5, bClear)
11070 **
11071 **   Returns the current auxiliary data pointer for the fts5 extension
11072 **   function. See the xSetAuxdata() method for details.
11073 **
11074 **   If the bClear argument is non-zero, then the auxiliary data is cleared
11075 **   (set to NULL) before this function returns. In this case the xDelete,
11076 **   if any, is not invoked.
11077 **
11078 **
11079 ** xRowCount(pFts5, pnRow)
11080 **
11081 **   This function is used to retrieve the total number of rows in the table.
11082 **   In other words, the same value that would be returned by:
11083 **
11084 **        SELECT count(*) FROM ftstable;
11085 **
11086 ** xPhraseFirst()
11087 **   This function is used, along with type Fts5PhraseIter and the xPhraseNext
11088 **   method, to iterate through all instances of a single query phrase within
11089 **   the current row. This is the same information as is accessible via the
11090 **   xInstCount/xInst APIs. While the xInstCount/xInst APIs are more convenient
11091 **   to use, this API may be faster under some circumstances. To iterate
11092 **   through instances of phrase iPhrase, use the following code:
11093 **
11094 **       Fts5PhraseIter iter;
11095 **       int iCol, iOff;
11096 **       for(pApi->xPhraseFirst(pFts, iPhrase, &iter, &iCol, &iOff);
11097 **           iCol>=0;
11098 **           pApi->xPhraseNext(pFts, &iter, &iCol, &iOff)
11099 **       ){
11100 **         // An instance of phrase iPhrase at offset iOff of column iCol
11101 **       }
11102 **
11103 **   The Fts5PhraseIter structure is defined above. Applications should not
11104 **   modify this structure directly - it should only be used as shown above
11105 **   with the xPhraseFirst() and xPhraseNext() API methods (and by
11106 **   xPhraseFirstColumn() and xPhraseNextColumn() as illustrated below).
11107 **
11108 **   This API can be quite slow if used with an FTS5 table created with the
11109 **   "detail=none" or "detail=column" option. If the FTS5 table is created
11110 **   with either "detail=none" or "detail=column" and "content=" option
11111 **   (i.e. if it is a contentless table), then this API always iterates
11112 **   through an empty set (all calls to xPhraseFirst() set iCol to -1).
11113 **
11114 ** xPhraseNext()
11115 **   See xPhraseFirst above.
11116 **
11117 ** xPhraseFirstColumn()
11118 **   This function and xPhraseNextColumn() are similar to the xPhraseFirst()
11119 **   and xPhraseNext() APIs described above. The difference is that instead
11120 **   of iterating through all instances of a phrase in the current row, these
11121 **   APIs are used to iterate through the set of columns in the current row
11122 **   that contain one or more instances of a specified phrase. For example:
11123 **
11124 **       Fts5PhraseIter iter;
11125 **       int iCol;
11126 **       for(pApi->xPhraseFirstColumn(pFts, iPhrase, &iter, &iCol);
11127 **           iCol>=0;
11128 **           pApi->xPhraseNextColumn(pFts, &iter, &iCol)
11129 **       ){
11130 **         // Column iCol contains at least one instance of phrase iPhrase
11131 **       }
11132 **
11133 **   This API can be quite slow if used with an FTS5 table created with the
11134 **   "detail=none" option. If the FTS5 table is created with either
11135 **   "detail=none" "content=" option (i.e. if it is a contentless table),
11136 **   then this API always iterates through an empty set (all calls to
11137 **   xPhraseFirstColumn() set iCol to -1).
11138 **
11139 **   The information accessed using this API and its companion
11140 **   xPhraseFirstColumn() may also be obtained using xPhraseFirst/xPhraseNext
11141 **   (or xInst/xInstCount). The chief advantage of this API is that it is
11142 **   significantly more efficient than those alternatives when used with
11143 **   "detail=column" tables.
11144 **
11145 ** xPhraseNextColumn()
11146 **   See xPhraseFirstColumn above.
11147 */
11148 struct Fts5ExtensionApi
11149 {
11150     int iVersion; /* Currently always set to 3 */
11151 
11152     void* function(Fts5Context*) xUserData;
11153 
11154     int function(Fts5Context*) xColumnCount;
11155     int function(Fts5Context*, sqlite3_int64* pnRow) xRowCount;
11156     int function(Fts5Context*, int iCol, sqlite3_int64* pnToken) xColumnTotalSize;
11157 
11158     /* Text to tokenize */
11159     /* Context passed to xToken() */
11160     /* Callback */
11161     int function(Fts5Context*, const(char)* pText, int nText, void* pCtx, int function(void*, int, const(char)*, int, int, int) xToken) xTokenize;
11162 
11163     int function(Fts5Context*) xPhraseCount;
11164     int function(Fts5Context*, int iPhrase) xPhraseSize;
11165 
11166     int function(Fts5Context*, int* pnInst) xInstCount;
11167     int function(Fts5Context*, int iIdx, int* piPhrase, int* piCol, int* piOff) xInst;
11168 
11169     sqlite3_int64 function(Fts5Context*) xRowid;
11170     int function(Fts5Context*, int iCol, const(char*)* pz, int* pn) xColumnText;
11171     int function(Fts5Context*, int iCol, int* pnToken) xColumnSize;
11172 
11173     int function(Fts5Context*, int iPhrase, void* pUserData, int function(const(Fts5ExtensionApi)*, Fts5Context*, void*)) xQueryPhrase;
11174     int function(Fts5Context*, void* pAux, void function(void*) xDelete) xSetAuxdata;
11175     void* function(Fts5Context*, int bClear) xGetAuxdata;
11176 
11177     int function(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*, int*) xPhraseFirst;
11178     void function(Fts5Context*, Fts5PhraseIter*, int* piCol, int* piOff) xPhraseNext;
11179 
11180     int function(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*) xPhraseFirstColumn;
11181     void function(Fts5Context*, Fts5PhraseIter*, int* piCol) xPhraseNextColumn;
11182 }
11183 
11184 /*
11185 ** CUSTOM AUXILIARY FUNCTIONS
11186 *************************************************************************/
11187 
11188 /*************************************************************************
11189 ** CUSTOM TOKENIZERS
11190 **
11191 ** Applications may also register custom tokenizer types. A tokenizer
11192 ** is registered by providing fts5 with a populated instance of the
11193 ** following structure. All structure methods must be defined, setting
11194 ** any member of the fts5_tokenizer struct to NULL leads to undefined
11195 ** behaviour. The structure methods are expected to function as follows:
11196 **
11197 ** xCreate:
11198 **   This function is used to allocate and initialize a tokenizer instance.
11199 **   A tokenizer instance is required to actually tokenize text.
11200 **
11201 **   The first argument passed to this function is a copy of the (void*)
11202 **   pointer provided by the application when the fts5_tokenizer object
11203 **   was registered with FTS5 (the third argument to xCreateTokenizer()).
11204 **   The second and third arguments are an array of nul-terminated strings
11205 **   containing the tokenizer arguments, if any, specified following the
11206 **   tokenizer name as part of the CREATE VIRTUAL TABLE statement used
11207 **   to create the FTS5 table.
11208 **
11209 **   The final argument is an output variable. If successful, (*ppOut)
11210 **   should be set to point to the new tokenizer handle and SQLITE_OK
11211 **   returned. If an error occurs, some value other than SQLITE_OK should
11212 **   be returned. In this case, fts5 assumes that the final value of *ppOut
11213 **   is undefined.
11214 **
11215 ** xDelete:
11216 **   This function is invoked to delete a tokenizer handle previously
11217 **   allocated using xCreate(). Fts5 guarantees that this function will
11218 **   be invoked exactly once for each successful call to xCreate().
11219 **
11220 ** xTokenize:
11221 **   This function is expected to tokenize the nText byte string indicated
11222 **   by argument pText. pText may or may not be nul-terminated. The first
11223 **   argument passed to this function is a pointer to an Fts5Tokenizer object
11224 **   returned by an earlier call to xCreate().
11225 **
11226 **   The second argument indicates the reason that FTS5 is requesting
11227 **   tokenization of the supplied text. This is always one of the following
11228 **   four values:
11229 **
11230 **   <ul><li> <b>FTS5_TOKENIZE_DOCUMENT</b> - A document is being inserted into
11231 **            or removed from the FTS table. The tokenizer is being invoked to
11232 **            determine the set of tokens to add to (or delete from) the
11233 **            FTS index.
11234 **
11235 **       <li> <b>FTS5_TOKENIZE_QUERY</b> - A MATCH query is being executed
11236 **            against the FTS index. The tokenizer is being called to tokenize
11237 **            a bareword or quoted string specified as part of the query.
11238 **
11239 **       <li> <b>(FTS5_TOKENIZE_QUERY | FTS5_TOKENIZE_PREFIX)</b> - Same as
11240 **            FTS5_TOKENIZE_QUERY, except that the bareword or quoted string is
11241 **            followed by a "*" character, indicating that the last token
11242 **            returned by the tokenizer will be treated as a token prefix.
11243 **
11244 **       <li> <b>FTS5_TOKENIZE_AUX</b> - The tokenizer is being invoked to
11245 **            satisfy an fts5_api.xTokenize() request made by an auxiliary
11246 **            function. Or an fts5_api.xColumnSize() request made by the same
11247 **            on a columnsize=0 database.
11248 **   </ul>
11249 **
11250 **   For each token in the input string, the supplied callback xToken() must
11251 **   be invoked. The first argument to it should be a copy of the pointer
11252 **   passed as the second argument to xTokenize(). The third and fourth
11253 **   arguments are a pointer to a buffer containing the token text, and the
11254 **   size of the token in bytes. The 4th and 5th arguments are the byte offsets
11255 **   of the first byte of and first byte immediately following the text from
11256 **   which the token is derived within the input.
11257 **
11258 **   The second argument passed to the xToken() callback ("tflags") should
11259 **   normally be set to 0. The exception is if the tokenizer supports
11260 **   synonyms. In this case see the discussion below for details.
11261 **
11262 **   FTS5 assumes the xToken() callback is invoked for each token in the
11263 **   order that they occur within the input text.
11264 **
11265 **   If an xToken() callback returns any value other than SQLITE_OK, then
11266 **   the tokenization should be abandoned and the xTokenize() method should
11267 **   immediately return a copy of the xToken() return value. Or, if the
11268 **   input buffer is exhausted, xTokenize() should return SQLITE_OK. Finally,
11269 **   if an error occurs with the xTokenize() implementation itself, it
11270 **   may abandon the tokenization and return any error code other than
11271 **   SQLITE_OK or SQLITE_DONE.
11272 **
11273 ** SYNONYM SUPPORT
11274 **
11275 **   Custom tokenizers may also support synonyms. Consider a case in which a
11276 **   user wishes to query for a phrase such as "first place". Using the
11277 **   built-in tokenizers, the FTS5 query 'first + place' will match instances
11278 **   of "first place" within the document set, but not alternative forms
11279 **   such as "1st place". In some applications, it would be better to match
11280 **   all instances of "first place" or "1st place" regardless of which form
11281 **   the user specified in the MATCH query text.
11282 **
11283 **   There are several ways to approach this in FTS5:
11284 **
11285 **   <ol><li> By mapping all synonyms to a single token. In this case, the
11286 **            In the above example, this means that the tokenizer returns the
11287 **            same token for inputs "first" and "1st". Say that token is in
11288 **            fact "first", so that when the user inserts the document "I won
11289 **            1st place" entries are added to the index for tokens "i", "won",
11290 **            "first" and "place". If the user then queries for '1st + place',
11291 **            the tokenizer substitutes "first" for "1st" and the query works
11292 **            as expected.
11293 **
11294 **       <li> By adding multiple synonyms for a single term to the FTS index.
11295 **            In this case, when tokenizing query text, the tokenizer may
11296 **            provide multiple synonyms for a single term within the document.
11297 **            FTS5 then queries the index for each synonym individually. For
11298 **            example, faced with the query:
11299 **
11300 **   <codeblock>
11301 **     ... MATCH 'first place'</codeblock>
11302 **
11303 **            the tokenizer offers both "1st" and "first" as synonyms for the
11304 **            first token in the MATCH query and FTS5 effectively runs a query
11305 **            similar to:
11306 **
11307 **   <codeblock>
11308 **     ... MATCH '(first OR 1st) place'</codeblock>
11309 **
11310 **            except that, for the purposes of auxiliary functions, the query
11311 **            still appears to contain just two phrases - "(first OR 1st)"
11312 **            being treated as a single phrase.
11313 **
11314 **       <li> By adding multiple synonyms for a single term to the FTS index.
11315 **            Using this method, when tokenizing document text, the tokenizer
11316 **            provides multiple synonyms for each token. So that when a
11317 **            document such as "I won first place" is tokenized, entries are
11318 **            added to the FTS index for "i", "won", "first", "1st" and
11319 **            "place".
11320 **
11321 **            This way, even if the tokenizer does not provide synonyms
11322 **            when tokenizing query text (it should not - to do would be
11323 **            inefficient), it doesn't matter if the user queries for
11324 **            'first + place' or '1st + place', as there are entries in the
11325 **            FTS index corresponding to both forms of the first token.
11326 **   </ol>
11327 **
11328 **   Whether it is parsing document or query text, any call to xToken that
11329 **   specifies a <i>tflags</i> argument with the FTS5_TOKEN_COLOCATED bit
11330 **   is considered to supply a synonym for the previous token. For example,
11331 **   when parsing the document "I won first place", a tokenizer that supports
11332 **   synonyms would call xToken() 5 times, as follows:
11333 **
11334 **   <codeblock>
11335 **       xToken(pCtx, 0, "i",                      1,  0,  1);
11336 **       xToken(pCtx, 0, "won",                    3,  2,  5);
11337 **       xToken(pCtx, 0, "first",                  5,  6, 11);
11338 **       xToken(pCtx, FTS5_TOKEN_COLOCATED, "1st", 3,  6, 11);
11339 **       xToken(pCtx, 0, "place",                  5, 12, 17);
11340 **</codeblock>
11341 **
11342 **   It is an error to specify the FTS5_TOKEN_COLOCATED flag the first time
11343 **   xToken() is called. Multiple synonyms may be specified for a single token
11344 **   by making multiple calls to xToken(FTS5_TOKEN_COLOCATED) in sequence.
11345 **   There is no limit to the number of synonyms that may be provided for a
11346 **   single token.
11347 **
11348 **   In many cases, method (1) above is the best approach. It does not add
11349 **   extra data to the FTS index or require FTS5 to query for multiple terms,
11350 **   so it is efficient in terms of disk space and query speed. However, it
11351 **   does not support prefix queries very well. If, as suggested above, the
11352 **   token "first" is substituted for "1st" by the tokenizer, then the query:
11353 **
11354 **   <codeblock>
11355 **     ... MATCH '1s*'</codeblock>
11356 **
11357 **   will not match documents that contain the token "1st" (as the tokenizer
11358 **   will probably not map "1s" to any prefix of "first").
11359 **
11360 **   For full prefix support, method (3) may be preferred. In this case,
11361 **   because the index contains entries for both "first" and "1st", prefix
11362 **   queries such as 'fi*' or '1s*' will match correctly. However, because
11363 **   extra entries are added to the FTS index, this method uses more space
11364 **   within the database.
11365 **
11366 **   Method (2) offers a midpoint between (1) and (3). Using this method,
11367 **   a query such as '1s*' will match documents that contain the literal
11368 **   token "1st", but not "first" (assuming the tokenizer is not able to
11369 **   provide synonyms for prefixes). However, a non-prefix query like '1st'
11370 **   will match against "1st" and "first". This method does not require
11371 **   extra disk space, as no extra entries are added to the FTS index.
11372 **   On the other hand, it may require more CPU cycles to run MATCH queries,
11373 **   as separate queries of the FTS index are required for each synonym.
11374 **
11375 **   When using methods (2) or (3), it is important that the tokenizer only
11376 **   provide synonyms when tokenizing document text (method (2)) or query
11377 **   text (method (3)), not both. Doing so will not cause any errors, but is
11378 **   inefficient.
11379 */
11380 struct Fts5Tokenizer;
11381 
11382 struct fts5_tokenizer
11383 {
11384     int function(void*, const(char*)* azArg, int nArg, Fts5Tokenizer** ppOut) xCreate;
11385     void function(Fts5Tokenizer*) xDelete;
11386 
11387     /* Mask of FTS5_TOKENIZE_* flags */
11388 
11389     /* Copy of 2nd argument to xTokenize() */
11390     /* Mask of FTS5_TOKEN_* flags */
11391     /* Pointer to buffer containing token */
11392     /* Size of token in bytes */
11393     /* Byte offset of token within input text */
11394     /* Byte offset of end of token within input text */
11395     int function(Fts5Tokenizer*, void* pCtx, int flags, const(char)* pText, int nText, int function(void* pCtx, int tflags, const(char)* pToken, int nToken, int iStart, int iEnd) xToken) xTokenize;
11396 }
11397 
11398 /* Flags that may be passed as the third argument to xTokenize() */
11399 enum FTS5_TOKENIZE_QUERY = 0x0001;
11400 enum FTS5_TOKENIZE_PREFIX = 0x0002;
11401 enum FTS5_TOKENIZE_DOCUMENT = 0x0004;
11402 enum FTS5_TOKENIZE_AUX = 0x0008;
11403 
11404 /* Flags that may be passed by the tokenizer implementation back to FTS5
11405 ** as the third argument to the supplied xToken callback. */
11406 enum FTS5_TOKEN_COLOCATED = 0x0001; /* Same position as prev. token */
11407 
11408 /*
11409 ** END OF CUSTOM TOKENIZERS
11410 *************************************************************************/
11411 
11412 /*************************************************************************
11413 ** FTS5 EXTENSION REGISTRATION API
11414 */
11415 struct fts5_api
11416 {
11417     int iVersion; /* Currently always set to 2 */
11418 
11419     /* Create a new tokenizer */
11420     int function(fts5_api* pApi, const(char)* zName, void* pContext, fts5_tokenizer* pTokenizer, void function(void*) xDestroy) xCreateTokenizer;
11421 
11422     /* Find an existing tokenizer */
11423     int function(fts5_api* pApi, const(char)* zName, void** ppContext, fts5_tokenizer* pTokenizer) xFindTokenizer;
11424 
11425     /* Create a new auxiliary function */
11426     int function(fts5_api* pApi, const(char)* zName, void* pContext, fts5_extension_function xFunction, void function(void*) xDestroy) xCreateFunction;
11427 }
11428 
11429 /*
11430 ** END OF REGISTRATION API
11431 *************************************************************************/
11432 
11433 /* end of the 'extern "C"' block */
11434 
11435 /* _FTS5_H */
11436 
11437 /******** End of fts5.h *********/