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