"Fossies" - the Fresh Open Source Software Archive

Member "cells-3.0.3/vendor/github.com/mattn/go-sqlite3/sqlite3-binding.h" (30 Nov 2021, 496554 Bytes) of package /linux/misc/pydio-cells-3.0.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

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