Video Processing Framework
D:/J_PROGRAMI/SPLINEPROJECT/CODE2/Db_Person/SQLite/sqlite3.h
Go to the documentation of this file.
00001 /*
00002 ** 2001 September 15
00003 **
00004 ** The author disclaims copyright to this source code.  In place of
00005 ** a legal notice, here is a blessing:
00006 **
00007 **    May you do good and not evil.
00008 **    May you find forgiveness for yourself and forgive others.
00009 **    May you share freely, never taking more than you give.
00010 **
00011 *************************************************************************
00012 ** This header file defines the interface that the SQLite library
00013 ** presents to client programs.  If a C-function, structure, datatype,
00014 ** or constant definition does not appear in this file, then it is
00015 ** not a published API of SQLite, is subject to change without
00016 ** notice, and should not be referenced by programs that use SQLite.
00017 **
00018 ** Some of the definitions that are in this file are marked as
00019 ** "experimental".  Experimental interfaces are normally new
00020 ** features recently added to SQLite.  We do not anticipate changes
00021 ** to experimental interfaces but reserve the right to make minor changes
00022 ** if experience from use "in the wild" suggest such changes are prudent.
00023 **
00024 ** The official C-language API documentation for SQLite is derived
00025 ** from comments in this file.  This file is the authoritative source
00026 ** on how SQLite interfaces are suppose to operate.
00027 **
00028 ** The name of this file under configuration management is "sqlite.h.in".
00029 ** The makefile makes some minor changes to this file (such as inserting
00030 ** the version number) and changes its name to "sqlite3.h" as
00031 ** part of the build process.
00032 */
00033 #ifndef _SQLITE3_H_
00034 #define _SQLITE3_H_
00035 #include <stdarg.h>     /* Needed for the definition of va_list */
00036 
00037 /*
00038 ** Make sure we can call this stuff from C++.
00039 */
00040 #ifdef __cplusplus
00041 extern "C" {
00042 #endif
00043 
00044 
00045 /*
00046 ** Add the ability to override 'extern'
00047 */
00048 #ifndef SQLITE_EXTERN
00049 # define SQLITE_EXTERN extern
00050 #endif
00051 
00052 #ifndef SQLITE_API
00053 # define SQLITE_API
00054 #endif
00055 
00056 
00057 /*
00058 ** These no-op macros are used in front of interfaces to mark those
00059 ** interfaces as either deprecated or experimental.  New applications
00060 ** should not use deprecated interfaces - they are support for backwards
00061 ** compatibility only.  Application writers should be aware that
00062 ** experimental interfaces are subject to change in point releases.
00063 **
00064 ** These macros used to resolve to various kinds of compiler magic that
00065 ** would generate warning messages when they were used.  But that
00066 ** compiler magic ended up generating such a flurry of bug reports
00067 ** that we have taken it all out and gone back to using simple
00068 ** noop macros.
00069 */
00070 #define SQLITE_DEPRECATED
00071 #define SQLITE_EXPERIMENTAL
00072 
00073 /*
00074 ** Ensure these symbols were not defined by some previous header file.
00075 */
00076 #ifdef SQLITE_VERSION
00077 # undef SQLITE_VERSION
00078 #endif
00079 #ifdef SQLITE_VERSION_NUMBER
00080 # undef SQLITE_VERSION_NUMBER
00081 #endif
00082 
00083 /*
00084 ** CAPI3REF: Compile-Time Library Version Numbers
00085 **
00086 ** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header
00087 ** evaluates to a string literal that is the SQLite version in the
00088 ** format "X.Y.Z" where X is the major version number (always 3 for
00089 ** SQLite3) and Y is the minor version number and Z is the release number.)^
00090 ** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer
00091 ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
00092 ** numbers used in [SQLITE_VERSION].)^
00093 ** The SQLITE_VERSION_NUMBER for any given release of SQLite will also
00094 ** be larger than the release from which it is derived.  Either Y will
00095 ** be held constant and Z will be incremented or else Y will be incremented
00096 ** and Z will be reset to zero.
00097 **
00098 ** Since version 3.6.18, SQLite source code has been stored in the
00099 ** <a href="http://www.fossil-scm.org/">Fossil configuration management
00100 ** system</a>.  ^The SQLITE_SOURCE_ID macro evaluates to
00101 ** a string which identifies a particular check-in of SQLite
00102 ** within its configuration management system.  ^The SQLITE_SOURCE_ID
00103 ** string contains the date and time of the check-in (UTC) and an SHA1
00104 ** hash of the entire source tree.
00105 **
00106 ** See also: [sqlite3_libversion()],
00107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
00108 ** [sqlite_version()] and [sqlite_source_id()].
00109 */
00110 #define SQLITE_VERSION        "3.7.2"
00111 #define SQLITE_VERSION_NUMBER 3007002
00112 #define SQLITE_SOURCE_ID      "2010-08-23 18:52:01 42537b60566f288167f1b5864a5435986838e3a3"
00113 
00114 /*
00115 ** CAPI3REF: Run-Time Library Version Numbers
00116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
00117 **
00118 ** These interfaces provide the same information as the [SQLITE_VERSION],
00119 ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
00120 ** but are associated with the library instead of the header file.  ^(Cautious
00121 ** programmers might include assert() statements in their application to
00122 ** verify that values returned by these interfaces match the macros in
00123 ** the header, and thus insure that the application is
00124 ** compiled with matching library and header files.
00125 **
00126 ** <blockquote><pre>
00127 ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
00128 ** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 );
00129 ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
00130 ** </pre></blockquote>)^
00131 **
00132 ** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
00133 ** macro.  ^The sqlite3_libversion() function returns a pointer to the
00134 ** to the sqlite3_version[] string constant.  The sqlite3_libversion()
00135 ** function is provided for use in DLLs since DLL users usually do not have
00136 ** direct access to string constants within the DLL.  ^The
00137 ** sqlite3_libversion_number() function returns an integer equal to
00138 ** [SQLITE_VERSION_NUMBER].  ^The sqlite3_sourceid() function returns 
00139 ** a pointer to a string constant whose value is the same as the 
00140 ** [SQLITE_SOURCE_ID] C preprocessor macro.
00141 **
00142 ** See also: [sqlite_version()] and [sqlite_source_id()].
00143 */
00144 SQLITE_API SQLITE_EXTERN const char sqlite3_version[];
00145 SQLITE_API const char *sqlite3_libversion(void);
00146 SQLITE_API const char *sqlite3_sourceid(void);
00147 SQLITE_API int sqlite3_libversion_number(void);
00148 
00149 /*
00150 ** CAPI3REF: Run-Time Library Compilation Options Diagnostics
00151 **
00152 ** ^The sqlite3_compileoption_used() function returns 0 or 1 
00153 ** indicating whether the specified option was defined at 
00154 ** compile time.  ^The SQLITE_ prefix may be omitted from the 
00155 ** option name passed to sqlite3_compileoption_used().  
00156 **
00157 ** ^The sqlite3_compileoption_get() function allows iterating
00158 ** over the list of options that were defined at compile time by
00159 ** returning the N-th compile time option string.  ^If N is out of range,
00160 ** sqlite3_compileoption_get() returns a NULL pointer.  ^The SQLITE_ 
00161 ** prefix is omitted from any strings returned by 
00162 ** sqlite3_compileoption_get().
00163 **
00164 ** ^Support for the diagnostic functions sqlite3_compileoption_used()
00165 ** and sqlite3_compileoption_get() may be omitted by specifying the 
00166 ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
00167 **
00168 ** See also: SQL functions [sqlite_compileoption_used()] and
00169 ** [sqlite_compileoption_get()] and the [compile_options pragma].
00170 */
00171 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
00172 SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
00173 SQLITE_API const char *sqlite3_compileoption_get(int N);
00174 #endif
00175 
00176 /*
00177 ** CAPI3REF: Test To See If The Library Is Threadsafe
00178 **
00179 ** ^The sqlite3_threadsafe() function returns zero if and only if
00180 ** SQLite was compiled mutexing code omitted due to the
00181 ** [SQLITE_THREADSAFE] compile-time option being set to 0.
00182 **
00183 ** SQLite can be compiled with or without mutexes.  When
00184 ** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes
00185 ** are enabled and SQLite is threadsafe.  When the
00186 ** [SQLITE_THREADSAFE] macro is 0, 
00187 ** the mutexes are omitted.  Without the mutexes, it is not safe
00188 ** to use SQLite concurrently from more than one thread.
00189 **
00190 ** Enabling mutexes incurs a measurable performance penalty.
00191 ** So if speed is of utmost importance, it makes sense to disable
00192 ** the mutexes.  But for maximum safety, mutexes should be enabled.
00193 ** ^The default behavior is for mutexes to be enabled.
00194 **
00195 ** This interface can be used by an application to make sure that the
00196 ** version of SQLite that it is linking against was compiled with
00197 ** the desired setting of the [SQLITE_THREADSAFE] macro.
00198 **
00199 ** This interface only reports on the compile-time mutex setting
00200 ** of the [SQLITE_THREADSAFE] flag.  If SQLite is compiled with
00201 ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
00202 ** can be fully or partially disabled using a call to [sqlite3_config()]
00203 ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
00204 ** or [SQLITE_CONFIG_MUTEX].  ^(The return value of the
00205 ** sqlite3_threadsafe() function shows only the compile-time setting of
00206 ** thread safety, not any run-time changes to that setting made by
00207 ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
00208 ** is unchanged by calls to sqlite3_config().)^
00209 **
00210 ** See the [threading mode] documentation for additional information.
00211 */
00212 SQLITE_API int sqlite3_threadsafe(void);
00213 
00214 /*
00215 ** CAPI3REF: Database Connection Handle
00216 ** KEYWORDS: {database connection} {database connections}
00217 **
00218 ** Each open SQLite database is represented by a pointer to an instance of
00219 ** the opaque structure named "sqlite3".  It is useful to think of an sqlite3
00220 ** pointer as an object.  The [sqlite3_open()], [sqlite3_open16()], and
00221 ** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]
00222 ** is its destructor.  There are many other interfaces (such as
00223 ** [sqlite3_prepare_v2()], [sqlite3_create_function()], and
00224 ** [sqlite3_busy_timeout()] to name but three) that are methods on an
00225 ** sqlite3 object.
00226 */
00227 typedef struct sqlite3 sqlite3;
00228 
00229 /*
00230 ** CAPI3REF: 64-Bit Integer Types
00231 ** KEYWORDS: sqlite_int64 sqlite_uint64
00232 **
00233 ** Because there is no cross-platform way to specify 64-bit integer types
00234 ** SQLite includes typedefs for 64-bit signed and unsigned integers.
00235 **
00236 ** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions.
00237 ** The sqlite_int64 and sqlite_uint64 types are supported for backwards
00238 ** compatibility only.
00239 **
00240 ** ^The sqlite3_int64 and sqlite_int64 types can store integer values
00241 ** between -9223372036854775808 and +9223372036854775807 inclusive.  ^The
00242 ** sqlite3_uint64 and sqlite_uint64 types can store integer values 
00243 ** between 0 and +18446744073709551615 inclusive.
00244 */
00245 #ifdef SQLITE_INT64_TYPE
00246   typedef SQLITE_INT64_TYPE sqlite_int64;
00247   typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
00248 #elif defined(_MSC_VER) || defined(__BORLANDC__)
00249   typedef __int64 sqlite_int64;
00250   typedef unsigned __int64 sqlite_uint64;
00251 #else
00252   typedef long long int sqlite_int64;
00253   typedef unsigned long long int sqlite_uint64;
00254 #endif
00255 typedef sqlite_int64 sqlite3_int64;
00256 typedef sqlite_uint64 sqlite3_uint64;
00257 
00258 /*
00259 ** If compiling for a processor that lacks floating point support,
00260 ** substitute integer for floating-point.
00261 */
00262 #ifdef SQLITE_OMIT_FLOATING_POINT
00263 # define double sqlite3_int64
00264 #endif
00265 
00266 /*
00267 ** CAPI3REF: Closing A Database Connection
00268 **
00269 ** ^The sqlite3_close() routine is the destructor for the [sqlite3] object.
00270 ** ^Calls to sqlite3_close() return SQLITE_OK if the [sqlite3] object is
00271 ** successfully destroyed and all associated resources are deallocated.
00272 **
00273 ** Applications must [sqlite3_finalize | finalize] all [prepared statements]
00274 ** and [sqlite3_blob_close | close] all [BLOB handles] associated with
00275 ** the [sqlite3] object prior to attempting to close the object.  ^If
00276 ** sqlite3_close() is called on a [database connection] that still has
00277 ** outstanding [prepared statements] or [BLOB handles], then it returns
00278 ** SQLITE_BUSY.
00279 **
00280 ** ^If [sqlite3_close()] is invoked while a transaction is open,
00281 ** the transaction is automatically rolled back.
00282 **
00283 ** The C parameter to [sqlite3_close(C)] must be either a NULL
00284 ** pointer or an [sqlite3] object pointer obtained
00285 ** from [sqlite3_open()], [sqlite3_open16()], or
00286 ** [sqlite3_open_v2()], and not previously closed.
00287 ** ^Calling sqlite3_close() with a NULL pointer argument is a 
00288 ** harmless no-op.
00289 */
00290 SQLITE_API int sqlite3_close(sqlite3 *);
00291 
00292 /*
00293 ** The type for a callback function.
00294 ** This is legacy and deprecated.  It is included for historical
00295 ** compatibility and is not documented.
00296 */
00297 typedef int (*sqlite3_callback)(void*,int,char**, char**);
00298 
00299 /*
00300 ** CAPI3REF: One-Step Query Execution Interface
00301 **
00302 ** The sqlite3_exec() interface is a convenience wrapper around
00303 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
00304 ** that allows an application to run multiple statements of SQL
00305 ** without having to use a lot of C code. 
00306 **
00307 ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
00308 ** semicolon-separate SQL statements passed into its 2nd argument,
00309 ** in the context of the [database connection] passed in as its 1st
00310 ** argument.  ^If the callback function of the 3rd argument to
00311 ** sqlite3_exec() is not NULL, then it is invoked for each result row
00312 ** coming out of the evaluated SQL statements.  ^The 4th argument to
00313 ** to sqlite3_exec() is relayed through to the 1st argument of each
00314 ** callback invocation.  ^If the callback pointer to sqlite3_exec()
00315 ** is NULL, then no callback is ever invoked and result rows are
00316 ** ignored.
00317 **
00318 ** ^If an error occurs while evaluating the SQL statements passed into
00319 ** sqlite3_exec(), then execution of the current statement stops and
00320 ** subsequent statements are skipped.  ^If the 5th parameter to sqlite3_exec()
00321 ** is not NULL then any error message is written into memory obtained
00322 ** from [sqlite3_malloc()] and passed back through the 5th parameter.
00323 ** To avoid memory leaks, the application should invoke [sqlite3_free()]
00324 ** on error message strings returned through the 5th parameter of
00325 ** of sqlite3_exec() after the error message string is no longer needed.
00326 ** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors
00327 ** occur, then sqlite3_exec() sets the pointer in its 5th parameter to
00328 ** NULL before returning.
00329 **
00330 ** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec()
00331 ** routine returns SQLITE_ABORT without invoking the callback again and
00332 ** without running any subsequent SQL statements.
00333 **
00334 ** ^The 2nd argument to the sqlite3_exec() callback function is the
00335 ** number of columns in the result.  ^The 3rd argument to the sqlite3_exec()
00336 ** callback is an array of pointers to strings obtained as if from
00337 ** [sqlite3_column_text()], one for each column.  ^If an element of a
00338 ** result row is NULL then the corresponding string pointer for the
00339 ** sqlite3_exec() callback is a NULL pointer.  ^The 4th argument to the
00340 ** sqlite3_exec() callback is an array of pointers to strings where each
00341 ** entry represents the name of corresponding result column as obtained
00342 ** from [sqlite3_column_name()].
00343 **
00344 ** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
00345 ** to an empty string, or a pointer that contains only whitespace and/or 
00346 ** SQL comments, then no SQL statements are evaluated and the database
00347 ** is not changed.
00348 **
00349 ** Restrictions:
00350 **
00351 ** <ul>
00352 ** <li> The application must insure that the 1st parameter to sqlite3_exec()
00353 **      is a valid and open [database connection].
00354 ** <li> The application must not close [database connection] specified by
00355 **      the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
00356 ** <li> The application must not modify the SQL statement text passed into
00357 **      the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
00358 ** </ul>
00359 */
00360 SQLITE_API int sqlite3_exec(
00361   sqlite3*,                                  /* An open database */
00362   const char *sql,                           /* SQL to be evaluated */
00363   int (*callback)(void*,int,char**,char**),  /* Callback function */
00364   void *,                                    /* 1st argument to callback */
00365   char **errmsg                              /* Error msg written here */
00366 );
00367 
00368 /*
00369 ** CAPI3REF: Result Codes
00370 ** KEYWORDS: SQLITE_OK {error code} {error codes}
00371 ** KEYWORDS: {result code} {result codes}
00372 **
00373 ** Many SQLite functions return an integer result code from the set shown
00374 ** here in order to indicates success or failure.
00375 **
00376 ** New error codes may be added in future versions of SQLite.
00377 **
00378 ** See also: [SQLITE_IOERR_READ | extended result codes]
00379 */
00380 #define SQLITE_OK           0   /* Successful result */
00381 /* beginning-of-error-codes */
00382 #define SQLITE_ERROR        1   /* SQL error or missing database */
00383 #define SQLITE_INTERNAL     2   /* Internal logic error in SQLite */
00384 #define SQLITE_PERM         3   /* Access permission denied */
00385 #define SQLITE_ABORT        4   /* Callback routine requested an abort */
00386 #define SQLITE_BUSY         5   /* The database file is locked */
00387 #define SQLITE_LOCKED       6   /* A table in the database is locked */
00388 #define SQLITE_NOMEM        7   /* A malloc() failed */
00389 #define SQLITE_READONLY     8   /* Attempt to write a readonly database */
00390 #define SQLITE_INTERRUPT    9   /* Operation terminated by sqlite3_interrupt()*/
00391 #define SQLITE_IOERR       10   /* Some kind of disk I/O error occurred */
00392 #define SQLITE_CORRUPT     11   /* The database disk image is malformed */
00393 #define SQLITE_NOTFOUND    12   /* NOT USED. Table or record not found */
00394 #define SQLITE_FULL        13   /* Insertion failed because database is full */
00395 #define SQLITE_CANTOPEN    14   /* Unable to open the database file */
00396 #define SQLITE_PROTOCOL    15   /* Database lock protocol error */
00397 #define SQLITE_EMPTY       16   /* Database is empty */
00398 #define SQLITE_SCHEMA      17   /* The database schema changed */
00399 #define SQLITE_TOOBIG      18   /* String or BLOB exceeds size limit */
00400 #define SQLITE_CONSTRAINT  19   /* Abort due to constraint violation */
00401 #define SQLITE_MISMATCH    20   /* Data type mismatch */
00402 #define SQLITE_MISUSE      21   /* Library used incorrectly */
00403 #define SQLITE_NOLFS       22   /* Uses OS features not supported on host */
00404 #define SQLITE_AUTH        23   /* Authorization denied */
00405 #define SQLITE_FORMAT      24   /* Auxiliary database format error */
00406 #define SQLITE_RANGE       25   /* 2nd parameter to sqlite3_bind out of range */
00407 #define SQLITE_NOTADB      26   /* File opened that is not a database file */
00408 #define SQLITE_ROW         100  /* sqlite3_step() has another row ready */
00409 #define SQLITE_DONE        101  /* sqlite3_step() has finished executing */
00410 /* end-of-error-codes */
00411 
00412 /*
00413 ** CAPI3REF: Extended Result Codes
00414 ** KEYWORDS: {extended error code} {extended error codes}
00415 ** KEYWORDS: {extended result code} {extended result codes}
00416 **
00417 ** In its default configuration, SQLite API routines return one of 26 integer
00418 ** [SQLITE_OK | result codes].  However, experience has shown that many of
00419 ** these result codes are too coarse-grained.  They do not provide as
00420 ** much information about problems as programmers might like.  In an effort to
00421 ** address this, newer versions of SQLite (version 3.3.8 and later) include
00422 ** support for additional result codes that provide more detailed information
00423 ** about errors. The extended result codes are enabled or disabled
00424 ** on a per database connection basis using the
00425 ** [sqlite3_extended_result_codes()] API.
00426 **
00427 ** Some of the available extended result codes are listed here.
00428 ** One may expect the number of extended result codes will be expand
00429 ** over time.  Software that uses extended result codes should expect
00430 ** to see new result codes in future releases of SQLite.
00431 **
00432 ** The SQLITE_OK result code will never be extended.  It will always
00433 ** be exactly zero.
00434 */
00435 #define SQLITE_IOERR_READ              (SQLITE_IOERR | (1<<8))
00436 #define SQLITE_IOERR_SHORT_READ        (SQLITE_IOERR | (2<<8))
00437 #define SQLITE_IOERR_WRITE             (SQLITE_IOERR | (3<<8))
00438 #define SQLITE_IOERR_FSYNC             (SQLITE_IOERR | (4<<8))
00439 #define SQLITE_IOERR_DIR_FSYNC         (SQLITE_IOERR | (5<<8))
00440 #define SQLITE_IOERR_TRUNCATE          (SQLITE_IOERR | (6<<8))
00441 #define SQLITE_IOERR_FSTAT             (SQLITE_IOERR | (7<<8))
00442 #define SQLITE_IOERR_UNLOCK            (SQLITE_IOERR | (8<<8))
00443 #define SQLITE_IOERR_RDLOCK            (SQLITE_IOERR | (9<<8))
00444 #define SQLITE_IOERR_DELETE            (SQLITE_IOERR | (10<<8))
00445 #define SQLITE_IOERR_BLOCKED           (SQLITE_IOERR | (11<<8))
00446 #define SQLITE_IOERR_NOMEM             (SQLITE_IOERR | (12<<8))
00447 #define SQLITE_IOERR_ACCESS            (SQLITE_IOERR | (13<<8))
00448 #define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))
00449 #define SQLITE_IOERR_LOCK              (SQLITE_IOERR | (15<<8))
00450 #define SQLITE_IOERR_CLOSE             (SQLITE_IOERR | (16<<8))
00451 #define SQLITE_IOERR_DIR_CLOSE         (SQLITE_IOERR | (17<<8))
00452 #define SQLITE_IOERR_SHMOPEN           (SQLITE_IOERR | (18<<8))
00453 #define SQLITE_IOERR_SHMSIZE           (SQLITE_IOERR | (19<<8))
00454 #define SQLITE_IOERR_SHMLOCK           (SQLITE_IOERR | (20<<8))
00455 #define SQLITE_LOCKED_SHAREDCACHE      (SQLITE_LOCKED |  (1<<8))
00456 #define SQLITE_BUSY_RECOVERY           (SQLITE_BUSY   |  (1<<8))
00457 #define SQLITE_CANTOPEN_NOTEMPDIR      (SQLITE_CANTOPEN | (1<<8))
00458 
00459 /*
00460 ** CAPI3REF: Flags For File Open Operations
00461 **
00462 ** These bit values are intended for use in the
00463 ** 3rd parameter to the [sqlite3_open_v2()] interface and
00464 ** in the 4th parameter to the xOpen method of the
00465 ** [sqlite3_vfs] object.
00466 */
00467 #define SQLITE_OPEN_READONLY         0x00000001  /* Ok for sqlite3_open_v2() */
00468 #define SQLITE_OPEN_READWRITE        0x00000002  /* Ok for sqlite3_open_v2() */
00469 #define SQLITE_OPEN_CREATE           0x00000004  /* Ok for sqlite3_open_v2() */
00470 #define SQLITE_OPEN_DELETEONCLOSE    0x00000008  /* VFS only */
00471 #define SQLITE_OPEN_EXCLUSIVE        0x00000010  /* VFS only */
00472 #define SQLITE_OPEN_AUTOPROXY        0x00000020  /* VFS only */
00473 #define SQLITE_OPEN_MAIN_DB          0x00000100  /* VFS only */
00474 #define SQLITE_OPEN_TEMP_DB          0x00000200  /* VFS only */
00475 #define SQLITE_OPEN_TRANSIENT_DB     0x00000400  /* VFS only */
00476 #define SQLITE_OPEN_MAIN_JOURNAL     0x00000800  /* VFS only */
00477 #define SQLITE_OPEN_TEMP_JOURNAL     0x00001000  /* VFS only */
00478 #define SQLITE_OPEN_SUBJOURNAL       0x00002000  /* VFS only */
00479 #define SQLITE_OPEN_MASTER_JOURNAL   0x00004000  /* VFS only */
00480 #define SQLITE_OPEN_NOMUTEX          0x00008000  /* Ok for sqlite3_open_v2() */
00481 #define SQLITE_OPEN_FULLMUTEX        0x00010000  /* Ok for sqlite3_open_v2() */
00482 #define SQLITE_OPEN_SHAREDCACHE      0x00020000  /* Ok for sqlite3_open_v2() */
00483 #define SQLITE_OPEN_PRIVATECACHE     0x00040000  /* Ok for sqlite3_open_v2() */
00484 #define SQLITE_OPEN_WAL              0x00080000  /* VFS only */
00485 
00486 /*
00487 ** CAPI3REF: Device Characteristics
00488 **
00489 ** The xDeviceCharacteristics method of the [sqlite3_io_methods]
00490 ** object returns an integer which is a vector of the these
00491 ** bit values expressing I/O characteristics of the mass storage
00492 ** device that holds the file that the [sqlite3_io_methods]
00493 ** refers to.
00494 **
00495 ** The SQLITE_IOCAP_ATOMIC property means that all writes of
00496 ** any size are atomic.  The SQLITE_IOCAP_ATOMICnnn values
00497 ** mean that writes of blocks that are nnn bytes in size and
00498 ** are aligned to an address which is an integer multiple of
00499 ** nnn are atomic.  The SQLITE_IOCAP_SAFE_APPEND value means
00500 ** that when data is appended to a file, the data is appended
00501 ** first then the size of the file is extended, never the other
00502 ** way around.  The SQLITE_IOCAP_SEQUENTIAL property means that
00503 ** information is written to disk in the same order as calls
00504 ** to xWrite().
00505 */
00506 #define SQLITE_IOCAP_ATOMIC                 0x00000001
00507 #define SQLITE_IOCAP_ATOMIC512              0x00000002
00508 #define SQLITE_IOCAP_ATOMIC1K               0x00000004
00509 #define SQLITE_IOCAP_ATOMIC2K               0x00000008
00510 #define SQLITE_IOCAP_ATOMIC4K               0x00000010
00511 #define SQLITE_IOCAP_ATOMIC8K               0x00000020
00512 #define SQLITE_IOCAP_ATOMIC16K              0x00000040
00513 #define SQLITE_IOCAP_ATOMIC32K              0x00000080
00514 #define SQLITE_IOCAP_ATOMIC64K              0x00000100
00515 #define SQLITE_IOCAP_SAFE_APPEND            0x00000200
00516 #define SQLITE_IOCAP_SEQUENTIAL             0x00000400
00517 #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN  0x00000800
00518 
00519 /*
00520 ** CAPI3REF: File Locking Levels
00521 **
00522 ** SQLite uses one of these integer values as the second
00523 ** argument to calls it makes to the xLock() and xUnlock() methods
00524 ** of an [sqlite3_io_methods] object.
00525 */
00526 #define SQLITE_LOCK_NONE          0
00527 #define SQLITE_LOCK_SHARED        1
00528 #define SQLITE_LOCK_RESERVED      2
00529 #define SQLITE_LOCK_PENDING       3
00530 #define SQLITE_LOCK_EXCLUSIVE     4
00531 
00532 /*
00533 ** CAPI3REF: Synchronization Type Flags
00534 **
00535 ** When SQLite invokes the xSync() method of an
00536 ** [sqlite3_io_methods] object it uses a combination of
00537 ** these integer values as the second argument.
00538 **
00539 ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the
00540 ** sync operation only needs to flush data to mass storage.  Inode
00541 ** information need not be flushed. If the lower four bits of the flag
00542 ** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics.
00543 ** If the lower four bits equal SQLITE_SYNC_FULL, that means
00544 ** to use Mac OS X style fullsync instead of fsync().
00545 */
00546 #define SQLITE_SYNC_NORMAL        0x00002
00547 #define SQLITE_SYNC_FULL          0x00003
00548 #define SQLITE_SYNC_DATAONLY      0x00010
00549 
00550 /*
00551 ** CAPI3REF: OS Interface Open File Handle
00552 **
00553 ** An [sqlite3_file] object represents an open file in the 
00554 ** [sqlite3_vfs | OS interface layer].  Individual OS interface
00555 ** implementations will
00556 ** want to subclass this object by appending additional fields
00557 ** for their own use.  The pMethods entry is a pointer to an
00558 ** [sqlite3_io_methods] object that defines methods for performing
00559 ** I/O operations on the open file.
00560 */
00561 typedef struct sqlite3_file sqlite3_file;
00562 struct sqlite3_file {
00563   const struct sqlite3_io_methods *pMethods;  /* Methods for an open file */
00564 };
00565 
00566 /*
00567 ** CAPI3REF: OS Interface File Virtual Methods Object
00568 **
00569 ** Every file opened by the [sqlite3_vfs] xOpen method populates an
00570 ** [sqlite3_file] object (or, more commonly, a subclass of the
00571 ** [sqlite3_file] object) with a pointer to an instance of this object.
00572 ** This object defines the methods used to perform various operations
00573 ** against the open file represented by the [sqlite3_file] object.
00574 **
00575 ** If the xOpen method sets the sqlite3_file.pMethods element 
00576 ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
00577 ** may be invoked even if the xOpen reported that it failed.  The
00578 ** only way to prevent a call to xClose following a failed xOpen
00579 ** is for the xOpen to set the sqlite3_file.pMethods element to NULL.
00580 **
00581 ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
00582 ** [SQLITE_SYNC_FULL].  The first choice is the normal fsync().
00583 ** The second choice is a Mac OS X style fullsync.  The [SQLITE_SYNC_DATAONLY]
00584 ** flag may be ORed in to indicate that only the data of the file
00585 ** and not its inode needs to be synced.
00586 **
00587 ** The integer values to xLock() and xUnlock() are one of
00588 ** <ul>
00589 ** <li> [SQLITE_LOCK_NONE],
00590 ** <li> [SQLITE_LOCK_SHARED],
00591 ** <li> [SQLITE_LOCK_RESERVED],
00592 ** <li> [SQLITE_LOCK_PENDING], or
00593 ** <li> [SQLITE_LOCK_EXCLUSIVE].
00594 ** </ul>
00595 ** xLock() increases the lock. xUnlock() decreases the lock.
00596 ** The xCheckReservedLock() method checks whether any database connection,
00597 ** either in this process or in some other process, is holding a RESERVED,
00598 ** PENDING, or EXCLUSIVE lock on the file.  It returns true
00599 ** if such a lock exists and false otherwise.
00600 **
00601 ** The xFileControl() method is a generic interface that allows custom
00602 ** VFS implementations to directly control an open file using the
00603 ** [sqlite3_file_control()] interface.  The second "op" argument is an
00604 ** integer opcode.  The third argument is a generic pointer intended to
00605 ** point to a structure that may contain arguments or space in which to
00606 ** write return values.  Potential uses for xFileControl() might be
00607 ** functions to enable blocking locks with timeouts, to change the
00608 ** locking strategy (for example to use dot-file locks), to inquire
00609 ** about the status of a lock, or to break stale locks.  The SQLite
00610 ** core reserves all opcodes less than 100 for its own use.
00611 ** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available.
00612 ** Applications that define a custom xFileControl method should use opcodes
00613 ** greater than 100 to avoid conflicts.
00614 **
00615 ** The xSectorSize() method returns the sector size of the
00616 ** device that underlies the file.  The sector size is the
00617 ** minimum write that can be performed without disturbing
00618 ** other bytes in the file.  The xDeviceCharacteristics()
00619 ** method returns a bit vector describing behaviors of the
00620 ** underlying device:
00621 **
00622 ** <ul>
00623 ** <li> [SQLITE_IOCAP_ATOMIC]
00624 ** <li> [SQLITE_IOCAP_ATOMIC512]
00625 ** <li> [SQLITE_IOCAP_ATOMIC1K]
00626 ** <li> [SQLITE_IOCAP_ATOMIC2K]
00627 ** <li> [SQLITE_IOCAP_ATOMIC4K]
00628 ** <li> [SQLITE_IOCAP_ATOMIC8K]
00629 ** <li> [SQLITE_IOCAP_ATOMIC16K]
00630 ** <li> [SQLITE_IOCAP_ATOMIC32K]
00631 ** <li> [SQLITE_IOCAP_ATOMIC64K]
00632 ** <li> [SQLITE_IOCAP_SAFE_APPEND]
00633 ** <li> [SQLITE_IOCAP_SEQUENTIAL]
00634 ** </ul>
00635 **
00636 ** The SQLITE_IOCAP_ATOMIC property means that all writes of
00637 ** any size are atomic.  The SQLITE_IOCAP_ATOMICnnn values
00638 ** mean that writes of blocks that are nnn bytes in size and
00639 ** are aligned to an address which is an integer multiple of
00640 ** nnn are atomic.  The SQLITE_IOCAP_SAFE_APPEND value means
00641 ** that when data is appended to a file, the data is appended
00642 ** first then the size of the file is extended, never the other
00643 ** way around.  The SQLITE_IOCAP_SEQUENTIAL property means that
00644 ** information is written to disk in the same order as calls
00645 ** to xWrite().
00646 **
00647 ** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill
00648 ** in the unread portions of the buffer with zeros.  A VFS that
00649 ** fails to zero-fill short reads might seem to work.  However,
00650 ** failure to zero-fill short reads will eventually lead to
00651 ** database corruption.
00652 */
00653 typedef struct sqlite3_io_methods sqlite3_io_methods;
00654 struct sqlite3_io_methods {
00655   int iVersion;
00656   int (*xClose)(sqlite3_file*);
00657   int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
00658   int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);
00659   int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);
00660   int (*xSync)(sqlite3_file*, int flags);
00661   int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);
00662   int (*xLock)(sqlite3_file*, int);
00663   int (*xUnlock)(sqlite3_file*, int);
00664   int (*xCheckReservedLock)(sqlite3_file*, int *pResOut);
00665   int (*xFileControl)(sqlite3_file*, int op, void *pArg);
00666   int (*xSectorSize)(sqlite3_file*);
00667   int (*xDeviceCharacteristics)(sqlite3_file*);
00668   /* Methods above are valid for version 1 */
00669   int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**);
00670   int (*xShmLock)(sqlite3_file*, int offset, int n, int flags);
00671   void (*xShmBarrier)(sqlite3_file*);
00672   int (*xShmUnmap)(sqlite3_file*, int deleteFlag);
00673   /* Methods above are valid for version 2 */
00674   /* Additional methods may be added in future releases */
00675 };
00676 
00677 /*
00678 ** CAPI3REF: Standard File Control Opcodes
00679 **
00680 ** These integer constants are opcodes for the xFileControl method
00681 ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
00682 ** interface.
00683 **
00684 ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging.  This
00685 ** opcode causes the xFileControl method to write the current state of
00686 ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
00687 ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
00688 ** into an integer that the pArg argument points to. This capability
00689 ** is used during testing and only needs to be supported when SQLITE_TEST
00690 ** is defined.
00691 **
00692 ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
00693 ** layer a hint of how large the database file will grow to be during the
00694 ** current transaction.  This hint is not guaranteed to be accurate but it
00695 ** is often close.  The underlying VFS might choose to preallocate database
00696 ** file space based on this hint in order to help writes to the database
00697 ** file run faster.
00698 **
00699 ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
00700 ** extends and truncates the database file in chunks of a size specified
00701 ** by the user. The fourth argument to [sqlite3_file_control()] should 
00702 ** point to an integer (type int) containing the new chunk-size to use
00703 ** for the nominated database. Allocating database file space in large
00704 ** chunks (say 1MB at a time), may reduce file-system fragmentation and
00705 ** improve performance on some systems.
00706 */
00707 #define SQLITE_FCNTL_LOCKSTATE        1
00708 #define SQLITE_GET_LOCKPROXYFILE      2
00709 #define SQLITE_SET_LOCKPROXYFILE      3
00710 #define SQLITE_LAST_ERRNO             4
00711 #define SQLITE_FCNTL_SIZE_HINT        5
00712 #define SQLITE_FCNTL_CHUNK_SIZE       6
00713 
00714 /*
00715 ** CAPI3REF: Mutex Handle
00716 **
00717 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
00718 ** abstract type for a mutex object.  The SQLite core never looks
00719 ** at the internal representation of an [sqlite3_mutex].  It only
00720 ** deals with pointers to the [sqlite3_mutex] object.
00721 **
00722 ** Mutexes are created using [sqlite3_mutex_alloc()].
00723 */
00724 typedef struct sqlite3_mutex sqlite3_mutex;
00725 
00726 /*
00727 ** CAPI3REF: OS Interface Object
00728 **
00729 ** An instance of the sqlite3_vfs object defines the interface between
00730 ** the SQLite core and the underlying operating system.  The "vfs"
00731 ** in the name of the object stands for "virtual file system".
00732 **
00733 ** The value of the iVersion field is initially 1 but may be larger in
00734 ** future versions of SQLite.  Additional fields may be appended to this
00735 ** object when the iVersion value is increased.  Note that the structure
00736 ** of the sqlite3_vfs object changes in the transaction between
00737 ** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not
00738 ** modified.
00739 **
00740 ** The szOsFile field is the size of the subclassed [sqlite3_file]
00741 ** structure used by this VFS.  mxPathname is the maximum length of
00742 ** a pathname in this VFS.
00743 **
00744 ** Registered sqlite3_vfs objects are kept on a linked list formed by
00745 ** the pNext pointer.  The [sqlite3_vfs_register()]
00746 ** and [sqlite3_vfs_unregister()] interfaces manage this list
00747 ** in a thread-safe way.  The [sqlite3_vfs_find()] interface
00748 ** searches the list.  Neither the application code nor the VFS
00749 ** implementation should use the pNext pointer.
00750 **
00751 ** The pNext field is the only field in the sqlite3_vfs
00752 ** structure that SQLite will ever modify.  SQLite will only access
00753 ** or modify this field while holding a particular static mutex.
00754 ** The application should never modify anything within the sqlite3_vfs
00755 ** object once the object has been registered.
00756 **
00757 ** The zName field holds the name of the VFS module.  The name must
00758 ** be unique across all VFS modules.
00759 **
00760 ** SQLite will guarantee that the zFilename parameter to xOpen
00761 ** is either a NULL pointer or string obtained
00762 ** from xFullPathname().  SQLite further guarantees that
00763 ** the string will be valid and unchanged until xClose() is
00764 ** called. Because of the previous sentence,
00765 ** the [sqlite3_file] can safely store a pointer to the
00766 ** filename if it needs to remember the filename for some reason.
00767 ** If the zFilename parameter is xOpen is a NULL pointer then xOpen
00768 ** must invent its own temporary name for the file.  Whenever the 
00769 ** xFilename parameter is NULL it will also be the case that the
00770 ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
00771 **
00772 ** The flags argument to xOpen() includes all bits set in
00773 ** the flags argument to [sqlite3_open_v2()].  Or if [sqlite3_open()]
00774 ** or [sqlite3_open16()] is used, then flags includes at least
00775 ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]. 
00776 ** If xOpen() opens a file read-only then it sets *pOutFlags to
00777 ** include [SQLITE_OPEN_READONLY].  Other bits in *pOutFlags may be set.
00778 **
00779 ** SQLite will also add one of the following flags to the xOpen()
00780 ** call, depending on the object being opened:
00781 **
00782 ** <ul>
00783 ** <li>  [SQLITE_OPEN_MAIN_DB]
00784 ** <li>  [SQLITE_OPEN_MAIN_JOURNAL]
00785 ** <li>  [SQLITE_OPEN_TEMP_DB]
00786 ** <li>  [SQLITE_OPEN_TEMP_JOURNAL]
00787 ** <li>  [SQLITE_OPEN_TRANSIENT_DB]
00788 ** <li>  [SQLITE_OPEN_SUBJOURNAL]
00789 ** <li>  [SQLITE_OPEN_MASTER_JOURNAL]
00790 ** </ul>
00791 **
00792 ** The file I/O implementation can use the object type flags to
00793 ** change the way it deals with files.  For example, an application
00794 ** that does not care about crash recovery or rollback might make
00795 ** the open of a journal file a no-op.  Writes to this journal would
00796 ** also be no-ops, and any attempt to read the journal would return
00797 ** SQLITE_IOERR.  Or the implementation might recognize that a database
00798 ** file will be doing page-aligned sector reads and writes in a random
00799 ** order and set up its I/O subsystem accordingly.
00800 **
00801 ** SQLite might also add one of the following flags to the xOpen method:
00802 **
00803 ** <ul>
00804 ** <li> [SQLITE_OPEN_DELETEONCLOSE]
00805 ** <li> [SQLITE_OPEN_EXCLUSIVE]
00806 ** </ul>
00807 **
00808 ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
00809 ** deleted when it is closed.  The [SQLITE_OPEN_DELETEONCLOSE]
00810 ** will be set for TEMP  databases, journals and for subjournals.
00811 **
00812 ** The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
00813 ** with the [SQLITE_OPEN_CREATE] flag, which are both directly
00814 ** analogous to the O_EXCL and O_CREAT flags of the POSIX open()
00815 ** API.  The SQLITE_OPEN_EXCLUSIVE flag, when paired with the 
00816 ** SQLITE_OPEN_CREATE, is used to indicate that file should always
00817 ** be created, and that it is an error if it already exists.
00818 ** It is <i>not</i> used to indicate the file should be opened 
00819 ** for exclusive access.
00820 **
00821 ** At least szOsFile bytes of memory are allocated by SQLite
00822 ** to hold the  [sqlite3_file] structure passed as the third
00823 ** argument to xOpen.  The xOpen method does not have to
00824 ** allocate the structure; it should just fill it in.  Note that
00825 ** the xOpen method must set the sqlite3_file.pMethods to either
00826 ** a valid [sqlite3_io_methods] object or to NULL.  xOpen must do
00827 ** this even if the open fails.  SQLite expects that the sqlite3_file.pMethods
00828 ** element will be valid after xOpen returns regardless of the success
00829 ** or failure of the xOpen call.
00830 **
00831 ** The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
00832 ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
00833 ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
00834 ** to test whether a file is at least readable.   The file can be a
00835 ** directory.
00836 **
00837 ** SQLite will always allocate at least mxPathname+1 bytes for the
00838 ** output buffer xFullPathname.  The exact size of the output buffer
00839 ** is also passed as a parameter to both  methods. If the output buffer
00840 ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
00841 ** handled as a fatal error by SQLite, vfs implementations should endeavor
00842 ** to prevent this by setting mxPathname to a sufficiently large value.
00843 **
00844 ** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
00845 ** interfaces are not strictly a part of the filesystem, but they are
00846 ** included in the VFS structure for completeness.
00847 ** The xRandomness() function attempts to return nBytes bytes
00848 ** of good-quality randomness into zOut.  The return value is
00849 ** the actual number of bytes of randomness obtained.
00850 ** The xSleep() method causes the calling thread to sleep for at
00851 ** least the number of microseconds given.  The xCurrentTime()
00852 ** method returns a Julian Day Number for the current date and time as
00853 ** a floating point value.
00854 ** The xCurrentTimeInt64() method returns, as an integer, the Julian
00855 ** Day Number multipled by 86400000 (the number of milliseconds in 
00856 ** a 24-hour day).  
00857 ** ^SQLite will use the xCurrentTimeInt64() method to get the current
00858 ** date and time if that method is available (if iVersion is 2 or 
00859 ** greater and the function pointer is not NULL) and will fall back
00860 ** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
00861 */
00862 typedef struct sqlite3_vfs sqlite3_vfs;
00863 struct sqlite3_vfs {
00864   int iVersion;            /* Structure version number (currently 2) */
00865   int szOsFile;            /* Size of subclassed sqlite3_file */
00866   int mxPathname;          /* Maximum file pathname length */
00867   sqlite3_vfs *pNext;      /* Next registered VFS */
00868   const char *zName;       /* Name of this virtual file system */
00869   void *pAppData;          /* Pointer to application-specific data */
00870   int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*,
00871                int flags, int *pOutFlags);
00872   int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
00873   int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);
00874   int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
00875   void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
00876   void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
00877   void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void);
00878   void (*xDlClose)(sqlite3_vfs*, void*);
00879   int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
00880   int (*xSleep)(sqlite3_vfs*, int microseconds);
00881   int (*xCurrentTime)(sqlite3_vfs*, double*);
00882   int (*xGetLastError)(sqlite3_vfs*, int, char *);
00883   /*
00884   ** The methods above are in version 1 of the sqlite_vfs object
00885   ** definition.  Those that follow are added in version 2 or later
00886   */
00887   int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
00888   /*
00889   ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
00890   ** New fields may be appended in figure versions.  The iVersion
00891   ** value will increment whenever this happens. 
00892   */
00893 };
00894 
00895 /*
00896 ** CAPI3REF: Flags for the xAccess VFS method
00897 **
00898 ** These integer constants can be used as the third parameter to
00899 ** the xAccess method of an [sqlite3_vfs] object.  They determine
00900 ** what kind of permissions the xAccess method is looking for.
00901 ** With SQLITE_ACCESS_EXISTS, the xAccess method
00902 ** simply checks whether the file exists.
00903 ** With SQLITE_ACCESS_READWRITE, the xAccess method
00904 ** checks whether the named directory is both readable and writable
00905 ** (in other words, if files can be added, removed, and renamed within
00906 ** the directory).
00907 ** The SQLITE_ACCESS_READWRITE constant is currently used only by the
00908 ** [temp_store_directory pragma], though this could change in a future
00909 ** release of SQLite.
00910 ** With SQLITE_ACCESS_READ, the xAccess method
00911 ** checks whether the file is readable.  The SQLITE_ACCESS_READ constant is
00912 ** currently unused, though it might be used in a future release of
00913 ** SQLite.
00914 */
00915 #define SQLITE_ACCESS_EXISTS    0
00916 #define SQLITE_ACCESS_READWRITE 1   /* Used by PRAGMA temp_store_directory */
00917 #define SQLITE_ACCESS_READ      2   /* Unused */
00918 
00919 /*
00920 ** CAPI3REF: Flags for the xShmLock VFS method
00921 **
00922 ** These integer constants define the various locking operations
00923 ** allowed by the xShmLock method of [sqlite3_io_methods].  The
00924 ** following are the only legal combinations of flags to the
00925 ** xShmLock method:
00926 **
00927 ** <ul>
00928 ** <li>  SQLITE_SHM_LOCK | SQLITE_SHM_SHARED
00929 ** <li>  SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE
00930 ** <li>  SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED
00931 ** <li>  SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE
00932 ** </ul>
00933 **
00934 ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as
00935 ** was given no the corresponding lock.  
00936 **
00937 ** The xShmLock method can transition between unlocked and SHARED or
00938 ** between unlocked and EXCLUSIVE.  It cannot transition between SHARED
00939 ** and EXCLUSIVE.
00940 */
00941 #define SQLITE_SHM_UNLOCK       1
00942 #define SQLITE_SHM_LOCK         2
00943 #define SQLITE_SHM_SHARED       4
00944 #define SQLITE_SHM_EXCLUSIVE    8
00945 
00946 /*
00947 ** CAPI3REF: Maximum xShmLock index
00948 **
00949 ** The xShmLock method on [sqlite3_io_methods] may use values
00950 ** between 0 and this upper bound as its "offset" argument.
00951 ** The SQLite core will never attempt to acquire or release a
00952 ** lock outside of this range
00953 */
00954 #define SQLITE_SHM_NLOCK        8
00955 
00956 
00957 /*
00958 ** CAPI3REF: Initialize The SQLite Library
00959 **
00960 ** ^The sqlite3_initialize() routine initializes the
00961 ** SQLite library.  ^The sqlite3_shutdown() routine
00962 ** deallocates any resources that were allocated by sqlite3_initialize().
00963 ** These routines are designed to aid in process initialization and
00964 ** shutdown on embedded systems.  Workstation applications using
00965 ** SQLite normally do not need to invoke either of these routines.
00966 **
00967 ** A call to sqlite3_initialize() is an "effective" call if it is
00968 ** the first time sqlite3_initialize() is invoked during the lifetime of
00969 ** the process, or if it is the first time sqlite3_initialize() is invoked
00970 ** following a call to sqlite3_shutdown().  ^(Only an effective call
00971 ** of sqlite3_initialize() does any initialization.  All other calls
00972 ** are harmless no-ops.)^
00973 **
00974 ** A call to sqlite3_shutdown() is an "effective" call if it is the first
00975 ** call to sqlite3_shutdown() since the last sqlite3_initialize().  ^(Only
00976 ** an effective call to sqlite3_shutdown() does any deinitialization.
00977 ** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^
00978 **
00979 ** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown()
00980 ** is not.  The sqlite3_shutdown() interface must only be called from a
00981 ** single thread.  All open [database connections] must be closed and all
00982 ** other SQLite resources must be deallocated prior to invoking
00983 ** sqlite3_shutdown().
00984 **
00985 ** Among other things, ^sqlite3_initialize() will invoke
00986 ** sqlite3_os_init().  Similarly, ^sqlite3_shutdown()
00987 ** will invoke sqlite3_os_end().
00988 **
00989 ** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success.
00990 ** ^If for some reason, sqlite3_initialize() is unable to initialize
00991 ** the library (perhaps it is unable to allocate a needed resource such
00992 ** as a mutex) it returns an [error code] other than [SQLITE_OK].
00993 **
00994 ** ^The sqlite3_initialize() routine is called internally by many other
00995 ** SQLite interfaces so that an application usually does not need to
00996 ** invoke sqlite3_initialize() directly.  For example, [sqlite3_open()]
00997 ** calls sqlite3_initialize() so the SQLite library will be automatically
00998 ** initialized when [sqlite3_open()] is called if it has not be initialized
00999 ** already.  ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
01000 ** compile-time option, then the automatic calls to sqlite3_initialize()
01001 ** are omitted and the application must call sqlite3_initialize() directly
01002 ** prior to using any other SQLite interface.  For maximum portability,
01003 ** it is recommended that applications always invoke sqlite3_initialize()
01004 ** directly prior to using any other SQLite interface.  Future releases
01005 ** of SQLite may require this.  In other words, the behavior exhibited
01006 ** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the
01007 ** default behavior in some future release of SQLite.
01008 **
01009 ** The sqlite3_os_init() routine does operating-system specific
01010 ** initialization of the SQLite library.  The sqlite3_os_end()
01011 ** routine undoes the effect of sqlite3_os_init().  Typical tasks
01012 ** performed by these routines include allocation or deallocation
01013 ** of static resources, initialization of global variables,
01014 ** setting up a default [sqlite3_vfs] module, or setting up
01015 ** a default configuration using [sqlite3_config()].
01016 **
01017 ** The application should never invoke either sqlite3_os_init()
01018 ** or sqlite3_os_end() directly.  The application should only invoke
01019 ** sqlite3_initialize() and sqlite3_shutdown().  The sqlite3_os_init()
01020 ** interface is called automatically by sqlite3_initialize() and
01021 ** sqlite3_os_end() is called by sqlite3_shutdown().  Appropriate
01022 ** implementations for sqlite3_os_init() and sqlite3_os_end()
01023 ** are built into SQLite when it is compiled for Unix, Windows, or OS/2.
01024 ** When [custom builds | built for other platforms]
01025 ** (using the [SQLITE_OS_OTHER=1] compile-time
01026 ** option) the application must supply a suitable implementation for
01027 ** sqlite3_os_init() and sqlite3_os_end().  An application-supplied
01028 ** implementation of sqlite3_os_init() or sqlite3_os_end()
01029 ** must return [SQLITE_OK] on success and some other [error code] upon
01030 ** failure.
01031 */
01032 SQLITE_API int sqlite3_initialize(void);
01033 SQLITE_API int sqlite3_shutdown(void);
01034 SQLITE_API int sqlite3_os_init(void);
01035 SQLITE_API int sqlite3_os_end(void);
01036 
01037 /*
01038 ** CAPI3REF: Configuring The SQLite Library
01039 **
01040 ** The sqlite3_config() interface is used to make global configuration
01041 ** changes to SQLite in order to tune SQLite to the specific needs of
01042 ** the application.  The default configuration is recommended for most
01043 ** applications and so this routine is usually not necessary.  It is
01044 ** provided to support rare applications with unusual needs.
01045 **
01046 ** The sqlite3_config() interface is not threadsafe.  The application
01047 ** must insure that no other SQLite interfaces are invoked by other
01048 ** threads while sqlite3_config() is running.  Furthermore, sqlite3_config()
01049 ** may only be invoked prior to library initialization using
01050 ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].
01051 ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before
01052 ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE.
01053 ** Note, however, that ^sqlite3_config() can be called as part of the
01054 ** implementation of an application-defined [sqlite3_os_init()].
01055 **
01056 ** The first argument to sqlite3_config() is an integer
01057 ** [SQLITE_CONFIG_SINGLETHREAD | configuration option] that determines
01058 ** what property of SQLite is to be configured.  Subsequent arguments
01059 ** vary depending on the [SQLITE_CONFIG_SINGLETHREAD | configuration option]
01060 ** in the first argument.
01061 **
01062 ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
01063 ** ^If the option is unknown or SQLite is unable to set the option
01064 ** then this routine returns a non-zero [error code].
01065 */
01066 SQLITE_API int sqlite3_config(int, ...);
01067 
01068 /*
01069 ** CAPI3REF: Configure database connections
01070 **
01071 ** The sqlite3_db_config() interface is used to make configuration
01072 ** changes to a [database connection].  The interface is similar to
01073 ** [sqlite3_config()] except that the changes apply to a single
01074 ** [database connection] (specified in the first argument).  The
01075 ** sqlite3_db_config() interface should only be used immediately after
01076 ** the database connection is created using [sqlite3_open()],
01077 ** [sqlite3_open16()], or [sqlite3_open_v2()].  
01078 **
01079 ** The second argument to sqlite3_db_config(D,V,...)  is the
01080 ** configuration verb - an integer code that indicates what
01081 ** aspect of the [database connection] is being configured.
01082 ** The only choice for this value is [SQLITE_DBCONFIG_LOOKASIDE].
01083 ** New verbs are likely to be added in future releases of SQLite.
01084 ** Additional arguments depend on the verb.
01085 **
01086 ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
01087 ** the call is considered successful.
01088 */
01089 SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
01090 
01091 /*
01092 ** CAPI3REF: Memory Allocation Routines
01093 **
01094 ** An instance of this object defines the interface between SQLite
01095 ** and low-level memory allocation routines.
01096 **
01097 ** This object is used in only one place in the SQLite interface.
01098 ** A pointer to an instance of this object is the argument to
01099 ** [sqlite3_config()] when the configuration option is
01100 ** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC].  
01101 ** By creating an instance of this object
01102 ** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC])
01103 ** during configuration, an application can specify an alternative
01104 ** memory allocation subsystem for SQLite to use for all of its
01105 ** dynamic memory needs.
01106 **
01107 ** Note that SQLite comes with several [built-in memory allocators]
01108 ** that are perfectly adequate for the overwhelming majority of applications
01109 ** and that this object is only useful to a tiny minority of applications
01110 ** with specialized memory allocation requirements.  This object is
01111 ** also used during testing of SQLite in order to specify an alternative
01112 ** memory allocator that simulates memory out-of-memory conditions in
01113 ** order to verify that SQLite recovers gracefully from such
01114 ** conditions.
01115 **
01116 ** The xMalloc and xFree methods must work like the
01117 ** malloc() and free() functions from the standard C library.
01118 ** The xRealloc method must work like realloc() from the standard C library
01119 ** with the exception that if the second argument to xRealloc is zero,
01120 ** xRealloc must be a no-op - it must not perform any allocation or
01121 ** deallocation.  ^SQLite guarantees that the second argument to
01122 ** xRealloc is always a value returned by a prior call to xRoundup.
01123 ** And so in cases where xRoundup always returns a positive number,
01124 ** xRealloc can perform exactly as the standard library realloc() and
01125 ** still be in compliance with this specification.
01126 **
01127 ** xSize should return the allocated size of a memory allocation
01128 ** previously obtained from xMalloc or xRealloc.  The allocated size
01129 ** is always at least as big as the requested size but may be larger.
01130 **
01131 ** The xRoundup method returns what would be the allocated size of
01132 ** a memory allocation given a particular requested size.  Most memory
01133 ** allocators round up memory allocations at least to the next multiple
01134 ** of 8.  Some allocators round up to a larger multiple or to a power of 2.
01135 ** Every memory allocation request coming in through [sqlite3_malloc()]
01136 ** or [sqlite3_realloc()] first calls xRoundup.  If xRoundup returns 0, 
01137 ** that causes the corresponding memory allocation to fail.
01138 **
01139 ** The xInit method initializes the memory allocator.  (For example,
01140 ** it might allocate any require mutexes or initialize internal data
01141 ** structures.  The xShutdown method is invoked (indirectly) by
01142 ** [sqlite3_shutdown()] and should deallocate any resources acquired
01143 ** by xInit.  The pAppData pointer is used as the only parameter to
01144 ** xInit and xShutdown.
01145 **
01146 ** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes
01147 ** the xInit method, so the xInit method need not be threadsafe.  The
01148 ** xShutdown method is only called from [sqlite3_shutdown()] so it does
01149 ** not need to be threadsafe either.  For all other methods, SQLite
01150 ** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the
01151 ** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which
01152 ** it is by default) and so the methods are automatically serialized.
01153 ** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other
01154 ** methods must be threadsafe or else make their own arrangements for
01155 ** serialization.
01156 **
01157 ** SQLite will never invoke xInit() more than once without an intervening
01158 ** call to xShutdown().
01159 */
01160 typedef struct sqlite3_mem_methods sqlite3_mem_methods;
01161 struct sqlite3_mem_methods {
01162   void *(*xMalloc)(int);         /* Memory allocation function */
01163   void (*xFree)(void*);          /* Free a prior allocation */
01164   void *(*xRealloc)(void*,int);  /* Resize an allocation */
01165   int (*xSize)(void*);           /* Return the size of an allocation */
01166   int (*xRoundup)(int);          /* Round up request size to allocation size */
01167   int (*xInit)(void*);           /* Initialize the memory allocator */
01168   void (*xShutdown)(void*);      /* Deinitialize the memory allocator */
01169   void *pAppData;                /* Argument to xInit() and xShutdown() */
01170 };
01171 
01172 /*
01173 ** CAPI3REF: Configuration Options
01174 **
01175 ** These constants are the available integer configuration options that
01176 ** can be passed as the first argument to the [sqlite3_config()] interface.
01177 **
01178 ** New configuration options may be added in future releases of SQLite.
01179 ** Existing configuration options might be discontinued.  Applications
01180 ** should check the return code from [sqlite3_config()] to make sure that
01181 ** the call worked.  The [sqlite3_config()] interface will return a
01182 ** non-zero [error code] if a discontinued or unsupported configuration option
01183 ** is invoked.
01184 **
01185 ** <dl>
01186 ** <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
01187 ** <dd>There are no arguments to this option.  ^This option sets the
01188 ** [threading mode] to Single-thread.  In other words, it disables
01189 ** all mutexing and puts SQLite into a mode where it can only be used
01190 ** by a single thread.   ^If SQLite is compiled with
01191 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
01192 ** it is not possible to change the [threading mode] from its default
01193 ** value of Single-thread and so [sqlite3_config()] will return 
01194 ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
01195 ** configuration option.</dd>
01196 **
01197 ** <dt>SQLITE_CONFIG_MULTITHREAD</dt>
01198 ** <dd>There are no arguments to this option.  ^This option sets the
01199 ** [threading mode] to Multi-thread.  In other words, it disables
01200 ** mutexing on [database connection] and [prepared statement] objects.
01201 ** The application is responsible for serializing access to
01202 ** [database connections] and [prepared statements].  But other mutexes
01203 ** are enabled so that SQLite will be safe to use in a multi-threaded
01204 ** environment as long as no two threads attempt to use the same
01205 ** [database connection] at the same time.  ^If SQLite is compiled with
01206 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
01207 ** it is not possible to set the Multi-thread [threading mode] and
01208 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
01209 ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
01210 **
01211 ** <dt>SQLITE_CONFIG_SERIALIZED</dt>
01212 ** <dd>There are no arguments to this option.  ^This option sets the
01213 ** [threading mode] to Serialized. In other words, this option enables
01214 ** all mutexes including the recursive
01215 ** mutexes on [database connection] and [prepared statement] objects.
01216 ** In this mode (which is the default when SQLite is compiled with
01217 ** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access
01218 ** to [database connections] and [prepared statements] so that the
01219 ** application is free to use the same [database connection] or the
01220 ** same [prepared statement] in different threads at the same time.
01221 ** ^If SQLite is compiled with
01222 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
01223 ** it is not possible to set the Serialized [threading mode] and
01224 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
01225 ** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
01226 **
01227 ** <dt>SQLITE_CONFIG_MALLOC</dt>
01228 ** <dd> ^(This option takes a single argument which is a pointer to an
01229 ** instance of the [sqlite3_mem_methods] structure.  The argument specifies
01230 ** alternative low-level memory allocation routines to be used in place of
01231 ** the memory allocation routines built into SQLite.)^ ^SQLite makes
01232 ** its own private copy of the content of the [sqlite3_mem_methods] structure
01233 ** before the [sqlite3_config()] call returns.</dd>
01234 **
01235 ** <dt>SQLITE_CONFIG_GETMALLOC</dt>
01236 ** <dd> ^(This option takes a single argument which is a pointer to an
01237 ** instance of the [sqlite3_mem_methods] structure.  The [sqlite3_mem_methods]
01238 ** structure is filled with the currently defined memory allocation routines.)^
01239 ** This option can be used to overload the default memory allocation
01240 ** routines with a wrapper that simulations memory allocation failure or
01241 ** tracks memory usage, for example. </dd>
01242 **
01243 ** <dt>SQLITE_CONFIG_MEMSTATUS</dt>
01244 ** <dd> ^This option takes single argument of type int, interpreted as a 
01245 ** boolean, which enables or disables the collection of memory allocation 
01246 ** statistics. ^(When memory allocation statistics are disabled, the 
01247 ** following SQLite interfaces become non-operational:
01248 **   <ul>
01249 **   <li> [sqlite3_memory_used()]
01250 **   <li> [sqlite3_memory_highwater()]
01251 **   <li> [sqlite3_soft_heap_limit()]
01252 **   <li> [sqlite3_status()]
01253 **   </ul>)^
01254 ** ^Memory allocation statistics are enabled by default unless SQLite is
01255 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
01256 ** allocation statistics are disabled by default.
01257 ** </dd>
01258 **
01259 ** <dt>SQLITE_CONFIG_SCRATCH</dt>
01260 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
01261 ** scratch memory.  There are three arguments:  A pointer an 8-byte
01262 ** aligned memory buffer from which the scrach allocations will be
01263 ** drawn, the size of each scratch allocation (sz),
01264 ** and the maximum number of scratch allocations (N).  The sz
01265 ** argument must be a multiple of 16. The sz parameter should be a few bytes
01266 ** larger than the actual scratch space required due to internal overhead.
01267 ** The first argument must be a pointer to an 8-byte aligned buffer
01268 ** of at least sz*N bytes of memory.
01269 ** ^SQLite will use no more than one scratch buffer per thread.  So
01270 ** N should be set to the expected maximum number of threads.  ^SQLite will
01271 ** never require a scratch buffer that is more than 6 times the database
01272 ** page size. ^If SQLite needs needs additional scratch memory beyond 
01273 ** what is provided by this configuration option, then 
01274 ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
01275 **
01276 ** <dt>SQLITE_CONFIG_PAGECACHE</dt>
01277 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
01278 ** the database page cache with the default page cache implemenation.  
01279 ** This configuration should not be used if an application-define page
01280 ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option.
01281 ** There are three arguments to this option: A pointer to 8-byte aligned
01282 ** memory, the size of each page buffer (sz), and the number of pages (N).
01283 ** The sz argument should be the size of the largest database page
01284 ** (a power of two between 512 and 32768) plus a little extra for each
01285 ** page header.  ^The page header size is 20 to 40 bytes depending on
01286 ** the host architecture.  ^It is harmless, apart from the wasted memory,
01287 ** to make sz a little too large.  The first
01288 ** argument should point to an allocation of at least sz*N bytes of memory.
01289 ** ^SQLite will use the memory provided by the first argument to satisfy its
01290 ** memory needs for the first N pages that it adds to cache.  ^If additional
01291 ** page cache memory is needed beyond what is provided by this option, then
01292 ** SQLite goes to [sqlite3_malloc()] for the additional storage space.
01293 ** ^The implementation might use one or more of the N buffers to hold 
01294 ** memory accounting information. The pointer in the first argument must
01295 ** be aligned to an 8-byte boundary or subsequent behavior of SQLite
01296 ** will be undefined.</dd>
01297 **
01298 ** <dt>SQLITE_CONFIG_HEAP</dt>
01299 ** <dd> ^This option specifies a static memory buffer that SQLite will use
01300 ** for all of its dynamic memory allocation needs beyond those provided
01301 ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
01302 ** There are three arguments: An 8-byte aligned pointer to the memory,
01303 ** the number of bytes in the memory buffer, and the minimum allocation size.
01304 ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
01305 ** to using its default memory allocator (the system malloc() implementation),
01306 ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC].  ^If the
01307 ** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
01308 ** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
01309 ** allocator is engaged to handle all of SQLites memory allocation needs.
01310 ** The first pointer (the memory pointer) must be aligned to an 8-byte
01311 ** boundary or subsequent behavior of SQLite will be undefined.</dd>
01312 **
01313 ** <dt>SQLITE_CONFIG_MUTEX</dt>
01314 ** <dd> ^(This option takes a single argument which is a pointer to an
01315 ** instance of the [sqlite3_mutex_methods] structure.  The argument specifies
01316 ** alternative low-level mutex routines to be used in place
01317 ** the mutex routines built into SQLite.)^  ^SQLite makes a copy of the
01318 ** content of the [sqlite3_mutex_methods] structure before the call to
01319 ** [sqlite3_config()] returns. ^If SQLite is compiled with
01320 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
01321 ** the entire mutexing subsystem is omitted from the build and hence calls to
01322 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
01323 ** return [SQLITE_ERROR].</dd>
01324 **
01325 ** <dt>SQLITE_CONFIG_GETMUTEX</dt>
01326 ** <dd> ^(This option takes a single argument which is a pointer to an
01327 ** instance of the [sqlite3_mutex_methods] structure.  The
01328 ** [sqlite3_mutex_methods]
01329 ** structure is filled with the currently defined mutex routines.)^
01330 ** This option can be used to overload the default mutex allocation
01331 ** routines with a wrapper used to track mutex usage for performance
01332 ** profiling or testing, for example.   ^If SQLite is compiled with
01333 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
01334 ** the entire mutexing subsystem is omitted from the build and hence calls to
01335 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
01336 ** return [SQLITE_ERROR].</dd>
01337 **
01338 ** <dt>SQLITE_CONFIG_LOOKASIDE</dt>
01339 ** <dd> ^(This option takes two arguments that determine the default
01340 ** memory allocation for the lookaside memory allocator on each
01341 ** [database connection].  The first argument is the
01342 ** size of each lookaside buffer slot and the second is the number of
01343 ** slots allocated to each database connection.)^  ^(This option sets the
01344 ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
01345 ** verb to [sqlite3_db_config()] can be used to change the lookaside
01346 ** configuration on individual connections.)^ </dd>
01347 **
01348 ** <dt>SQLITE_CONFIG_PCACHE</dt>
01349 ** <dd> ^(This option takes a single argument which is a pointer to
01350 ** an [sqlite3_pcache_methods] object.  This object specifies the interface
01351 ** to a custom page cache implementation.)^  ^SQLite makes a copy of the
01352 ** object and uses it for page cache memory allocations.</dd>
01353 **
01354 ** <dt>SQLITE_CONFIG_GETPCACHE</dt>
01355 ** <dd> ^(This option takes a single argument which is a pointer to an
01356 ** [sqlite3_pcache_methods] object.  SQLite copies of the current
01357 ** page cache implementation into that object.)^ </dd>
01358 **
01359 ** <dt>SQLITE_CONFIG_LOG</dt>
01360 ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
01361 ** function with a call signature of void(*)(void*,int,const char*), 
01362 ** and a pointer to void. ^If the function pointer is not NULL, it is
01363 ** invoked by [sqlite3_log()] to process each logging event.  ^If the
01364 ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
01365 ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
01366 ** passed through as the first parameter to the application-defined logger
01367 ** function whenever that function is invoked.  ^The second parameter to
01368 ** the logger function is a copy of the first parameter to the corresponding
01369 ** [sqlite3_log()] call and is intended to be a [result code] or an
01370 ** [extended result code].  ^The third parameter passed to the logger is
01371 ** log message after formatting via [sqlite3_snprintf()].
01372 ** The SQLite logging interface is not reentrant; the logger function
01373 ** supplied by the application must not invoke any SQLite interface.
01374 ** In a multi-threaded application, the application-defined logger
01375 ** function must be threadsafe. </dd>
01376 **
01377 ** </dl>
01378 */
01379 #define SQLITE_CONFIG_SINGLETHREAD  1  /* nil */
01380 #define SQLITE_CONFIG_MULTITHREAD   2  /* nil */
01381 #define SQLITE_CONFIG_SERIALIZED    3  /* nil */
01382 #define SQLITE_CONFIG_MALLOC        4  /* sqlite3_mem_methods* */
01383 #define SQLITE_CONFIG_GETMALLOC     5  /* sqlite3_mem_methods* */
01384 #define SQLITE_CONFIG_SCRATCH       6  /* void*, int sz, int N */
01385 #define SQLITE_CONFIG_PAGECACHE     7  /* void*, int sz, int N */
01386 #define SQLITE_CONFIG_HEAP          8  /* void*, int nByte, int min */
01387 #define SQLITE_CONFIG_MEMSTATUS     9  /* boolean */
01388 #define SQLITE_CONFIG_MUTEX        10  /* sqlite3_mutex_methods* */
01389 #define SQLITE_CONFIG_GETMUTEX     11  /* sqlite3_mutex_methods* */
01390 /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ 
01391 #define SQLITE_CONFIG_LOOKASIDE    13  /* int int */
01392 #define SQLITE_CONFIG_PCACHE       14  /* sqlite3_pcache_methods* */
01393 #define SQLITE_CONFIG_GETPCACHE    15  /* sqlite3_pcache_methods* */
01394 #define SQLITE_CONFIG_LOG          16  /* xFunc, void* */
01395 
01396 /*
01397 ** CAPI3REF: Database Connection Configuration Options
01398 **
01399 ** These constants are the available integer configuration options that
01400 ** can be passed as the second argument to the [sqlite3_db_config()] interface.
01401 **
01402 ** New configuration options may be added in future releases of SQLite.
01403 ** Existing configuration options might be discontinued.  Applications
01404 ** should check the return code from [sqlite3_db_config()] to make sure that
01405 ** the call worked.  ^The [sqlite3_db_config()] interface will return a
01406 ** non-zero [error code] if a discontinued or unsupported configuration option
01407 ** is invoked.
01408 **
01409 ** <dl>
01410 ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
01411 ** <dd> ^This option takes three additional arguments that determine the 
01412 ** [lookaside memory allocator] configuration for the [database connection].
01413 ** ^The first argument (the third parameter to [sqlite3_db_config()] is a
01414 ** pointer to an memory buffer to use for lookaside memory.
01415 ** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb
01416 ** may be NULL in which case SQLite will allocate the
01417 ** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the
01418 ** size of each lookaside buffer slot.  ^The third argument is the number of
01419 ** slots.  The size of the buffer in the first argument must be greater than
01420 ** or equal to the product of the second and third arguments.  The buffer
01421 ** must be aligned to an 8-byte boundary.  ^If the second argument to
01422 ** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
01423 ** rounded down to the next smaller
01424 ** multiple of 8.  See also: [SQLITE_CONFIG_LOOKASIDE]</dd>
01425 **
01426 ** </dl>
01427 */
01428 #define SQLITE_DBCONFIG_LOOKASIDE    1001  /* void* int int */
01429 
01430 
01431 /*
01432 ** CAPI3REF: Enable Or Disable Extended Result Codes
01433 **
01434 ** ^The sqlite3_extended_result_codes() routine enables or disables the
01435 ** [extended result codes] feature of SQLite. ^The extended result
01436 ** codes are disabled by default for historical compatibility.
01437 */
01438 SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
01439 
01440 /*
01441 ** CAPI3REF: Last Insert Rowid
01442 **
01443 ** ^Each entry in an SQLite table has a unique 64-bit signed
01444 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
01445 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
01446 ** names are not also used by explicitly declared columns. ^If
01447 ** the table has a column of type [INTEGER PRIMARY KEY] then that column
01448 ** is another alias for the rowid.
01449 **
01450 ** ^This routine returns the [rowid] of the most recent
01451 ** successful [INSERT] into the database from the [database connection]
01452 ** in the first argument.  ^If no successful [INSERT]s
01453 ** have ever occurred on that database connection, zero is returned.
01454 **
01455 ** ^(If an [INSERT] occurs within a trigger, then the [rowid] of the inserted
01456 ** row is returned by this routine as long as the trigger is running.
01457 ** But once the trigger terminates, the value returned by this routine
01458 ** reverts to the last value inserted before the trigger fired.)^
01459 **
01460 ** ^An [INSERT] that fails due to a constraint violation is not a
01461 ** successful [INSERT] and does not change the value returned by this
01462 ** routine.  ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
01463 ** and INSERT OR ABORT make no changes to the return value of this
01464 ** routine when their insertion fails.  ^(When INSERT OR REPLACE
01465 ** encounters a constraint violation, it does not fail.  The
01466 ** INSERT continues to completion after deleting rows that caused
01467 ** the constraint problem so INSERT OR REPLACE will always change
01468 ** the return value of this interface.)^
01469 **
01470 ** ^For the purposes of this routine, an [INSERT] is considered to
01471 ** be successful even if it is subsequently rolled back.
01472 **
01473 ** This function is accessible to SQL statements via the
01474 ** [last_insert_rowid() SQL function].
01475 **
01476 ** If a separate thread performs a new [INSERT] on the same
01477 ** database connection while the [sqlite3_last_insert_rowid()]
01478 ** function is running and thus changes the last insert [rowid],
01479 ** then the value returned by [sqlite3_last_insert_rowid()] is
01480 ** unpredictable and might not equal either the old or the new
01481 ** last insert [rowid].
01482 */
01483 SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
01484 
01485 /*
01486 ** CAPI3REF: Count The Number Of Rows Modified
01487 **
01488 ** ^This function returns the number of database rows that were changed
01489 ** or inserted or deleted by the most recently completed SQL statement
01490 ** on the [database connection] specified by the first parameter.
01491 ** ^(Only changes that are directly specified by the [INSERT], [UPDATE],
01492 ** or [DELETE] statement are counted.  Auxiliary changes caused by
01493 ** triggers or [foreign key actions] are not counted.)^ Use the
01494 ** [sqlite3_total_changes()] function to find the total number of changes
01495 ** including changes caused by triggers and foreign key actions.
01496 **
01497 ** ^Changes to a view that are simulated by an [INSTEAD OF trigger]
01498 ** are not counted.  Only real table changes are counted.
01499 **
01500 ** ^(A "row change" is a change to a single row of a single table
01501 ** caused by an INSERT, DELETE, or UPDATE statement.  Rows that
01502 ** are changed as side effects of [REPLACE] constraint resolution,
01503 ** rollback, ABORT processing, [DROP TABLE], or by any other
01504 ** mechanisms do not count as direct row changes.)^
01505 **
01506 ** A "trigger context" is a scope of execution that begins and
01507 ** ends with the script of a [CREATE TRIGGER | trigger]. 
01508 ** Most SQL statements are
01509 ** evaluated outside of any trigger.  This is the "top level"
01510 ** trigger context.  If a trigger fires from the top level, a
01511 ** new trigger context is entered for the duration of that one
01512 ** trigger.  Subtriggers create subcontexts for their duration.
01513 **
01514 ** ^Calling [sqlite3_exec()] or [sqlite3_step()] recursively does
01515 ** not create a new trigger context.
01516 **
01517 ** ^This function returns the number of direct row changes in the
01518 ** most recent INSERT, UPDATE, or DELETE statement within the same
01519 ** trigger context.
01520 **
01521 ** ^Thus, when called from the top level, this function returns the
01522 ** number of changes in the most recent INSERT, UPDATE, or DELETE
01523 ** that also occurred at the top level.  ^(Within the body of a trigger,
01524 ** the sqlite3_changes() interface can be called to find the number of
01525 ** changes in the most recently completed INSERT, UPDATE, or DELETE
01526 ** statement within the body of the same trigger.
01527 ** However, the number returned does not include changes
01528 ** caused by subtriggers since those have their own context.)^
01529 **
01530 ** See also the [sqlite3_total_changes()] interface, the
01531 ** [count_changes pragma], and the [changes() SQL function].
01532 **
01533 ** If a separate thread makes changes on the same database connection
01534 ** while [sqlite3_changes()] is running then the value returned
01535 ** is unpredictable and not meaningful.
01536 */
01537 SQLITE_API int sqlite3_changes(sqlite3*);
01538 
01539 /*
01540 ** CAPI3REF: Total Number Of Rows Modified
01541 **
01542 ** ^This function returns the number of row changes caused by [INSERT],
01543 ** [UPDATE] or [DELETE] statements since the [database connection] was opened.
01544 ** ^(The count returned by sqlite3_total_changes() includes all changes
01545 ** from all [CREATE TRIGGER | trigger] contexts and changes made by
01546 ** [foreign key actions]. However,
01547 ** the count does not include changes used to implement [REPLACE] constraints,
01548 ** do rollbacks or ABORT processing, or [DROP TABLE] processing.  The
01549 ** count does not include rows of views that fire an [INSTEAD OF trigger],
01550 ** though if the INSTEAD OF trigger makes changes of its own, those changes 
01551 ** are counted.)^
01552 ** ^The sqlite3_total_changes() function counts the changes as soon as
01553 ** the statement that makes them is completed (when the statement handle
01554 ** is passed to [sqlite3_reset()] or [sqlite3_finalize()]).
01555 **
01556 ** See also the [sqlite3_changes()] interface, the
01557 ** [count_changes pragma], and the [total_changes() SQL function].
01558 **
01559 ** If a separate thread makes changes on the same database connection
01560 ** while [sqlite3_total_changes()] is running then the value
01561 ** returned is unpredictable and not meaningful.
01562 */
01563 SQLITE_API int sqlite3_total_changes(sqlite3*);
01564 
01565 /*
01566 ** CAPI3REF: Interrupt A Long-Running Query
01567 **
01568 ** ^This function causes any pending database operation to abort and
01569 ** return at its earliest opportunity. This routine is typically
01570 ** called in response to a user action such as pressing "Cancel"
01571 ** or Ctrl-C where the user wants a long query operation to halt
01572 ** immediately.
01573 **
01574 ** ^It is safe to call this routine from a thread different from the
01575 ** thread that is currently running the database operation.  But it
01576 ** is not safe to call this routine with a [database connection] that
01577 ** is closed or might close before sqlite3_interrupt() returns.
01578 **
01579 ** ^If an SQL operation is very nearly finished at the time when
01580 ** sqlite3_interrupt() is called, then it might not have an opportunity
01581 ** to be interrupted and might continue to completion.
01582 **
01583 ** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT].
01584 ** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE
01585 ** that is inside an explicit transaction, then the entire transaction
01586 ** will be rolled back automatically.
01587 **
01588 ** ^The sqlite3_interrupt(D) call is in effect until all currently running
01589 ** SQL statements on [database connection] D complete.  ^Any new SQL statements
01590 ** that are started after the sqlite3_interrupt() call and before the 
01591 ** running statements reaches zero are interrupted as if they had been
01592 ** running prior to the sqlite3_interrupt() call.  ^New SQL statements
01593 ** that are started after the running statement count reaches zero are
01594 ** not effected by the sqlite3_interrupt().
01595 ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
01596 ** SQL statements is a no-op and has no effect on SQL statements
01597 ** that are started after the sqlite3_interrupt() call returns.
01598 **
01599 ** If the database connection closes while [sqlite3_interrupt()]
01600 ** is running then bad things will likely happen.
01601 */
01602 SQLITE_API void sqlite3_interrupt(sqlite3*);
01603 
01604 /*
01605 ** CAPI3REF: Determine If An SQL Statement Is Complete
01606 **
01607 ** These routines are useful during command-line input to determine if the
01608 ** currently entered text seems to form a complete SQL statement or
01609 ** if additional input is needed before sending the text into
01610 ** SQLite for parsing.  ^These routines return 1 if the input string
01611 ** appears to be a complete SQL statement.  ^A statement is judged to be
01612 ** complete if it ends with a semicolon token and is not a prefix of a
01613 ** well-formed CREATE TRIGGER statement.  ^Semicolons that are embedded within
01614 ** string literals or quoted identifier names or comments are not
01615 ** independent tokens (they are part of the token in which they are
01616 ** embedded) and thus do not count as a statement terminator.  ^Whitespace
01617 ** and comments that follow the final semicolon are ignored.
01618 **
01619 ** ^These routines return 0 if the statement is incomplete.  ^If a
01620 ** memory allocation fails, then SQLITE_NOMEM is returned.
01621 **
01622 ** ^These routines do not parse the SQL statements thus
01623 ** will not detect syntactically incorrect SQL.
01624 **
01625 ** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior 
01626 ** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked
01627 ** automatically by sqlite3_complete16().  If that initialization fails,
01628 ** then the return value from sqlite3_complete16() will be non-zero
01629 ** regardless of whether or not the input SQL is complete.)^
01630 **
01631 ** The input to [sqlite3_complete()] must be a zero-terminated
01632 ** UTF-8 string.
01633 **
01634 ** The input to [sqlite3_complete16()] must be a zero-terminated
01635 ** UTF-16 string in native byte order.
01636 */
01637 SQLITE_API int sqlite3_complete(const char *sql);
01638 SQLITE_API int sqlite3_complete16(const void *sql);
01639 
01640 /*
01641 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
01642 **
01643 ** ^This routine sets a callback function that might be invoked whenever
01644 ** an attempt is made to open a database table that another thread
01645 ** or process has locked.
01646 **
01647 ** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]
01648 ** is returned immediately upon encountering the lock.  ^If the busy callback
01649 ** is not NULL, then the callback might be invoked with two arguments.
01650 **
01651 ** ^The first argument to the busy handler is a copy of the void* pointer which
01652 ** is the third argument to sqlite3_busy_handler().  ^The second argument to
01653 ** the busy handler callback is the number of times that the busy handler has
01654 ** been invoked for this locking event.  ^If the
01655 ** busy callback returns 0, then no additional attempts are made to
01656 ** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned.
01657 ** ^If the callback returns non-zero, then another attempt
01658 ** is made to open the database for reading and the cycle repeats.
01659 **
01660 ** The presence of a busy handler does not guarantee that it will be invoked
01661 ** when there is lock contention. ^If SQLite determines that invoking the busy
01662 ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
01663 ** or [SQLITE_IOERR_BLOCKED] instead of invoking the busy handler.
01664 ** Consider a scenario where one process is holding a read lock that
01665 ** it is trying to promote to a reserved lock and
01666 ** a second process is holding a reserved lock that it is trying
01667 ** to promote to an exclusive lock.  The first process cannot proceed
01668 ** because it is blocked by the second and the second process cannot
01669 ** proceed because it is blocked by the first.  If both processes
01670 ** invoke the busy handlers, neither will make any progress.  Therefore,
01671 ** SQLite returns [SQLITE_BUSY] for the first process, hoping that this
01672 ** will induce the first process to release its read lock and allow
01673 ** the second process to proceed.
01674 **
01675 ** ^The default busy callback is NULL.
01676 **
01677 ** ^The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED]
01678 ** when SQLite is in the middle of a large transaction where all the
01679 ** changes will not fit into the in-memory cache.  SQLite will
01680 ** already hold a RESERVED lock on the database file, but it needs
01681 ** to promote this lock to EXCLUSIVE so that it can spill cache
01682 ** pages into the database file without harm to concurrent
01683 ** readers.  ^If it is unable to promote the lock, then the in-memory
01684 ** cache will be left in an inconsistent state and so the error
01685 ** code is promoted from the relatively benign [SQLITE_BUSY] to
01686 ** the more severe [SQLITE_IOERR_BLOCKED].  ^This error code promotion
01687 ** forces an automatic rollback of the changes.  See the
01688 ** <a href="/cvstrac/wiki?p=CorruptionFollowingBusyError">
01689 ** CorruptionFollowingBusyError</a> wiki page for a discussion of why
01690 ** this is important.
01691 **
01692 ** ^(There can only be a single busy handler defined for each
01693 ** [database connection].  Setting a new busy handler clears any
01694 ** previously set handler.)^  ^Note that calling [sqlite3_busy_timeout()]
01695 ** will also set or clear the busy handler.
01696 **
01697 ** The busy callback should not take any actions which modify the
01698 ** database connection that invoked the busy handler.  Any such actions
01699 ** result in undefined behavior.
01700 ** 
01701 ** A busy handler must not close the database connection
01702 ** or [prepared statement] that invoked the busy handler.
01703 */
01704 SQLITE_API int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*);
01705 
01706 /*
01707 ** CAPI3REF: Set A Busy Timeout
01708 **
01709 ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
01710 ** for a specified amount of time when a table is locked.  ^The handler
01711 ** will sleep multiple times until at least "ms" milliseconds of sleeping
01712 ** have accumulated.  ^After at least "ms" milliseconds of sleeping,
01713 ** the handler returns 0 which causes [sqlite3_step()] to return
01714 ** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED].
01715 **
01716 ** ^Calling this routine with an argument less than or equal to zero
01717 ** turns off all busy handlers.
01718 **
01719 ** ^(There can only be a single busy handler for a particular
01720 ** [database connection] any any given moment.  If another busy handler
01721 ** was defined  (using [sqlite3_busy_handler()]) prior to calling
01722 ** this routine, that other busy handler is cleared.)^
01723 */
01724 SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
01725 
01726 /*
01727 ** CAPI3REF: Convenience Routines For Running Queries
01728 **
01729 ** Definition: A <b>result table</b> is memory data structure created by the
01730 ** [sqlite3_get_table()] interface.  A result table records the
01731 ** complete query results from one or more queries.
01732 **
01733 ** The table conceptually has a number of rows and columns.  But
01734 ** these numbers are not part of the result table itself.  These
01735 ** numbers are obtained separately.  Let N be the number of rows
01736 ** and M be the number of columns.
01737 **
01738 ** A result table is an array of pointers to zero-terminated UTF-8 strings.
01739 ** There are (N+1)*M elements in the array.  The first M pointers point
01740 ** to zero-terminated strings that  contain the names of the columns.
01741 ** The remaining entries all point to query results.  NULL values result
01742 ** in NULL pointers.  All other values are in their UTF-8 zero-terminated
01743 ** string representation as returned by [sqlite3_column_text()].
01744 **
01745 ** A result table might consist of one or more memory allocations.
01746 ** It is not safe to pass a result table directly to [sqlite3_free()].
01747 ** A result table should be deallocated using [sqlite3_free_table()].
01748 **
01749 ** As an example of the result table format, suppose a query result
01750 ** is as follows:
01751 **
01752 ** <blockquote><pre>
01753 **        Name        | Age
01754 **        -----------------------
01755 **        Alice       | 43
01756 **        Bob         | 28
01757 **        Cindy       | 21
01758 ** </pre></blockquote>
01759 **
01760 ** There are two column (M==2) and three rows (N==3).  Thus the
01761 ** result table has 8 entries.  Suppose the result table is stored
01762 ** in an array names azResult.  Then azResult holds this content:
01763 **
01764 ** <blockquote><pre>
01765 **        azResult&#91;0] = "Name";
01766 **        azResult&#91;1] = "Age";
01767 **        azResult&#91;2] = "Alice";
01768 **        azResult&#91;3] = "43";
01769 **        azResult&#91;4] = "Bob";
01770 **        azResult&#91;5] = "28";
01771 **        azResult&#91;6] = "Cindy";
01772 **        azResult&#91;7] = "21";
01773 ** </pre></blockquote>
01774 **
01775 ** ^The sqlite3_get_table() function evaluates one or more
01776 ** semicolon-separated SQL statements in the zero-terminated UTF-8
01777 ** string of its 2nd parameter and returns a result table to the
01778 ** pointer given in its 3rd parameter.
01779 **
01780 ** After the application has finished with the result from sqlite3_get_table(),
01781 ** it should pass the result table pointer to sqlite3_free_table() in order to
01782 ** release the memory that was malloced.  Because of the way the
01783 ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
01784 ** function must not try to call [sqlite3_free()] directly.  Only
01785 ** [sqlite3_free_table()] is able to release the memory properly and safely.
01786 **
01787 ** ^(The sqlite3_get_table() interface is implemented as a wrapper around
01788 ** [sqlite3_exec()].  The sqlite3_get_table() routine does not have access
01789 ** to any internal data structures of SQLite.  It uses only the public
01790 ** interface defined here.  As a consequence, errors that occur in the
01791 ** wrapper layer outside of the internal [sqlite3_exec()] call are not
01792 ** reflected in subsequent calls to [sqlite3_errcode()] or
01793 ** [sqlite3_errmsg()].)^
01794 */
01795 SQLITE_API int sqlite3_get_table(
01796   sqlite3 *db,          /* An open database */
01797   const char *zSql,     /* SQL to be evaluated */
01798   char ***pazResult,    /* Results of the query */
01799   int *pnRow,           /* Number of result rows written here */
01800   int *pnColumn,        /* Number of result columns written here */
01801   char **pzErrmsg       /* Error msg written here */
01802 );
01803 SQLITE_API void sqlite3_free_table(char **result);
01804 
01805 /*
01806 ** CAPI3REF: Formatted String Printing Functions
01807 **
01808 ** These routines are work-alikes of the "printf()" family of functions
01809 ** from the standard C library.
01810 **
01811 ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
01812 ** results into memory obtained from [sqlite3_malloc()].
01813 ** The strings returned by these two routines should be
01814 ** released by [sqlite3_free()].  ^Both routines return a
01815 ** NULL pointer if [sqlite3_malloc()] is unable to allocate enough
01816 ** memory to hold the resulting string.
01817 **
01818 ** ^(In sqlite3_snprintf() routine is similar to "snprintf()" from
01819 ** the standard C library.  The result is written into the
01820 ** buffer supplied as the second parameter whose size is given by
01821 ** the first parameter. Note that the order of the
01822 ** first two parameters is reversed from snprintf().)^  This is an
01823 ** historical accident that cannot be fixed without breaking
01824 ** backwards compatibility.  ^(Note also that sqlite3_snprintf()
01825 ** returns a pointer to its buffer instead of the number of
01826 ** characters actually written into the buffer.)^  We admit that
01827 ** the number of characters written would be a more useful return
01828 ** value but we cannot change the implementation of sqlite3_snprintf()
01829 ** now without breaking compatibility.
01830 **
01831 ** ^As long as the buffer size is greater than zero, sqlite3_snprintf()
01832 ** guarantees that the buffer is always zero-terminated.  ^The first
01833 ** parameter "n" is the total size of the buffer, including space for
01834 ** the zero terminator.  So the longest string that can be completely
01835 ** written will be n-1 characters.
01836 **
01837 ** These routines all implement some additional formatting
01838 ** options that are useful for constructing SQL statements.
01839 ** All of the usual printf() formatting options apply.  In addition, there
01840 ** is are "%q", "%Q", and "%z" options.
01841 **
01842 ** ^(The %q option works like %s in that it substitutes a null-terminated
01843 ** string from the argument list.  But %q also doubles every '\'' character.
01844 ** %q is designed for use inside a string literal.)^  By doubling each '\''
01845 ** character it escapes that character and allows it to be inserted into
01846 ** the string.
01847 **
01848 ** For example, assume the string variable zText contains text as follows:
01849 **
01850 ** <blockquote><pre>
01851 **  char *zText = "It's a happy day!";
01852 ** </pre></blockquote>
01853 **
01854 ** One can use this text in an SQL statement as follows:
01855 **
01856 ** <blockquote><pre>
01857 **  char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText);
01858 **  sqlite3_exec(db, zSQL, 0, 0, 0);
01859 **  sqlite3_free(zSQL);
01860 ** </pre></blockquote>
01861 **
01862 ** Because the %q format string is used, the '\'' character in zText
01863 ** is escaped and the SQL generated is as follows:
01864 **
01865 ** <blockquote><pre>
01866 **  INSERT INTO table1 VALUES('It''s a happy day!')
01867 ** </pre></blockquote>
01868 **
01869 ** This is correct.  Had we used %s instead of %q, the generated SQL
01870 ** would have looked like this:
01871 **
01872 ** <blockquote><pre>
01873 **  INSERT INTO table1 VALUES('It's a happy day!');
01874 ** </pre></blockquote>
01875 **
01876 ** This second example is an SQL syntax error.  As a general rule you should
01877 ** always use %q instead of %s when inserting text into a string literal.
01878 **
01879 ** ^(The %Q option works like %q except it also adds single quotes around
01880 ** the outside of the total string.  Additionally, if the parameter in the
01881 ** argument list is a NULL pointer, %Q substitutes the text "NULL" (without
01882 ** single quotes).)^  So, for example, one could say:
01883 **
01884 ** <blockquote><pre>
01885 **  char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
01886 **  sqlite3_exec(db, zSQL, 0, 0, 0);
01887 **  sqlite3_free(zSQL);
01888 ** </pre></blockquote>
01889 **
01890 ** The code above will render a correct SQL statement in the zSQL
01891 ** variable even if the zText variable is a NULL pointer.
01892 **
01893 ** ^(The "%z" formatting option works like "%s" but with the
01894 ** addition that after the string has been read and copied into
01895 ** the result, [sqlite3_free()] is called on the input string.)^
01896 */
01897 SQLITE_API char *sqlite3_mprintf(const char*,...);
01898 SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
01899 SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
01900 
01901 /*
01902 ** CAPI3REF: Memory Allocation Subsystem
01903 **
01904 ** The SQLite core uses these three routines for all of its own
01905 ** internal memory allocation needs. "Core" in the previous sentence
01906 ** does not include operating-system specific VFS implementation.  The
01907 ** Windows VFS uses native malloc() and free() for some operations.
01908 **
01909 ** ^The sqlite3_malloc() routine returns a pointer to a block
01910 ** of memory at least N bytes in length, where N is the parameter.
01911 ** ^If sqlite3_malloc() is unable to obtain sufficient free
01912 ** memory, it returns a NULL pointer.  ^If the parameter N to
01913 ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
01914 ** a NULL pointer.
01915 **
01916 ** ^Calling sqlite3_free() with a pointer previously returned
01917 ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
01918 ** that it might be reused.  ^The sqlite3_free() routine is
01919 ** a no-op if is called with a NULL pointer.  Passing a NULL pointer
01920 ** to sqlite3_free() is harmless.  After being freed, memory
01921 ** should neither be read nor written.  Even reading previously freed
01922 ** memory might result in a segmentation fault or other severe error.
01923 ** Memory corruption, a segmentation fault, or other severe error
01924 ** might result if sqlite3_free() is called with a non-NULL pointer that
01925 ** was not obtained from sqlite3_malloc() or sqlite3_realloc().
01926 **
01927 ** ^(The sqlite3_realloc() interface attempts to resize a
01928 ** prior memory allocation to be at least N bytes, where N is the
01929 ** second parameter.  The memory allocation to be resized is the first
01930 ** parameter.)^ ^ If the first parameter to sqlite3_realloc()
01931 ** is a NULL pointer then its behavior is identical to calling
01932 ** sqlite3_malloc(N) where N is the second parameter to sqlite3_realloc().
01933 ** ^If the second parameter to sqlite3_realloc() is zero or
01934 ** negative then the behavior is exactly the same as calling
01935 ** sqlite3_free(P) where P is the first parameter to sqlite3_realloc().
01936 ** ^sqlite3_realloc() returns a pointer to a memory allocation
01937 ** of at least N bytes in size or NULL if sufficient memory is unavailable.
01938 ** ^If M is the size of the prior allocation, then min(N,M) bytes
01939 ** of the prior allocation are copied into the beginning of buffer returned
01940 ** by sqlite3_realloc() and the prior allocation is freed.
01941 ** ^If sqlite3_realloc() returns NULL, then the prior allocation
01942 ** is not freed.
01943 **
01944 ** ^The memory returned by sqlite3_malloc() and sqlite3_realloc()
01945 ** is always aligned to at least an 8 byte boundary.
01946 **
01947 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define
01948 ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in
01949 ** implementation of these routines to be omitted.  That capability
01950 ** is no longer provided.  Only built-in memory allocators can be used.
01951 **
01952 ** The Windows OS interface layer calls
01953 ** the system malloc() and free() directly when converting
01954 ** filenames between the UTF-8 encoding used by SQLite
01955 ** and whatever filename encoding is used by the particular Windows
01956 ** installation.  Memory allocation errors are detected, but
01957 ** they are reported back as [SQLITE_CANTOPEN] or
01958 ** [SQLITE_IOERR] rather than [SQLITE_NOMEM].
01959 **
01960 ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
01961 ** must be either NULL or else pointers obtained from a prior
01962 ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
01963 ** not yet been released.
01964 **
01965 ** The application must not read or write any part of
01966 ** a block of memory after it has been released using
01967 ** [sqlite3_free()] or [sqlite3_realloc()].
01968 */
01969 SQLITE_API void *sqlite3_malloc(int);
01970 SQLITE_API void *sqlite3_realloc(void*, int);
01971 SQLITE_API void sqlite3_free(void*);
01972 
01973 /*
01974 ** CAPI3REF: Memory Allocator Statistics
01975 **
01976 ** SQLite provides these two interfaces for reporting on the status
01977 ** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()]
01978 ** routines, which form the built-in memory allocation subsystem.
01979 **
01980 ** ^The [sqlite3_memory_used()] routine returns the number of bytes
01981 ** of memory currently outstanding (malloced but not freed).
01982 ** ^The [sqlite3_memory_highwater()] routine returns the maximum
01983 ** value of [sqlite3_memory_used()] since the high-water mark
01984 ** was last reset.  ^The values returned by [sqlite3_memory_used()] and
01985 ** [sqlite3_memory_highwater()] include any overhead
01986 ** added by SQLite in its implementation of [sqlite3_malloc()],
01987 ** but not overhead added by the any underlying system library
01988 ** routines that [sqlite3_malloc()] may call.
01989 **
01990 ** ^The memory high-water mark is reset to the current value of
01991 ** [sqlite3_memory_used()] if and only if the parameter to
01992 ** [sqlite3_memory_highwater()] is true.  ^The value returned
01993 ** by [sqlite3_memory_highwater(1)] is the high-water mark
01994 ** prior to the reset.
01995 */
01996 SQLITE_API sqlite3_int64 sqlite3_memory_used(void);
01997 SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag);
01998 
01999 /*
02000 ** CAPI3REF: Pseudo-Random Number Generator
02001 **
02002 ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
02003 ** select random [ROWID | ROWIDs] when inserting new records into a table that
02004 ** already uses the largest possible [ROWID].  The PRNG is also used for
02005 ** the build-in random() and randomblob() SQL functions.  This interface allows
02006 ** applications to access the same PRNG for other purposes.
02007 **
02008 ** ^A call to this routine stores N bytes of randomness into buffer P.
02009 **
02010 ** ^The first time this routine is invoked (either internally or by
02011 ** the application) the PRNG is seeded using randomness obtained
02012 ** from the xRandomness method of the default [sqlite3_vfs] object.
02013 ** ^On all subsequent invocations, the pseudo-randomness is generated
02014 ** internally and without recourse to the [sqlite3_vfs] xRandomness
02015 ** method.
02016 */
02017 SQLITE_API void sqlite3_randomness(int N, void *P);
02018 
02019 /*
02020 ** CAPI3REF: Compile-Time Authorization Callbacks
02021 **
02022 ** ^This routine registers a authorizer callback with a particular
02023 ** [database connection], supplied in the first argument.
02024 ** ^The authorizer callback is invoked as SQL statements are being compiled
02025 ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
02026 ** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()].  ^At various
02027 ** points during the compilation process, as logic is being created
02028 ** to perform various actions, the authorizer callback is invoked to
02029 ** see if those actions are allowed.  ^The authorizer callback should
02030 ** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the
02031 ** specific action but allow the SQL statement to continue to be
02032 ** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be
02033 ** rejected with an error.  ^If the authorizer callback returns
02034 ** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY]
02035 ** then the [sqlite3_prepare_v2()] or equivalent call that triggered
02036 ** the authorizer will fail with an error message.
02037 **
02038 ** When the callback returns [SQLITE_OK], that means the operation
02039 ** requested is ok.  ^When the callback returns [SQLITE_DENY], the
02040 ** [sqlite3_prepare_v2()] or equivalent call that triggered the
02041 ** authorizer will fail with an error message explaining that
02042 ** access is denied. 
02043 **
02044 ** ^The first parameter to the authorizer callback is a copy of the third
02045 ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
02046 ** to the callback is an integer [SQLITE_COPY | action code] that specifies
02047 ** the particular action to be authorized. ^The third through sixth parameters
02048 ** to the callback are zero-terminated strings that contain additional
02049 ** details about the action to be authorized.
02050 **
02051 ** ^If the action code is [SQLITE_READ]
02052 ** and the callback returns [SQLITE_IGNORE] then the
02053 ** [prepared statement] statement is constructed to substitute
02054 ** a NULL value in place of the table column that would have
02055 ** been read if [SQLITE_OK] had been returned.  The [SQLITE_IGNORE]
02056 ** return can be used to deny an untrusted user access to individual
02057 ** columns of a table.
02058 ** ^If the action code is [SQLITE_DELETE] and the callback returns
02059 ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
02060 ** [truncate optimization] is disabled and all rows are deleted individually.
02061 **
02062 ** An authorizer is used when [sqlite3_prepare | preparing]
02063 ** SQL statements from an untrusted source, to ensure that the SQL statements
02064 ** do not try to access data they are not allowed to see, or that they do not
02065 ** try to execute malicious statements that damage the database.  For
02066 ** example, an application may allow a user to enter arbitrary
02067 ** SQL queries for evaluation by a database.  But the application does
02068 ** not want the user to be able to make arbitrary changes to the
02069 ** database.  An authorizer could then be put in place while the
02070 ** user-entered SQL is being [sqlite3_prepare | prepared] that
02071 ** disallows everything except [SELECT] statements.
02072 **
02073 ** Applications that need to process SQL from untrusted sources
02074 ** might also consider lowering resource limits using [sqlite3_limit()]
02075 ** and limiting database size using the [max_page_count] [PRAGMA]
02076 ** in addition to using an authorizer.
02077 **
02078 ** ^(Only a single authorizer can be in place on a database connection
02079 ** at a time.  Each call to sqlite3_set_authorizer overrides the
02080 ** previous call.)^  ^Disable the authorizer by installing a NULL callback.
02081 ** The authorizer is disabled by default.
02082 **
02083 ** The authorizer callback must not do anything that will modify
02084 ** the database connection that invoked the authorizer callback.
02085 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
02086 ** database connections for the meaning of "modify" in this paragraph.
02087 **
02088 ** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the
02089 ** statement might be re-prepared during [sqlite3_step()] due to a 
02090 ** schema change.  Hence, the application should ensure that the
02091 ** correct authorizer callback remains in place during the [sqlite3_step()].
02092 **
02093 ** ^Note that the authorizer callback is invoked only during
02094 ** [sqlite3_prepare()] or its variants.  Authorization is not
02095 ** performed during statement evaluation in [sqlite3_step()], unless
02096 ** as stated in the previous paragraph, sqlite3_step() invokes
02097 ** sqlite3_prepare_v2() to reprepare a statement after a schema change.
02098 */
02099 SQLITE_API int sqlite3_set_authorizer(
02100   sqlite3*,
02101   int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
02102   void *pUserData
02103 );
02104 
02105 /*
02106 ** CAPI3REF: Authorizer Return Codes
02107 **
02108 ** The [sqlite3_set_authorizer | authorizer callback function] must
02109 ** return either [SQLITE_OK] or one of these two constants in order
02110 ** to signal SQLite whether or not the action is permitted.  See the
02111 ** [sqlite3_set_authorizer | authorizer documentation] for additional
02112 ** information.
02113 */
02114 #define SQLITE_DENY   1   /* Abort the SQL statement with an error */
02115 #define SQLITE_IGNORE 2   /* Don't allow access, but don't generate an error */
02116 
02117 /*
02118 ** CAPI3REF: Authorizer Action Codes
02119 **
02120 ** The [sqlite3_set_authorizer()] interface registers a callback function
02121 ** that is invoked to authorize certain SQL statement actions.  The
02122 ** second parameter to the callback is an integer code that specifies
02123 ** what action is being authorized.  These are the integer action codes that
02124 ** the authorizer callback may be passed.
02125 **
02126 ** These action code values signify what kind of operation is to be
02127 ** authorized.  The 3rd and 4th parameters to the authorization
02128 ** callback function will be parameters or NULL depending on which of these
02129 ** codes is used as the second parameter.  ^(The 5th parameter to the
02130 ** authorizer callback is the name of the database ("main", "temp",
02131 ** etc.) if applicable.)^  ^The 6th parameter to the authorizer callback
02132 ** is the name of the inner-most trigger or view that is responsible for
02133 ** the access attempt or NULL if this access attempt is directly from
02134 ** top-level SQL code.
02135 */
02136 /******************************************* 3rd ************ 4th ***********/
02137 #define SQLITE_CREATE_INDEX          1   /* Index Name      Table Name      */
02138 #define SQLITE_CREATE_TABLE          2   /* Table Name      NULL            */
02139 #define SQLITE_CREATE_TEMP_INDEX     3   /* Index Name      Table Name      */
02140 #define SQLITE_CREATE_TEMP_TABLE     4   /* Table Name      NULL            */
02141 #define SQLITE_CREATE_TEMP_TRIGGER   5   /* Trigger Name    Table Name      */
02142 #define SQLITE_CREATE_TEMP_VIEW      6   /* View Name       NULL            */
02143 #define SQLITE_CREATE_TRIGGER        7   /* Trigger Name    Table Name      */
02144 #define SQLITE_CREATE_VIEW           8   /* View Name       NULL            */
02145 #define SQLITE_DELETE                9   /* Table Name      NULL            */
02146 #define SQLITE_DROP_INDEX           10   /* Index Name      Table Name      */
02147 #define SQLITE_DROP_TABLE           11   /* Table Name      NULL            */
02148 #define SQLITE_DROP_TEMP_INDEX      12   /* Index Name      Table Name      */
02149 #define SQLITE_DROP_TEMP_TABLE      13   /* Table Name      NULL            */
02150 #define SQLITE_DROP_TEMP_TRIGGER    14   /* Trigger Name    Table Name      */
02151 #define SQLITE_DROP_TEMP_VIEW       15   /* View Name       NULL            */
02152 #define SQLITE_DROP_TRIGGER         16   /* Trigger Name    Table Name      */
02153 #define SQLITE_DROP_VIEW            17   /* View Name       NULL            */
02154 #define SQLITE_INSERT               18   /* Table Name      NULL            */
02155 #define SQLITE_PRAGMA               19   /* Pragma Name     1st arg or NULL */
02156 #define SQLITE_READ                 20   /* Table Name      Column Name     */
02157 #define SQLITE_SELECT               21   /* NULL            NULL            */
02158 #define SQLITE_TRANSACTION          22   /* Operation       NULL            */
02159 #define SQLITE_UPDATE               23   /* Table Name      Column Name     */
02160 #define SQLITE_ATTACH               24   /* Filename        NULL            */
02161 #define SQLITE_DETACH               25   /* Database Name   NULL            */
02162 #define SQLITE_ALTER_TABLE          26   /* Database Name   Table Name      */
02163 #define SQLITE_REINDEX              27   /* Index Name      NULL            */
02164 #define SQLITE_ANALYZE              28   /* Table Name      NULL            */
02165 #define SQLITE_CREATE_VTABLE        29   /* Table Name      Module Name     */
02166 #define SQLITE_DROP_VTABLE          30   /* Table Name      Module Name     */
02167 #define SQLITE_FUNCTION             31   /* NULL            Function Name   */
02168 #define SQLITE_SAVEPOINT            32   /* Operation       Savepoint Name  */
02169 #define SQLITE_COPY                  0   /* No longer used */
02170 
02171 /*
02172 ** CAPI3REF: Tracing And Profiling Functions
02173 **
02174 ** These routines register callback functions that can be used for
02175 ** tracing and profiling the execution of SQL statements.
02176 **
02177 ** ^The callback function registered by sqlite3_trace() is invoked at
02178 ** various times when an SQL statement is being run by [sqlite3_step()].
02179 ** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the
02180 ** SQL statement text as the statement first begins executing.
02181 ** ^(Additional sqlite3_trace() callbacks might occur
02182 ** as each triggered subprogram is entered.  The callbacks for triggers
02183 ** contain a UTF-8 SQL comment that identifies the trigger.)^
02184 **
02185 ** ^The callback function registered by sqlite3_profile() is invoked
02186 ** as each SQL statement finishes.  ^The profile callback contains
02187 ** the original statement text and an estimate of wall-clock time
02188 ** of how long that statement took to run.  ^The profile callback
02189 ** time is in units of nanoseconds, however the current implementation
02190 ** is only capable of millisecond resolution so the six least significant
02191 ** digits in the time are meaningless.  Future versions of SQLite
02192 ** might provide greater resolution on the profiler callback.  The
02193 ** sqlite3_profile() function is considered experimental and is
02194 ** subject to change in future versions of SQLite.
02195 */
02196 SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*);
02197 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*,
02198    void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
02199 
02200 /*
02201 ** CAPI3REF: Query Progress Callbacks
02202 **
02203 ** ^This routine configures a callback function - the
02204 ** progress callback - that is invoked periodically during long
02205 ** running calls to [sqlite3_exec()], [sqlite3_step()] and
02206 ** [sqlite3_get_table()].  An example use for this
02207 ** interface is to keep a GUI updated during a large query.
02208 **
02209 ** ^If the progress callback returns non-zero, the operation is
02210 ** interrupted.  This feature can be used to implement a
02211 ** "Cancel" button on a GUI progress dialog box.
02212 **
02213 ** The progress handler must not do anything that will modify
02214 ** the database connection that invoked the progress handler.
02215 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
02216 ** database connections for the meaning of "modify" in this paragraph.
02217 **
02218 */
02219 SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
02220 
02221 /*
02222 ** CAPI3REF: Opening A New Database Connection
02223 **
02224 ** ^These routines open an SQLite database file whose name is given by the
02225 ** filename argument. ^The filename argument is interpreted as UTF-8 for
02226 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
02227 ** order for sqlite3_open16(). ^(A [database connection] handle is usually
02228 ** returned in *ppDb, even if an error occurs.  The only exception is that
02229 ** if SQLite is unable to allocate memory to hold the [sqlite3] object,
02230 ** a NULL will be written into *ppDb instead of a pointer to the [sqlite3]
02231 ** object.)^ ^(If the database is opened (and/or created) successfully, then
02232 ** [SQLITE_OK] is returned.  Otherwise an [error code] is returned.)^ ^The
02233 ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
02234 ** an English language description of the error following a failure of any
02235 ** of the sqlite3_open() routines.
02236 **
02237 ** ^The default encoding for the database will be UTF-8 if
02238 ** sqlite3_open() or sqlite3_open_v2() is called and
02239 ** UTF-16 in the native byte order if sqlite3_open16() is used.
02240 **
02241 ** Whether or not an error occurs when it is opened, resources
02242 ** associated with the [database connection] handle should be released by
02243 ** passing it to [sqlite3_close()] when it is no longer required.
02244 **
02245 ** The sqlite3_open_v2() interface works like sqlite3_open()
02246 ** except that it accepts two additional parameters for additional control
02247 ** over the new database connection.  ^(The flags parameter to
02248 ** sqlite3_open_v2() can take one of
02249 ** the following three values, optionally combined with the 
02250 ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE],
02251 ** and/or [SQLITE_OPEN_PRIVATECACHE] flags:)^
02252 **
02253 ** <dl>
02254 ** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
02255 ** <dd>The database is opened in read-only mode.  If the database does not
02256 ** already exist, an error is returned.</dd>)^
02257 **
02258 ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
02259 ** <dd>The database is opened for reading and writing if possible, or reading
02260 ** only if the file is write protected by the operating system.  In either
02261 ** case the database must already exist, otherwise an error is returned.</dd>)^
02262 **
02263 ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
02264 ** <dd>The database is opened for reading and writing, and is creates it if
02265 ** it does not already exist. This is the behavior that is always used for
02266 ** sqlite3_open() and sqlite3_open16().</dd>)^
02267 ** </dl>
02268 **
02269 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
02270 ** combinations shown above or one of the combinations shown above combined
02271 ** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX],
02272 ** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_SHAREDCACHE] flags,
02273 ** then the behavior is undefined.
02274 **
02275 ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
02276 ** opens in the multi-thread [threading mode] as long as the single-thread
02277 ** mode has not been set at compile-time or start-time.  ^If the
02278 ** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens
02279 ** in the serialized [threading mode] unless single-thread was
02280 ** previously selected at compile-time or start-time.
02281 ** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be
02282 ** eligible to use [shared cache mode], regardless of whether or not shared
02283 ** cache is enabled using [sqlite3_enable_shared_cache()].  ^The
02284 ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not
02285 ** participate in [shared cache mode] even if it is enabled.
02286 **
02287 ** ^If the filename is ":memory:", then a private, temporary in-memory database
02288 ** is created for the connection.  ^This in-memory database will vanish when
02289 ** the database connection is closed.  Future versions of SQLite might
02290 ** make use of additional special filenames that begin with the ":" character.
02291 ** It is recommended that when a database filename actually does begin with
02292 ** a ":" character you should prefix the filename with a pathname such as
02293 ** "./" to avoid ambiguity.
02294 **
02295 ** ^If the filename is an empty string, then a private, temporary
02296 ** on-disk database will be created.  ^This private database will be
02297 ** automatically deleted as soon as the database connection is closed.
02298 **
02299 ** ^The fourth parameter to sqlite3_open_v2() is the name of the
02300 ** [sqlite3_vfs] object that defines the operating system interface that
02301 ** the new database connection should use.  ^If the fourth parameter is
02302 ** a NULL pointer then the default [sqlite3_vfs] object is used.
02303 **
02304 ** <b>Note to Windows users:</b>  The encoding used for the filename argument
02305 ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
02306 ** codepage is currently defined.  Filenames containing international
02307 ** characters must be converted to UTF-8 prior to passing them into
02308 ** sqlite3_open() or sqlite3_open_v2().
02309 */
02310 SQLITE_API int sqlite3_open(
02311   const char *filename,   /* Database filename (UTF-8) */
02312   sqlite3 **ppDb          /* OUT: SQLite db handle */
02313 );
02314 SQLITE_API int sqlite3_open16(
02315   const void *filename,   /* Database filename (UTF-16) */
02316   sqlite3 **ppDb          /* OUT: SQLite db handle */
02317 );
02318 SQLITE_API int sqlite3_open_v2(
02319   const char *filename,   /* Database filename (UTF-8) */
02320   sqlite3 **ppDb,         /* OUT: SQLite db handle */
02321   int flags,              /* Flags */
02322   const char *zVfs        /* Name of VFS module to use */
02323 );
02324 
02325 /*
02326 ** CAPI3REF: Error Codes And Messages
02327 **
02328 ** ^The sqlite3_errcode() interface returns the numeric [result code] or
02329 ** [extended result code] for the most recent failed sqlite3_* API call
02330 ** associated with a [database connection]. If a prior API call failed
02331 ** but the most recent API call succeeded, the return value from
02332 ** sqlite3_errcode() is undefined.  ^The sqlite3_extended_errcode()
02333 ** interface is the same except that it always returns the 
02334 ** [extended result code] even when extended result codes are
02335 ** disabled.
02336 **
02337 ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
02338 ** text that describes the error, as either UTF-8 or UTF-16 respectively.
02339 ** ^(Memory to hold the error message string is managed internally.
02340 ** The application does not need to worry about freeing the result.
02341 ** However, the error string might be overwritten or deallocated by
02342 ** subsequent calls to other SQLite interface functions.)^
02343 **
02344 ** When the serialized [threading mode] is in use, it might be the
02345 ** case that a second error occurs on a separate thread in between
02346 ** the time of the first error and the call to these interfaces.
02347 ** When that happens, the second error will be reported since these
02348 ** interfaces always report the most recent result.  To avoid
02349 ** this, each thread can obtain exclusive use of the [database connection] D
02350 ** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning
02351 ** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after
02352 ** all calls to the interfaces listed here are completed.
02353 **
02354 ** If an interface fails with SQLITE_MISUSE, that means the interface
02355 ** was invoked incorrectly by the application.  In that case, the
02356 ** error code and message may or may not be set.
02357 */
02358 SQLITE_API int sqlite3_errcode(sqlite3 *db);
02359 SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
02360 SQLITE_API const char *sqlite3_errmsg(sqlite3*);
02361 SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
02362 
02363 /*
02364 ** CAPI3REF: SQL Statement Object
02365 ** KEYWORDS: {prepared statement} {prepared statements}
02366 **
02367 ** An instance of this object represents a single SQL statement.
02368 ** This object is variously known as a "prepared statement" or a
02369 ** "compiled SQL statement" or simply as a "statement".
02370 **
02371 ** The life of a statement object goes something like this:
02372 **
02373 ** <ol>
02374 ** <li> Create the object using [sqlite3_prepare_v2()] or a related
02375 **      function.
02376 ** <li> Bind values to [host parameters] using the sqlite3_bind_*()
02377 **      interfaces.
02378 ** <li> Run the SQL by calling [sqlite3_step()] one or more times.
02379 ** <li> Reset the statement using [sqlite3_reset()] then go back
02380 **      to step 2.  Do this zero or more times.
02381 ** <li> Destroy the object using [sqlite3_finalize()].
02382 ** </ol>
02383 **
02384 ** Refer to documentation on individual methods above for additional
02385 ** information.
02386 */
02387 typedef struct sqlite3_stmt sqlite3_stmt;
02388 
02389 /*
02390 ** CAPI3REF: Run-time Limits
02391 **
02392 ** ^(This interface allows the size of various constructs to be limited
02393 ** on a connection by connection basis.  The first parameter is the
02394 ** [database connection] whose limit is to be set or queried.  The
02395 ** second parameter is one of the [limit categories] that define a
02396 ** class of constructs to be size limited.  The third parameter is the
02397 ** new limit for that construct.  The function returns the old limit.)^
02398 **
02399 ** ^If the new limit is a negative number, the limit is unchanged.
02400 ** ^(For the limit category of SQLITE_LIMIT_XYZ there is a 
02401 ** [limits | hard upper bound]
02402 ** set by a compile-time C preprocessor macro named 
02403 ** [limits | SQLITE_MAX_XYZ].
02404 ** (The "_LIMIT_" in the name is changed to "_MAX_".))^
02405 ** ^Attempts to increase a limit above its hard upper bound are
02406 ** silently truncated to the hard upper bound.
02407 **
02408 ** Run-time limits are intended for use in applications that manage
02409 ** both their own internal database and also databases that are controlled
02410 ** by untrusted external sources.  An example application might be a
02411 ** web browser that has its own databases for storing history and
02412 ** separate databases controlled by JavaScript applications downloaded
02413 ** off the Internet.  The internal databases can be given the
02414 ** large, default limits.  Databases managed by external sources can
02415 ** be given much smaller limits designed to prevent a denial of service
02416 ** attack.  Developers might also want to use the [sqlite3_set_authorizer()]
02417 ** interface to further control untrusted SQL.  The size of the database
02418 ** created by an untrusted script can be contained using the
02419 ** [max_page_count] [PRAGMA].
02420 **
02421 ** New run-time limit categories may be added in future releases.
02422 */
02423 SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
02424 
02425 /*
02426 ** CAPI3REF: Run-Time Limit Categories
02427 ** KEYWORDS: {limit category} {*limit categories}
02428 **
02429 ** These constants define various performance limits
02430 ** that can be lowered at run-time using [sqlite3_limit()].
02431 ** The synopsis of the meanings of the various limits is shown below.
02432 ** Additional information is available at [limits | Limits in SQLite].
02433 **
02434 ** <dl>
02435 ** ^(<dt>SQLITE_LIMIT_LENGTH</dt>
02436 ** <dd>The maximum size of any string or BLOB or table row.<dd>)^
02437 **
02438 ** ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
02439 ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
02440 **
02441 ** ^(<dt>SQLITE_LIMIT_COLUMN</dt>
02442 ** <dd>The maximum number of columns in a table definition or in the
02443 ** result set of a [SELECT] or the maximum number of columns in an index
02444 ** or in an ORDER BY or GROUP BY clause.</dd>)^
02445 **
02446 ** ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
02447 ** <dd>The maximum depth of the parse tree on any expression.</dd>)^
02448 **
02449 ** ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
02450 ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
02451 **
02452 ** ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
02453 ** <dd>The maximum number of instructions in a virtual machine program
02454 ** used to implement an SQL statement.</dd>)^
02455 **
02456 ** ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
02457 ** <dd>The maximum number of arguments on a function.</dd>)^
02458 **
02459 ** ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
02460 ** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
02461 **
02462 ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
02463 ** <dd>The maximum length of the pattern argument to the [LIKE] or
02464 ** [GLOB] operators.</dd>)^
02465 **
02466 ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
02467 ** <dd>The maximum number of variables in an SQL statement that can
02468 ** be bound.</dd>)^
02469 **
02470 ** ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
02471 ** <dd>The maximum depth of recursion for triggers.</dd>)^
02472 ** </dl>
02473 */
02474 #define SQLITE_LIMIT_LENGTH                    0
02475 #define SQLITE_LIMIT_SQL_LENGTH                1
02476 #define SQLITE_LIMIT_COLUMN                    2
02477 #define SQLITE_LIMIT_EXPR_DEPTH                3
02478 #define SQLITE_LIMIT_COMPOUND_SELECT           4
02479 #define SQLITE_LIMIT_VDBE_OP                   5
02480 #define SQLITE_LIMIT_FUNCTION_ARG              6
02481 #define SQLITE_LIMIT_ATTACHED                  7
02482 #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH       8
02483 #define SQLITE_LIMIT_VARIABLE_NUMBER           9
02484 #define SQLITE_LIMIT_TRIGGER_DEPTH            10
02485 
02486 /*
02487 ** CAPI3REF: Compiling An SQL Statement
02488 ** KEYWORDS: {SQL statement compiler}
02489 **
02490 ** To execute an SQL query, it must first be compiled into a byte-code
02491 ** program using one of these routines.
02492 **
02493 ** The first argument, "db", is a [database connection] obtained from a
02494 ** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or
02495 ** [sqlite3_open16()].  The database connection must not have been closed.
02496 **
02497 ** The second argument, "zSql", is the statement to be compiled, encoded
02498 ** as either UTF-8 or UTF-16.  The sqlite3_prepare() and sqlite3_prepare_v2()
02499 ** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2()
02500 ** use UTF-16.
02501 **
02502 ** ^If the nByte argument is less than zero, then zSql is read up to the
02503 ** first zero terminator. ^If nByte is non-negative, then it is the maximum
02504 ** number of  bytes read from zSql.  ^When nByte is non-negative, the
02505 ** zSql string ends at either the first '\000' or '\u0000' character or
02506 ** the nByte-th byte, whichever comes first. If the caller knows
02507 ** that the supplied string is nul-terminated, then there is a small
02508 ** performance advantage to be gained by passing an nByte parameter that
02509 ** is equal to the number of bytes in the input string <i>including</i>
02510 ** the nul-terminator bytes.
02511 **
02512 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
02513 ** past the end of the first SQL statement in zSql.  These routines only
02514 ** compile the first statement in zSql, so *pzTail is left pointing to
02515 ** what remains uncompiled.
02516 **
02517 ** ^*ppStmt is left pointing to a compiled [prepared statement] that can be
02518 ** executed using [sqlite3_step()].  ^If there is an error, *ppStmt is set
02519 ** to NULL.  ^If the input text contains no SQL (if the input is an empty
02520 ** string or a comment) then *ppStmt is set to NULL.
02521 ** The calling procedure is responsible for deleting the compiled
02522 ** SQL statement using [sqlite3_finalize()] after it has finished with it.
02523 ** ppStmt may not be NULL.
02524 **
02525 ** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK];
02526 ** otherwise an [error code] is returned.
02527 **
02528 ** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are
02529 ** recommended for all new programs. The two older interfaces are retained
02530 ** for backwards compatibility, but their use is discouraged.
02531 ** ^In the "v2" interfaces, the prepared statement
02532 ** that is returned (the [sqlite3_stmt] object) contains a copy of the
02533 ** original SQL text. This causes the [sqlite3_step()] interface to
02534 ** behave differently in three ways:
02535 **
02536 ** <ol>
02537 ** <li>
02538 ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
02539 ** always used to do, [sqlite3_step()] will automatically recompile the SQL
02540 ** statement and try to run it again.  ^If the schema has changed in
02541 ** a way that makes the statement no longer valid, [sqlite3_step()] will still
02542 ** return [SQLITE_SCHEMA].  But unlike the legacy behavior, [SQLITE_SCHEMA] is
02543 ** now a fatal error.  Calling [sqlite3_prepare_v2()] again will not make the
02544 ** error go away.  Note: use [sqlite3_errmsg()] to find the text
02545 ** of the parsing error that results in an [SQLITE_SCHEMA] return.
02546 ** </li>
02547 **
02548 ** <li>
02549 ** ^When an error occurs, [sqlite3_step()] will return one of the detailed
02550 ** [error codes] or [extended error codes].  ^The legacy behavior was that
02551 ** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code
02552 ** and the application would have to make a second call to [sqlite3_reset()]
02553 ** in order to find the underlying cause of the problem. With the "v2" prepare
02554 ** interfaces, the underlying reason for the error is returned immediately.
02555 ** </li>
02556 **
02557 ** <li>
02558 ** ^If the value of a [parameter | host parameter] in the WHERE clause might
02559 ** change the query plan for a statement, then the statement may be
02560 ** automatically recompiled (as if there had been a schema change) on the first 
02561 ** [sqlite3_step()] call following any change to the 
02562 ** [sqlite3_bind_text | bindings] of the [parameter]. 
02563 ** </li>
02564 ** </ol>
02565 */
02566 SQLITE_API int sqlite3_prepare(
02567   sqlite3 *db,            /* Database handle */
02568   const char *zSql,       /* SQL statement, UTF-8 encoded */
02569   int nByte,              /* Maximum length of zSql in bytes. */
02570   sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
02571   const char **pzTail     /* OUT: Pointer to unused portion of zSql */
02572 );
02573 SQLITE_API int sqlite3_prepare_v2(
02574   sqlite3 *db,            /* Database handle */
02575   const char *zSql,       /* SQL statement, UTF-8 encoded */
02576   int nByte,              /* Maximum length of zSql in bytes. */
02577   sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
02578   const char **pzTail     /* OUT: Pointer to unused portion of zSql */
02579 );
02580 SQLITE_API int sqlite3_prepare16(
02581   sqlite3 *db,            /* Database handle */
02582   const void *zSql,       /* SQL statement, UTF-16 encoded */
02583   int nByte,              /* Maximum length of zSql in bytes. */
02584   sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
02585   const void **pzTail     /* OUT: Pointer to unused portion of zSql */
02586 );
02587 SQLITE_API int sqlite3_prepare16_v2(
02588   sqlite3 *db,            /* Database handle */
02589   const void *zSql,       /* SQL statement, UTF-16 encoded */
02590   int nByte,              /* Maximum length of zSql in bytes. */
02591   sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
02592   const void **pzTail     /* OUT: Pointer to unused portion of zSql */
02593 );
02594 
02595 /*
02596 ** CAPI3REF: Retrieving Statement SQL
02597 **
02598 ** ^This interface can be used to retrieve a saved copy of the original
02599 ** SQL text used to create a [prepared statement] if that statement was
02600 ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()].
02601 */
02602 SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
02603 
02604 /*
02605 ** CAPI3REF: Dynamically Typed Value Object
02606 ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
02607 **
02608 ** SQLite uses the sqlite3_value object to represent all values
02609 ** that can be stored in a database table. SQLite uses dynamic typing
02610 ** for the values it stores.  ^Values stored in sqlite3_value objects
02611 ** can be integers, floating point values, strings, BLOBs, or NULL.
02612 **
02613 ** An sqlite3_value object may be either "protected" or "unprotected".
02614 ** Some interfaces require a protected sqlite3_value.  Other interfaces
02615 ** will accept either a protected or an unprotected sqlite3_value.
02616 ** Every interface that accepts sqlite3_value arguments specifies
02617 ** whether or not it requires a protected sqlite3_value.
02618 **
02619 ** The terms "protected" and "unprotected" refer to whether or not
02620 ** a mutex is held.  A internal mutex is held for a protected
02621 ** sqlite3_value object but no mutex is held for an unprotected
02622 ** sqlite3_value object.  If SQLite is compiled to be single-threaded
02623 ** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)
02624 ** or if SQLite is run in one of reduced mutex modes 
02625 ** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
02626 ** then there is no distinction between protected and unprotected
02627 ** sqlite3_value objects and they can be used interchangeably.  However,
02628 ** for maximum code portability it is recommended that applications
02629 ** still make the distinction between between protected and unprotected
02630 ** sqlite3_value objects even when not strictly required.
02631 **
02632 ** ^The sqlite3_value objects that are passed as parameters into the
02633 ** implementation of [application-defined SQL functions] are protected.
02634 ** ^The sqlite3_value object returned by
02635 ** [sqlite3_column_value()] is unprotected.
02636 ** Unprotected sqlite3_value objects may only be used with
02637 ** [sqlite3_result_value()] and [sqlite3_bind_value()].
02638 ** The [sqlite3_value_blob | sqlite3_value_type()] family of
02639 ** interfaces require protected sqlite3_value objects.
02640 */
02641 typedef struct Mem sqlite3_value;
02642 
02643 /*
02644 ** CAPI3REF: SQL Function Context Object
02645 **
02646 ** The context in which an SQL function executes is stored in an
02647 ** sqlite3_context object.  ^A pointer to an sqlite3_context object
02648 ** is always first parameter to [application-defined SQL functions].
02649 ** The application-defined SQL function implementation will pass this
02650 ** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
02651 ** [sqlite3_aggregate_context()], [sqlite3_user_data()],
02652 ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
02653 ** and/or [sqlite3_set_auxdata()].
02654 */
02655 typedef struct sqlite3_context sqlite3_context;
02656 
02657 /*
02658 ** CAPI3REF: Binding Values To Prepared Statements
02659 ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
02660 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
02661 **
02662 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
02663 ** literals may be replaced by a [parameter] that matches one of following
02664 ** templates:
02665 **
02666 ** <ul>
02667 ** <li>  ?
02668 ** <li>  ?NNN
02669 ** <li>  :VVV
02670 ** <li>  @VVV
02671 ** <li>  $VVV
02672 ** </ul>
02673 **
02674 ** In the templates above, NNN represents an integer literal,
02675 ** and VVV represents an alphanumeric identifier.)^  ^The values of these
02676 ** parameters (also called "host parameter names" or "SQL parameters")
02677 ** can be set using the sqlite3_bind_*() routines defined here.
02678 **
02679 ** ^The first argument to the sqlite3_bind_*() routines is always
02680 ** a pointer to the [sqlite3_stmt] object returned from
02681 ** [sqlite3_prepare_v2()] or its variants.
02682 **
02683 ** ^The second argument is the index of the SQL parameter to be set.
02684 ** ^The leftmost SQL parameter has an index of 1.  ^When the same named
02685 ** SQL parameter is used more than once, second and subsequent
02686 ** occurrences have the same index as the first occurrence.
02687 ** ^The index for named parameters can be looked up using the
02688 ** [sqlite3_bind_parameter_index()] API if desired.  ^The index
02689 ** for "?NNN" parameters is the value of NNN.
02690 ** ^The NNN value must be between 1 and the [sqlite3_limit()]
02691 ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999).
02692 **
02693 ** ^The third argument is the value to bind to the parameter.
02694 **
02695 ** ^(In those routines that have a fourth argument, its value is the
02696 ** number of bytes in the parameter.  To be clear: the value is the
02697 ** number of <u>bytes</u> in the value, not the number of characters.)^
02698 ** ^If the fourth parameter is negative, the length of the string is
02699 ** the number of bytes up to the first zero terminator.
02700 **
02701 ** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and
02702 ** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
02703 ** string after SQLite has finished with it. ^If the fifth argument is
02704 ** the special value [SQLITE_STATIC], then SQLite assumes that the
02705 ** information is in static, unmanaged space and does not need to be freed.
02706 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
02707 ** SQLite makes its own private copy of the data immediately, before
02708 ** the sqlite3_bind_*() routine returns.
02709 **
02710 ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
02711 ** is filled with zeroes.  ^A zeroblob uses a fixed amount of memory
02712 ** (just an integer to hold its size) while it is being processed.
02713 ** Zeroblobs are intended to serve as placeholders for BLOBs whose
02714 ** content is later written using
02715 ** [sqlite3_blob_open | incremental BLOB I/O] routines.
02716 ** ^A negative value for the zeroblob results in a zero-length BLOB.
02717 **
02718 ** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
02719 ** for the [prepared statement] or with a prepared statement for which
02720 ** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
02721 ** then the call will return [SQLITE_MISUSE].  If any sqlite3_bind_()
02722 ** routine is passed a [prepared statement] that has been finalized, the
02723 ** result is undefined and probably harmful.
02724 **
02725 ** ^Bindings are not cleared by the [sqlite3_reset()] routine.
02726 ** ^Unbound parameters are interpreted as NULL.
02727 **
02728 ** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an
02729 ** [error code] if anything goes wrong.
02730 ** ^[SQLITE_RANGE] is returned if the parameter
02731 ** index is out of range.  ^[SQLITE_NOMEM] is returned if malloc() fails.
02732 **
02733 ** See also: [sqlite3_bind_parameter_count()],
02734 ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
02735 */
02736 SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
02737 SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
02738 SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);
02739 SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
02740 SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
02741 SQLITE_API int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*));
02742 SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
02743 SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
02744 SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
02745 
02746 /*
02747 ** CAPI3REF: Number Of SQL Parameters
02748 **
02749 ** ^This routine can be used to find the number of [SQL parameters]
02750 ** in a [prepared statement].  SQL parameters are tokens of the
02751 ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
02752 ** placeholders for values that are [sqlite3_bind_blob | bound]
02753 ** to the parameters at a later time.
02754 **
02755 ** ^(This routine actually returns the index of the largest (rightmost)
02756 ** parameter. For all forms except ?NNN, this will correspond to the
02757 ** number of unique parameters.  If parameters of the ?NNN form are used,
02758 ** there may be gaps in the list.)^
02759 **
02760 ** See also: [sqlite3_bind_blob|sqlite3_bind()],
02761 ** [sqlite3_bind_parameter_name()], and
02762 ** [sqlite3_bind_parameter_index()].
02763 */
02764 SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*);
02765 
02766 /*
02767 ** CAPI3REF: Name Of A Host Parameter
02768 **
02769 ** ^The sqlite3_bind_parameter_name(P,N) interface returns
02770 ** the name of the N-th [SQL parameter] in the [prepared statement] P.
02771 ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
02772 ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
02773 ** respectively.
02774 ** In other words, the initial ":" or "$" or "@" or "?"
02775 ** is included as part of the name.)^
02776 ** ^Parameters of the form "?" without a following integer have no name
02777 ** and are referred to as "nameless" or "anonymous parameters".
02778 **
02779 ** ^The first host parameter has an index of 1, not 0.
02780 **
02781 ** ^If the value N is out of range or if the N-th parameter is
02782 ** nameless, then NULL is returned.  ^The returned string is
02783 ** always in UTF-8 encoding even if the named parameter was
02784 ** originally specified as UTF-16 in [sqlite3_prepare16()] or
02785 ** [sqlite3_prepare16_v2()].
02786 **
02787 ** See also: [sqlite3_bind_blob|sqlite3_bind()],
02788 ** [sqlite3_bind_parameter_count()], and
02789 ** [sqlite3_bind_parameter_index()].
02790 */
02791 SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
02792 
02793 /*
02794 ** CAPI3REF: Index Of A Parameter With A Given Name
02795 **
02796 ** ^Return the index of an SQL parameter given its name.  ^The
02797 ** index value returned is suitable for use as the second
02798 ** parameter to [sqlite3_bind_blob|sqlite3_bind()].  ^A zero
02799 ** is returned if no matching parameter is found.  ^The parameter
02800 ** name must be given in UTF-8 even if the original statement
02801 ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()].
02802 **
02803 ** See also: [sqlite3_bind_blob|sqlite3_bind()],
02804 ** [sqlite3_bind_parameter_count()], and
02805 ** [sqlite3_bind_parameter_index()].
02806 */
02807 SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
02808 
02809 /*
02810 ** CAPI3REF: Reset All Bindings On A Prepared Statement
02811 **
02812 ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
02813 ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
02814 ** ^Use this routine to reset all host parameters to NULL.
02815 */
02816 SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*);
02817 
02818 /*
02819 ** CAPI3REF: Number Of Columns In A Result Set
02820 **
02821 ** ^Return the number of columns in the result set returned by the
02822 ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL
02823 ** statement that does not return data (for example an [UPDATE]).
02824 */
02825 SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);
02826 
02827 /*
02828 ** CAPI3REF: Column Names In A Result Set
02829 **
02830 ** ^These routines return the name assigned to a particular column
02831 ** in the result set of a [SELECT] statement.  ^The sqlite3_column_name()
02832 ** interface returns a pointer to a zero-terminated UTF-8 string
02833 ** and sqlite3_column_name16() returns a pointer to a zero-terminated
02834 ** UTF-16 string.  ^The first parameter is the [prepared statement]
02835 ** that implements the [SELECT] statement. ^The second parameter is the
02836 ** column number.  ^The leftmost column is number 0.
02837 **
02838 ** ^The returned string pointer is valid until either the [prepared statement]
02839 ** is destroyed by [sqlite3_finalize()] or until the next call to
02840 ** sqlite3_column_name() or sqlite3_column_name16() on the same column.
02841 **
02842 ** ^If sqlite3_malloc() fails during the processing of either routine
02843 ** (for example during a conversion from UTF-8 to UTF-16) then a
02844 ** NULL pointer is returned.
02845 **
02846 ** ^The name of a result column is the value of the "AS" clause for
02847 ** that column, if there is an AS clause.  If there is no AS clause
02848 ** then the name of the column is unspecified and may change from
02849 ** one release of SQLite to the next.
02850 */
02851 SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N);
02852 SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N);
02853 
02854 /*
02855 ** CAPI3REF: Source Of Data In A Query Result
02856 **
02857 ** ^These routines provide a means to determine the database, table, and
02858 ** table column that is the origin of a particular result column in
02859 ** [SELECT] statement.
02860 ** ^The name of the database or table or column can be returned as
02861 ** either a UTF-8 or UTF-16 string.  ^The _database_ routines return
02862 ** the database name, the _table_ routines return the table name, and
02863 ** the origin_ routines return the column name.
02864 ** ^The returned string is valid until the [prepared statement] is destroyed
02865 ** using [sqlite3_finalize()] or until the same information is requested
02866 ** again in a different encoding.
02867 **
02868 ** ^The names returned are the original un-aliased names of the
02869 ** database, table, and column.
02870 **
02871 ** ^The first argument to these interfaces is a [prepared statement].
02872 ** ^These functions return information about the Nth result column returned by
02873 ** the statement, where N is the second function argument.
02874 ** ^The left-most column is column 0 for these routines.
02875 **
02876 ** ^If the Nth column returned by the statement is an expression or
02877 ** subquery and is not a column value, then all of these functions return
02878 ** NULL.  ^These routine might also return NULL if a memory allocation error
02879 ** occurs.  ^Otherwise, they return the name of the attached database, table,
02880 ** or column that query result column was extracted from.
02881 **
02882 ** ^As with all other SQLite APIs, those whose names end with "16" return
02883 ** UTF-16 encoded strings and the other functions return UTF-8.
02884 **
02885 ** ^These APIs are only available if the library was compiled with the
02886 ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
02887 **
02888 ** If two or more threads call one or more of these routines against the same
02889 ** prepared statement and column at the same time then the results are
02890 ** undefined.
02891 **
02892 ** If two or more threads call one or more
02893 ** [sqlite3_column_database_name | column metadata interfaces]
02894 ** for the same [prepared statement] and result column
02895 ** at the same time then the results are undefined.
02896 */
02897 SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int);
02898 SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
02899 SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int);
02900 SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
02901 SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
02902 SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);
02903 
02904 /*
02905 ** CAPI3REF: Declared Datatype Of A Query Result
02906 **
02907 ** ^(The first parameter is a [prepared statement].
02908 ** If this statement is a [SELECT] statement and the Nth column of the
02909 ** returned result set of that [SELECT] is a table column (not an
02910 ** expression or subquery) then the declared type of the table
02911 ** column is returned.)^  ^If the Nth column of the result set is an
02912 ** expression or subquery, then a NULL pointer is returned.
02913 ** ^The returned string is always UTF-8 encoded.
02914 **
02915 ** ^(For example, given the database schema:
02916 **
02917 ** CREATE TABLE t1(c1 VARIANT);
02918 **
02919 ** and the following statement to be compiled:
02920 **
02921 ** SELECT c1 + 1, c1 FROM t1;
02922 **
02923 ** this routine would return the string "VARIANT" for the second result
02924 ** column (i==1), and a NULL pointer for the first result column (i==0).)^
02925 **
02926 ** ^SQLite uses dynamic run-time typing.  ^So just because a column
02927 ** is declared to contain a particular type does not mean that the
02928 ** data stored in that column is of the declared type.  SQLite is
02929 ** strongly typed, but the typing is dynamic not static.  ^Type
02930 ** is associated with individual values, not with the containers
02931 ** used to hold those values.
02932 */
02933 SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int);
02934 SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int);
02935 
02936 /*
02937 ** CAPI3REF: Evaluate An SQL Statement
02938 **
02939 ** After a [prepared statement] has been prepared using either
02940 ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy
02941 ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
02942 ** must be called one or more times to evaluate the statement.
02943 **
02944 ** The details of the behavior of the sqlite3_step() interface depend
02945 ** on whether the statement was prepared using the newer "v2" interface
02946 ** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy
02947 ** interface [sqlite3_prepare()] and [sqlite3_prepare16()].  The use of the
02948 ** new "v2" interface is recommended for new applications but the legacy
02949 ** interface will continue to be supported.
02950 **
02951 ** ^In the legacy interface, the return value will be either [SQLITE_BUSY],
02952 ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
02953 ** ^With the "v2" interface, any of the other [result codes] or
02954 ** [extended result codes] might be returned as well.
02955 **
02956 ** ^[SQLITE_BUSY] means that the database engine was unable to acquire the
02957 ** database locks it needs to do its job.  ^If the statement is a [COMMIT]
02958 ** or occurs outside of an explicit transaction, then you can retry the
02959 ** statement.  If the statement is not a [COMMIT] and occurs within a
02960 ** explicit transaction then you should rollback the transaction before
02961 ** continuing.
02962 **
02963 ** ^[SQLITE_DONE] means that the statement has finished executing
02964 ** successfully.  sqlite3_step() should not be called again on this virtual
02965 ** machine without first calling [sqlite3_reset()] to reset the virtual
02966 ** machine back to its initial state.
02967 **
02968 ** ^If the SQL statement being executed returns any data, then [SQLITE_ROW]
02969 ** is returned each time a new row of data is ready for processing by the
02970 ** caller. The values may be accessed using the [column access functions].
02971 ** sqlite3_step() is called again to retrieve the next row of data.
02972 **
02973 ** ^[SQLITE_ERROR] means that a run-time error (such as a constraint
02974 ** violation) has occurred.  sqlite3_step() should not be called again on
02975 ** the VM. More information may be found by calling [sqlite3_errmsg()].
02976 ** ^With the legacy interface, a more specific error code (for example,
02977 ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
02978 ** can be obtained by calling [sqlite3_reset()] on the
02979 ** [prepared statement].  ^In the "v2" interface,
02980 ** the more specific error code is returned directly by sqlite3_step().
02981 **
02982 ** [SQLITE_MISUSE] means that the this routine was called inappropriately.
02983 ** Perhaps it was called on a [prepared statement] that has
02984 ** already been [sqlite3_finalize | finalized] or on one that had
02985 ** previously returned [SQLITE_ERROR] or [SQLITE_DONE].  Or it could
02986 ** be the case that the same database connection is being used by two or
02987 ** more threads at the same moment in time.
02988 **
02989 ** For all versions of SQLite up to and including 3.6.23.1, it was required
02990 ** after sqlite3_step() returned anything other than [SQLITE_ROW] that
02991 ** [sqlite3_reset()] be called before any subsequent invocation of
02992 ** sqlite3_step().  Failure to invoke [sqlite3_reset()] in this way would
02993 ** result in an [SQLITE_MISUSE] return from sqlite3_step().  But after
02994 ** version 3.6.23.1, sqlite3_step() began calling [sqlite3_reset()] 
02995 ** automatically in this circumstance rather than returning [SQLITE_MISUSE].  
02996 **
02997 ** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step()
02998 ** API always returns a generic error code, [SQLITE_ERROR], following any
02999 ** error other than [SQLITE_BUSY] and [SQLITE_MISUSE].  You must call
03000 ** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the
03001 ** specific [error codes] that better describes the error.
03002 ** We admit that this is a goofy design.  The problem has been fixed
03003 ** with the "v2" interface.  If you prepare all of your SQL statements
03004 ** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead
03005 ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces,
03006 ** then the more specific [error codes] are returned directly
03007 ** by sqlite3_step().  The use of the "v2" interface is recommended.
03008 */
03009 SQLITE_API int sqlite3_step(sqlite3_stmt*);
03010 
03011 /*
03012 ** CAPI3REF: Number of columns in a result set
03013 **
03014 ** ^The sqlite3_data_count(P) the number of columns in the
03015 ** of the result set of [prepared statement] P.
03016 */
03017 SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
03018 
03019 /*
03020 ** CAPI3REF: Fundamental Datatypes
03021 ** KEYWORDS: SQLITE_TEXT
03022 **
03023 ** ^(Every value in SQLite has one of five fundamental datatypes:
03024 **
03025 ** <ul>
03026 ** <li> 64-bit signed integer
03027 ** <li> 64-bit IEEE floating point number
03028 ** <li> string
03029 ** <li> BLOB
03030 ** <li> NULL
03031 ** </ul>)^
03032 **
03033 ** These constants are codes for each of those types.
03034 **
03035 ** Note that the SQLITE_TEXT constant was also used in SQLite version 2
03036 ** for a completely different meaning.  Software that links against both
03037 ** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not
03038 ** SQLITE_TEXT.
03039 */
03040 #define SQLITE_INTEGER  1
03041 #define SQLITE_FLOAT    2
03042 #define SQLITE_BLOB     4
03043 #define SQLITE_NULL     5
03044 #ifdef SQLITE_TEXT
03045 # undef SQLITE_TEXT
03046 #else
03047 # define SQLITE_TEXT     3
03048 #endif
03049 #define SQLITE3_TEXT     3
03050 
03051 /*
03052 ** CAPI3REF: Result Values From A Query
03053 ** KEYWORDS: {column access functions}
03054 **
03055 ** These routines form the "result set" interface.
03056 **
03057 ** ^These routines return information about a single column of the current
03058 ** result row of a query.  ^In every case the first argument is a pointer
03059 ** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*]
03060 ** that was returned from [sqlite3_prepare_v2()] or one of its variants)
03061 ** and the second argument is the index of the column for which information
03062 ** should be returned. ^The leftmost column of the result set has the index 0.
03063 ** ^The number of columns in the result can be determined using
03064 ** [sqlite3_column_count()].
03065 **
03066 ** If the SQL statement does not currently point to a valid row, or if the
03067 ** column index is out of range, the result is undefined.
03068 ** These routines may only be called when the most recent call to
03069 ** [sqlite3_step()] has returned [SQLITE_ROW] and neither
03070 ** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently.
03071 ** If any of these routines are called after [sqlite3_reset()] or
03072 ** [sqlite3_finalize()] or after [sqlite3_step()] has returned
03073 ** something other than [SQLITE_ROW], the results are undefined.
03074 ** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()]
03075 ** are called from a different thread while any of these routines
03076 ** are pending, then the results are undefined.
03077 **
03078 ** ^The sqlite3_column_type() routine returns the
03079 ** [SQLITE_INTEGER | datatype code] for the initial data type
03080 ** of the result column.  ^The returned value is one of [SQLITE_INTEGER],
03081 ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].  The value
03082 ** returned by sqlite3_column_type() is only meaningful if no type
03083 ** conversions have occurred as described below.  After a type conversion,
03084 ** the value returned by sqlite3_column_type() is undefined.  Future
03085 ** versions of SQLite may change the behavior of sqlite3_column_type()
03086 ** following a type conversion.
03087 **
03088 ** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes()
03089 ** routine returns the number of bytes in that BLOB or string.
03090 ** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts
03091 ** the string to UTF-8 and then returns the number of bytes.
03092 ** ^If the result is a numeric value then sqlite3_column_bytes() uses
03093 ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
03094 ** the number of bytes in that string.
03095 ** ^The value returned does not include the zero terminator at the end
03096 ** of the string.  ^For clarity: the value returned is the number of
03097 ** bytes in the string, not the number of characters.
03098 **
03099 ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
03100 ** even empty strings, are always zero terminated.  ^The return
03101 ** value from sqlite3_column_blob() for a zero-length BLOB is an arbitrary
03102 ** pointer, possibly even a NULL pointer.
03103 **
03104 ** ^The sqlite3_column_bytes16() routine is similar to sqlite3_column_bytes()
03105 ** but leaves the result in UTF-16 in native byte order instead of UTF-8.
03106 ** ^The zero terminator is not included in this count.
03107 **
03108 ** ^The object returned by [sqlite3_column_value()] is an
03109 ** [unprotected sqlite3_value] object.  An unprotected sqlite3_value object
03110 ** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()].
03111 ** If the [unprotected sqlite3_value] object returned by
03112 ** [sqlite3_column_value()] is used in any other way, including calls
03113 ** to routines like [sqlite3_value_int()], [sqlite3_value_text()],
03114 ** or [sqlite3_value_bytes()], then the behavior is undefined.
03115 **
03116 ** These routines attempt to convert the value where appropriate.  ^For
03117 ** example, if the internal representation is FLOAT and a text result
03118 ** is requested, [sqlite3_snprintf()] is used internally to perform the
03119 ** conversion automatically.  ^(The following table details the conversions
03120 ** that are applied:
03121 **
03122 ** <blockquote>
03123 ** <table border="1">
03124 ** <tr><th> Internal<br>Type <th> Requested<br>Type <th>  Conversion
03125 **
03126 ** <tr><td>  NULL    <td> INTEGER   <td> Result is 0
03127 ** <tr><td>  NULL    <td>  FLOAT    <td> Result is 0.0
03128 ** <tr><td>  NULL    <td>   TEXT    <td> Result is NULL pointer
03129 ** <tr><td>  NULL    <td>   BLOB    <td> Result is NULL pointer
03130 ** <tr><td> INTEGER  <td>  FLOAT    <td> Convert from integer to float
03131 ** <tr><td> INTEGER  <td>   TEXT    <td> ASCII rendering of the integer
03132 ** <tr><td> INTEGER  <td>   BLOB    <td> Same as INTEGER->TEXT
03133 ** <tr><td>  FLOAT   <td> INTEGER   <td> Convert from float to integer
03134 ** <tr><td>  FLOAT   <td>   TEXT    <td> ASCII rendering of the float
03135 ** <tr><td>  FLOAT   <td>   BLOB    <td> Same as FLOAT->TEXT
03136 ** <tr><td>  TEXT    <td> INTEGER   <td> Use atoi()
03137 ** <tr><td>  TEXT    <td>  FLOAT    <td> Use atof()
03138 ** <tr><td>  TEXT    <td>   BLOB    <td> No change
03139 ** <tr><td>  BLOB    <td> INTEGER   <td> Convert to TEXT then use atoi()
03140 ** <tr><td>  BLOB    <td>  FLOAT    <td> Convert to TEXT then use atof()
03141 ** <tr><td>  BLOB    <td>   TEXT    <td> Add a zero terminator if needed
03142 ** </table>
03143 ** </blockquote>)^
03144 **
03145 ** The table above makes reference to standard C library functions atoi()
03146 ** and atof().  SQLite does not really use these functions.  It has its
03147 ** own equivalent internal routines.  The atoi() and atof() names are
03148 ** used in the table for brevity and because they are familiar to most
03149 ** C programmers.
03150 **
03151 ** ^Note that when type conversions occur, pointers returned by prior
03152 ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
03153 ** sqlite3_column_text16() may be invalidated.
03154 ** ^(Type conversions and pointer invalidations might occur
03155 ** in the following cases:
03156 **
03157 ** <ul>
03158 ** <li> The initial content is a BLOB and sqlite3_column_text() or
03159 **      sqlite3_column_text16() is called.  A zero-terminator might
03160 **      need to be added to the string.</li>
03161 ** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or
03162 **      sqlite3_column_text16() is called.  The content must be converted
03163 **      to UTF-16.</li>
03164 ** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or
03165 **      sqlite3_column_text() is called.  The content must be converted
03166 **      to UTF-8.</li>
03167 ** </ul>)^
03168 **
03169 ** ^Conversions between UTF-16be and UTF-16le are always done in place and do
03170 ** not invalidate a prior pointer, though of course the content of the buffer
03171 ** that the prior pointer points to will have been modified.  Other kinds
03172 ** of conversion are done in place when it is possible, but sometimes they
03173 ** are not possible and in those cases prior pointers are invalidated.
03174 **
03175 ** ^(The safest and easiest to remember policy is to invoke these routines
03176 ** in one of the following ways:
03177 **
03178 ** <ul>
03179 **  <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
03180 **  <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
03181 **  <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
03182 ** </ul>)^
03183 **
03184 ** In other words, you should call sqlite3_column_text(),
03185 ** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result
03186 ** into the desired format, then invoke sqlite3_column_bytes() or
03187 ** sqlite3_column_bytes16() to find the size of the result.  Do not mix calls
03188 ** to sqlite3_column_text() or sqlite3_column_blob() with calls to
03189 ** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16()
03190 ** with calls to sqlite3_column_bytes().
03191 **
03192 ** ^The pointers returned are valid until a type conversion occurs as
03193 ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
03194 ** [sqlite3_finalize()] is called.  ^The memory space used to hold strings
03195 ** and BLOBs is freed automatically.  Do <b>not</b> pass the pointers returned
03196 ** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
03197 ** [sqlite3_free()].
03198 **
03199 ** ^(If a memory allocation error occurs during the evaluation of any
03200 ** of these routines, a default value is returned.  The default value
03201 ** is either the integer 0, the floating point number 0.0, or a NULL
03202 ** pointer.  Subsequent calls to [sqlite3_errcode()] will return
03203 ** [SQLITE_NOMEM].)^
03204 */
03205 SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
03206 SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
03207 SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
03208 SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol);
03209 SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol);
03210 SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
03211 SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
03212 SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
03213 SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol);
03214 SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
03215 
03216 /*
03217 ** CAPI3REF: Destroy A Prepared Statement Object
03218 **
03219 ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
03220 ** ^If the statement was executed successfully or not executed at all, then
03221 ** SQLITE_OK is returned. ^If execution of the statement failed then an
03222 ** [error code] or [extended error code] is returned.
03223 **
03224 ** ^This routine can be called at any point during the execution of the
03225 ** [prepared statement].  ^If the virtual machine has not
03226 ** completed execution when this routine is called, that is like
03227 ** encountering an error or an [sqlite3_interrupt | interrupt].
03228 ** ^Incomplete updates may be rolled back and transactions canceled,
03229 ** depending on the circumstances, and the
03230 ** [error code] returned will be [SQLITE_ABORT].
03231 */
03232 SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);
03233 
03234 /*
03235 ** CAPI3REF: Reset A Prepared Statement Object
03236 **
03237 ** The sqlite3_reset() function is called to reset a [prepared statement]
03238 ** object back to its initial state, ready to be re-executed.
03239 ** ^Any SQL statement variables that had values bound to them using
03240 ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
03241 ** Use [sqlite3_clear_bindings()] to reset the bindings.
03242 **
03243 ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S
03244 ** back to the beginning of its program.
03245 **
03246 ** ^If the most recent call to [sqlite3_step(S)] for the
03247 ** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE],
03248 ** or if [sqlite3_step(S)] has never before been called on S,
03249 ** then [sqlite3_reset(S)] returns [SQLITE_OK].
03250 **
03251 ** ^If the most recent call to [sqlite3_step(S)] for the
03252 ** [prepared statement] S indicated an error, then
03253 ** [sqlite3_reset(S)] returns an appropriate [error code].
03254 **
03255 ** ^The [sqlite3_reset(S)] interface does not change the values
03256 ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
03257 */
03258 SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
03259 
03260 /*
03261 ** CAPI3REF: Create Or Redefine SQL Functions
03262 ** KEYWORDS: {function creation routines}
03263 ** KEYWORDS: {application-defined SQL function}
03264 ** KEYWORDS: {application-defined SQL functions}
03265 **
03266 ** ^These two functions (collectively known as "function creation routines")
03267 ** are used to add SQL functions or aggregates or to redefine the behavior
03268 ** of existing SQL functions or aggregates.  The only difference between the
03269 ** two is that the second parameter, the name of the (scalar) function or
03270 ** aggregate, is encoded in UTF-8 for sqlite3_create_function() and UTF-16
03271 ** for sqlite3_create_function16().
03272 **
03273 ** ^The first parameter is the [database connection] to which the SQL
03274 ** function is to be added.  ^If an application uses more than one database
03275 ** connection then application-defined SQL functions must be added
03276 ** to each database connection separately.
03277 **
03278 ** The second parameter is the name of the SQL function to be created or
03279 ** redefined.  ^The length of the name is limited to 255 bytes, exclusive of
03280 ** the zero-terminator.  Note that the name length limit is in bytes, not
03281 ** characters.  ^Any attempt to create a function with a longer name
03282 ** will result in [SQLITE_ERROR] being returned.
03283 **
03284 ** ^The third parameter (nArg)
03285 ** is the number of arguments that the SQL function or
03286 ** aggregate takes. ^If this parameter is -1, then the SQL function or
03287 ** aggregate may take any number of arguments between 0 and the limit
03288 ** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]).  If the third
03289 ** parameter is less than -1 or greater than 127 then the behavior is
03290 ** undefined.
03291 **
03292 ** The fourth parameter, eTextRep, specifies what
03293 ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
03294 ** its parameters.  Any SQL function implementation should be able to work
03295 ** work with UTF-8, UTF-16le, or UTF-16be.  But some implementations may be
03296 ** more efficient with one encoding than another.  ^An application may
03297 ** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
03298 ** times with the same function but with different values of eTextRep.
03299 ** ^When multiple implementations of the same function are available, SQLite
03300 ** will pick the one that involves the least amount of data conversion.
03301 ** If there is only a single implementation which does not care what text
03302 ** encoding is used, then the fourth argument should be [SQLITE_ANY].
03303 **
03304 ** ^(The fifth parameter is an arbitrary pointer.  The implementation of the
03305 ** function can gain access to this pointer using [sqlite3_user_data()].)^
03306 **
03307 ** The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are
03308 ** pointers to C-language functions that implement the SQL function or
03309 ** aggregate. ^A scalar SQL function requires an implementation of the xFunc
03310 ** callback only; NULL pointers should be passed as the xStep and xFinal
03311 ** parameters. ^An aggregate SQL function requires an implementation of xStep
03312 ** and xFinal and NULL should be passed for xFunc. ^To delete an existing
03313 ** SQL function or aggregate, pass NULL for all three function callbacks.
03314 **
03315 ** ^It is permitted to register multiple implementations of the same
03316 ** functions with the same name but with either differing numbers of
03317 ** arguments or differing preferred text encodings.  ^SQLite will use
03318 ** the implementation that most closely matches the way in which the
03319 ** SQL function is used.  ^A function implementation with a non-negative
03320 ** nArg parameter is a better match than a function implementation with
03321 ** a negative nArg.  ^A function where the preferred text encoding
03322 ** matches the database encoding is a better
03323 ** match than a function where the encoding is different.  
03324 ** ^A function where the encoding difference is between UTF16le and UTF16be
03325 ** is a closer match than a function where the encoding difference is
03326 ** between UTF8 and UTF16.
03327 **
03328 ** ^Built-in functions may be overloaded by new application-defined functions.
03329 ** ^The first application-defined function with a given name overrides all
03330 ** built-in functions in the same [database connection] with the same name.
03331 ** ^Subsequent application-defined functions of the same name only override 
03332 ** prior application-defined functions that are an exact match for the
03333 ** number of parameters and preferred encoding.
03334 **
03335 ** ^An application-defined function is permitted to call other
03336 ** SQLite interfaces.  However, such calls must not
03337 ** close the database connection nor finalize or reset the prepared
03338 ** statement in which the function is running.
03339 */
03340 SQLITE_API int sqlite3_create_function(
03341   sqlite3 *db,
03342   const char *zFunctionName,
03343   int nArg,
03344   int eTextRep,
03345   void *pApp,
03346   void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
03347   void (*xStep)(sqlite3_context*,int,sqlite3_value**),
03348   void (*xFinal)(sqlite3_context*)
03349 );
03350 SQLITE_API int sqlite3_create_function16(
03351   sqlite3 *db,
03352   const void *zFunctionName,
03353   int nArg,
03354   int eTextRep,
03355   void *pApp,
03356   void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
03357   void (*xStep)(sqlite3_context*,int,sqlite3_value**),
03358   void (*xFinal)(sqlite3_context*)
03359 );
03360 
03361 /*
03362 ** CAPI3REF: Text Encodings
03363 **
03364 ** These constant define integer codes that represent the various
03365 ** text encodings supported by SQLite.
03366 */
03367 #define SQLITE_UTF8           1
03368 #define SQLITE_UTF16LE        2
03369 #define SQLITE_UTF16BE        3
03370 #define SQLITE_UTF16          4    /* Use native byte order */
03371 #define SQLITE_ANY            5    /* sqlite3_create_function only */
03372 #define SQLITE_UTF16_ALIGNED  8    /* sqlite3_create_collation only */
03373 
03374 /*
03375 ** CAPI3REF: Deprecated Functions
03376 ** DEPRECATED
03377 **
03378 ** These functions are [deprecated].  In order to maintain
03379 ** backwards compatibility with older code, these functions continue 
03380 ** to be supported.  However, new applications should avoid
03381 ** the use of these functions.  To help encourage people to avoid
03382 ** using these functions, we are not going to tell you what they do.
03383 */
03384 #ifndef SQLITE_OMIT_DEPRECATED
03385 SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
03386 SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
03387 SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
03388 SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void);
03389 SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);
03390 SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),void*,sqlite3_int64);
03391 #endif
03392 
03393 /*
03394 ** CAPI3REF: Obtaining SQL Function Parameter Values
03395 **
03396 ** The C-language implementation of SQL functions and aggregates uses
03397 ** this set of interface routines to access the parameter values on
03398 ** the function or aggregate.
03399 **
03400 ** The xFunc (for scalar functions) or xStep (for aggregates) parameters
03401 ** to [sqlite3_create_function()] and [sqlite3_create_function16()]
03402 ** define callbacks that implement the SQL functions and aggregates.
03403 ** The 4th parameter to these callbacks is an array of pointers to
03404 ** [protected sqlite3_value] objects.  There is one [sqlite3_value] object for
03405 ** each parameter to the SQL function.  These routines are used to
03406 ** extract values from the [sqlite3_value] objects.
03407 **
03408 ** These routines work only with [protected sqlite3_value] objects.
03409 ** Any attempt to use these routines on an [unprotected sqlite3_value]
03410 ** object results in undefined behavior.
03411 **
03412 ** ^These routines work just like the corresponding [column access functions]
03413 ** except that  these routines take a single [protected sqlite3_value] object
03414 ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
03415 **
03416 ** ^The sqlite3_value_text16() interface extracts a UTF-16 string
03417 ** in the native byte-order of the host machine.  ^The
03418 ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
03419 ** extract UTF-16 strings as big-endian and little-endian respectively.
03420 **
03421 ** ^(The sqlite3_value_numeric_type() interface attempts to apply
03422 ** numeric affinity to the value.  This means that an attempt is
03423 ** made to convert the value to an integer or floating point.  If
03424 ** such a conversion is possible without loss of information (in other
03425 ** words, if the value is a string that looks like a number)
03426 ** then the conversion is performed.  Otherwise no conversion occurs.
03427 ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^
03428 **
03429 ** Please pay particular attention to the fact that the pointer returned
03430 ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
03431 ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
03432 ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
03433 ** or [sqlite3_value_text16()].
03434 **
03435 ** These routines must be called from the same thread as
03436 ** the SQL function that supplied the [sqlite3_value*] parameters.
03437 */
03438 SQLITE_API const void *sqlite3_value_blob(sqlite3_value*);
03439 SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
03440 SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
03441 SQLITE_API double sqlite3_value_double(sqlite3_value*);
03442 SQLITE_API int sqlite3_value_int(sqlite3_value*);
03443 SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
03444 SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*);
03445 SQLITE_API const void *sqlite3_value_text16(sqlite3_value*);
03446 SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*);
03447 SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
03448 SQLITE_API int sqlite3_value_type(sqlite3_value*);
03449 SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
03450 
03451 /*
03452 ** CAPI3REF: Obtain Aggregate Function Context
03453 **
03454 ** Implementations of aggregate SQL functions use this
03455 ** routine to allocate memory for storing their state.
03456 **
03457 ** ^The first time the sqlite3_aggregate_context(C,N) routine is called 
03458 ** for a particular aggregate function, SQLite
03459 ** allocates N of memory, zeroes out that memory, and returns a pointer
03460 ** to the new memory. ^On second and subsequent calls to
03461 ** sqlite3_aggregate_context() for the same aggregate function instance,
03462 ** the same buffer is returned.  Sqlite3_aggregate_context() is normally
03463 ** called once for each invocation of the xStep callback and then one
03464 ** last time when the xFinal callback is invoked.  ^(When no rows match
03465 ** an aggregate query, the xStep() callback of the aggregate function
03466 ** implementation is never called and xFinal() is called exactly once.
03467 ** In those cases, sqlite3_aggregate_context() might be called for the
03468 ** first time from within xFinal().)^
03469 **
03470 ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer if N is
03471 ** less than or equal to zero or if a memory allocate error occurs.
03472 **
03473 ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
03474 ** determined by the N parameter on first successful call.  Changing the
03475 ** value of N in subsequent call to sqlite3_aggregate_context() within
03476 ** the same aggregate function instance will not resize the memory
03477 ** allocation.)^
03478 **
03479 ** ^SQLite automatically frees the memory allocated by 
03480 ** sqlite3_aggregate_context() when the aggregate query concludes.
03481 **
03482 ** The first parameter must be a copy of the
03483 ** [sqlite3_context | SQL function context] that is the first parameter
03484 ** to the xStep or xFinal callback routine that implements the aggregate
03485 ** function.
03486 **
03487 ** This routine must be called from the same thread in which
03488 ** the aggregate SQL function is running.
03489 */
03490 SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
03491 
03492 /*
03493 ** CAPI3REF: User Data For Functions
03494 **
03495 ** ^The sqlite3_user_data() interface returns a copy of
03496 ** the pointer that was the pUserData parameter (the 5th parameter)
03497 ** of the [sqlite3_create_function()]
03498 ** and [sqlite3_create_function16()] routines that originally
03499 ** registered the application defined function.
03500 **
03501 ** This routine must be called from the same thread in which
03502 ** the application-defined function is running.
03503 */
03504 SQLITE_API void *sqlite3_user_data(sqlite3_context*);
03505 
03506 /*
03507 ** CAPI3REF: Database Connection For Functions
03508 **
03509 ** ^The sqlite3_context_db_handle() interface returns a copy of
03510 ** the pointer to the [database connection] (the 1st parameter)
03511 ** of the [sqlite3_create_function()]
03512 ** and [sqlite3_create_function16()] routines that originally
03513 ** registered the application defined function.
03514 */
03515 SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
03516 
03517 /*
03518 ** CAPI3REF: Function Auxiliary Data
03519 **
03520 ** The following two functions may be used by scalar SQL functions to
03521 ** associate metadata with argument values. If the same value is passed to
03522 ** multiple invocations of the same SQL function during query execution, under
03523 ** some circumstances the associated metadata may be preserved. This may
03524 ** be used, for example, to add a regular-expression matching scalar
03525 ** function. The compiled version of the regular expression is stored as
03526 ** metadata associated with the SQL value passed as the regular expression
03527 ** pattern.  The compiled regular expression can be reused on multiple
03528 ** invocations of the same function so that the original pattern string
03529 ** does not need to be recompiled on each invocation.
03530 **
03531 ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
03532 ** associated by the sqlite3_set_auxdata() function with the Nth argument
03533 ** value to the application-defined function. ^If no metadata has been ever
03534 ** been set for the Nth argument of the function, or if the corresponding
03535 ** function parameter has changed since the meta-data was set,
03536 ** then sqlite3_get_auxdata() returns a NULL pointer.
03537 **
03538 ** ^The sqlite3_set_auxdata() interface saves the metadata
03539 ** pointed to by its 3rd parameter as the metadata for the N-th
03540 ** argument of the application-defined function.  Subsequent
03541 ** calls to sqlite3_get_auxdata() might return this data, if it has
03542 ** not been destroyed.
03543 ** ^If it is not NULL, SQLite will invoke the destructor
03544 ** function given by the 4th parameter to sqlite3_set_auxdata() on
03545 ** the metadata when the corresponding function parameter changes
03546 ** or when the SQL statement completes, whichever comes first.
03547 **
03548 ** SQLite is free to call the destructor and drop metadata on any
03549 ** parameter of any function at any time.  ^The only guarantee is that
03550 ** the destructor will be called before the metadata is dropped.
03551 **
03552 ** ^(In practice, metadata is preserved between function calls for
03553 ** expressions that are constant at compile time. This includes literal
03554 ** values and [parameters].)^
03555 **
03556 ** These routines must be called from the same thread in which
03557 ** the SQL function is running.
03558 */
03559 SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);
03560 SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));
03561 
03562 
03563 /*
03564 ** CAPI3REF: Constants Defining Special Destructor Behavior
03565 **
03566 ** These are special values for the destructor that is passed in as the
03567 ** final argument to routines like [sqlite3_result_blob()].  ^If the destructor
03568 ** argument is SQLITE_STATIC, it means that the content pointer is constant
03569 ** and will never change.  It does not need to be destroyed.  ^The
03570 ** SQLITE_TRANSIENT value means that the content will likely change in
03571 ** the near future and that SQLite should make its own private copy of
03572 ** the content before returning.
03573 **
03574 ** The typedef is necessary to work around problems in certain
03575 ** C++ compilers.  See ticket #2191.
03576 */
03577 typedef void (*sqlite3_destructor_type)(void*);
03578 #define SQLITE_STATIC      ((sqlite3_destructor_type)0)
03579 #define SQLITE_TRANSIENT   ((sqlite3_destructor_type)-1)
03580 
03581 /*
03582 ** CAPI3REF: Setting The Result Of An SQL Function
03583 **
03584 ** These routines are used by the xFunc or xFinal callbacks that
03585 ** implement SQL functions and aggregates.  See
03586 ** [sqlite3_create_function()] and [sqlite3_create_function16()]
03587 ** for additional information.
03588 **
03589 ** These functions work very much like the [parameter binding] family of
03590 ** functions used to bind values to host parameters in prepared statements.
03591 ** Refer to the [SQL parameter] documentation for additional information.
03592 **
03593 ** ^The sqlite3_result_blob() interface sets the result from
03594 ** an application-defined function to be the BLOB whose content is pointed
03595 ** to by the second parameter and which is N bytes long where N is the
03596 ** third parameter.
03597 **
03598 ** ^The sqlite3_result_zeroblob() interfaces set the result of
03599 ** the application-defined function to be a BLOB containing all zero
03600 ** bytes and N bytes in size, where N is the value of the 2nd parameter.
03601 **
03602 ** ^The sqlite3_result_double() interface sets the result from
03603 ** an application-defined function to be a floating point value specified
03604 ** by its 2nd argument.
03605 **
03606 ** ^The sqlite3_result_error() and sqlite3_result_error16() functions
03607 ** cause the implemented SQL function to throw an exception.
03608 ** ^SQLite uses the string pointed to by the
03609 ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()
03610 ** as the text of an error message.  ^SQLite interprets the error
03611 ** message string from sqlite3_result_error() as UTF-8. ^SQLite
03612 ** interprets the string from sqlite3_result_error16() as UTF-16 in native
03613 ** byte order.  ^If the third parameter to sqlite3_result_error()
03614 ** or sqlite3_result_error16() is negative then SQLite takes as the error
03615 ** message all text up through the first zero character.
03616 ** ^If the third parameter to sqlite3_result_error() or
03617 ** sqlite3_result_error16() is non-negative then SQLite takes that many
03618 ** bytes (not characters) from the 2nd parameter as the error message.
03619 ** ^The sqlite3_result_error() and sqlite3_result_error16()
03620 ** routines make a private copy of the error message text before
03621 ** they return.  Hence, the calling function can deallocate or
03622 ** modify the text after they return without harm.
03623 ** ^The sqlite3_result_error_code() function changes the error code
03624 ** returned by SQLite as a result of an error in a function.  ^By default,
03625 ** the error code is SQLITE_ERROR.  ^A subsequent call to sqlite3_result_error()
03626 ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR.
03627 **
03628 ** ^The sqlite3_result_toobig() interface causes SQLite to throw an error
03629 ** indicating that a string or BLOB is too long to represent.
03630 **
03631 ** ^The sqlite3_result_nomem() interface causes SQLite to throw an error
03632 ** indicating that a memory allocation failed.
03633 **
03634 ** ^The sqlite3_result_int() interface sets the return value
03635 ** of the application-defined function to be the 32-bit signed integer
03636 ** value given in the 2nd argument.
03637 ** ^The sqlite3_result_int64() interface sets the return value
03638 ** of the application-defined function to be the 64-bit signed integer
03639 ** value given in the 2nd argument.
03640 **
03641 ** ^The sqlite3_result_null() interface sets the return value
03642 ** of the application-defined function to be NULL.
03643 **
03644 ** ^The sqlite3_result_text(), sqlite3_result_text16(),
03645 ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
03646 ** set the return value of the application-defined function to be
03647 ** a text string which is represented as UTF-8, UTF-16 native byte order,
03648 ** UTF-16 little endian, or UTF-16 big endian, respectively.
03649 ** ^SQLite takes the text result from the application from
03650 ** the 2nd parameter of the sqlite3_result_text* interfaces.
03651 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
03652 ** is negative, then SQLite takes result text from the 2nd parameter
03653 ** through the first zero character.
03654 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
03655 ** is non-negative, then as many bytes (not characters) of the text
03656 ** pointed to by the 2nd parameter are taken as the application-defined
03657 ** function result.
03658 ** ^If the 4th parameter to the sqlite3_result_text* interfaces
03659 ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
03660 ** function as the destructor on the text or BLOB result when it has
03661 ** finished using that result.
03662 ** ^If the 4th parameter to the sqlite3_result_text* interfaces or to
03663 ** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite
03664 ** assumes that the text or BLOB result is in constant space and does not
03665 ** copy the content of the parameter nor call a destructor on the content
03666 ** when it has finished using that result.
03667 ** ^If the 4th parameter to the sqlite3_result_text* interfaces
03668 ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
03669 ** then SQLite makes a copy of the result into space obtained from
03670 ** from [sqlite3_malloc()] before it returns.
03671 **
03672 ** ^The sqlite3_result_value() interface sets the result of
03673 ** the application-defined function to be a copy the
03674 ** [unprotected sqlite3_value] object specified by the 2nd parameter.  ^The
03675 ** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
03676 ** so that the [sqlite3_value] specified in the parameter may change or
03677 ** be deallocated after sqlite3_result_value() returns without harm.
03678 ** ^A [protected sqlite3_value] object may always be used where an
03679 ** [unprotected sqlite3_value] object is required, so either
03680 ** kind of [sqlite3_value] object can be used with this interface.
03681 **
03682 ** If these routines are called from within the different thread
03683 ** than the one containing the application-defined function that received
03684 ** the [sqlite3_context] pointer, the results are undefined.
03685 */
03686 SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
03687 SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
03688 SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
03689 SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
03690 SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
03691 SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
03692 SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int);
03693 SQLITE_API void sqlite3_result_int(sqlite3_context*, int);
03694 SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
03695 SQLITE_API void sqlite3_result_null(sqlite3_context*);
03696 SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
03697 SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
03698 SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
03699 SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
03700 SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
03701 SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
03702 
03703 /*
03704 ** CAPI3REF: Define New Collating Sequences
03705 **
03706 ** These functions are used to add new collation sequences to the
03707 ** [database connection] specified as the first argument.
03708 **
03709 ** ^The name of the new collation sequence is specified as a UTF-8 string
03710 ** for sqlite3_create_collation() and sqlite3_create_collation_v2()
03711 ** and a UTF-16 string for sqlite3_create_collation16(). ^In all cases
03712 ** the name is passed as the second function argument.
03713 **
03714 ** ^The third argument may be one of the constants [SQLITE_UTF8],
03715 ** [SQLITE_UTF16LE], or [SQLITE_UTF16BE], indicating that the user-supplied
03716 ** routine expects to be passed pointers to strings encoded using UTF-8,
03717 ** UTF-16 little-endian, or UTF-16 big-endian, respectively. ^The
03718 ** third argument might also be [SQLITE_UTF16] to indicate that the routine
03719 ** expects pointers to be UTF-16 strings in the native byte order, or the
03720 ** argument can be [SQLITE_UTF16_ALIGNED] if the
03721 ** the routine expects pointers to 16-bit word aligned strings
03722 ** of UTF-16 in the native byte order.
03723 **
03724 ** A pointer to the user supplied routine must be passed as the fifth
03725 ** argument.  ^If it is NULL, this is the same as deleting the collation
03726 ** sequence (so that SQLite cannot call it any more).
03727 ** ^Each time the application supplied function is invoked, it is passed
03728 ** as its first parameter a copy of the void* passed as the fourth argument
03729 ** to sqlite3_create_collation() or sqlite3_create_collation16().
03730 **
03731 ** ^The remaining arguments to the application-supplied routine are two strings,
03732 ** each represented by a (length, data) pair and encoded in the encoding
03733 ** that was passed as the third argument when the collation sequence was
03734 ** registered.  The application defined collation routine should
03735 ** return negative, zero or positive if the first string is less than,
03736 ** equal to, or greater than the second string. i.e. (STRING1 - STRING2).
03737 **
03738 ** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
03739 ** except that it takes an extra argument which is a destructor for
03740 ** the collation.  ^The destructor is called when the collation is
03741 ** destroyed and is passed a copy of the fourth parameter void* pointer
03742 ** of the sqlite3_create_collation_v2().
03743 ** ^Collations are destroyed when they are overridden by later calls to the
03744 ** collation creation functions or when the [database connection] is closed
03745 ** using [sqlite3_close()].
03746 **
03747 ** See also:  [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].
03748 */
03749 SQLITE_API int sqlite3_create_collation(
03750   sqlite3*, 
03751   const char *zName, 
03752   int eTextRep, 
03753   void*,
03754   int(*xCompare)(void*,int,const void*,int,const void*)
03755 );
03756 SQLITE_API int sqlite3_create_collation_v2(
03757   sqlite3*, 
03758   const char *zName, 
03759   int eTextRep, 
03760   void*,
03761   int(*xCompare)(void*,int,const void*,int,const void*),
03762   void(*xDestroy)(void*)
03763 );
03764 SQLITE_API int sqlite3_create_collation16(
03765   sqlite3*, 
03766   const void *zName,
03767   int eTextRep, 
03768   void*,
03769   int(*xCompare)(void*,int,const void*,int,const void*)
03770 );
03771 
03772 /*
03773 ** CAPI3REF: Collation Needed Callbacks
03774 **
03775 ** ^To avoid having to register all collation sequences before a database
03776 ** can be used, a single callback function may be registered with the
03777 ** [database connection] to be invoked whenever an undefined collation
03778 ** sequence is required.
03779 **
03780 ** ^If the function is registered using the sqlite3_collation_needed() API,
03781 ** then it is passed the names of undefined collation sequences as strings
03782 ** encoded in UTF-8. ^If sqlite3_collation_needed16() is used,
03783 ** the names are passed as UTF-16 in machine native byte order.
03784 ** ^A call to either function replaces the existing collation-needed callback.
03785 **
03786 ** ^(When the callback is invoked, the first argument passed is a copy
03787 ** of the second argument to sqlite3_collation_needed() or
03788 ** sqlite3_collation_needed16().  The second argument is the database
03789 ** connection.  The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE],
03790 ** or [SQLITE_UTF16LE], indicating the most desirable form of the collation
03791 ** sequence function required.  The fourth parameter is the name of the
03792 ** required collation sequence.)^
03793 **
03794 ** The callback function should register the desired collation using
03795 ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
03796 ** [sqlite3_create_collation_v2()].
03797 */
03798 SQLITE_API int sqlite3_collation_needed(
03799   sqlite3*, 
03800   void*, 
03801   void(*)(void*,sqlite3*,int eTextRep,const char*)
03802 );
03803 SQLITE_API int sqlite3_collation_needed16(
03804   sqlite3*, 
03805   void*,
03806   void(*)(void*,sqlite3*,int eTextRep,const void*)
03807 );
03808 
03809 #ifdef SQLITE_HAS_CODEC
03810 /*
03811 ** Specify the key for an encrypted database.  This routine should be
03812 ** called right after sqlite3_open().
03813 **
03814 ** The code to implement this API is not available in the public release
03815 ** of SQLite.
03816 */
03817 SQLITE_API int sqlite3_key(
03818   sqlite3 *db,                   /* Database to be rekeyed */
03819   const void *pKey, int nKey     /* The key */
03820 );
03821 
03822 /*
03823 ** Change the key on an open database.  If the current database is not
03824 ** encrypted, this routine will encrypt it.  If pNew==0 or nNew==0, the
03825 ** database is decrypted.
03826 **
03827 ** The code to implement this API is not available in the public release
03828 ** of SQLite.
03829 */
03830 SQLITE_API int sqlite3_rekey(
03831   sqlite3 *db,                   /* Database to be rekeyed */
03832   const void *pKey, int nKey     /* The new key */
03833 );
03834 
03835 /*
03836 ** Specify the activation key for a SEE database.  Unless 
03837 ** activated, none of the SEE routines will work.
03838 */
03839 SQLITE_API void sqlite3_activate_see(
03840   const char *zPassPhrase        /* Activation phrase */
03841 );
03842 #endif
03843 
03844 #ifdef SQLITE_ENABLE_CEROD
03845 /*
03846 ** Specify the activation key for a CEROD database.  Unless 
03847 ** activated, none of the CEROD routines will work.
03848 */
03849 SQLITE_API void sqlite3_activate_cerod(
03850   const char *zPassPhrase        /* Activation phrase */
03851 );
03852 #endif
03853 
03854 /*
03855 ** CAPI3REF: Suspend Execution For A Short Time
03856 **
03857 ** ^The sqlite3_sleep() function causes the current thread to suspend execution
03858 ** for at least a number of milliseconds specified in its parameter.
03859 **
03860 ** ^If the operating system does not support sleep requests with
03861 ** millisecond time resolution, then the time will be rounded up to
03862 ** the nearest second. ^The number of milliseconds of sleep actually
03863 ** requested from the operating system is returned.
03864 **
03865 ** ^SQLite implements this interface by calling the xSleep()
03866 ** method of the default [sqlite3_vfs] object.
03867 */
03868 SQLITE_API int sqlite3_sleep(int);
03869 
03870 /*
03871 ** CAPI3REF: Name Of The Folder Holding Temporary Files
03872 **
03873 ** ^(If this global variable is made to point to a string which is
03874 ** the name of a folder (a.k.a. directory), then all temporary files
03875 ** created by SQLite when using a built-in [sqlite3_vfs | VFS]
03876 ** will be placed in that directory.)^  ^If this variable
03877 ** is a NULL pointer, then SQLite performs a search for an appropriate
03878 ** temporary file directory.
03879 **
03880 ** It is not safe to read or modify this variable in more than one
03881 ** thread at a time.  It is not safe to read or modify this variable
03882 ** if a [database connection] is being used at the same time in a separate
03883 ** thread.
03884 ** It is intended that this variable be set once
03885 ** as part of process initialization and before any SQLite interface
03886 ** routines have been called and that this variable remain unchanged
03887 ** thereafter.
03888 **
03889 ** ^The [temp_store_directory pragma] may modify this variable and cause
03890 ** it to point to memory obtained from [sqlite3_malloc].  ^Furthermore,
03891 ** the [temp_store_directory pragma] always assumes that any string
03892 ** that this variable points to is held in memory obtained from 
03893 ** [sqlite3_malloc] and the pragma may attempt to free that memory
03894 ** using [sqlite3_free].
03895 ** Hence, if this variable is modified directly, either it should be
03896 ** made NULL or made to point to memory obtained from [sqlite3_malloc]
03897 ** or else the use of the [temp_store_directory pragma] should be avoided.
03898 */
03899 SQLITE_API SQLITE_EXTERN char *sqlite3_temp_directory;
03900 
03901 /*
03902 ** CAPI3REF: Test For Auto-Commit Mode
03903 ** KEYWORDS: {autocommit mode}
03904 **
03905 ** ^The sqlite3_get_autocommit() interface returns non-zero or
03906 ** zero if the given database connection is or is not in autocommit mode,
03907 ** respectively.  ^Autocommit mode is on by default.
03908 ** ^Autocommit mode is disabled by a [BEGIN] statement.
03909 ** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK].
03910 **
03911 ** If certain kinds of errors occur on a statement within a multi-statement
03912 ** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR],
03913 ** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the
03914 ** transaction might be rolled back automatically.  The only way to
03915 ** find out whether SQLite automatically rolled back the transaction after
03916 ** an error is to use this function.
03917 **
03918 ** If another thread changes the autocommit status of the database
03919 ** connection while this routine is running, then the return value
03920 ** is undefined.
03921 */
03922 SQLITE_API int sqlite3_get_autocommit(sqlite3*);
03923 
03924 /*
03925 ** CAPI3REF: Find The Database Handle Of A Prepared Statement
03926 **
03927 ** ^The sqlite3_db_handle interface returns the [database connection] handle
03928 ** to which a [prepared statement] belongs.  ^The [database connection]
03929 ** returned by sqlite3_db_handle is the same [database connection]
03930 ** that was the first argument
03931 ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
03932 ** create the statement in the first place.
03933 */
03934 SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
03935 
03936 /*
03937 ** CAPI3REF: Find the next prepared statement
03938 **
03939 ** ^This interface returns a pointer to the next [prepared statement] after
03940 ** pStmt associated with the [database connection] pDb.  ^If pStmt is NULL
03941 ** then this interface returns a pointer to the first prepared statement
03942 ** associated with the database connection pDb.  ^If no prepared statement
03943 ** satisfies the conditions of this routine, it returns NULL.
03944 **
03945 ** The [database connection] pointer D in a call to
03946 ** [sqlite3_next_stmt(D,S)] must refer to an open database
03947 ** connection and in particular must not be a NULL pointer.
03948 */
03949 SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
03950 
03951 /*
03952 ** CAPI3REF: Commit And Rollback Notification Callbacks
03953 **
03954 ** ^The sqlite3_commit_hook() interface registers a callback
03955 ** function to be invoked whenever a transaction is [COMMIT | committed].
03956 ** ^Any callback set by a previous call to sqlite3_commit_hook()
03957 ** for the same database connection is overridden.
03958 ** ^The sqlite3_rollback_hook() interface registers a callback
03959 ** function to be invoked whenever a transaction is [ROLLBACK | rolled back].
03960 ** ^Any callback set by a previous call to sqlite3_rollback_hook()
03961 ** for the same database connection is overridden.
03962 ** ^The pArg argument is passed through to the callback.
03963 ** ^If the callback on a commit hook function returns non-zero,
03964 ** then the commit is converted into a rollback.
03965 **
03966 ** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions
03967 ** return the P argument from the previous call of the same function
03968 ** on the same [database connection] D, or NULL for
03969 ** the first call for each function on D.
03970 **
03971 ** The callback implementation must not do anything that will modify
03972 ** the database connection that invoked the callback.  Any actions
03973 ** to modify the database connection must be deferred until after the
03974 ** completion of the [sqlite3_step()] call that triggered the commit
03975 ** or rollback hook in the first place.
03976 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
03977 ** database connections for the meaning of "modify" in this paragraph.
03978 **
03979 ** ^Registering a NULL function disables the callback.
03980 **
03981 ** ^When the commit hook callback routine returns zero, the [COMMIT]
03982 ** operation is allowed to continue normally.  ^If the commit hook
03983 ** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK].
03984 ** ^The rollback hook is invoked on a rollback that results from a commit
03985 ** hook returning non-zero, just as it would be with any other rollback.
03986 **
03987 ** ^For the purposes of this API, a transaction is said to have been
03988 ** rolled back if an explicit "ROLLBACK" statement is executed, or
03989 ** an error or constraint causes an implicit rollback to occur.
03990 ** ^The rollback callback is not invoked if a transaction is
03991 ** automatically rolled back because the database connection is closed.
03992 **
03993 ** See also the [sqlite3_update_hook()] interface.
03994 */
03995 SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
03996 SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
03997 
03998 /*
03999 ** CAPI3REF: Data Change Notification Callbacks
04000 **
04001 ** ^The sqlite3_update_hook() interface registers a callback function
04002 ** with the [database connection] identified by the first argument
04003 ** to be invoked whenever a row is updated, inserted or deleted.
04004 ** ^Any callback set by a previous call to this function
04005 ** for the same database connection is overridden.
04006 **
04007 ** ^The second argument is a pointer to the function to invoke when a
04008 ** row is updated, inserted or deleted.
04009 ** ^The first argument to the callback is a copy of the third argument
04010 ** to sqlite3_update_hook().
04011 ** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
04012 ** or [SQLITE_UPDATE], depending on the operation that caused the callback
04013 ** to be invoked.
04014 ** ^The third and fourth arguments to the callback contain pointers to the
04015 ** database and table name containing the affected row.
04016 ** ^The final callback parameter is the [rowid] of the row.
04017 ** ^In the case of an update, this is the [rowid] after the update takes place.
04018 **
04019 ** ^(The update hook is not invoked when internal system tables are
04020 ** modified (i.e. sqlite_master and sqlite_sequence).)^
04021 **
04022 ** ^In the current implementation, the update hook
04023 ** is not invoked when duplication rows are deleted because of an
04024 ** [ON CONFLICT | ON CONFLICT REPLACE] clause.  ^Nor is the update hook
04025 ** invoked when rows are deleted using the [truncate optimization].
04026 ** The exceptions defined in this paragraph might change in a future
04027 ** release of SQLite.
04028 **
04029 ** The update hook implementation must not do anything that will modify
04030 ** the database connection that invoked the update hook.  Any actions
04031 ** to modify the database connection must be deferred until after the
04032 ** completion of the [sqlite3_step()] call that triggered the update hook.
04033 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
04034 ** database connections for the meaning of "modify" in this paragraph.
04035 **
04036 ** ^The sqlite3_update_hook(D,C,P) function
04037 ** returns the P argument from the previous call
04038 ** on the same [database connection] D, or NULL for
04039 ** the first call on D.
04040 **
04041 ** See also the [sqlite3_commit_hook()] and [sqlite3_rollback_hook()]
04042 ** interfaces.
04043 */
04044 SQLITE_API void *sqlite3_update_hook(
04045   sqlite3*, 
04046   void(*)(void *,int ,char const *,char const *,sqlite3_int64),
04047   void*
04048 );
04049 
04050 /*
04051 ** CAPI3REF: Enable Or Disable Shared Pager Cache
04052 ** KEYWORDS: {shared cache}
04053 **
04054 ** ^(This routine enables or disables the sharing of the database cache
04055 ** and schema data structures between [database connection | connections]
04056 ** to the same database. Sharing is enabled if the argument is true
04057 ** and disabled if the argument is false.)^
04058 **
04059 ** ^Cache sharing is enabled and disabled for an entire process.
04060 ** This is a change as of SQLite version 3.5.0. In prior versions of SQLite,
04061 ** sharing was enabled or disabled for each thread separately.
04062 **
04063 ** ^(The cache sharing mode set by this interface effects all subsequent
04064 ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
04065 ** Existing database connections continue use the sharing mode
04066 ** that was in effect at the time they were opened.)^
04067 **
04068 ** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled
04069 ** successfully.  An [error code] is returned otherwise.)^
04070 **
04071 ** ^Shared cache is disabled by default. But this might change in
04072 ** future releases of SQLite.  Applications that care about shared
04073 ** cache setting should set it explicitly.
04074 **
04075 ** See Also:  [SQLite Shared-Cache Mode]
04076 */
04077 SQLITE_API int sqlite3_enable_shared_cache(int);
04078 
04079 /*
04080 ** CAPI3REF: Attempt To Free Heap Memory
04081 **
04082 ** ^The sqlite3_release_memory() interface attempts to free N bytes
04083 ** of heap memory by deallocating non-essential memory allocations
04084 ** held by the database library.   Memory used to cache database
04085 ** pages to improve performance is an example of non-essential memory.
04086 ** ^sqlite3_release_memory() returns the number of bytes actually freed,
04087 ** which might be more or less than the amount requested.
04088 */
04089 SQLITE_API int sqlite3_release_memory(int);
04090 
04091 /*
04092 ** CAPI3REF: Impose A Limit On Heap Size
04093 **
04094 ** ^The sqlite3_soft_heap_limit() interface places a "soft" limit
04095 ** on the amount of heap memory that may be allocated by SQLite.
04096 ** ^If an internal allocation is requested that would exceed the
04097 ** soft heap limit, [sqlite3_release_memory()] is invoked one or
04098 ** more times to free up some space before the allocation is performed.
04099 **
04100 ** ^The limit is called "soft" because if [sqlite3_release_memory()]
04101 ** cannot free sufficient memory to prevent the limit from being exceeded,
04102 ** the memory is allocated anyway and the current operation proceeds.
04103 **
04104 ** ^A negative or zero value for N means that there is no soft heap limit and
04105 ** [sqlite3_release_memory()] will only be called when memory is exhausted.
04106 ** ^The default value for the soft heap limit is zero.
04107 **
04108 ** ^(SQLite makes a best effort to honor the soft heap limit.
04109 ** But if the soft heap limit cannot be honored, execution will
04110 ** continue without error or notification.)^  This is why the limit is
04111 ** called a "soft" limit.  It is advisory only.
04112 **
04113 ** Prior to SQLite version 3.5.0, this routine only constrained the memory
04114 ** allocated by a single thread - the same thread in which this routine
04115 ** runs.  Beginning with SQLite version 3.5.0, the soft heap limit is
04116 ** applied to all threads. The value specified for the soft heap limit
04117 ** is an upper bound on the total memory allocation for all threads. In
04118 ** version 3.5.0 there is no mechanism for limiting the heap usage for
04119 ** individual threads.
04120 */
04121 SQLITE_API void sqlite3_soft_heap_limit(int);
04122 
04123 /*
04124 ** CAPI3REF: Extract Metadata About A Column Of A Table
04125 **
04126 ** ^This routine returns metadata about a specific column of a specific
04127 ** database table accessible using the [database connection] handle
04128 ** passed as the first function argument.
04129 **
04130 ** ^The column is identified by the second, third and fourth parameters to
04131 ** this function. ^The second parameter is either the name of the database
04132 ** (i.e. "main", "temp", or an attached database) containing the specified
04133 ** table or NULL. ^If it is NULL, then all attached databases are searched
04134 ** for the table using the same algorithm used by the database engine to
04135 ** resolve unqualified table references.
04136 **
04137 ** ^The third and fourth parameters to this function are the table and column
04138 ** name of the desired column, respectively. Neither of these parameters
04139 ** may be NULL.
04140 **
04141 ** ^Metadata is returned by writing to the memory locations passed as the 5th
04142 ** and subsequent parameters to this function. ^Any of these arguments may be
04143 ** NULL, in which case the corresponding element of metadata is omitted.
04144 **
04145 ** ^(<blockquote>
04146 ** <table border="1">
04147 ** <tr><th> Parameter <th> Output<br>Type <th>  Description
04148 **
04149 ** <tr><td> 5th <td> const char* <td> Data type
04150 ** <tr><td> 6th <td> const char* <td> Name of default collation sequence
04151 ** <tr><td> 7th <td> int         <td> True if column has a NOT NULL constraint
04152 ** <tr><td> 8th <td> int         <td> True if column is part of the PRIMARY KEY
04153 ** <tr><td> 9th <td> int         <td> True if column is [AUTOINCREMENT]
04154 ** </table>
04155 ** </blockquote>)^
04156 **
04157 ** ^The memory pointed to by the character pointers returned for the
04158 ** declaration type and collation sequence is valid only until the next
04159 ** call to any SQLite API function.
04160 **
04161 ** ^If the specified table is actually a view, an [error code] is returned.
04162 **
04163 ** ^If the specified column is "rowid", "oid" or "_rowid_" and an
04164 ** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
04165 ** parameters are set for the explicitly declared column. ^(If there is no
04166 ** explicitly declared [INTEGER PRIMARY KEY] column, then the output
04167 ** parameters are set as follows:
04168 **
04169 ** <pre>
04170 **     data type: "INTEGER"
04171 **     collation sequence: "BINARY"
04172 **     not null: 0
04173 **     primary key: 1
04174 **     auto increment: 0
04175 ** </pre>)^
04176 **
04177 ** ^(This function may load one or more schemas from database files. If an
04178 ** error occurs during this process, or if the requested table or column
04179 ** cannot be found, an [error code] is returned and an error message left
04180 ** in the [database connection] (to be retrieved using sqlite3_errmsg()).)^
04181 **
04182 ** ^This API is only available if the library was compiled with the
04183 ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined.
04184 */
04185 SQLITE_API int sqlite3_table_column_metadata(
04186   sqlite3 *db,                /* Connection handle */
04187   const char *zDbName,        /* Database name or NULL */
04188   const char *zTableName,     /* Table name */
04189   const char *zColumnName,    /* Column name */
04190   char const **pzDataType,    /* OUTPUT: Declared data type */
04191   char const **pzCollSeq,     /* OUTPUT: Collation sequence name */
04192   int *pNotNull,              /* OUTPUT: True if NOT NULL constraint exists */
04193   int *pPrimaryKey,           /* OUTPUT: True if column part of PK */
04194   int *pAutoinc               /* OUTPUT: True if column is auto-increment */
04195 );
04196 
04197 /*
04198 ** CAPI3REF: Load An Extension
04199 **
04200 ** ^This interface loads an SQLite extension library from the named file.
04201 **
04202 ** ^The sqlite3_load_extension() interface attempts to load an
04203 ** SQLite extension library contained in the file zFile.
04204 **
04205 ** ^The entry point is zProc.
04206 ** ^zProc may be 0, in which case the name of the entry point
04207 ** defaults to "sqlite3_extension_init".
04208 ** ^The sqlite3_load_extension() interface returns
04209 ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
04210 ** ^If an error occurs and pzErrMsg is not 0, then the
04211 ** [sqlite3_load_extension()] interface shall attempt to
04212 ** fill *pzErrMsg with error message text stored in memory
04213 ** obtained from [sqlite3_malloc()]. The calling function
04214 ** should free this memory by calling [sqlite3_free()].
04215 **
04216 ** ^Extension loading must be enabled using
04217 ** [sqlite3_enable_load_extension()] prior to calling this API,
04218 ** otherwise an error will be returned.
04219 **
04220 ** See also the [load_extension() SQL function].
04221 */
04222 SQLITE_API int sqlite3_load_extension(
04223   sqlite3 *db,          /* Load the extension into this database connection */
04224   const char *zFile,    /* Name of the shared library containing extension */
04225   const char *zProc,    /* Entry point.  Derived from zFile if 0 */
04226   char **pzErrMsg       /* Put error message here if not 0 */
04227 );
04228 
04229 /*
04230 ** CAPI3REF: Enable Or Disable Extension Loading
04231 **
04232 ** ^So as not to open security holes in older applications that are
04233 ** unprepared to deal with extension loading, and as a means of disabling
04234 ** extension loading while evaluating user-entered SQL, the following API
04235 ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
04236 **
04237 ** ^Extension loading is off by default. See ticket #1863.
04238 ** ^Call the sqlite3_enable_load_extension() routine with onoff==1
04239 ** to turn extension loading on and call it with onoff==0 to turn
04240 ** it back off again.
04241 */
04242 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
04243 
04244 /*
04245 ** CAPI3REF: Automatically Load An Extensions
04246 **
04247 ** ^This API can be invoked at program startup in order to register
04248 ** one or more statically linked extensions that will be available
04249 ** to all new [database connections].
04250 **
04251 ** ^(This routine stores a pointer to the extension entry point
04252 ** in an array that is obtained from [sqlite3_malloc()].  That memory
04253 ** is deallocated by [sqlite3_reset_auto_extension()].)^
04254 **
04255 ** ^This function registers an extension entry point that is
04256 ** automatically invoked whenever a new [database connection]
04257 ** is opened using [sqlite3_open()], [sqlite3_open16()],
04258 ** or [sqlite3_open_v2()].
04259 ** ^Duplicate extensions are detected so calling this routine
04260 ** multiple times with the same extension is harmless.
04261 ** ^Automatic extensions apply across all threads.
04262 */
04263 SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void));
04264 
04265 /*
04266 ** CAPI3REF: Reset Automatic Extension Loading
04267 **
04268 ** ^(This function disables all previously registered automatic
04269 ** extensions. It undoes the effect of all prior
04270 ** [sqlite3_auto_extension()] calls.)^
04271 **
04272 ** ^This function disables automatic extensions in all threads.
04273 */
04274 SQLITE_API void sqlite3_reset_auto_extension(void);
04275 
04276 /*
04277 ** The interface to the virtual-table mechanism is currently considered
04278 ** to be experimental.  The interface might change in incompatible ways.
04279 ** If this is a problem for you, do not use the interface at this time.
04280 **
04281 ** When the virtual-table mechanism stabilizes, we will declare the
04282 ** interface fixed, support it indefinitely, and remove this comment.
04283 */
04284 
04285 /*
04286 ** Structures used by the virtual table interface
04287 */
04288 typedef struct sqlite3_vtab sqlite3_vtab;
04289 typedef struct sqlite3_index_info sqlite3_index_info;
04290 typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor;
04291 typedef struct sqlite3_module sqlite3_module;
04292 
04293 /*
04294 ** CAPI3REF: Virtual Table Object
04295 ** KEYWORDS: sqlite3_module {virtual table module}
04296 **
04297 ** This structure, sometimes called a a "virtual table module", 
04298 ** defines the implementation of a [virtual tables].  
04299 ** This structure consists mostly of methods for the module.
04300 **
04301 ** ^A virtual table module is created by filling in a persistent
04302 ** instance of this structure and passing a pointer to that instance
04303 ** to [sqlite3_create_module()] or [sqlite3_create_module_v2()].
04304 ** ^The registration remains valid until it is replaced by a different
04305 ** module or until the [database connection] closes.  The content
04306 ** of this structure must not change while it is registered with
04307 ** any database connection.
04308 */
04309 struct sqlite3_module {
04310   int iVersion;
04311   int (*xCreate)(sqlite3*, void *pAux,
04312                int argc, const char *const*argv,
04313                sqlite3_vtab **ppVTab, char**);
04314   int (*xConnect)(sqlite3*, void *pAux,
04315                int argc, const char *const*argv,
04316                sqlite3_vtab **ppVTab, char**);
04317   int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
04318   int (*xDisconnect)(sqlite3_vtab *pVTab);
04319   int (*xDestroy)(sqlite3_vtab *pVTab);
04320   int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor);
04321   int (*xClose)(sqlite3_vtab_cursor*);
04322   int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr,
04323                 int argc, sqlite3_value **argv);
04324   int (*xNext)(sqlite3_vtab_cursor*);
04325   int (*xEof)(sqlite3_vtab_cursor*);
04326   int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int);
04327   int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid);
04328   int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *);
04329   int (*xBegin)(sqlite3_vtab *pVTab);
04330   int (*xSync)(sqlite3_vtab *pVTab);
04331   int (*xCommit)(sqlite3_vtab *pVTab);
04332   int (*xRollback)(sqlite3_vtab *pVTab);
04333   int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
04334                        void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
04335                        void **ppArg);
04336   int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
04337 };
04338 
04339 /*
04340 ** CAPI3REF: Virtual Table Indexing Information
04341 ** KEYWORDS: sqlite3_index_info
04342 **
04343 ** The sqlite3_index_info structure and its substructures is used as part
04344 ** of the [virtual table] interface to
04345 ** pass information into and receive the reply from the [xBestIndex]
04346 ** method of a [virtual table module].  The fields under **Inputs** are the
04347 ** inputs to xBestIndex and are read-only.  xBestIndex inserts its
04348 ** results into the **Outputs** fields.
04349 **
04350 ** ^(The aConstraint[] array records WHERE clause constraints of the form:
04351 **
04352 ** <blockquote>column OP expr</blockquote>
04353 **
04354 ** where OP is =, &lt;, &lt;=, &gt;, or &gt;=.)^  ^(The particular operator is
04355 ** stored in aConstraint[].op using one of the
04356 ** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^
04357 ** ^(The index of the column is stored in
04358 ** aConstraint[].iColumn.)^  ^(aConstraint[].usable is TRUE if the
04359 ** expr on the right-hand side can be evaluated (and thus the constraint
04360 ** is usable) and false if it cannot.)^
04361 **
04362 ** ^The optimizer automatically inverts terms of the form "expr OP column"
04363 ** and makes other simplifications to the WHERE clause in an attempt to
04364 ** get as many WHERE clause terms into the form shown above as possible.
04365 ** ^The aConstraint[] array only reports WHERE clause terms that are
04366 ** relevant to the particular virtual table being queried.
04367 **
04368 ** ^Information about the ORDER BY clause is stored in aOrderBy[].
04369 ** ^Each term of aOrderBy records a column of the ORDER BY clause.
04370 **
04371 ** The [xBestIndex] method must fill aConstraintUsage[] with information
04372 ** about what parameters to pass to xFilter.  ^If argvIndex>0 then
04373 ** the right-hand side of the corresponding aConstraint[] is evaluated
04374 ** and becomes the argvIndex-th entry in argv.  ^(If aConstraintUsage[].omit
04375 ** is true, then the constraint is assumed to be fully handled by the
04376 ** virtual table and is not checked again by SQLite.)^
04377 **
04378 ** ^The idxNum and idxPtr values are recorded and passed into the
04379 ** [xFilter] method.
04380 ** ^[sqlite3_free()] is used to free idxPtr if and only if
04381 ** needToFreeIdxPtr is true.
04382 **
04383 ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
04384 ** the correct order to satisfy the ORDER BY clause so that no separate
04385 ** sorting step is required.
04386 **
04387 ** ^The estimatedCost value is an estimate of the cost of doing the
04388 ** particular lookup.  A full scan of a table with N entries should have
04389 ** a cost of N.  A binary search of a table of N entries should have a
04390 ** cost of approximately log(N).
04391 */
04392 struct sqlite3_index_info {
04393   /* Inputs */
04394   int nConstraint;           /* Number of entries in aConstraint */
04395   struct sqlite3_index_constraint {
04396      int iColumn;              /* Column on left-hand side of constraint */
04397      unsigned char op;         /* Constraint operator */
04398      unsigned char usable;     /* True if this constraint is usable */
04399      int iTermOffset;          /* Used internally - xBestIndex should ignore */
04400   } *aConstraint;            /* Table of WHERE clause constraints */
04401   int nOrderBy;              /* Number of terms in the ORDER BY clause */
04402   struct sqlite3_index_orderby {
04403      int iColumn;              /* Column number */
04404      unsigned char desc;       /* True for DESC.  False for ASC. */
04405   } *aOrderBy;               /* The ORDER BY clause */
04406   /* Outputs */
04407   struct sqlite3_index_constraint_usage {
04408     int argvIndex;           /* if >0, constraint is part of argv to xFilter */
04409     unsigned char omit;      /* Do not code a test for this constraint */
04410   } *aConstraintUsage;
04411   int idxNum;                /* Number used to identify the index */
04412   char *idxStr;              /* String, possibly obtained from sqlite3_malloc */
04413   int needToFreeIdxStr;      /* Free idxStr using sqlite3_free() if true */
04414   int orderByConsumed;       /* True if output is already ordered */
04415   double estimatedCost;      /* Estimated cost of using this index */
04416 };
04417 
04418 /*
04419 ** CAPI3REF: Virtual Table Constraint Operator Codes
04420 **
04421 ** These macros defined the allowed values for the
04422 ** [sqlite3_index_info].aConstraint[].op field.  Each value represents
04423 ** an operator that is part of a constraint term in the wHERE clause of
04424 ** a query that uses a [virtual table].
04425 */
04426 #define SQLITE_INDEX_CONSTRAINT_EQ    2
04427 #define SQLITE_INDEX_CONSTRAINT_GT    4
04428 #define SQLITE_INDEX_CONSTRAINT_LE    8
04429 #define SQLITE_INDEX_CONSTRAINT_LT    16
04430 #define SQLITE_INDEX_CONSTRAINT_GE    32
04431 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
04432 
04433 /*
04434 ** CAPI3REF: Register A Virtual Table Implementation
04435 **
04436 ** ^These routines are used to register a new [virtual table module] name.
04437 ** ^Module names must be registered before
04438 ** creating a new [virtual table] using the module and before using a
04439 ** preexisting [virtual table] for the module.
04440 **
04441 ** ^The module name is registered on the [database connection] specified
04442 ** by the first parameter.  ^The name of the module is given by the 
04443 ** second parameter.  ^The third parameter is a pointer to
04444 ** the implementation of the [virtual table module].   ^The fourth
04445 ** parameter is an arbitrary client data pointer that is passed through
04446 ** into the [xCreate] and [xConnect] methods of the virtual table module
04447 ** when a new virtual table is be being created or reinitialized.
04448 **
04449 ** ^The sqlite3_create_module_v2() interface has a fifth parameter which
04450 ** is a pointer to a destructor for the pClientData.  ^SQLite will
04451 ** invoke the destructor function (if it is not NULL) when SQLite
04452 ** no longer needs the pClientData pointer.  ^The sqlite3_create_module()
04453 ** interface is equivalent to sqlite3_create_module_v2() with a NULL
04454 ** destructor.
04455 */
04456 SQLITE_API int sqlite3_create_module(
04457   sqlite3 *db,               /* SQLite connection to register module with */
04458   const char *zName,         /* Name of the module */
04459   const sqlite3_module *p,   /* Methods for the module */
04460   void *pClientData          /* Client data for xCreate/xConnect */
04461 );
04462 SQLITE_API int sqlite3_create_module_v2(
04463   sqlite3 *db,               /* SQLite connection to register module with */
04464   const char *zName,         /* Name of the module */
04465   const sqlite3_module *p,   /* Methods for the module */
04466   void *pClientData,         /* Client data for xCreate/xConnect */
04467   void(*xDestroy)(void*)     /* Module destructor function */
04468 );
04469 
04470 /*
04471 ** CAPI3REF: Virtual Table Instance Object
04472 ** KEYWORDS: sqlite3_vtab
04473 **
04474 ** Every [virtual table module] implementation uses a subclass
04475 ** of this object to describe a particular instance
04476 ** of the [virtual table].  Each subclass will
04477 ** be tailored to the specific needs of the module implementation.
04478 ** The purpose of this superclass is to define certain fields that are
04479 ** common to all module implementations.
04480 **
04481 ** ^Virtual tables methods can set an error message by assigning a
04482 ** string obtained from [sqlite3_mprintf()] to zErrMsg.  The method should
04483 ** take care that any prior string is freed by a call to [sqlite3_free()]
04484 ** prior to assigning a new string to zErrMsg.  ^After the error message
04485 ** is delivered up to the client application, the string will be automatically
04486 ** freed by sqlite3_free() and the zErrMsg field will be zeroed.
04487 */
04488 struct sqlite3_vtab {
04489   const sqlite3_module *pModule;  /* The module for this virtual table */
04490   int nRef;                       /* NO LONGER USED */
04491   char *zErrMsg;                  /* Error message from sqlite3_mprintf() */
04492   /* Virtual table implementations will typically add additional fields */
04493 };
04494 
04495 /*
04496 ** CAPI3REF: Virtual Table Cursor Object
04497 ** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
04498 **
04499 ** Every [virtual table module] implementation uses a subclass of the
04500 ** following structure to describe cursors that point into the
04501 ** [virtual table] and are used
04502 ** to loop through the virtual table.  Cursors are created using the
04503 ** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed
04504 ** by the [sqlite3_module.xClose | xClose] method.  Cursors are used
04505 ** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods
04506 ** of the module.  Each module implementation will define
04507 ** the content of a cursor structure to suit its own needs.
04508 **
04509 ** This superclass exists in order to define fields of the cursor that
04510 ** are common to all implementations.
04511 */
04512 struct sqlite3_vtab_cursor {
04513   sqlite3_vtab *pVtab;      /* Virtual table of this cursor */
04514   /* Virtual table implementations will typically add additional fields */
04515 };
04516 
04517 /*
04518 ** CAPI3REF: Declare The Schema Of A Virtual Table
04519 **
04520 ** ^The [xCreate] and [xConnect] methods of a
04521 ** [virtual table module] call this interface
04522 ** to declare the format (the names and datatypes of the columns) of
04523 ** the virtual tables they implement.
04524 */
04525 SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
04526 
04527 /*
04528 ** CAPI3REF: Overload A Function For A Virtual Table
04529 **
04530 ** ^(Virtual tables can provide alternative implementations of functions
04531 ** using the [xFindFunction] method of the [virtual table module].  
04532 ** But global versions of those functions
04533 ** must exist in order to be overloaded.)^
04534 **
04535 ** ^(This API makes sure a global version of a function with a particular
04536 ** name and number of parameters exists.  If no such function exists
04537 ** before this API is called, a new function is created.)^  ^The implementation
04538 ** of the new function always causes an exception to be thrown.  So
04539 ** the new function is not good for anything by itself.  Its only
04540 ** purpose is to be a placeholder function that can be overloaded
04541 ** by a [virtual table].
04542 */
04543 SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
04544 
04545 /*
04546 ** The interface to the virtual-table mechanism defined above (back up
04547 ** to a comment remarkably similar to this one) is currently considered
04548 ** to be experimental.  The interface might change in incompatible ways.
04549 ** If this is a problem for you, do not use the interface at this time.
04550 **
04551 ** When the virtual-table mechanism stabilizes, we will declare the
04552 ** interface fixed, support it indefinitely, and remove this comment.
04553 */
04554 
04555 /*
04556 ** CAPI3REF: A Handle To An Open BLOB
04557 ** KEYWORDS: {BLOB handle} {BLOB handles}
04558 **
04559 ** An instance of this object represents an open BLOB on which
04560 ** [sqlite3_blob_open | incremental BLOB I/O] can be performed.
04561 ** ^Objects of this type are created by [sqlite3_blob_open()]
04562 ** and destroyed by [sqlite3_blob_close()].
04563 ** ^The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces
04564 ** can be used to read or write small subsections of the BLOB.
04565 ** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes.
04566 */
04567 typedef struct sqlite3_blob sqlite3_blob;
04568 
04569 /*
04570 ** CAPI3REF: Open A BLOB For Incremental I/O
04571 **
04572 ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
04573 ** in row iRow, column zColumn, table zTable in database zDb;
04574 ** in other words, the same BLOB that would be selected by:
04575 **
04576 ** <pre>
04577 **     SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
04578 ** </pre>)^
04579 **
04580 ** ^If the flags parameter is non-zero, then the BLOB is opened for read
04581 ** and write access. ^If it is zero, the BLOB is opened for read access.
04582 ** ^It is not possible to open a column that is part of an index or primary 
04583 ** key for writing. ^If [foreign key constraints] are enabled, it is 
04584 ** not possible to open a column that is part of a [child key] for writing.
04585 **
04586 ** ^Note that the database name is not the filename that contains
04587 ** the database but rather the symbolic name of the database that
04588 ** appears after the AS keyword when the database is connected using [ATTACH].
04589 ** ^For the main database file, the database name is "main".
04590 ** ^For TEMP tables, the database name is "temp".
04591 **
04592 ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is written
04593 ** to *ppBlob. Otherwise an [error code] is returned and *ppBlob is set
04594 ** to be a null pointer.)^
04595 ** ^This function sets the [database connection] error code and message
04596 ** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()] and related
04597 ** functions. ^Note that the *ppBlob variable is always initialized in a
04598 ** way that makes it safe to invoke [sqlite3_blob_close()] on *ppBlob
04599 ** regardless of the success or failure of this routine.
04600 **
04601 ** ^(If the row that a BLOB handle points to is modified by an
04602 ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
04603 ** then the BLOB handle is marked as "expired".
04604 ** This is true if any column of the row is changed, even a column
04605 ** other than the one the BLOB handle is open on.)^
04606 ** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for
04607 ** a expired BLOB handle fail with an return code of [SQLITE_ABORT].
04608 ** ^(Changes written into a BLOB prior to the BLOB expiring are not
04609 ** rolled back by the expiration of the BLOB.  Such changes will eventually
04610 ** commit if the transaction continues to completion.)^
04611 **
04612 ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
04613 ** the opened blob.  ^The size of a blob may not be changed by this
04614 ** interface.  Use the [UPDATE] SQL command to change the size of a
04615 ** blob.
04616 **
04617 ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
04618 ** and the built-in [zeroblob] SQL function can be used, if desired,
04619 ** to create an empty, zero-filled blob in which to read or write using
04620 ** this interface.
04621 **
04622 ** To avoid a resource leak, every open [BLOB handle] should eventually
04623 ** be released by a call to [sqlite3_blob_close()].
04624 */
04625 SQLITE_API int sqlite3_blob_open(
04626   sqlite3*,
04627   const char *zDb,
04628   const char *zTable,
04629   const char *zColumn,
04630   sqlite3_int64 iRow,
04631   int flags,
04632   sqlite3_blob **ppBlob
04633 );
04634 
04635 /*
04636 ** CAPI3REF: Close A BLOB Handle
04637 **
04638 ** ^Closes an open [BLOB handle].
04639 **
04640 ** ^Closing a BLOB shall cause the current transaction to commit
04641 ** if there are no other BLOBs, no pending prepared statements, and the
04642 ** database connection is in [autocommit mode].
04643 ** ^If any writes were made to the BLOB, they might be held in cache
04644 ** until the close operation if they will fit.
04645 **
04646 ** ^(Closing the BLOB often forces the changes
04647 ** out to disk and so if any I/O errors occur, they will likely occur
04648 ** at the time when the BLOB is closed.  Any errors that occur during
04649 ** closing are reported as a non-zero return value.)^
04650 **
04651 ** ^(The BLOB is closed unconditionally.  Even if this routine returns
04652 ** an error code, the BLOB is still closed.)^
04653 **
04654 ** ^Calling this routine with a null pointer (such as would be returned
04655 ** by a failed call to [sqlite3_blob_open()]) is a harmless no-op.
04656 */
04657 SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
04658 
04659 /*
04660 ** CAPI3REF: Return The Size Of An Open BLOB
04661 **
04662 ** ^Returns the size in bytes of the BLOB accessible via the 
04663 ** successfully opened [BLOB handle] in its only argument.  ^The
04664 ** incremental blob I/O routines can only read or overwriting existing
04665 ** blob content; they cannot change the size of a blob.
04666 **
04667 ** This routine only works on a [BLOB handle] which has been created
04668 ** by a prior successful call to [sqlite3_blob_open()] and which has not
04669 ** been closed by [sqlite3_blob_close()].  Passing any other pointer in
04670 ** to this routine results in undefined and probably undesirable behavior.
04671 */
04672 SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *);
04673 
04674 /*
04675 ** CAPI3REF: Read Data From A BLOB Incrementally
04676 **
04677 ** ^(This function is used to read data from an open [BLOB handle] into a
04678 ** caller-supplied buffer. N bytes of data are copied into buffer Z
04679 ** from the open BLOB, starting at offset iOffset.)^
04680 **
04681 ** ^If offset iOffset is less than N bytes from the end of the BLOB,
04682 ** [SQLITE_ERROR] is returned and no data is read.  ^If N or iOffset is
04683 ** less than zero, [SQLITE_ERROR] is returned and no data is read.
04684 ** ^The size of the blob (and hence the maximum value of N+iOffset)
04685 ** can be determined using the [sqlite3_blob_bytes()] interface.
04686 **
04687 ** ^An attempt to read from an expired [BLOB handle] fails with an
04688 ** error code of [SQLITE_ABORT].
04689 **
04690 ** ^(On success, sqlite3_blob_read() returns SQLITE_OK.
04691 ** Otherwise, an [error code] or an [extended error code] is returned.)^
04692 **
04693 ** This routine only works on a [BLOB handle] which has been created
04694 ** by a prior successful call to [sqlite3_blob_open()] and which has not
04695 ** been closed by [sqlite3_blob_close()].  Passing any other pointer in
04696 ** to this routine results in undefined and probably undesirable behavior.
04697 **
04698 ** See also: [sqlite3_blob_write()].
04699 */
04700 SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
04701 
04702 /*
04703 ** CAPI3REF: Write Data Into A BLOB Incrementally
04704 **
04705 ** ^This function is used to write data into an open [BLOB handle] from a
04706 ** caller-supplied buffer. ^N bytes of data are copied from the buffer Z
04707 ** into the open BLOB, starting at offset iOffset.
04708 **
04709 ** ^If the [BLOB handle] passed as the first argument was not opened for
04710 ** writing (the flags parameter to [sqlite3_blob_open()] was zero),
04711 ** this function returns [SQLITE_READONLY].
04712 **
04713 ** ^This function may only modify the contents of the BLOB; it is
04714 ** not possible to increase the size of a BLOB using this API.
04715 ** ^If offset iOffset is less than N bytes from the end of the BLOB,
04716 ** [SQLITE_ERROR] is returned and no data is written.  ^If N is
04717 ** less than zero [SQLITE_ERROR] is returned and no data is written.
04718 ** The size of the BLOB (and hence the maximum value of N+iOffset)
04719 ** can be determined using the [sqlite3_blob_bytes()] interface.
04720 **
04721 ** ^An attempt to write to an expired [BLOB handle] fails with an
04722 ** error code of [SQLITE_ABORT].  ^Writes to the BLOB that occurred
04723 ** before the [BLOB handle] expired are not rolled back by the
04724 ** expiration of the handle, though of course those changes might
04725 ** have been overwritten by the statement that expired the BLOB handle
04726 ** or by other independent statements.
04727 **
04728 ** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
04729 ** Otherwise, an  [error code] or an [extended error code] is returned.)^
04730 **
04731 ** This routine only works on a [BLOB handle] which has been created
04732 ** by a prior successful call to [sqlite3_blob_open()] and which has not
04733 ** been closed by [sqlite3_blob_close()].  Passing any other pointer in
04734 ** to this routine results in undefined and probably undesirable behavior.
04735 **
04736 ** See also: [sqlite3_blob_read()].
04737 */
04738 SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
04739 
04740 /*
04741 ** CAPI3REF: Virtual File System Objects
04742 **
04743 ** A virtual filesystem (VFS) is an [sqlite3_vfs] object
04744 ** that SQLite uses to interact
04745 ** with the underlying operating system.  Most SQLite builds come with a
04746 ** single default VFS that is appropriate for the host computer.
04747 ** New VFSes can be registered and existing VFSes can be unregistered.
04748 ** The following interfaces are provided.
04749 **
04750 ** ^The sqlite3_vfs_find() interface returns a pointer to a VFS given its name.
04751 ** ^Names are case sensitive.
04752 ** ^Names are zero-terminated UTF-8 strings.
04753 ** ^If there is no match, a NULL pointer is returned.
04754 ** ^If zVfsName is NULL then the default VFS is returned.
04755 **
04756 ** ^New VFSes are registered with sqlite3_vfs_register().
04757 ** ^Each new VFS becomes the default VFS if the makeDflt flag is set.
04758 ** ^The same VFS can be registered multiple times without injury.
04759 ** ^To make an existing VFS into the default VFS, register it again
04760 ** with the makeDflt flag set.  If two different VFSes with the
04761 ** same name are registered, the behavior is undefined.  If a
04762 ** VFS is registered with a name that is NULL or an empty string,
04763 ** then the behavior is undefined.
04764 **
04765 ** ^Unregister a VFS with the sqlite3_vfs_unregister() interface.
04766 ** ^(If the default VFS is unregistered, another VFS is chosen as
04767 ** the default.  The choice for the new VFS is arbitrary.)^
04768 */
04769 SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName);
04770 SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
04771 SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*);
04772 
04773 /*
04774 ** CAPI3REF: Mutexes
04775 **
04776 ** The SQLite core uses these routines for thread
04777 ** synchronization. Though they are intended for internal
04778 ** use by SQLite, code that links against SQLite is
04779 ** permitted to use any of these routines.
04780 **
04781 ** The SQLite source code contains multiple implementations
04782 ** of these mutex routines.  An appropriate implementation
04783 ** is selected automatically at compile-time.  ^(The following
04784 ** implementations are available in the SQLite core:
04785 **
04786 ** <ul>
04787 ** <li>   SQLITE_MUTEX_OS2
04788 ** <li>   SQLITE_MUTEX_PTHREAD
04789 ** <li>   SQLITE_MUTEX_W32
04790 ** <li>   SQLITE_MUTEX_NOOP
04791 ** </ul>)^
04792 **
04793 ** ^The SQLITE_MUTEX_NOOP implementation is a set of routines
04794 ** that does no real locking and is appropriate for use in
04795 ** a single-threaded application.  ^The SQLITE_MUTEX_OS2,
04796 ** SQLITE_MUTEX_PTHREAD, and SQLITE_MUTEX_W32 implementations
04797 ** are appropriate for use on OS/2, Unix, and Windows.
04798 **
04799 ** ^(If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
04800 ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
04801 ** implementation is included with the library. In this case the
04802 ** application must supply a custom mutex implementation using the
04803 ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
04804 ** before calling sqlite3_initialize() or any other public sqlite3_
04805 ** function that calls sqlite3_initialize().)^
04806 **
04807 ** ^The sqlite3_mutex_alloc() routine allocates a new
04808 ** mutex and returns a pointer to it. ^If it returns NULL
04809 ** that means that a mutex could not be allocated.  ^SQLite
04810 ** will unwind its stack and return an error.  ^(The argument
04811 ** to sqlite3_mutex_alloc() is one of these integer constants:
04812 **
04813 ** <ul>
04814 ** <li>  SQLITE_MUTEX_FAST
04815 ** <li>  SQLITE_MUTEX_RECURSIVE
04816 ** <li>  SQLITE_MUTEX_STATIC_MASTER
04817 ** <li>  SQLITE_MUTEX_STATIC_MEM
04818 ** <li>  SQLITE_MUTEX_STATIC_MEM2
04819 ** <li>  SQLITE_MUTEX_STATIC_PRNG
04820 ** <li>  SQLITE_MUTEX_STATIC_LRU
04821 ** <li>  SQLITE_MUTEX_STATIC_LRU2
04822 ** </ul>)^
04823 **
04824 ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
04825 ** cause sqlite3_mutex_alloc() to create
04826 ** a new mutex.  ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
04827 ** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
04828 ** The mutex implementation does not need to make a distinction
04829 ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
04830 ** not want to.  ^SQLite will only request a recursive mutex in
04831 ** cases where it really needs one.  ^If a faster non-recursive mutex
04832 ** implementation is available on the host platform, the mutex subsystem
04833 ** might return such a mutex in response to SQLITE_MUTEX_FAST.
04834 **
04835 ** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other
04836 ** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return
04837 ** a pointer to a static preexisting mutex.  ^Six static mutexes are
04838 ** used by the current version of SQLite.  Future versions of SQLite
04839 ** may add additional static mutexes.  Static mutexes are for internal
04840 ** use by SQLite only.  Applications that use SQLite mutexes should
04841 ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
04842 ** SQLITE_MUTEX_RECURSIVE.
04843 **
04844 ** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
04845 ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
04846 ** returns a different mutex on every call.  ^But for the static
04847 ** mutex types, the same mutex is returned on every call that has
04848 ** the same type number.
04849 **
04850 ** ^The sqlite3_mutex_free() routine deallocates a previously
04851 ** allocated dynamic mutex.  ^SQLite is careful to deallocate every
04852 ** dynamic mutex that it allocates.  The dynamic mutexes must not be in
04853 ** use when they are deallocated.  Attempting to deallocate a static
04854 ** mutex results in undefined behavior.  ^SQLite never deallocates
04855 ** a static mutex.
04856 **
04857 ** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
04858 ** to enter a mutex.  ^If another thread is already within the mutex,
04859 ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
04860 ** SQLITE_BUSY.  ^The sqlite3_mutex_try() interface returns [SQLITE_OK]
04861 ** upon successful entry.  ^(Mutexes created using
04862 ** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.
04863 ** In such cases the,
04864 ** mutex must be exited an equal number of times before another thread
04865 ** can enter.)^  ^(If the same thread tries to enter any other
04866 ** kind of mutex more than once, the behavior is undefined.
04867 ** SQLite will never exhibit
04868 ** such behavior in its own use of mutexes.)^
04869 **
04870 ** ^(Some systems (for example, Windows 95) do not support the operation
04871 ** implemented by sqlite3_mutex_try().  On those systems, sqlite3_mutex_try()
04872 ** will always return SQLITE_BUSY.  The SQLite core only ever uses
04873 ** sqlite3_mutex_try() as an optimization so this is acceptable behavior.)^
04874 **
04875 ** ^The sqlite3_mutex_leave() routine exits a mutex that was
04876 ** previously entered by the same thread.   ^(The behavior
04877 ** is undefined if the mutex is not currently entered by the
04878 ** calling thread or is not currently allocated.  SQLite will
04879 ** never do either.)^
04880 **
04881 ** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or
04882 ** sqlite3_mutex_leave() is a NULL pointer, then all three routines
04883 ** behave as no-ops.
04884 **
04885 ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()].
04886 */
04887 SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int);
04888 SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*);
04889 SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*);
04890 SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);
04891 SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);
04892 
04893 /*
04894 ** CAPI3REF: Mutex Methods Object
04895 **
04896 ** An instance of this structure defines the low-level routines
04897 ** used to allocate and use mutexes.
04898 **
04899 ** Usually, the default mutex implementations provided by SQLite are
04900 ** sufficient, however the user has the option of substituting a custom
04901 ** implementation for specialized deployments or systems for which SQLite
04902 ** does not provide a suitable implementation. In this case, the user
04903 ** creates and populates an instance of this structure to pass
04904 ** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option.
04905 ** Additionally, an instance of this structure can be used as an
04906 ** output variable when querying the system for the current mutex
04907 ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
04908 **
04909 ** ^The xMutexInit method defined by this structure is invoked as
04910 ** part of system initialization by the sqlite3_initialize() function.
04911 ** ^The xMutexInit routine is calle by SQLite exactly once for each
04912 ** effective call to [sqlite3_initialize()].
04913 **
04914 ** ^The xMutexEnd method defined by this structure is invoked as
04915 ** part of system shutdown by the sqlite3_shutdown() function. The
04916 ** implementation of this method is expected to release all outstanding
04917 ** resources obtained by the mutex methods implementation, especially
04918 ** those obtained by the xMutexInit method.  ^The xMutexEnd()
04919 ** interface is invoked exactly once for each call to [sqlite3_shutdown()].
04920 **
04921 ** ^(The remaining seven methods defined by this structure (xMutexAlloc,
04922 ** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and
04923 ** xMutexNotheld) implement the following interfaces (respectively):
04924 **
04925 ** <ul>
04926 **   <li>  [sqlite3_mutex_alloc()] </li>
04927 **   <li>  [sqlite3_mutex_free()] </li>
04928 **   <li>  [sqlite3_mutex_enter()] </li>
04929 **   <li>  [sqlite3_mutex_try()] </li>
04930 **   <li>  [sqlite3_mutex_leave()] </li>
04931 **   <li>  [sqlite3_mutex_held()] </li>
04932 **   <li>  [sqlite3_mutex_notheld()] </li>
04933 ** </ul>)^
04934 **
04935 ** The only difference is that the public sqlite3_XXX functions enumerated
04936 ** above silently ignore any invocations that pass a NULL pointer instead
04937 ** of a valid mutex handle. The implementations of the methods defined
04938 ** by this structure are not required to handle this case, the results
04939 ** of passing a NULL pointer instead of a valid mutex handle are undefined
04940 ** (i.e. it is acceptable to provide an implementation that segfaults if
04941 ** it is passed a NULL pointer).
04942 **
04943 ** The xMutexInit() method must be threadsafe.  ^It must be harmless to
04944 ** invoke xMutexInit() multiple times within the same process and without
04945 ** intervening calls to xMutexEnd().  Second and subsequent calls to
04946 ** xMutexInit() must be no-ops.
04947 **
04948 ** ^xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()]
04949 ** and its associates).  ^Similarly, xMutexAlloc() must not use SQLite memory
04950 ** allocation for a static mutex.  ^However xMutexAlloc() may use SQLite
04951 ** memory allocation for a fast or recursive mutex.
04952 **
04953 ** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is
04954 ** called, but only if the prior call to xMutexInit returned SQLITE_OK.
04955 ** If xMutexInit fails in any way, it is expected to clean up after itself
04956 ** prior to returning.
04957 */
04958 typedef struct sqlite3_mutex_methods sqlite3_mutex_methods;
04959 struct sqlite3_mutex_methods {
04960   int (*xMutexInit)(void);
04961   int (*xMutexEnd)(void);
04962   sqlite3_mutex *(*xMutexAlloc)(int);
04963   void (*xMutexFree)(sqlite3_mutex *);
04964   void (*xMutexEnter)(sqlite3_mutex *);
04965   int (*xMutexTry)(sqlite3_mutex *);
04966   void (*xMutexLeave)(sqlite3_mutex *);
04967   int (*xMutexHeld)(sqlite3_mutex *);
04968   int (*xMutexNotheld)(sqlite3_mutex *);
04969 };
04970 
04971 /*
04972 ** CAPI3REF: Mutex Verification Routines
04973 **
04974 ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
04975 ** are intended for use inside assert() statements.  ^The SQLite core
04976 ** never uses these routines except inside an assert() and applications
04977 ** are advised to follow the lead of the core.  ^The SQLite core only
04978 ** provides implementations for these routines when it is compiled
04979 ** with the SQLITE_DEBUG flag.  ^External mutex implementations
04980 ** are only required to provide these routines if SQLITE_DEBUG is
04981 ** defined and if NDEBUG is not defined.
04982 **
04983 ** ^These routines should return true if the mutex in their argument
04984 ** is held or not held, respectively, by the calling thread.
04985 **
04986 ** ^The implementation is not required to provided versions of these
04987 ** routines that actually work. If the implementation does not provide working
04988 ** versions of these routines, it should at least provide stubs that always
04989 ** return true so that one does not get spurious assertion failures.
04990 **
04991 ** ^If the argument to sqlite3_mutex_held() is a NULL pointer then
04992 ** the routine should return 1.   This seems counter-intuitive since
04993 ** clearly the mutex cannot be held if it does not exist.  But the
04994 ** the reason the mutex does not exist is because the build is not
04995 ** using mutexes.  And we do not want the assert() containing the
04996 ** call to sqlite3_mutex_held() to fail, so a non-zero return is
04997 ** the appropriate thing to do.  ^The sqlite3_mutex_notheld()
04998 ** interface should also return 1 when given a NULL pointer.
04999 */
05000 #ifndef NDEBUG
05001 SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*);
05002 SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*);
05003 #endif
05004 
05005 /*
05006 ** CAPI3REF: Mutex Types
05007 **
05008 ** The [sqlite3_mutex_alloc()] interface takes a single argument
05009 ** which is one of these integer constants.
05010 **
05011 ** The set of static mutexes may change from one SQLite release to the
05012 ** next.  Applications that override the built-in mutex logic must be
05013 ** prepared to accommodate additional static mutexes.
05014 */
05015 #define SQLITE_MUTEX_FAST             0
05016 #define SQLITE_MUTEX_RECURSIVE        1
05017 #define SQLITE_MUTEX_STATIC_MASTER    2
05018 #define SQLITE_MUTEX_STATIC_MEM       3  /* sqlite3_malloc() */
05019 #define SQLITE_MUTEX_STATIC_MEM2      4  /* NOT USED */
05020 #define SQLITE_MUTEX_STATIC_OPEN      4  /* sqlite3BtreeOpen() */
05021 #define SQLITE_MUTEX_STATIC_PRNG      5  /* sqlite3_random() */
05022 #define SQLITE_MUTEX_STATIC_LRU       6  /* lru page list */
05023 #define SQLITE_MUTEX_STATIC_LRU2      7  /* lru page list */
05024 
05025 /*
05026 ** CAPI3REF: Retrieve the mutex for a database connection
05027 **
05028 ** ^This interface returns a pointer the [sqlite3_mutex] object that 
05029 ** serializes access to the [database connection] given in the argument
05030 ** when the [threading mode] is Serialized.
05031 ** ^If the [threading mode] is Single-thread or Multi-thread then this
05032 ** routine returns a NULL pointer.
05033 */
05034 SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*);
05035 
05036 /*
05037 ** CAPI3REF: Low-Level Control Of Database Files
05038 **
05039 ** ^The [sqlite3_file_control()] interface makes a direct call to the
05040 ** xFileControl method for the [sqlite3_io_methods] object associated
05041 ** with a particular database identified by the second argument. ^The
05042 ** name of the database "main" for the main database or "temp" for the
05043 ** TEMP database, or the name that appears after the AS keyword for
05044 ** databases that are added using the [ATTACH] SQL command.
05045 ** ^A NULL pointer can be used in place of "main" to refer to the
05046 ** main database file.
05047 ** ^The third and fourth parameters to this routine
05048 ** are passed directly through to the second and third parameters of
05049 ** the xFileControl method.  ^The return value of the xFileControl
05050 ** method becomes the return value of this routine.
05051 **
05052 ** ^If the second parameter (zDbName) does not match the name of any
05053 ** open database file, then SQLITE_ERROR is returned.  ^This error
05054 ** code is not remembered and will not be recalled by [sqlite3_errcode()]
05055 ** or [sqlite3_errmsg()].  The underlying xFileControl method might
05056 ** also return SQLITE_ERROR.  There is no way to distinguish between
05057 ** an incorrect zDbName and an SQLITE_ERROR return from the underlying
05058 ** xFileControl method.
05059 **
05060 ** See also: [SQLITE_FCNTL_LOCKSTATE]
05061 */
05062 SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
05063 
05064 /*
05065 ** CAPI3REF: Testing Interface
05066 **
05067 ** ^The sqlite3_test_control() interface is used to read out internal
05068 ** state of SQLite and to inject faults into SQLite for testing
05069 ** purposes.  ^The first parameter is an operation code that determines
05070 ** the number, meaning, and operation of all subsequent parameters.
05071 **
05072 ** This interface is not for use by applications.  It exists solely
05073 ** for verifying the correct operation of the SQLite library.  Depending
05074 ** on how the SQLite library is compiled, this interface might not exist.
05075 **
05076 ** The details of the operation codes, their meanings, the parameters
05077 ** they take, and what they do are all subject to change without notice.
05078 ** Unlike most of the SQLite API, this function is not guaranteed to
05079 ** operate consistently from one release to the next.
05080 */
05081 SQLITE_API int sqlite3_test_control(int op, ...);
05082 
05083 /*
05084 ** CAPI3REF: Testing Interface Operation Codes
05085 **
05086 ** These constants are the valid operation code parameters used
05087 ** as the first argument to [sqlite3_test_control()].
05088 **
05089 ** These parameters and their meanings are subject to change
05090 ** without notice.  These values are for testing purposes only.
05091 ** Applications should not use any of these parameters or the
05092 ** [sqlite3_test_control()] interface.
05093 */
05094 #define SQLITE_TESTCTRL_FIRST                    5
05095 #define SQLITE_TESTCTRL_PRNG_SAVE                5
05096 #define SQLITE_TESTCTRL_PRNG_RESTORE             6
05097 #define SQLITE_TESTCTRL_PRNG_RESET               7
05098 #define SQLITE_TESTCTRL_BITVEC_TEST              8
05099 #define SQLITE_TESTCTRL_FAULT_INSTALL            9
05100 #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS     10
05101 #define SQLITE_TESTCTRL_PENDING_BYTE            11
05102 #define SQLITE_TESTCTRL_ASSERT                  12
05103 #define SQLITE_TESTCTRL_ALWAYS                  13
05104 #define SQLITE_TESTCTRL_RESERVE                 14
05105 #define SQLITE_TESTCTRL_OPTIMIZATIONS           15
05106 #define SQLITE_TESTCTRL_ISKEYWORD               16
05107 #define SQLITE_TESTCTRL_PGHDRSZ                 17
05108 #define SQLITE_TESTCTRL_LAST                    17
05109 
05110 /*
05111 ** CAPI3REF: SQLite Runtime Status
05112 **
05113 ** ^This interface is used to retrieve runtime status information
05114 ** about the performance of SQLite, and optionally to reset various
05115 ** highwater marks.  ^The first argument is an integer code for
05116 ** the specific parameter to measure.  ^(Recognized integer codes
05117 ** are of the form [SQLITE_STATUS_MEMORY_USED | SQLITE_STATUS_...].)^
05118 ** ^The current value of the parameter is returned into *pCurrent.
05119 ** ^The highest recorded value is returned in *pHighwater.  ^If the
05120 ** resetFlag is true, then the highest record value is reset after
05121 ** *pHighwater is written.  ^(Some parameters do not record the highest
05122 ** value.  For those parameters
05123 ** nothing is written into *pHighwater and the resetFlag is ignored.)^
05124 ** ^(Other parameters record only the highwater mark and not the current
05125 ** value.  For these latter parameters nothing is written into *pCurrent.)^
05126 **
05127 ** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a
05128 ** non-zero [error code] on failure.
05129 **
05130 ** This routine is threadsafe but is not atomic.  This routine can be
05131 ** called while other threads are running the same or different SQLite
05132 ** interfaces.  However the values returned in *pCurrent and
05133 ** *pHighwater reflect the status of SQLite at different points in time
05134 ** and it is possible that another thread might change the parameter
05135 ** in between the times when *pCurrent and *pHighwater are written.
05136 **
05137 ** See also: [sqlite3_db_status()]
05138 */
05139 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
05140 
05141 
05142 /*
05143 ** CAPI3REF: Status Parameters
05144 **
05145 ** These integer constants designate various run-time status parameters
05146 ** that can be returned by [sqlite3_status()].
05147 **
05148 ** <dl>
05149 ** ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
05150 ** <dd>This parameter is the current amount of memory checked out
05151 ** using [sqlite3_malloc()], either directly or indirectly.  The
05152 ** figure includes calls made to [sqlite3_malloc()] by the application
05153 ** and internal memory usage by the SQLite library.  Scratch memory
05154 ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
05155 ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
05156 ** this parameter.  The amount returned is the sum of the allocation
05157 ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
05158 **
05159 ** ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
05160 ** <dd>This parameter records the largest memory allocation request
05161 ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
05162 ** internal equivalents).  Only the value returned in the
05163 ** *pHighwater parameter to [sqlite3_status()] is of interest.  
05164 ** The value written into the *pCurrent parameter is undefined.</dd>)^
05165 **
05166 ** ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
05167 ** <dd>This parameter records the number of separate memory allocations.</dd>)^
05168 **
05169 ** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
05170 ** <dd>This parameter returns the number of pages used out of the
05171 ** [pagecache memory allocator] that was configured using 
05172 ** [SQLITE_CONFIG_PAGECACHE].  The
05173 ** value returned is in pages, not in bytes.</dd>)^
05174 **
05175 ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
05176 ** <dd>This parameter returns the number of bytes of page cache
05177 ** allocation which could not be statisfied by the [SQLITE_CONFIG_PAGECACHE]
05178 ** buffer and where forced to overflow to [sqlite3_malloc()].  The
05179 ** returned value includes allocations that overflowed because they
05180 ** where too large (they were larger than the "sz" parameter to
05181 ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
05182 ** no space was left in the page cache.</dd>)^
05183 **
05184 ** ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
05185 ** <dd>This parameter records the largest memory allocation request
05186 ** handed to [pagecache memory allocator].  Only the value returned in the
05187 ** *pHighwater parameter to [sqlite3_status()] is of interest.  
05188 ** The value written into the *pCurrent parameter is undefined.</dd>)^
05189 **
05190 ** ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
05191 ** <dd>This parameter returns the number of allocations used out of the
05192 ** [scratch memory allocator] configured using
05193 ** [SQLITE_CONFIG_SCRATCH].  The value returned is in allocations, not
05194 ** in bytes.  Since a single thread may only have one scratch allocation
05195 ** outstanding at time, this parameter also reports the number of threads
05196 ** using scratch memory at the same time.</dd>)^
05197 **
05198 ** ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
05199 ** <dd>This parameter returns the number of bytes of scratch memory
05200 ** allocation which could not be statisfied by the [SQLITE_CONFIG_SCRATCH]
05201 ** buffer and where forced to overflow to [sqlite3_malloc()].  The values
05202 ** returned include overflows because the requested allocation was too
05203 ** larger (that is, because the requested allocation was larger than the
05204 ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
05205 ** slots were available.
05206 ** </dd>)^
05207 **
05208 ** ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
05209 ** <dd>This parameter records the largest memory allocation request
05210 ** handed to [scratch memory allocator].  Only the value returned in the
05211 ** *pHighwater parameter to [sqlite3_status()] is of interest.  
05212 ** The value written into the *pCurrent parameter is undefined.</dd>)^
05213 **
05214 ** ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
05215 ** <dd>This parameter records the deepest parser stack.  It is only
05216 ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
05217 ** </dl>
05218 **
05219 ** New status parameters may be added from time to time.
05220 */
05221 #define SQLITE_STATUS_MEMORY_USED          0
05222 #define SQLITE_STATUS_PAGECACHE_USED       1
05223 #define SQLITE_STATUS_PAGECACHE_OVERFLOW   2
05224 #define SQLITE_STATUS_SCRATCH_USED         3
05225 #define SQLITE_STATUS_SCRATCH_OVERFLOW     4
05226 #define SQLITE_STATUS_MALLOC_SIZE          5
05227 #define SQLITE_STATUS_PARSER_STACK         6
05228 #define SQLITE_STATUS_PAGECACHE_SIZE       7
05229 #define SQLITE_STATUS_SCRATCH_SIZE         8
05230 #define SQLITE_STATUS_MALLOC_COUNT         9
05231 
05232 /*
05233 ** CAPI3REF: Database Connection Status
05234 **
05235 ** ^This interface is used to retrieve runtime status information 
05236 ** about a single [database connection].  ^The first argument is the
05237 ** database connection object to be interrogated.  ^The second argument
05238 ** is an integer constant, taken from the set of
05239 ** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros, that
05240 ** determines the parameter to interrogate.  The set of 
05241 ** [SQLITE_DBSTATUS_LOOKASIDE_USED | SQLITE_DBSTATUS_*] macros is likely
05242 ** to grow in future releases of SQLite.
05243 **
05244 ** ^The current value of the requested parameter is written into *pCur
05245 ** and the highest instantaneous value is written into *pHiwtr.  ^If
05246 ** the resetFlg is true, then the highest instantaneous value is
05247 ** reset back down to the current value.
05248 **
05249 ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
05250 */
05251 SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
05252 
05253 /*
05254 ** CAPI3REF: Status Parameters for database connections
05255 **
05256 ** These constants are the available integer "verbs" that can be passed as
05257 ** the second argument to the [sqlite3_db_status()] interface.
05258 **
05259 ** New verbs may be added in future releases of SQLite. Existing verbs
05260 ** might be discontinued. Applications should check the return code from
05261 ** [sqlite3_db_status()] to make sure that the call worked.
05262 ** The [sqlite3_db_status()] interface will return a non-zero error code
05263 ** if a discontinued or unsupported verb is invoked.
05264 **
05265 ** <dl>
05266 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
05267 ** <dd>This parameter returns the number of lookaside memory slots currently
05268 ** checked out.</dd>)^
05269 **
05270 ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
05271 ** <dd>This parameter returns the approximate number of of bytes of heap
05272 ** memory used by all pager caches associated with the database connection.)^
05273 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
05274 **
05275 ** ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
05276 ** <dd>This parameter returns the approximate number of of bytes of heap
05277 ** memory used to store the schema for all databases associated
05278 ** with the connection - main, temp, and any [ATTACH]-ed databases.)^ 
05279 ** ^The full amount of memory used by the schemas is reported, even if the
05280 ** schema memory is shared with other database connections due to
05281 ** [shared cache mode] being enabled.
05282 ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
05283 **
05284 ** ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
05285 ** <dd>This parameter returns the approximate number of of bytes of heap
05286 ** and lookaside memory used by all prepared statements associated with
05287 ** the database connection.)^
05288 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
05289 ** </dd>
05290 ** </dl>
05291 */
05292 #define SQLITE_DBSTATUS_LOOKASIDE_USED     0
05293 #define SQLITE_DBSTATUS_CACHE_USED         1
05294 #define SQLITE_DBSTATUS_SCHEMA_USED        2
05295 #define SQLITE_DBSTATUS_STMT_USED          3
05296 #define SQLITE_DBSTATUS_MAX                3   /* Largest defined DBSTATUS */
05297 
05298 
05299 /*
05300 ** CAPI3REF: Prepared Statement Status
05301 **
05302 ** ^(Each prepared statement maintains various
05303 ** [SQLITE_STMTSTATUS_SORT | counters] that measure the number
05304 ** of times it has performed specific operations.)^  These counters can
05305 ** be used to monitor the performance characteristics of the prepared
05306 ** statements.  For example, if the number of table steps greatly exceeds
05307 ** the number of table searches or result rows, that would tend to indicate
05308 ** that the prepared statement is using a full table scan rather than
05309 ** an index.  
05310 **
05311 ** ^(This interface is used to retrieve and reset counter values from
05312 ** a [prepared statement].  The first argument is the prepared statement
05313 ** object to be interrogated.  The second argument
05314 ** is an integer code for a specific [SQLITE_STMTSTATUS_SORT | counter]
05315 ** to be interrogated.)^
05316 ** ^The current value of the requested counter is returned.
05317 ** ^If the resetFlg is true, then the counter is reset to zero after this
05318 ** interface call returns.
05319 **
05320 ** See also: [sqlite3_status()] and [sqlite3_db_status()].
05321 */
05322 SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
05323 
05324 /*
05325 ** CAPI3REF: Status Parameters for prepared statements
05326 **
05327 ** These preprocessor macros define integer codes that name counter
05328 ** values associated with the [sqlite3_stmt_status()] interface.
05329 ** The meanings of the various counters are as follows:
05330 **
05331 ** <dl>
05332 ** <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
05333 ** <dd>^This is the number of times that SQLite has stepped forward in
05334 ** a table as part of a full table scan.  Large numbers for this counter
05335 ** may indicate opportunities for performance improvement through 
05336 ** careful use of indices.</dd>
05337 **
05338 ** <dt>SQLITE_STMTSTATUS_SORT</dt>
05339 ** <dd>^This is the number of sort operations that have occurred.
05340 ** A non-zero value in this counter may indicate an opportunity to
05341 ** improvement performance through careful use of indices.</dd>
05342 **
05343 ** <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
05344 ** <dd>^This is the number of rows inserted into transient indices that
05345 ** were created automatically in order to help joins run faster.
05346 ** A non-zero value in this counter may indicate an opportunity to
05347 ** improvement performance by adding permanent indices that do not
05348 ** need to be reinitialized each time the statement is run.</dd>
05349 **
05350 ** </dl>
05351 */
05352 #define SQLITE_STMTSTATUS_FULLSCAN_STEP     1
05353 #define SQLITE_STMTSTATUS_SORT              2
05354 #define SQLITE_STMTSTATUS_AUTOINDEX         3
05355 
05356 /*
05357 ** CAPI3REF: Custom Page Cache Object
05358 **
05359 ** The sqlite3_pcache type is opaque.  It is implemented by
05360 ** the pluggable module.  The SQLite core has no knowledge of
05361 ** its size or internal structure and never deals with the
05362 ** sqlite3_pcache object except by holding and passing pointers
05363 ** to the object.
05364 **
05365 ** See [sqlite3_pcache_methods] for additional information.
05366 */
05367 typedef struct sqlite3_pcache sqlite3_pcache;
05368 
05369 /*
05370 ** CAPI3REF: Application Defined Page Cache.
05371 ** KEYWORDS: {page cache}
05372 **
05373 ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
05374 ** register an alternative page cache implementation by passing in an 
05375 ** instance of the sqlite3_pcache_methods structure.)^ The majority of the 
05376 ** heap memory used by SQLite is used by the page cache to cache data read 
05377 ** from, or ready to be written to, the database file. By implementing a 
05378 ** custom page cache using this API, an application can control more 
05379 ** precisely the amount of memory consumed by SQLite, the way in which 
05380 ** that memory is allocated and released, and the policies used to 
05381 ** determine exactly which parts of a database file are cached and for 
05382 ** how long.
05383 **
05384 ** ^(The contents of the sqlite3_pcache_methods structure are copied to an
05385 ** internal buffer by SQLite within the call to [sqlite3_config].  Hence
05386 ** the application may discard the parameter after the call to
05387 ** [sqlite3_config()] returns.)^
05388 **
05389 ** ^The xInit() method is called once for each call to [sqlite3_initialize()]
05390 ** (usually only once during the lifetime of the process). ^(The xInit()
05391 ** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^
05392 ** ^The xInit() method can set up up global structures and/or any mutexes
05393 ** required by the custom page cache implementation. 
05394 **
05395 ** ^The xShutdown() method is called from within [sqlite3_shutdown()], 
05396 ** if the application invokes this API. It can be used to clean up 
05397 ** any outstanding resources before process shutdown, if required.
05398 **
05399 ** ^SQLite holds a [SQLITE_MUTEX_RECURSIVE] mutex when it invokes
05400 ** the xInit method, so the xInit method need not be threadsafe.  ^The
05401 ** xShutdown method is only called from [sqlite3_shutdown()] so it does
05402 ** not need to be threadsafe either.  All other methods must be threadsafe
05403 ** in multithreaded applications.
05404 **
05405 ** ^SQLite will never invoke xInit() more than once without an intervening
05406 ** call to xShutdown().
05407 **
05408 ** ^The xCreate() method is used to construct a new cache instance.  SQLite
05409 ** will typically create one cache instance for each open database file,
05410 ** though this is not guaranteed. ^The
05411 ** first parameter, szPage, is the size in bytes of the pages that must
05412 ** be allocated by the cache.  ^szPage will not be a power of two.  ^szPage
05413 ** will the page size of the database file that is to be cached plus an
05414 ** increment (here called "R") of about 100 or 200.  ^SQLite will use the
05415 ** extra R bytes on each page to store metadata about the underlying
05416 ** database page on disk.  The value of R depends
05417 ** on the SQLite version, the target platform, and how SQLite was compiled.
05418 ** ^R is constant for a particular build of SQLite.  ^The second argument to
05419 ** xCreate(), bPurgeable, is true if the cache being created will
05420 ** be used to cache database pages of a file stored on disk, or
05421 ** false if it is used for an in-memory database. ^The cache implementation
05422 ** does not have to do anything special based with the value of bPurgeable;
05423 ** it is purely advisory.  ^On a cache where bPurgeable is false, SQLite will
05424 ** never invoke xUnpin() except to deliberately delete a page.
05425 ** ^In other words, a cache created with bPurgeable set to false will
05426 ** never contain any unpinned pages.
05427 **
05428 ** ^(The xCachesize() method may be called at any time by SQLite to set the
05429 ** suggested maximum cache-size (number of pages stored by) the cache
05430 ** instance passed as the first argument. This is the value configured using
05431 ** the SQLite "[PRAGMA cache_size]" command.)^  ^As with the bPurgeable
05432 ** parameter, the implementation is not required to do anything with this
05433 ** value; it is advisory only.
05434 **
05435 ** ^The xPagecount() method should return the number of pages currently
05436 ** stored in the cache.
05437 ** 
05438 ** ^The xFetch() method is used to fetch a page and return a pointer to it. 
05439 ** ^A 'page', in this context, is a buffer of szPage bytes aligned at an
05440 ** 8-byte boundary. ^The page to be fetched is determined by the key. ^The
05441 ** mimimum key value is 1. After it has been retrieved using xFetch, the page 
05442 ** is considered to be "pinned".
05443 **
05444 ** ^If the requested page is already in the page cache, then the page cache
05445 ** implementation must return a pointer to the page buffer with its content
05446 ** intact.  ^(If the requested page is not already in the cache, then the
05447 ** behavior of the cache implementation is determined by the value of the
05448 ** createFlag parameter passed to xFetch, according to the following table:
05449 **
05450 ** <table border=1 width=85% align=center>
05451 ** <tr><th> createFlag <th> Behaviour when page is not already in cache
05452 ** <tr><td> 0 <td> Do not allocate a new page.  Return NULL.
05453 ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.
05454 **                 Otherwise return NULL.
05455 ** <tr><td> 2 <td> Make every effort to allocate a new page.  Only return
05456 **                 NULL if allocating a new page is effectively impossible.
05457 ** </table>)^
05458 **
05459 ** SQLite will normally invoke xFetch() with a createFlag of 0 or 1.  If
05460 ** a call to xFetch() with createFlag==1 returns NULL, then SQLite will
05461 ** attempt to unpin one or more cache pages by spilling the content of
05462 ** pinned pages to disk and synching the operating system disk cache. After
05463 ** attempting to unpin pages, the xFetch() method will be invoked again with
05464 ** a createFlag of 2.
05465 **
05466 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
05467 ** as its second argument. ^(If the third parameter, discard, is non-zero,
05468 ** then the page should be evicted from the cache. In this case SQLite 
05469 ** assumes that the next time the page is retrieved from the cache using
05470 ** the xFetch() method, it will be zeroed.)^ ^If the discard parameter is
05471 ** zero, then the page is considered to be unpinned. ^The cache implementation
05472 ** may choose to evict unpinned pages at any time.
05473 **
05474 ** ^(The cache is not required to perform any reference counting. A single 
05475 ** call to xUnpin() unpins the page regardless of the number of prior calls 
05476 ** to xFetch().)^
05477 **
05478 ** ^The xRekey() method is used to change the key value associated with the
05479 ** page passed as the second argument from oldKey to newKey. ^If the cache
05480 ** previously contains an entry associated with newKey, it should be
05481 ** discarded. ^Any prior cache entry associated with newKey is guaranteed not
05482 ** to be pinned.
05483 **
05484 ** ^When SQLite calls the xTruncate() method, the cache must discard all
05485 ** existing cache entries with page numbers (keys) greater than or equal
05486 ** to the value of the iLimit parameter passed to xTruncate(). ^If any
05487 ** of these pages are pinned, they are implicitly unpinned, meaning that
05488 ** they can be safely discarded.
05489 **
05490 ** ^The xDestroy() method is used to delete a cache allocated by xCreate().
05491 ** All resources associated with the specified cache should be freed. ^After
05492 ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
05493 ** handle invalid, and will not use it with any other sqlite3_pcache_methods
05494 ** functions.
05495 */
05496 typedef struct sqlite3_pcache_methods sqlite3_pcache_methods;
05497 struct sqlite3_pcache_methods {
05498   void *pArg;
05499   int (*xInit)(void*);
05500   void (*xShutdown)(void*);
05501   sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable);
05502   void (*xCachesize)(sqlite3_pcache*, int nCachesize);
05503   int (*xPagecount)(sqlite3_pcache*);
05504   void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
05505   void (*xUnpin)(sqlite3_pcache*, void*, int discard);
05506   void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey);
05507   void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
05508   void (*xDestroy)(sqlite3_pcache*);
05509 };
05510 
05511 /*
05512 ** CAPI3REF: Online Backup Object
05513 **
05514 ** The sqlite3_backup object records state information about an ongoing
05515 ** online backup operation.  ^The sqlite3_backup object is created by
05516 ** a call to [sqlite3_backup_init()] and is destroyed by a call to
05517 ** [sqlite3_backup_finish()].
05518 **
05519 ** See Also: [Using the SQLite Online Backup API]
05520 */
05521 typedef struct sqlite3_backup sqlite3_backup;
05522 
05523 /*
05524 ** CAPI3REF: Online Backup API.
05525 **
05526 ** The backup API copies the content of one database into another.
05527 ** It is useful either for creating backups of databases or
05528 ** for copying in-memory databases to or from persistent files. 
05529 **
05530 ** See Also: [Using the SQLite Online Backup API]
05531 **
05532 ** ^Exclusive access is required to the destination database for the 
05533 ** duration of the operation. ^However the source database is only
05534 ** read-locked while it is actually being read; it is not locked
05535 ** continuously for the entire backup operation. ^Thus, the backup may be
05536 ** performed on a live source database without preventing other users from
05537 ** reading or writing to the source database while the backup is underway.
05538 ** 
05539 ** ^(To perform a backup operation: 
05540 **   <ol>
05541 **     <li><b>sqlite3_backup_init()</b> is called once to initialize the
05542 **         backup, 
05543 **     <li><b>sqlite3_backup_step()</b> is called one or more times to transfer 
05544 **         the data between the two databases, and finally
05545 **     <li><b>sqlite3_backup_finish()</b> is called to release all resources 
05546 **         associated with the backup operation. 
05547 **   </ol>)^
05548 ** There should be exactly one call to sqlite3_backup_finish() for each
05549 ** successful call to sqlite3_backup_init().
05550 **
05551 ** <b>sqlite3_backup_init()</b>
05552 **
05553 ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the 
05554 ** [database connection] associated with the destination database 
05555 ** and the database name, respectively.
05556 ** ^The database name is "main" for the main database, "temp" for the
05557 ** temporary database, or the name specified after the AS keyword in
05558 ** an [ATTACH] statement for an attached database.
05559 ** ^The S and M arguments passed to 
05560 ** sqlite3_backup_init(D,N,S,M) identify the [database connection]
05561 ** and database name of the source database, respectively.
05562 ** ^The source and destination [database connections] (parameters S and D)
05563 ** must be different or else sqlite3_backup_init(D,N,S,M) will file with
05564 ** an error.
05565 **
05566 ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
05567 ** returned and an error code and error message are store3d in the
05568 ** destination [database connection] D.
05569 ** ^The error code and message for the failed call to sqlite3_backup_init()
05570 ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
05571 ** [sqlite3_errmsg16()] functions.
05572 ** ^A successful call to sqlite3_backup_init() returns a pointer to an
05573 ** [sqlite3_backup] object.
05574 ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and
05575 ** sqlite3_backup_finish() functions to perform the specified backup 
05576 ** operation.
05577 **
05578 ** <b>sqlite3_backup_step()</b>
05579 **
05580 ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between 
05581 ** the source and destination databases specified by [sqlite3_backup] object B.
05582 ** ^If N is negative, all remaining source pages are copied. 
05583 ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
05584 ** are still more pages to be copied, then the function resturns [SQLITE_OK].
05585 ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
05586 ** from source to destination, then it returns [SQLITE_DONE].
05587 ** ^If an error occurs while running sqlite3_backup_step(B,N),
05588 ** then an [error code] is returned. ^As well as [SQLITE_OK] and
05589 ** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
05590 ** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an
05591 ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code.
05592 **
05593 ** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
05594 ** <ol>
05595 ** <li> the destination database was opened read-only, or
05596 ** <li> the destination database is using write-ahead-log journaling
05597 ** and the destination and source page sizes differ, or
05598 ** <li> The destination database is an in-memory database and the
05599 ** destination and source page sizes differ.
05600 ** </ol>)^
05601 **
05602 ** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
05603 ** the [sqlite3_busy_handler | busy-handler function]
05604 ** is invoked (if one is specified). ^If the 
05605 ** busy-handler returns non-zero before the lock is available, then 
05606 ** [SQLITE_BUSY] is returned to the caller. ^In this case the call to
05607 ** sqlite3_backup_step() can be retried later. ^If the source
05608 ** [database connection]
05609 ** is being used to write to the source database when sqlite3_backup_step()
05610 ** is called, then [SQLITE_LOCKED] is returned immediately. ^Again, in this
05611 ** case the call to sqlite3_backup_step() can be retried later on. ^(If
05612 ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or
05613 ** [SQLITE_READONLY] is returned, then 
05614 ** there is no point in retrying the call to sqlite3_backup_step(). These 
05615 ** errors are considered fatal.)^  The application must accept 
05616 ** that the backup operation has failed and pass the backup operation handle 
05617 ** to the sqlite3_backup_finish() to release associated resources.
05618 **
05619 ** ^The first call to sqlite3_backup_step() obtains an exclusive lock
05620 ** on the destination file. ^The exclusive lock is not released until either 
05621 ** sqlite3_backup_finish() is called or the backup operation is complete 
05622 ** and sqlite3_backup_step() returns [SQLITE_DONE].  ^Every call to
05623 ** sqlite3_backup_step() obtains a [shared lock] on the source database that
05624 ** lasts for the duration of the sqlite3_backup_step() call.
05625 ** ^Because the source database is not locked between calls to
05626 ** sqlite3_backup_step(), the source database may be modified mid-way
05627 ** through the backup process.  ^If the source database is modified by an
05628 ** external process or via a database connection other than the one being
05629 ** used by the backup operation, then the backup will be automatically
05630 ** restarted by the next call to sqlite3_backup_step(). ^If the source 
05631 ** database is modified by the using the same database connection as is used
05632 ** by the backup operation, then the backup database is automatically
05633 ** updated at the same time.
05634 **
05635 ** <b>sqlite3_backup_finish()</b>
05636 **
05637 ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the 
05638 ** application wishes to abandon the backup operation, the application
05639 ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish().
05640 ** ^The sqlite3_backup_finish() interfaces releases all
05641 ** resources associated with the [sqlite3_backup] object. 
05642 ** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any
05643 ** active write-transaction on the destination database is rolled back.
05644 ** The [sqlite3_backup] object is invalid
05645 ** and may not be used following a call to sqlite3_backup_finish().
05646 **
05647 ** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
05648 ** sqlite3_backup_step() errors occurred, regardless or whether or not
05649 ** sqlite3_backup_step() completed.
05650 ** ^If an out-of-memory condition or IO error occurred during any prior
05651 ** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
05652 ** sqlite3_backup_finish() returns the corresponding [error code].
05653 **
05654 ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
05655 ** is not a permanent error and does not affect the return value of
05656 ** sqlite3_backup_finish().
05657 **
05658 ** <b>sqlite3_backup_remaining(), sqlite3_backup_pagecount()</b>
05659 **
05660 ** ^Each call to sqlite3_backup_step() sets two values inside
05661 ** the [sqlite3_backup] object: the number of pages still to be backed
05662 ** up and the total number of pages in the source database file.
05663 ** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces
05664 ** retrieve these two values, respectively.
05665 **
05666 ** ^The values returned by these functions are only updated by
05667 ** sqlite3_backup_step(). ^If the source database is modified during a backup
05668 ** operation, then the values are not updated to account for any extra
05669 ** pages that need to be updated or the size of the source database file
05670 ** changing.
05671 **
05672 ** <b>Concurrent Usage of Database Handles</b>
05673 **
05674 ** ^The source [database connection] may be used by the application for other
05675 ** purposes while a backup operation is underway or being initialized.
05676 ** ^If SQLite is compiled and configured to support threadsafe database
05677 ** connections, then the source database connection may be used concurrently
05678 ** from within other threads.
05679 **
05680 ** However, the application must guarantee that the destination 
05681 ** [database connection] is not passed to any other API (by any thread) after 
05682 ** sqlite3_backup_init() is called and before the corresponding call to
05683 ** sqlite3_backup_finish().  SQLite does not currently check to see
05684 ** if the application incorrectly accesses the destination [database connection]
05685 ** and so no error code is reported, but the operations may malfunction
05686 ** nevertheless.  Use of the destination database connection while a
05687 ** backup is in progress might also also cause a mutex deadlock.
05688 **
05689 ** If running in [shared cache mode], the application must
05690 ** guarantee that the shared cache used by the destination database
05691 ** is not accessed while the backup is running. In practice this means
05692 ** that the application must guarantee that the disk file being 
05693 ** backed up to is not accessed by any connection within the process,
05694 ** not just the specific connection that was passed to sqlite3_backup_init().
05695 **
05696 ** The [sqlite3_backup] object itself is partially threadsafe. Multiple 
05697 ** threads may safely make multiple concurrent calls to sqlite3_backup_step().
05698 ** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount()
05699 ** APIs are not strictly speaking threadsafe. If they are invoked at the
05700 ** same time as another thread is invoking sqlite3_backup_step() it is
05701 ** possible that they return invalid values.
05702 */
05703 SQLITE_API sqlite3_backup *sqlite3_backup_init(
05704   sqlite3 *pDest,                        /* Destination database handle */
05705   const char *zDestName,                 /* Destination database name */
05706   sqlite3 *pSource,                      /* Source database handle */
05707   const char *zSourceName                /* Source database name */
05708 );
05709 SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage);
05710 SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p);
05711 SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);
05712 SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);
05713 
05714 /*
05715 ** CAPI3REF: Unlock Notification
05716 **
05717 ** ^When running in shared-cache mode, a database operation may fail with
05718 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
05719 ** individual tables within the shared-cache cannot be obtained. See
05720 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking. 
05721 ** ^This API may be used to register a callback that SQLite will invoke 
05722 ** when the connection currently holding the required lock relinquishes it.
05723 ** ^This API is only available if the library was compiled with the
05724 ** [SQLITE_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined.
05725 **
05726 ** See Also: [Using the SQLite Unlock Notification Feature].
05727 **
05728 ** ^Shared-cache locks are released when a database connection concludes
05729 ** its current transaction, either by committing it or rolling it back. 
05730 **
05731 ** ^When a connection (known as the blocked connection) fails to obtain a
05732 ** shared-cache lock and SQLITE_LOCKED is returned to the caller, the
05733 ** identity of the database connection (the blocking connection) that
05734 ** has locked the required resource is stored internally. ^After an 
05735 ** application receives an SQLITE_LOCKED error, it may call the
05736 ** sqlite3_unlock_notify() method with the blocked connection handle as 
05737 ** the first argument to register for a callback that will be invoked
05738 ** when the blocking connections current transaction is concluded. ^The
05739 ** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
05740 ** call that concludes the blocking connections transaction.
05741 **
05742 ** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
05743 ** there is a chance that the blocking connection will have already
05744 ** concluded its transaction by the time sqlite3_unlock_notify() is invoked.
05745 ** If this happens, then the specified callback is invoked immediately,
05746 ** from within the call to sqlite3_unlock_notify().)^
05747 **
05748 ** ^If the blocked connection is attempting to obtain a write-lock on a
05749 ** shared-cache table, and more than one other connection currently holds
05750 ** a read-lock on the same table, then SQLite arbitrarily selects one of 
05751 ** the other connections to use as the blocking connection.
05752 **
05753 ** ^(There may be at most one unlock-notify callback registered by a 
05754 ** blocked connection. If sqlite3_unlock_notify() is called when the
05755 ** blocked connection already has a registered unlock-notify callback,
05756 ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
05757 ** called with a NULL pointer as its second argument, then any existing
05758 ** unlock-notify callback is canceled. ^The blocked connections 
05759 ** unlock-notify callback may also be canceled by closing the blocked
05760 ** connection using [sqlite3_close()].
05761 **
05762 ** The unlock-notify callback is not reentrant. If an application invokes
05763 ** any sqlite3_xxx API functions from within an unlock-notify callback, a
05764 ** crash or deadlock may be the result.
05765 **
05766 ** ^Unless deadlock is detected (see below), sqlite3_unlock_notify() always
05767 ** returns SQLITE_OK.
05768 **
05769 ** <b>Callback Invocation Details</b>
05770 **
05771 ** When an unlock-notify callback is registered, the application provides a 
05772 ** single void* pointer that is passed to the callback when it is invoked.
05773 ** However, the signature of the callback function allows SQLite to pass
05774 ** it an array of void* context pointers. The first argument passed to
05775 ** an unlock-notify callback is a pointer to an array of void* pointers,
05776 ** and the second is the number of entries in the array.
05777 **
05778 ** When a blocking connections transaction is concluded, there may be
05779 ** more than one blocked connection that has registered for an unlock-notify
05780 ** callback. ^If two or more such blocked connections have specified the
05781 ** same callback function, then instead of invoking the callback function
05782 ** multiple times, it is invoked once with the set of void* context pointers
05783 ** specified by the blocked connections bundled together into an array.
05784 ** This gives the application an opportunity to prioritize any actions 
05785 ** related to the set of unblocked database connections.
05786 **
05787 ** <b>Deadlock Detection</b>
05788 **
05789 ** Assuming that after registering for an unlock-notify callback a 
05790 ** database waits for the callback to be issued before taking any further
05791 ** action (a reasonable assumption), then using this API may cause the
05792 ** application to deadlock. For example, if connection X is waiting for
05793 ** connection Y's transaction to be concluded, and similarly connection
05794 ** Y is waiting on connection X's transaction, then neither connection
05795 ** will proceed and the system may remain deadlocked indefinitely.
05796 **
05797 ** To avoid this scenario, the sqlite3_unlock_notify() performs deadlock
05798 ** detection. ^If a given call to sqlite3_unlock_notify() would put the
05799 ** system in a deadlocked state, then SQLITE_LOCKED is returned and no
05800 ** unlock-notify callback is registered. The system is said to be in
05801 ** a deadlocked state if connection A has registered for an unlock-notify
05802 ** callback on the conclusion of connection B's transaction, and connection
05803 ** B has itself registered for an unlock-notify callback when connection
05804 ** A's transaction is concluded. ^Indirect deadlock is also detected, so
05805 ** the system is also considered to be deadlocked if connection B has
05806 ** registered for an unlock-notify callback on the conclusion of connection
05807 ** C's transaction, where connection C is waiting on connection A. ^Any
05808 ** number of levels of indirection are allowed.
05809 **
05810 ** <b>The "DROP TABLE" Exception</b>
05811 **
05812 ** When a call to [sqlite3_step()] returns SQLITE_LOCKED, it is almost 
05813 ** always appropriate to call sqlite3_unlock_notify(). There is however,
05814 ** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement,
05815 ** SQLite checks if there are any currently executing SELECT statements
05816 ** that belong to the same connection. If there are, SQLITE_LOCKED is
05817 ** returned. In this case there is no "blocking connection", so invoking
05818 ** sqlite3_unlock_notify() results in the unlock-notify callback being
05819 ** invoked immediately. If the application then re-attempts the "DROP TABLE"
05820 ** or "DROP INDEX" query, an infinite loop might be the result.
05821 **
05822 ** One way around this problem is to check the extended error code returned
05823 ** by an sqlite3_step() call. ^(If there is a blocking connection, then the
05824 ** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in
05825 ** the special "DROP TABLE/INDEX" case, the extended error code is just 
05826 ** SQLITE_LOCKED.)^
05827 */
05828 SQLITE_API int sqlite3_unlock_notify(
05829   sqlite3 *pBlocked,                          /* Waiting connection */
05830   void (*xNotify)(void **apArg, int nArg),    /* Callback function to invoke */
05831   void *pNotifyArg                            /* Argument to pass to xNotify */
05832 );
05833 
05834 
05835 /*
05836 ** CAPI3REF: String Comparison
05837 **
05838 ** ^The [sqlite3_strnicmp()] API allows applications and extensions to
05839 ** compare the contents of two buffers containing UTF-8 strings in a
05840 ** case-independent fashion, using the same definition of case independence 
05841 ** that SQLite uses internally when comparing identifiers.
05842 */
05843 SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
05844 
05845 /*
05846 ** CAPI3REF: Error Logging Interface
05847 **
05848 ** ^The [sqlite3_log()] interface writes a message into the error log
05849 ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
05850 ** ^If logging is enabled, the zFormat string and subsequent arguments are
05851 ** used with [sqlite3_snprintf()] to generate the final output string.
05852 **
05853 ** The sqlite3_log() interface is intended for use by extensions such as
05854 ** virtual tables, collating functions, and SQL functions.  While there is
05855 ** nothing to prevent an application from calling sqlite3_log(), doing so
05856 ** is considered bad form.
05857 **
05858 ** The zFormat string must not be NULL.
05859 **
05860 ** To avoid deadlocks and other threading problems, the sqlite3_log() routine
05861 ** will not use dynamically allocated memory.  The log message is stored in
05862 ** a fixed-length buffer on the stack.  If the log message is longer than
05863 ** a few hundred characters, it will be truncated to the length of the
05864 ** buffer.
05865 */
05866 SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...);
05867 
05868 /*
05869 ** CAPI3REF: Write-Ahead Log Commit Hook
05870 **
05871 ** ^The [sqlite3_wal_hook()] function is used to register a callback that
05872 ** will be invoked each time a database connection commits data to a
05873 ** [write-ahead log] (i.e. whenever a transaction is committed in
05874 ** [journal_mode | journal_mode=WAL mode]). 
05875 **
05876 ** ^The callback is invoked by SQLite after the commit has taken place and 
05877 ** the associated write-lock on the database released, so the implementation 
05878 ** may read, write or [checkpoint] the database as required.
05879 **
05880 ** ^The first parameter passed to the callback function when it is invoked
05881 ** is a copy of the third parameter passed to sqlite3_wal_hook() when
05882 ** registering the callback. ^The second is a copy of the database handle.
05883 ** ^The third parameter is the name of the database that was written to -
05884 ** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter
05885 ** is the number of pages currently in the write-ahead log file,
05886 ** including those that were just committed.
05887 **
05888 ** The callback function should normally return [SQLITE_OK].  ^If an error
05889 ** code is returned, that error will propagate back up through the
05890 ** SQLite code base to cause the statement that provoked the callback
05891 ** to report an error, though the commit will have still occurred. If the
05892 ** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value
05893 ** that does not correspond to any valid SQLite error code, the results
05894 ** are undefined.
05895 **
05896 ** A single database handle may have at most a single write-ahead log callback 
05897 ** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any
05898 ** previously registered write-ahead log callback. ^Note that the
05899 ** [sqlite3_wal_autocheckpoint()] interface and the
05900 ** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will
05901 ** those overwrite any prior [sqlite3_wal_hook()] settings.
05902 */
05903 SQLITE_API void *sqlite3_wal_hook(
05904   sqlite3*, 
05905   int(*)(void *,sqlite3*,const char*,int),
05906   void*
05907 );
05908 
05909 /*
05910 ** CAPI3REF: Configure an auto-checkpoint
05911 **
05912 ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
05913 ** [sqlite3_wal_hook()] that causes any database on [database connection] D
05914 ** to automatically [checkpoint]
05915 ** after committing a transaction if there are N or
05916 ** more frames in the [write-ahead log] file.  ^Passing zero or 
05917 ** a negative value as the nFrame parameter disables automatic
05918 ** checkpoints entirely.
05919 **
05920 ** ^The callback registered by this function replaces any existing callback
05921 ** registered using [sqlite3_wal_hook()].  ^Likewise, registering a callback
05922 ** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
05923 ** configured by this function.
05924 **
05925 ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
05926 ** from SQL.
05927 **
05928 ** ^Every new [database connection] defaults to having the auto-checkpoint
05929 ** enabled with a threshold of 1000 pages.  The use of this interface
05930 ** is only necessary if the default setting is found to be suboptimal
05931 ** for a particular application.
05932 */
05933 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
05934 
05935 /*
05936 ** CAPI3REF: Checkpoint a database
05937 **
05938 ** ^The [sqlite3_wal_checkpoint(D,X)] interface causes database named X
05939 ** on [database connection] D to be [checkpointed].  ^If X is NULL or an
05940 ** empty string, then a checkpoint is run on all databases of
05941 ** connection D.  ^If the database connection D is not in
05942 ** [WAL | write-ahead log mode] then this interface is a harmless no-op.
05943 **
05944 ** ^The [wal_checkpoint pragma] can be used to invoke this interface
05945 ** from SQL.  ^The [sqlite3_wal_autocheckpoint()] interface and the
05946 ** [wal_autocheckpoint pragma] can be used to cause this interface to be
05947 ** run whenever the WAL reaches a certain size threshold.
05948 */
05949 SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
05950 
05951 /*
05952 ** Undo the hack that converts floating point types to integer for
05953 ** builds on processors without floating point support.
05954 */
05955 #ifdef SQLITE_OMIT_FLOATING_POINT
05956 # undef double
05957 #endif
05958 
05959 #ifdef __cplusplus
05960 }  /* End of the 'extern "C"' block */
05961 #endif
05962 #endif
05963 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines