sqlite3-binding.h raw

   1  #ifndef USE_LIBSQLITE3
   2  /*
   3  ** 2001-09-15
   4  **
   5  ** The author disclaims copyright to this source code.  In place of
   6  ** a legal notice, here is a blessing:
   7  **
   8  **    May you do good and not evil.
   9  **    May you find forgiveness for yourself and forgive others.
  10  **    May you share freely, never taking more than you give.
  11  **
  12  *************************************************************************
  13  ** This header file defines the interface that the SQLite library
  14  ** presents to client programs.  If a C-function, structure, datatype,
  15  ** or constant definition does not appear in this file, then it is
  16  ** not a published API of SQLite, is subject to change without
  17  ** notice, and should not be referenced by programs that use SQLite.
  18  **
  19  ** Some of the definitions that are in this file are marked as
  20  ** "experimental".  Experimental interfaces are normally new
  21  ** features recently added to SQLite.  We do not anticipate changes
  22  ** to experimental interfaces but reserve the right to make minor changes
  23  ** if experience from use "in the wild" suggest such changes are prudent.
  24  **
  25  ** The official C-language API documentation for SQLite is derived
  26  ** from comments in this file.  This file is the authoritative source
  27  ** on how SQLite interfaces are supposed to operate.
  28  **
  29  ** The name of this file under configuration management is "sqlite.h.in".
  30  ** The makefile makes some minor changes to this file (such as inserting
  31  ** the version number) and changes its name to "sqlite3.h" as
  32  ** part of the build process.
  33  */
  34  #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  ** Facilitate override of interface linkage and calling conventions.
  48  ** Be aware that these macros may not be used within this particular
  49  ** translation of the amalgamation and its associated header file.
  50  **
  51  ** The SQLITE_EXTERN and SQLITE_API macros are used to instruct the
  52  ** compiler that the target identifier should have external linkage.
  53  **
  54  ** The SQLITE_CDECL macro is used to set the calling convention for
  55  ** public functions that accept a variable number of arguments.
  56  **
  57  ** The SQLITE_APICALL macro is used to set the calling convention for
  58  ** public functions that accept a fixed number of arguments.
  59  **
  60  ** The SQLITE_STDCALL macro is no longer used and is now deprecated.
  61  **
  62  ** The SQLITE_CALLBACK macro is used to set the calling convention for
  63  ** function pointers.
  64  **
  65  ** The SQLITE_SYSAPI macro is used to set the calling convention for
  66  ** functions provided by the operating system.
  67  **
  68  ** Currently, the SQLITE_CDECL, SQLITE_APICALL, SQLITE_CALLBACK, and
  69  ** SQLITE_SYSAPI macros are used only when building for environments
  70  ** that require non-default calling conventions.
  71  */
  72  #ifndef SQLITE_EXTERN
  73  # define SQLITE_EXTERN extern
  74  #endif
  75  #ifndef SQLITE_API
  76  # define SQLITE_API
  77  #endif
  78  #ifndef SQLITE_CDECL
  79  # define SQLITE_CDECL
  80  #endif
  81  #ifndef SQLITE_APICALL
  82  # define SQLITE_APICALL
  83  #endif
  84  #ifndef SQLITE_STDCALL
  85  # define SQLITE_STDCALL SQLITE_APICALL
  86  #endif
  87  #ifndef SQLITE_CALLBACK
  88  # define SQLITE_CALLBACK
  89  #endif
  90  #ifndef SQLITE_SYSAPI
  91  # define SQLITE_SYSAPI
  92  #endif
  93  
  94  /*
  95  ** These no-op macros are used in front of interfaces to mark those
  96  ** interfaces as either deprecated or experimental.  New applications
  97  ** should not use deprecated interfaces - they are supported for backwards
  98  ** compatibility only.  Application writers should be aware that
  99  ** experimental interfaces are subject to change in point releases.
 100  **
 101  ** These macros used to resolve to various kinds of compiler magic that
 102  ** would generate warning messages when they were used.  But that
 103  ** compiler magic ended up generating such a flurry of bug reports
 104  ** that we have taken it all out and gone back to using simple
 105  ** noop macros.
 106  */
 107  #define SQLITE_DEPRECATED
 108  #define SQLITE_EXPERIMENTAL
 109  
 110  /*
 111  ** Ensure these symbols were not defined by some previous header file.
 112  */
 113  #ifdef SQLITE_VERSION
 114  # undef SQLITE_VERSION
 115  #endif
 116  #ifdef SQLITE_VERSION_NUMBER
 117  # undef SQLITE_VERSION_NUMBER
 118  #endif
 119  
 120  /*
 121  ** CAPI3REF: Compile-Time Library Version Numbers
 122  **
 123  ** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header
 124  ** evaluates to a string literal that is the SQLite version in the
 125  ** format "X.Y.Z" where X is the major version number (always 3 for
 126  ** SQLite3) and Y is the minor version number and Z is the release number.)^
 127  ** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer
 128  ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same
 129  ** numbers used in [SQLITE_VERSION].)^
 130  ** The SQLITE_VERSION_NUMBER for any given release of SQLite will also
 131  ** be larger than the release from which it is derived.  Either Y will
 132  ** be held constant and Z will be incremented or else Y will be incremented
 133  ** and Z will be reset to zero.
 134  **
 135  ** Since [version 3.6.18] ([dateof:3.6.18]),
 136  ** SQLite source code has been stored in the
 137  ** <a href="http://fossil-scm.org/">Fossil configuration management
 138  ** system</a>.  ^The SQLITE_SOURCE_ID macro evaluates to
 139  ** a string which identifies a particular check-in of SQLite
 140  ** within its configuration management system.  ^The SQLITE_SOURCE_ID
 141  ** string contains the date and time of the check-in (UTC) and a SHA1
 142  ** or SHA3-256 hash of the entire source tree.  If the source code has
 143  ** been edited in any way since it was last checked in, then the last
 144  ** four hexadecimal digits of the hash may be modified.
 145  **
 146  ** See also: [sqlite3_libversion()],
 147  ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
 148  ** [sqlite_version()] and [sqlite_source_id()].
 149  */
 150  #define SQLITE_VERSION        "3.50.4"
 151  #define SQLITE_VERSION_NUMBER 3050004
 152  #define SQLITE_SOURCE_ID      "2025-07-30 19:33:53 4d8adfb30e03f9cf27f800a2c1ba3c48fb4ca1b08b0f5ed59a4d5ecbf45e20a3"
 153  
 154  /*
 155  ** CAPI3REF: Run-Time Library Version Numbers
 156  ** KEYWORDS: sqlite3_version sqlite3_sourceid
 157  **
 158  ** These interfaces provide the same information as the [SQLITE_VERSION],
 159  ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
 160  ** but are associated with the library instead of the header file.  ^(Cautious
 161  ** programmers might include assert() statements in their application to
 162  ** verify that values returned by these interfaces match the macros in
 163  ** the header, and thus ensure that the application is
 164  ** compiled with matching library and header files.
 165  **
 166  ** <blockquote><pre>
 167  ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
 168  ** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 );
 169  ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
 170  ** </pre></blockquote>)^
 171  **
 172  ** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
 173  ** macro.  ^The sqlite3_libversion() function returns a pointer to the
 174  ** to the sqlite3_version[] string constant.  The sqlite3_libversion()
 175  ** function is provided for use in DLLs since DLL users usually do not have
 176  ** direct access to string constants within the DLL.  ^The
 177  ** sqlite3_libversion_number() function returns an integer equal to
 178  ** [SQLITE_VERSION_NUMBER].  ^(The sqlite3_sourceid() function returns
 179  ** a pointer to a string constant whose value is the same as the
 180  ** [SQLITE_SOURCE_ID] C preprocessor macro.  Except if SQLite is built
 181  ** using an edited copy of [the amalgamation], then the last four characters
 182  ** of the hash might be different from [SQLITE_SOURCE_ID].)^
 183  **
 184  ** See also: [sqlite_version()] and [sqlite_source_id()].
 185  */
 186  SQLITE_API SQLITE_EXTERN const char sqlite3_version[];
 187  SQLITE_API const char *sqlite3_libversion(void);
 188  SQLITE_API const char *sqlite3_sourceid(void);
 189  SQLITE_API int sqlite3_libversion_number(void);
 190  
 191  /*
 192  ** CAPI3REF: Run-Time Library Compilation Options Diagnostics
 193  **
 194  ** ^The sqlite3_compileoption_used() function returns 0 or 1
 195  ** indicating whether the specified option was defined at
 196  ** compile time.  ^The SQLITE_ prefix may be omitted from the
 197  ** option name passed to sqlite3_compileoption_used().
 198  **
 199  ** ^The sqlite3_compileoption_get() function allows iterating
 200  ** over the list of options that were defined at compile time by
 201  ** returning the N-th compile time option string.  ^If N is out of range,
 202  ** sqlite3_compileoption_get() returns a NULL pointer.  ^The SQLITE_
 203  ** prefix is omitted from any strings returned by
 204  ** sqlite3_compileoption_get().
 205  **
 206  ** ^Support for the diagnostic functions sqlite3_compileoption_used()
 207  ** and sqlite3_compileoption_get() may be omitted by specifying the
 208  ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.
 209  **
 210  ** See also: SQL functions [sqlite_compileoption_used()] and
 211  ** [sqlite_compileoption_get()] and the [compile_options pragma].
 212  */
 213  #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
 214  SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
 215  SQLITE_API const char *sqlite3_compileoption_get(int N);
 216  #else
 217  # define sqlite3_compileoption_used(X) 0
 218  # define sqlite3_compileoption_get(X)  ((void*)0)
 219  #endif
 220  
 221  /*
 222  ** CAPI3REF: Test To See If The Library Is Threadsafe
 223  **
 224  ** ^The sqlite3_threadsafe() function returns zero if and only if
 225  ** SQLite was compiled with mutexing code omitted due to the
 226  ** [SQLITE_THREADSAFE] compile-time option being set to 0.
 227  **
 228  ** SQLite can be compiled with or without mutexes.  When
 229  ** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes
 230  ** are enabled and SQLite is threadsafe.  When the
 231  ** [SQLITE_THREADSAFE] macro is 0,
 232  ** the mutexes are omitted.  Without the mutexes, it is not safe
 233  ** to use SQLite concurrently from more than one thread.
 234  **
 235  ** Enabling mutexes incurs a measurable performance penalty.
 236  ** So if speed is of utmost importance, it makes sense to disable
 237  ** the mutexes.  But for maximum safety, mutexes should be enabled.
 238  ** ^The default behavior is for mutexes to be enabled.
 239  **
 240  ** This interface can be used by an application to make sure that the
 241  ** version of SQLite that it is linking against was compiled with
 242  ** the desired setting of the [SQLITE_THREADSAFE] macro.
 243  **
 244  ** This interface only reports on the compile-time mutex setting
 245  ** of the [SQLITE_THREADSAFE] flag.  If SQLite is compiled with
 246  ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but
 247  ** can be fully or partially disabled using a call to [sqlite3_config()]
 248  ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],
 249  ** or [SQLITE_CONFIG_SERIALIZED].  ^(The return value of the
 250  ** sqlite3_threadsafe() function shows only the compile-time setting of
 251  ** thread safety, not any run-time changes to that setting made by
 252  ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()
 253  ** is unchanged by calls to sqlite3_config().)^
 254  **
 255  ** See the [threading mode] documentation for additional information.
 256  */
 257  SQLITE_API int sqlite3_threadsafe(void);
 258  
 259  /*
 260  ** CAPI3REF: Database Connection Handle
 261  ** KEYWORDS: {database connection} {database connections}
 262  **
 263  ** Each open SQLite database is represented by a pointer to an instance of
 264  ** the opaque structure named "sqlite3".  It is useful to think of an sqlite3
 265  ** pointer as an object.  The [sqlite3_open()], [sqlite3_open16()], and
 266  ** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]
 267  ** and [sqlite3_close_v2()] are its destructors.  There are many other
 268  ** interfaces (such as
 269  ** [sqlite3_prepare_v2()], [sqlite3_create_function()], and
 270  ** [sqlite3_busy_timeout()] to name but three) that are methods on an
 271  ** sqlite3 object.
 272  */
 273  typedef struct sqlite3 sqlite3;
 274  
 275  /*
 276  ** CAPI3REF: 64-Bit Integer Types
 277  ** KEYWORDS: sqlite_int64 sqlite_uint64
 278  **
 279  ** Because there is no cross-platform way to specify 64-bit integer types
 280  ** SQLite includes typedefs for 64-bit signed and unsigned integers.
 281  **
 282  ** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions.
 283  ** The sqlite_int64 and sqlite_uint64 types are supported for backwards
 284  ** compatibility only.
 285  **
 286  ** ^The sqlite3_int64 and sqlite_int64 types can store integer values
 287  ** between -9223372036854775808 and +9223372036854775807 inclusive.  ^The
 288  ** sqlite3_uint64 and sqlite_uint64 types can store integer values
 289  ** between 0 and +18446744073709551615 inclusive.
 290  */
 291  #ifdef SQLITE_INT64_TYPE
 292    typedef SQLITE_INT64_TYPE sqlite_int64;
 293  # ifdef SQLITE_UINT64_TYPE
 294      typedef SQLITE_UINT64_TYPE sqlite_uint64;
 295  # else
 296      typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
 297  # endif
 298  #elif defined(_MSC_VER) || defined(__BORLANDC__)
 299    typedef __int64 sqlite_int64;
 300    typedef unsigned __int64 sqlite_uint64;
 301  #else
 302    typedef long long int sqlite_int64;
 303    typedef unsigned long long int sqlite_uint64;
 304  #endif
 305  typedef sqlite_int64 sqlite3_int64;
 306  typedef sqlite_uint64 sqlite3_uint64;
 307  
 308  /*
 309  ** If compiling for a processor that lacks floating point support,
 310  ** substitute integer for floating-point.
 311  */
 312  #ifdef SQLITE_OMIT_FLOATING_POINT
 313  # define double sqlite3_int64
 314  #endif
 315  
 316  /*
 317  ** CAPI3REF: Closing A Database Connection
 318  ** DESTRUCTOR: sqlite3
 319  **
 320  ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors
 321  ** for the [sqlite3] object.
 322  ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if
 323  ** the [sqlite3] object is successfully destroyed and all associated
 324  ** resources are deallocated.
 325  **
 326  ** Ideally, applications should [sqlite3_finalize | finalize] all
 327  ** [prepared statements], [sqlite3_blob_close | close] all [BLOB handles], and
 328  ** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated
 329  ** with the [sqlite3] object prior to attempting to close the object.
 330  ** ^If the database connection is associated with unfinalized prepared
 331  ** statements, BLOB handlers, and/or unfinished sqlite3_backup objects then
 332  ** sqlite3_close() will leave the database connection open and return
 333  ** [SQLITE_BUSY]. ^If sqlite3_close_v2() is called with unfinalized prepared
 334  ** statements, unclosed BLOB handlers, and/or unfinished sqlite3_backups,
 335  ** it returns [SQLITE_OK] regardless, but instead of deallocating the database
 336  ** connection immediately, it marks the database connection as an unusable
 337  ** "zombie" and makes arrangements to automatically deallocate the database
 338  ** connection after all prepared statements are finalized, all BLOB handles
 339  ** are closed, and all backups have finished. The sqlite3_close_v2() interface
 340  ** is intended for use with host languages that are garbage collected, and
 341  ** where the order in which destructors are called is arbitrary.
 342  **
 343  ** ^If an [sqlite3] object is destroyed while a transaction is open,
 344  ** the transaction is automatically rolled back.
 345  **
 346  ** The C parameter to [sqlite3_close(C)] and [sqlite3_close_v2(C)]
 347  ** must be either a NULL
 348  ** pointer or an [sqlite3] object pointer obtained
 349  ** from [sqlite3_open()], [sqlite3_open16()], or
 350  ** [sqlite3_open_v2()], and not previously closed.
 351  ** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer
 352  ** argument is a harmless no-op.
 353  */
 354  SQLITE_API int sqlite3_close(sqlite3*);
 355  SQLITE_API int sqlite3_close_v2(sqlite3*);
 356  
 357  /*
 358  ** The type for a callback function.
 359  ** This is legacy and deprecated.  It is included for historical
 360  ** compatibility and is not documented.
 361  */
 362  typedef int (*sqlite3_callback)(void*,int,char**, char**);
 363  
 364  /*
 365  ** CAPI3REF: One-Step Query Execution Interface
 366  ** METHOD: sqlite3
 367  **
 368  ** The sqlite3_exec() interface is a convenience wrapper around
 369  ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],
 370  ** that allows an application to run multiple statements of SQL
 371  ** without having to use a lot of C code.
 372  **
 373  ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
 374  ** semicolon-separate SQL statements passed into its 2nd argument,
 375  ** in the context of the [database connection] passed in as its 1st
 376  ** argument.  ^If the callback function of the 3rd argument to
 377  ** sqlite3_exec() is not NULL, then it is invoked for each result row
 378  ** coming out of the evaluated SQL statements.  ^The 4th argument to
 379  ** sqlite3_exec() is relayed through to the 1st argument of each
 380  ** callback invocation.  ^If the callback pointer to sqlite3_exec()
 381  ** is NULL, then no callback is ever invoked and result rows are
 382  ** ignored.
 383  **
 384  ** ^If an error occurs while evaluating the SQL statements passed into
 385  ** sqlite3_exec(), then execution of the current statement stops and
 386  ** subsequent statements are skipped.  ^If the 5th parameter to sqlite3_exec()
 387  ** is not NULL then any error message is written into memory obtained
 388  ** from [sqlite3_malloc()] and passed back through the 5th parameter.
 389  ** To avoid memory leaks, the application should invoke [sqlite3_free()]
 390  ** on error message strings returned through the 5th parameter of
 391  ** sqlite3_exec() after the error message string is no longer needed.
 392  ** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors
 393  ** occur, then sqlite3_exec() sets the pointer in its 5th parameter to
 394  ** NULL before returning.
 395  **
 396  ** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec()
 397  ** routine returns SQLITE_ABORT without invoking the callback again and
 398  ** without running any subsequent SQL statements.
 399  **
 400  ** ^The 2nd argument to the sqlite3_exec() callback function is the
 401  ** number of columns in the result.  ^The 3rd argument to the sqlite3_exec()
 402  ** callback is an array of pointers to strings obtained as if from
 403  ** [sqlite3_column_text()], one for each column.  ^If an element of a
 404  ** result row is NULL then the corresponding string pointer for the
 405  ** sqlite3_exec() callback is a NULL pointer.  ^The 4th argument to the
 406  ** sqlite3_exec() callback is an array of pointers to strings where each
 407  ** entry represents the name of corresponding result column as obtained
 408  ** from [sqlite3_column_name()].
 409  **
 410  ** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer
 411  ** to an empty string, or a pointer that contains only whitespace and/or
 412  ** SQL comments, then no SQL statements are evaluated and the database
 413  ** is not changed.
 414  **
 415  ** Restrictions:
 416  **
 417  ** <ul>
 418  ** <li> The application must ensure that the 1st parameter to sqlite3_exec()
 419  **      is a valid and open [database connection].
 420  ** <li> The application must not close the [database connection] specified by
 421  **      the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.
 422  ** <li> The application must not modify the SQL statement text passed into
 423  **      the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.
 424  ** <li> The application must not dereference the arrays or string pointers
 425  **       passed as the 3rd and 4th callback parameters after it returns.
 426  ** </ul>
 427  */
 428  SQLITE_API int sqlite3_exec(
 429    sqlite3*,                                  /* An open database */
 430    const char *sql,                           /* SQL to be evaluated */
 431    int (*callback)(void*,int,char**,char**),  /* Callback function */
 432    void *,                                    /* 1st argument to callback */
 433    char **errmsg                              /* Error msg written here */
 434  );
 435  
 436  /*
 437  ** CAPI3REF: Result Codes
 438  ** KEYWORDS: {result code definitions}
 439  **
 440  ** Many SQLite functions return an integer result code from the set shown
 441  ** here in order to indicate success or failure.
 442  **
 443  ** New error codes may be added in future versions of SQLite.
 444  **
 445  ** See also: [extended result code definitions]
 446  */
 447  #define SQLITE_OK           0   /* Successful result */
 448  /* beginning-of-error-codes */
 449  #define SQLITE_ERROR        1   /* Generic error */
 450  #define SQLITE_INTERNAL     2   /* Internal logic error in SQLite */
 451  #define SQLITE_PERM         3   /* Access permission denied */
 452  #define SQLITE_ABORT        4   /* Callback routine requested an abort */
 453  #define SQLITE_BUSY         5   /* The database file is locked */
 454  #define SQLITE_LOCKED       6   /* A table in the database is locked */
 455  #define SQLITE_NOMEM        7   /* A malloc() failed */
 456  #define SQLITE_READONLY     8   /* Attempt to write a readonly database */
 457  #define SQLITE_INTERRUPT    9   /* Operation terminated by sqlite3_interrupt()*/
 458  #define SQLITE_IOERR       10   /* Some kind of disk I/O error occurred */
 459  #define SQLITE_CORRUPT     11   /* The database disk image is malformed */
 460  #define SQLITE_NOTFOUND    12   /* Unknown opcode in sqlite3_file_control() */
 461  #define SQLITE_FULL        13   /* Insertion failed because database is full */
 462  #define SQLITE_CANTOPEN    14   /* Unable to open the database file */
 463  #define SQLITE_PROTOCOL    15   /* Database lock protocol error */
 464  #define SQLITE_EMPTY       16   /* Internal use only */
 465  #define SQLITE_SCHEMA      17   /* The database schema changed */
 466  #define SQLITE_TOOBIG      18   /* String or BLOB exceeds size limit */
 467  #define SQLITE_CONSTRAINT  19   /* Abort due to constraint violation */
 468  #define SQLITE_MISMATCH    20   /* Data type mismatch */
 469  #define SQLITE_MISUSE      21   /* Library used incorrectly */
 470  #define SQLITE_NOLFS       22   /* Uses OS features not supported on host */
 471  #define SQLITE_AUTH        23   /* Authorization denied */
 472  #define SQLITE_FORMAT      24   /* Not used */
 473  #define SQLITE_RANGE       25   /* 2nd parameter to sqlite3_bind out of range */
 474  #define SQLITE_NOTADB      26   /* File opened that is not a database file */
 475  #define SQLITE_NOTICE      27   /* Notifications from sqlite3_log() */
 476  #define SQLITE_WARNING     28   /* Warnings from sqlite3_log() */
 477  #define SQLITE_ROW         100  /* sqlite3_step() has another row ready */
 478  #define SQLITE_DONE        101  /* sqlite3_step() has finished executing */
 479  /* end-of-error-codes */
 480  
 481  /*
 482  ** CAPI3REF: Extended Result Codes
 483  ** KEYWORDS: {extended result code definitions}
 484  **
 485  ** In its default configuration, SQLite API routines return one of 30 integer
 486  ** [result codes].  However, experience has shown that many of
 487  ** these result codes are too coarse-grained.  They do not provide as
 488  ** much information about problems as programmers might like.  In an effort to
 489  ** address this, newer versions of SQLite (version 3.3.8 [dateof:3.3.8]
 490  ** and later) include
 491  ** support for additional result codes that provide more detailed information
 492  ** about errors. These [extended result codes] are enabled or disabled
 493  ** on a per database connection basis using the
 494  ** [sqlite3_extended_result_codes()] API.  Or, the extended code for
 495  ** the most recent error can be obtained using
 496  ** [sqlite3_extended_errcode()].
 497  */
 498  #define SQLITE_ERROR_MISSING_COLLSEQ   (SQLITE_ERROR | (1<<8))
 499  #define SQLITE_ERROR_RETRY             (SQLITE_ERROR | (2<<8))
 500  #define SQLITE_ERROR_SNAPSHOT          (SQLITE_ERROR | (3<<8))
 501  #define SQLITE_IOERR_READ              (SQLITE_IOERR | (1<<8))
 502  #define SQLITE_IOERR_SHORT_READ        (SQLITE_IOERR | (2<<8))
 503  #define SQLITE_IOERR_WRITE             (SQLITE_IOERR | (3<<8))
 504  #define SQLITE_IOERR_FSYNC             (SQLITE_IOERR | (4<<8))
 505  #define SQLITE_IOERR_DIR_FSYNC         (SQLITE_IOERR | (5<<8))
 506  #define SQLITE_IOERR_TRUNCATE          (SQLITE_IOERR | (6<<8))
 507  #define SQLITE_IOERR_FSTAT             (SQLITE_IOERR | (7<<8))
 508  #define SQLITE_IOERR_UNLOCK            (SQLITE_IOERR | (8<<8))
 509  #define SQLITE_IOERR_RDLOCK            (SQLITE_IOERR | (9<<8))
 510  #define SQLITE_IOERR_DELETE            (SQLITE_IOERR | (10<<8))
 511  #define SQLITE_IOERR_BLOCKED           (SQLITE_IOERR | (11<<8))
 512  #define SQLITE_IOERR_NOMEM             (SQLITE_IOERR | (12<<8))
 513  #define SQLITE_IOERR_ACCESS            (SQLITE_IOERR | (13<<8))
 514  #define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))
 515  #define SQLITE_IOERR_LOCK              (SQLITE_IOERR | (15<<8))
 516  #define SQLITE_IOERR_CLOSE             (SQLITE_IOERR | (16<<8))
 517  #define SQLITE_IOERR_DIR_CLOSE         (SQLITE_IOERR | (17<<8))
 518  #define SQLITE_IOERR_SHMOPEN           (SQLITE_IOERR | (18<<8))
 519  #define SQLITE_IOERR_SHMSIZE           (SQLITE_IOERR | (19<<8))
 520  #define SQLITE_IOERR_SHMLOCK           (SQLITE_IOERR | (20<<8))
 521  #define SQLITE_IOERR_SHMMAP            (SQLITE_IOERR | (21<<8))
 522  #define SQLITE_IOERR_SEEK              (SQLITE_IOERR | (22<<8))
 523  #define SQLITE_IOERR_DELETE_NOENT      (SQLITE_IOERR | (23<<8))
 524  #define SQLITE_IOERR_MMAP              (SQLITE_IOERR | (24<<8))
 525  #define SQLITE_IOERR_GETTEMPPATH       (SQLITE_IOERR | (25<<8))
 526  #define SQLITE_IOERR_CONVPATH          (SQLITE_IOERR | (26<<8))
 527  #define SQLITE_IOERR_VNODE             (SQLITE_IOERR | (27<<8))
 528  #define SQLITE_IOERR_AUTH              (SQLITE_IOERR | (28<<8))
 529  #define SQLITE_IOERR_BEGIN_ATOMIC      (SQLITE_IOERR | (29<<8))
 530  #define SQLITE_IOERR_COMMIT_ATOMIC     (SQLITE_IOERR | (30<<8))
 531  #define SQLITE_IOERR_ROLLBACK_ATOMIC   (SQLITE_IOERR | (31<<8))
 532  #define SQLITE_IOERR_DATA              (SQLITE_IOERR | (32<<8))
 533  #define SQLITE_IOERR_CORRUPTFS         (SQLITE_IOERR | (33<<8))
 534  #define SQLITE_IOERR_IN_PAGE           (SQLITE_IOERR | (34<<8))
 535  #define SQLITE_LOCKED_SHAREDCACHE      (SQLITE_LOCKED |  (1<<8))
 536  #define SQLITE_LOCKED_VTAB             (SQLITE_LOCKED |  (2<<8))
 537  #define SQLITE_BUSY_RECOVERY           (SQLITE_BUSY   |  (1<<8))
 538  #define SQLITE_BUSY_SNAPSHOT           (SQLITE_BUSY   |  (2<<8))
 539  #define SQLITE_BUSY_TIMEOUT            (SQLITE_BUSY   |  (3<<8))
 540  #define SQLITE_CANTOPEN_NOTEMPDIR      (SQLITE_CANTOPEN | (1<<8))
 541  #define SQLITE_CANTOPEN_ISDIR          (SQLITE_CANTOPEN | (2<<8))
 542  #define SQLITE_CANTOPEN_FULLPATH       (SQLITE_CANTOPEN | (3<<8))
 543  #define SQLITE_CANTOPEN_CONVPATH       (SQLITE_CANTOPEN | (4<<8))
 544  #define SQLITE_CANTOPEN_DIRTYWAL       (SQLITE_CANTOPEN | (5<<8)) /* Not Used */
 545  #define SQLITE_CANTOPEN_SYMLINK        (SQLITE_CANTOPEN | (6<<8))
 546  #define SQLITE_CORRUPT_VTAB            (SQLITE_CORRUPT | (1<<8))
 547  #define SQLITE_CORRUPT_SEQUENCE        (SQLITE_CORRUPT | (2<<8))
 548  #define SQLITE_CORRUPT_INDEX           (SQLITE_CORRUPT | (3<<8))
 549  #define SQLITE_READONLY_RECOVERY       (SQLITE_READONLY | (1<<8))
 550  #define SQLITE_READONLY_CANTLOCK       (SQLITE_READONLY | (2<<8))
 551  #define SQLITE_READONLY_ROLLBACK       (SQLITE_READONLY | (3<<8))
 552  #define SQLITE_READONLY_DBMOVED        (SQLITE_READONLY | (4<<8))
 553  #define SQLITE_READONLY_CANTINIT       (SQLITE_READONLY | (5<<8))
 554  #define SQLITE_READONLY_DIRECTORY      (SQLITE_READONLY | (6<<8))
 555  #define SQLITE_ABORT_ROLLBACK          (SQLITE_ABORT | (2<<8))
 556  #define SQLITE_CONSTRAINT_CHECK        (SQLITE_CONSTRAINT | (1<<8))
 557  #define SQLITE_CONSTRAINT_COMMITHOOK   (SQLITE_CONSTRAINT | (2<<8))
 558  #define SQLITE_CONSTRAINT_FOREIGNKEY   (SQLITE_CONSTRAINT | (3<<8))
 559  #define SQLITE_CONSTRAINT_FUNCTION     (SQLITE_CONSTRAINT | (4<<8))
 560  #define SQLITE_CONSTRAINT_NOTNULL      (SQLITE_CONSTRAINT | (5<<8))
 561  #define SQLITE_CONSTRAINT_PRIMARYKEY   (SQLITE_CONSTRAINT | (6<<8))
 562  #define SQLITE_CONSTRAINT_TRIGGER      (SQLITE_CONSTRAINT | (7<<8))
 563  #define SQLITE_CONSTRAINT_UNIQUE       (SQLITE_CONSTRAINT | (8<<8))
 564  #define SQLITE_CONSTRAINT_VTAB         (SQLITE_CONSTRAINT | (9<<8))
 565  #define SQLITE_CONSTRAINT_ROWID        (SQLITE_CONSTRAINT |(10<<8))
 566  #define SQLITE_CONSTRAINT_PINNED       (SQLITE_CONSTRAINT |(11<<8))
 567  #define SQLITE_CONSTRAINT_DATATYPE     (SQLITE_CONSTRAINT |(12<<8))
 568  #define SQLITE_NOTICE_RECOVER_WAL      (SQLITE_NOTICE | (1<<8))
 569  #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
 570  #define SQLITE_NOTICE_RBU              (SQLITE_NOTICE | (3<<8))
 571  #define SQLITE_WARNING_AUTOINDEX       (SQLITE_WARNING | (1<<8))
 572  #define SQLITE_AUTH_USER               (SQLITE_AUTH | (1<<8))
 573  #define SQLITE_OK_LOAD_PERMANENTLY     (SQLITE_OK | (1<<8))
 574  #define SQLITE_OK_SYMLINK              (SQLITE_OK | (2<<8)) /* internal use only */
 575  
 576  /*
 577  ** CAPI3REF: Flags For File Open Operations
 578  **
 579  ** These bit values are intended for use in the
 580  ** 3rd parameter to the [sqlite3_open_v2()] interface and
 581  ** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
 582  **
 583  ** Only those flags marked as "Ok for sqlite3_open_v2()" may be
 584  ** used as the third argument to the [sqlite3_open_v2()] interface.
 585  ** The other flags have historically been ignored by sqlite3_open_v2(),
 586  ** though future versions of SQLite might change so that an error is
 587  ** raised if any of the disallowed bits are passed into sqlite3_open_v2().
 588  ** Applications should not depend on the historical behavior.
 589  **
 590  ** Note in particular that passing the SQLITE_OPEN_EXCLUSIVE flag into
 591  ** [sqlite3_open_v2()] does *not* cause the underlying database file
 592  ** to be opened using O_EXCL.  Passing SQLITE_OPEN_EXCLUSIVE into
 593  ** [sqlite3_open_v2()] has historically be a no-op and might become an
 594  ** error in future versions of SQLite.
 595  */
 596  #define SQLITE_OPEN_READONLY         0x00000001  /* Ok for sqlite3_open_v2() */
 597  #define SQLITE_OPEN_READWRITE        0x00000002  /* Ok for sqlite3_open_v2() */
 598  #define SQLITE_OPEN_CREATE           0x00000004  /* Ok for sqlite3_open_v2() */
 599  #define SQLITE_OPEN_DELETEONCLOSE    0x00000008  /* VFS only */
 600  #define SQLITE_OPEN_EXCLUSIVE        0x00000010  /* VFS only */
 601  #define SQLITE_OPEN_AUTOPROXY        0x00000020  /* VFS only */
 602  #define SQLITE_OPEN_URI              0x00000040  /* Ok for sqlite3_open_v2() */
 603  #define SQLITE_OPEN_MEMORY           0x00000080  /* Ok for sqlite3_open_v2() */
 604  #define SQLITE_OPEN_MAIN_DB          0x00000100  /* VFS only */
 605  #define SQLITE_OPEN_TEMP_DB          0x00000200  /* VFS only */
 606  #define SQLITE_OPEN_TRANSIENT_DB     0x00000400  /* VFS only */
 607  #define SQLITE_OPEN_MAIN_JOURNAL     0x00000800  /* VFS only */
 608  #define SQLITE_OPEN_TEMP_JOURNAL     0x00001000  /* VFS only */
 609  #define SQLITE_OPEN_SUBJOURNAL       0x00002000  /* VFS only */
 610  #define SQLITE_OPEN_SUPER_JOURNAL    0x00004000  /* VFS only */
 611  #define SQLITE_OPEN_NOMUTEX          0x00008000  /* Ok for sqlite3_open_v2() */
 612  #define SQLITE_OPEN_FULLMUTEX        0x00010000  /* Ok for sqlite3_open_v2() */
 613  #define SQLITE_OPEN_SHAREDCACHE      0x00020000  /* Ok for sqlite3_open_v2() */
 614  #define SQLITE_OPEN_PRIVATECACHE     0x00040000  /* Ok for sqlite3_open_v2() */
 615  #define SQLITE_OPEN_WAL              0x00080000  /* VFS only */
 616  #define SQLITE_OPEN_NOFOLLOW         0x01000000  /* Ok for sqlite3_open_v2() */
 617  #define SQLITE_OPEN_EXRESCODE        0x02000000  /* Extended result codes */
 618  
 619  /* Reserved:                         0x00F00000 */
 620  /* Legacy compatibility: */
 621  #define SQLITE_OPEN_MASTER_JOURNAL   0x00004000  /* VFS only */
 622  
 623  
 624  /*
 625  ** CAPI3REF: Device Characteristics
 626  **
 627  ** The xDeviceCharacteristics method of the [sqlite3_io_methods]
 628  ** object returns an integer which is a vector of these
 629  ** bit values expressing I/O characteristics of the mass storage
 630  ** device that holds the file that the [sqlite3_io_methods]
 631  ** refers to.
 632  **
 633  ** The SQLITE_IOCAP_ATOMIC property means that all writes of
 634  ** any size are atomic.  The SQLITE_IOCAP_ATOMICnnn values
 635  ** mean that writes of blocks that are nnn bytes in size and
 636  ** are aligned to an address which is an integer multiple of
 637  ** nnn are atomic.  The SQLITE_IOCAP_SAFE_APPEND value means
 638  ** that when data is appended to a file, the data is appended
 639  ** first then the size of the file is extended, never the other
 640  ** way around.  The SQLITE_IOCAP_SEQUENTIAL property means that
 641  ** information is written to disk in the same order as calls
 642  ** to xWrite().  The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
 643  ** after reboot following a crash or power loss, the only bytes in a
 644  ** file that were written at the application level might have changed
 645  ** and that adjacent bytes, even bytes within the same sector are
 646  ** guaranteed to be unchanged.  The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
 647  ** flag indicates that a file cannot be deleted when open.  The
 648  ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
 649  ** read-only media and cannot be changed even by processes with
 650  ** elevated privileges.
 651  **
 652  ** The SQLITE_IOCAP_BATCH_ATOMIC property means that the underlying
 653  ** filesystem supports doing multiple write operations atomically when those
 654  ** write operations are bracketed by [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] and
 655  ** [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE].
 656  **
 657  ** The SQLITE_IOCAP_SUBPAGE_READ property means that it is ok to read
 658  ** from the database file in amounts that are not a multiple of the
 659  ** page size and that do not begin at a page boundary.  Without this
 660  ** property, SQLite is careful to only do full-page reads and write
 661  ** on aligned pages, with the one exception that it will do a sub-page
 662  ** read of the first page to access the database header.
 663  */
 664  #define SQLITE_IOCAP_ATOMIC                 0x00000001
 665  #define SQLITE_IOCAP_ATOMIC512              0x00000002
 666  #define SQLITE_IOCAP_ATOMIC1K               0x00000004
 667  #define SQLITE_IOCAP_ATOMIC2K               0x00000008
 668  #define SQLITE_IOCAP_ATOMIC4K               0x00000010
 669  #define SQLITE_IOCAP_ATOMIC8K               0x00000020
 670  #define SQLITE_IOCAP_ATOMIC16K              0x00000040
 671  #define SQLITE_IOCAP_ATOMIC32K              0x00000080
 672  #define SQLITE_IOCAP_ATOMIC64K              0x00000100
 673  #define SQLITE_IOCAP_SAFE_APPEND            0x00000200
 674  #define SQLITE_IOCAP_SEQUENTIAL             0x00000400
 675  #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN  0x00000800
 676  #define SQLITE_IOCAP_POWERSAFE_OVERWRITE    0x00001000
 677  #define SQLITE_IOCAP_IMMUTABLE              0x00002000
 678  #define SQLITE_IOCAP_BATCH_ATOMIC           0x00004000
 679  #define SQLITE_IOCAP_SUBPAGE_READ           0x00008000
 680  
 681  /*
 682  ** CAPI3REF: File Locking Levels
 683  **
 684  ** SQLite uses one of these integer values as the second
 685  ** argument to calls it makes to the xLock() and xUnlock() methods
 686  ** of an [sqlite3_io_methods] object.  These values are ordered from
 687  ** lest restrictive to most restrictive.
 688  **
 689  ** The argument to xLock() is always SHARED or higher.  The argument to
 690  ** xUnlock is either SHARED or NONE.
 691  */
 692  #define SQLITE_LOCK_NONE          0       /* xUnlock() only */
 693  #define SQLITE_LOCK_SHARED        1       /* xLock() or xUnlock() */
 694  #define SQLITE_LOCK_RESERVED      2       /* xLock() only */
 695  #define SQLITE_LOCK_PENDING       3       /* xLock() only */
 696  #define SQLITE_LOCK_EXCLUSIVE     4       /* xLock() only */
 697  
 698  /*
 699  ** CAPI3REF: Synchronization Type Flags
 700  **
 701  ** When SQLite invokes the xSync() method of an
 702  ** [sqlite3_io_methods] object it uses a combination of
 703  ** these integer values as the second argument.
 704  **
 705  ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the
 706  ** sync operation only needs to flush data to mass storage.  Inode
 707  ** information need not be flushed. If the lower four bits of the flag
 708  ** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics.
 709  ** If the lower four bits equal SQLITE_SYNC_FULL, that means
 710  ** to use Mac OS X style fullsync instead of fsync().
 711  **
 712  ** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags
 713  ** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL
 714  ** settings.  The [synchronous pragma] determines when calls to the
 715  ** xSync VFS method occur and applies uniformly across all platforms.
 716  ** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how
 717  ** energetic or rigorous or forceful the sync operations are and
 718  ** only make a difference on Mac OSX for the default SQLite code.
 719  ** (Third-party VFS implementations might also make the distinction
 720  ** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the
 721  ** operating systems natively supported by SQLite, only Mac OSX
 722  ** cares about the difference.)
 723  */
 724  #define SQLITE_SYNC_NORMAL        0x00002
 725  #define SQLITE_SYNC_FULL          0x00003
 726  #define SQLITE_SYNC_DATAONLY      0x00010
 727  
 728  /*
 729  ** CAPI3REF: OS Interface Open File Handle
 730  **
 731  ** An [sqlite3_file] object represents an open file in the
 732  ** [sqlite3_vfs | OS interface layer].  Individual OS interface
 733  ** implementations will
 734  ** want to subclass this object by appending additional fields
 735  ** for their own use.  The pMethods entry is a pointer to an
 736  ** [sqlite3_io_methods] object that defines methods for performing
 737  ** I/O operations on the open file.
 738  */
 739  typedef struct sqlite3_file sqlite3_file;
 740  struct sqlite3_file {
 741    const struct sqlite3_io_methods *pMethods;  /* Methods for an open file */
 742  };
 743  
 744  /*
 745  ** CAPI3REF: OS Interface File Virtual Methods Object
 746  **
 747  ** Every file opened by the [sqlite3_vfs.xOpen] method populates an
 748  ** [sqlite3_file] object (or, more commonly, a subclass of the
 749  ** [sqlite3_file] object) with a pointer to an instance of this object.
 750  ** This object defines the methods used to perform various operations
 751  ** against the open file represented by the [sqlite3_file] object.
 752  **
 753  ** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element
 754  ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method
 755  ** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed.  The
 756  ** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen]
 757  ** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element
 758  ** to NULL.
 759  **
 760  ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or
 761  ** [SQLITE_SYNC_FULL].  The first choice is the normal fsync().
 762  ** The second choice is a Mac OS X style fullsync.  The [SQLITE_SYNC_DATAONLY]
 763  ** flag may be ORed in to indicate that only the data of the file
 764  ** and not its inode needs to be synced.
 765  **
 766  ** The integer values to xLock() and xUnlock() are one of
 767  ** <ul>
 768  ** <li> [SQLITE_LOCK_NONE],
 769  ** <li> [SQLITE_LOCK_SHARED],
 770  ** <li> [SQLITE_LOCK_RESERVED],
 771  ** <li> [SQLITE_LOCK_PENDING], or
 772  ** <li> [SQLITE_LOCK_EXCLUSIVE].
 773  ** </ul>
 774  ** xLock() upgrades the database file lock.  In other words, xLock() moves the
 775  ** database file lock in the direction NONE toward EXCLUSIVE. The argument to
 776  ** xLock() is always one of SHARED, RESERVED, PENDING, or EXCLUSIVE, never
 777  ** SQLITE_LOCK_NONE.  If the database file lock is already at or above the
 778  ** requested lock, then the call to xLock() is a no-op.
 779  ** xUnlock() downgrades the database file lock to either SHARED or NONE.
 780  ** If the lock is already at or below the requested lock state, then the call
 781  ** to xUnlock() is a no-op.
 782  ** The xCheckReservedLock() method checks whether any database connection,
 783  ** either in this process or in some other process, is holding a RESERVED,
 784  ** PENDING, or EXCLUSIVE lock on the file.  It returns, via its output
 785  ** pointer parameter, true if such a lock exists and false otherwise.
 786  **
 787  ** The xFileControl() method is a generic interface that allows custom
 788  ** VFS implementations to directly control an open file using the
 789  ** [sqlite3_file_control()] interface.  The second "op" argument is an
 790  ** integer opcode.  The third argument is a generic pointer intended to
 791  ** point to a structure that may contain arguments or space in which to
 792  ** write return values.  Potential uses for xFileControl() might be
 793  ** functions to enable blocking locks with timeouts, to change the
 794  ** locking strategy (for example to use dot-file locks), to inquire
 795  ** about the status of a lock, or to break stale locks.  The SQLite
 796  ** core reserves all opcodes less than 100 for its own use.
 797  ** A [file control opcodes | list of opcodes] less than 100 is available.
 798  ** Applications that define a custom xFileControl method should use opcodes
 799  ** greater than 100 to avoid conflicts.  VFS implementations should
 800  ** return [SQLITE_NOTFOUND] for file control opcodes that they do not
 801  ** recognize.
 802  **
 803  ** The xSectorSize() method returns the sector size of the
 804  ** device that underlies the file.  The sector size is the
 805  ** minimum write that can be performed without disturbing
 806  ** other bytes in the file.  The xDeviceCharacteristics()
 807  ** method returns a bit vector describing behaviors of the
 808  ** underlying device:
 809  **
 810  ** <ul>
 811  ** <li> [SQLITE_IOCAP_ATOMIC]
 812  ** <li> [SQLITE_IOCAP_ATOMIC512]
 813  ** <li> [SQLITE_IOCAP_ATOMIC1K]
 814  ** <li> [SQLITE_IOCAP_ATOMIC2K]
 815  ** <li> [SQLITE_IOCAP_ATOMIC4K]
 816  ** <li> [SQLITE_IOCAP_ATOMIC8K]
 817  ** <li> [SQLITE_IOCAP_ATOMIC16K]
 818  ** <li> [SQLITE_IOCAP_ATOMIC32K]
 819  ** <li> [SQLITE_IOCAP_ATOMIC64K]
 820  ** <li> [SQLITE_IOCAP_SAFE_APPEND]
 821  ** <li> [SQLITE_IOCAP_SEQUENTIAL]
 822  ** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
 823  ** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
 824  ** <li> [SQLITE_IOCAP_IMMUTABLE]
 825  ** <li> [SQLITE_IOCAP_BATCH_ATOMIC]
 826  ** <li> [SQLITE_IOCAP_SUBPAGE_READ]
 827  ** </ul>
 828  **
 829  ** The SQLITE_IOCAP_ATOMIC property means that all writes of
 830  ** any size are atomic.  The SQLITE_IOCAP_ATOMICnnn values
 831  ** mean that writes of blocks that are nnn bytes in size and
 832  ** are aligned to an address which is an integer multiple of
 833  ** nnn are atomic.  The SQLITE_IOCAP_SAFE_APPEND value means
 834  ** that when data is appended to a file, the data is appended
 835  ** first then the size of the file is extended, never the other
 836  ** way around.  The SQLITE_IOCAP_SEQUENTIAL property means that
 837  ** information is written to disk in the same order as calls
 838  ** to xWrite().
 839  **
 840  ** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill
 841  ** in the unread portions of the buffer with zeros.  A VFS that
 842  ** fails to zero-fill short reads might seem to work.  However,
 843  ** failure to zero-fill short reads will eventually lead to
 844  ** database corruption.
 845  */
 846  typedef struct sqlite3_io_methods sqlite3_io_methods;
 847  struct sqlite3_io_methods {
 848    int iVersion;
 849    int (*xClose)(sqlite3_file*);
 850    int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
 851    int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);
 852    int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);
 853    int (*xSync)(sqlite3_file*, int flags);
 854    int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);
 855    int (*xLock)(sqlite3_file*, int);
 856    int (*xUnlock)(sqlite3_file*, int);
 857    int (*xCheckReservedLock)(sqlite3_file*, int *pResOut);
 858    int (*xFileControl)(sqlite3_file*, int op, void *pArg);
 859    int (*xSectorSize)(sqlite3_file*);
 860    int (*xDeviceCharacteristics)(sqlite3_file*);
 861    /* Methods above are valid for version 1 */
 862    int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**);
 863    int (*xShmLock)(sqlite3_file*, int offset, int n, int flags);
 864    void (*xShmBarrier)(sqlite3_file*);
 865    int (*xShmUnmap)(sqlite3_file*, int deleteFlag);
 866    /* Methods above are valid for version 2 */
 867    int (*xFetch)(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp);
 868    int (*xUnfetch)(sqlite3_file*, sqlite3_int64 iOfst, void *p);
 869    /* Methods above are valid for version 3 */
 870    /* Additional methods may be added in future releases */
 871  };
 872  
 873  /*
 874  ** CAPI3REF: Standard File Control Opcodes
 875  ** KEYWORDS: {file control opcodes} {file control opcode}
 876  **
 877  ** These integer constants are opcodes for the xFileControl method
 878  ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
 879  ** interface.
 880  **
 881  ** <ul>
 882  ** <li>[[SQLITE_FCNTL_LOCKSTATE]]
 883  ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging.  This
 884  ** opcode causes the xFileControl method to write the current state of
 885  ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
 886  ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
 887  ** into an integer that the pArg argument points to.
 888  ** This capability is only available if SQLite is compiled with [SQLITE_DEBUG].
 889  **
 890  ** <li>[[SQLITE_FCNTL_SIZE_HINT]]
 891  ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
 892  ** layer a hint of how large the database file will grow to be during the
 893  ** current transaction.  This hint is not guaranteed to be accurate but it
 894  ** is often close.  The underlying VFS might choose to preallocate database
 895  ** file space based on this hint in order to help writes to the database
 896  ** file run faster.
 897  **
 898  ** <li>[[SQLITE_FCNTL_SIZE_LIMIT]]
 899  ** The [SQLITE_FCNTL_SIZE_LIMIT] opcode is used by in-memory VFS that
 900  ** implements [sqlite3_deserialize()] to set an upper bound on the size
 901  ** of the in-memory database.  The argument is a pointer to a [sqlite3_int64].
 902  ** If the integer pointed to is negative, then it is filled in with the
 903  ** current limit.  Otherwise the limit is set to the larger of the value
 904  ** of the integer pointed to and the current database size.  The integer
 905  ** pointed to is set to the new limit.
 906  **
 907  ** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
 908  ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
 909  ** extends and truncates the database file in chunks of a size specified
 910  ** by the user. The fourth argument to [sqlite3_file_control()] should
 911  ** point to an integer (type int) containing the new chunk-size to use
 912  ** for the nominated database. Allocating database file space in large
 913  ** chunks (say 1MB at a time), may reduce file-system fragmentation and
 914  ** improve performance on some systems.
 915  **
 916  ** <li>[[SQLITE_FCNTL_FILE_POINTER]]
 917  ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
 918  ** to the [sqlite3_file] object associated with a particular database
 919  ** connection.  See also [SQLITE_FCNTL_JOURNAL_POINTER].
 920  **
 921  ** <li>[[SQLITE_FCNTL_JOURNAL_POINTER]]
 922  ** The [SQLITE_FCNTL_JOURNAL_POINTER] opcode is used to obtain a pointer
 923  ** to the [sqlite3_file] object associated with the journal file (either
 924  ** the [rollback journal] or the [write-ahead log]) for a particular database
 925  ** connection.  See also [SQLITE_FCNTL_FILE_POINTER].
 926  **
 927  ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
 928  ** No longer in use.
 929  **
 930  ** <li>[[SQLITE_FCNTL_SYNC]]
 931  ** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and
 932  ** sent to the VFS immediately before the xSync method is invoked on a
 933  ** database file descriptor. Or, if the xSync method is not invoked
 934  ** because the user has configured SQLite with
 935  ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
 936  ** of the xSync method. In most cases, the pointer argument passed with
 937  ** this file-control is NULL. However, if the database file is being synced
 938  ** as part of a multi-database commit, the argument points to a nul-terminated
 939  ** string containing the transactions super-journal file name. VFSes that
 940  ** do not need this signal should silently ignore this opcode. Applications
 941  ** should not call [sqlite3_file_control()] with this opcode as doing so may
 942  ** disrupt the operation of the specialized VFSes that do require it.
 943  **
 944  ** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
 945  ** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite
 946  ** and sent to the VFS after a transaction has been committed immediately
 947  ** but before the database is unlocked. VFSes that do not need this signal
 948  ** should silently ignore this opcode. Applications should not call
 949  ** [sqlite3_file_control()] with this opcode as doing so may disrupt the
 950  ** operation of the specialized VFSes that do require it.
 951  **
 952  ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
 953  ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
 954  ** retry counts and intervals for certain disk I/O operations for the
 955  ** windows [VFS] in order to provide robustness in the presence of
 956  ** anti-virus programs.  By default, the windows VFS will retry file read,
 957  ** file write, and file delete operations up to 10 times, with a delay
 958  ** of 25 milliseconds before the first retry and with the delay increasing
 959  ** by an additional 25 milliseconds with each subsequent retry.  This
 960  ** opcode allows these two values (10 retries and 25 milliseconds of delay)
 961  ** to be adjusted.  The values are changed for all database connections
 962  ** within the same process.  The argument is a pointer to an array of two
 963  ** integers where the first integer is the new retry count and the second
 964  ** integer is the delay.  If either integer is negative, then the setting
 965  ** is not changed but instead the prior value of that setting is written
 966  ** into the array entry, allowing the current retry settings to be
 967  ** interrogated.  The zDbName parameter is ignored.
 968  **
 969  ** <li>[[SQLITE_FCNTL_PERSIST_WAL]]
 970  ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the
 971  ** persistent [WAL | Write Ahead Log] setting.  By default, the auxiliary
 972  ** write ahead log ([WAL file]) and shared memory
 973  ** files used for transaction control
 974  ** are automatically deleted when the latest connection to the database
 975  ** closes.  Setting persistent WAL mode causes those files to persist after
 976  ** close.  Persisting the files is useful when other processes that do not
 977  ** have write permission on the directory containing the database file want
 978  ** to read the database file, as the WAL and shared memory files must exist
 979  ** in order for the database to be readable.  The fourth parameter to
 980  ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
 981  ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
 982  ** WAL mode.  If the integer is -1, then it is overwritten with the current
 983  ** WAL persistence setting.
 984  **
 985  ** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]]
 986  ** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the
 987  ** persistent "powersafe-overwrite" or "PSOW" setting.  The PSOW setting
 988  ** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the
 989  ** xDeviceCharacteristics methods. The fourth parameter to
 990  ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
 991  ** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage
 992  ** mode.  If the integer is -1, then it is overwritten with the current
 993  ** zero-damage mode setting.
 994  **
 995  ** <li>[[SQLITE_FCNTL_OVERWRITE]]
 996  ** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening
 997  ** a write transaction to indicate that, unless it is rolled back for some
 998  ** reason, the entire database file will be overwritten by the current
 999  ** transaction. This is used by VACUUM operations.
1000  **
1001  ** <li>[[SQLITE_FCNTL_VFSNAME]]
1002  ** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of
1003  ** all [VFSes] in the VFS stack.  The names are of all VFS shims and the
1004  ** final bottom-level VFS are written into memory obtained from
1005  ** [sqlite3_malloc()] and the result is stored in the char* variable
1006  ** that the fourth parameter of [sqlite3_file_control()] points to.
1007  ** The caller is responsible for freeing the memory when done.  As with
1008  ** all file-control actions, there is no guarantee that this will actually
1009  ** do anything.  Callers should initialize the char* variable to a NULL
1010  ** pointer in case this file-control is not implemented.  This file-control
1011  ** is intended for diagnostic use only.
1012  **
1013  ** <li>[[SQLITE_FCNTL_VFS_POINTER]]
1014  ** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level
1015  ** [VFSes] currently in use.  ^(The argument X in
1016  ** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be
1017  ** of type "[sqlite3_vfs] **".  This opcodes will set *X
1018  ** to a pointer to the top-level VFS.)^
1019  ** ^When there are multiple VFS shims in the stack, this opcode finds the
1020  ** upper-most shim only.
1021  **
1022  ** <li>[[SQLITE_FCNTL_PRAGMA]]
1023  ** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA]
1024  ** file control is sent to the open [sqlite3_file] object corresponding
1025  ** to the database file to which the pragma statement refers. ^The argument
1026  ** to the [SQLITE_FCNTL_PRAGMA] file control is an array of
1027  ** pointers to strings (char**) in which the second element of the array
1028  ** is the name of the pragma and the third element is the argument to the
1029  ** pragma or NULL if the pragma has no argument.  ^The handler for an
1030  ** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element
1031  ** of the char** argument point to a string obtained from [sqlite3_mprintf()]
1032  ** or the equivalent and that string will become the result of the pragma or
1033  ** the error message if the pragma fails. ^If the
1034  ** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal
1035  ** [PRAGMA] processing continues.  ^If the [SQLITE_FCNTL_PRAGMA]
1036  ** file control returns [SQLITE_OK], then the parser assumes that the
1037  ** VFS has handled the PRAGMA itself and the parser generates a no-op
1038  ** prepared statement if result string is NULL, or that returns a copy
1039  ** of the result string if the string is non-NULL.
1040  ** ^If the [SQLITE_FCNTL_PRAGMA] file control returns
1041  ** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means
1042  ** that the VFS encountered an error while handling the [PRAGMA] and the
1043  ** compilation of the PRAGMA fails with an error.  ^The [SQLITE_FCNTL_PRAGMA]
1044  ** file control occurs at the beginning of pragma statement analysis and so
1045  ** it is able to override built-in [PRAGMA] statements.
1046  **
1047  ** <li>[[SQLITE_FCNTL_BUSYHANDLER]]
1048  ** ^The [SQLITE_FCNTL_BUSYHANDLER]
1049  ** file-control may be invoked by SQLite on the database file handle
1050  ** shortly after it is opened in order to provide a custom VFS with access
1051  ** to the connection's busy-handler callback. The argument is of type (void**)
1052  ** - an array of two (void *) values. The first (void *) actually points
1053  ** to a function of type (int (*)(void *)). In order to invoke the connection's
1054  ** busy-handler, this function should be invoked with the second (void *) in
1055  ** the array as the only argument. If it returns non-zero, then the operation
1056  ** should be retried. If it returns zero, the custom VFS should abandon the
1057  ** current operation.
1058  **
1059  ** <li>[[SQLITE_FCNTL_TEMPFILENAME]]
1060  ** ^Applications can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control
1061  ** to have SQLite generate a
1062  ** temporary filename using the same algorithm that is followed to generate
1063  ** temporary filenames for TEMP tables and other internal uses.  The
1064  ** argument should be a char** which will be filled with the filename
1065  ** written into memory obtained from [sqlite3_malloc()].  The caller should
1066  ** invoke [sqlite3_free()] on the result to avoid a memory leak.
1067  **
1068  ** <li>[[SQLITE_FCNTL_MMAP_SIZE]]
1069  ** The [SQLITE_FCNTL_MMAP_SIZE] file control is used to query or set the
1070  ** maximum number of bytes that will be used for memory-mapped I/O.
1071  ** The argument is a pointer to a value of type sqlite3_int64 that
1072  ** is an advisory maximum number of bytes in the file to memory map.  The
1073  ** pointer is overwritten with the old value.  The limit is not changed if
1074  ** the value originally pointed to is negative, and so the current limit
1075  ** can be queried by passing in a pointer to a negative number.  This
1076  ** file-control is used internally to implement [PRAGMA mmap_size].
1077  **
1078  ** <li>[[SQLITE_FCNTL_TRACE]]
1079  ** The [SQLITE_FCNTL_TRACE] file control provides advisory information
1080  ** to the VFS about what the higher layers of the SQLite stack are doing.
1081  ** This file control is used by some VFS activity tracing [shims].
1082  ** The argument is a zero-terminated string.  Higher layers in the
1083  ** SQLite stack may generate instances of this file control if
1084  ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.
1085  **
1086  ** <li>[[SQLITE_FCNTL_HAS_MOVED]]
1087  ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a
1088  ** pointer to an integer and it writes a boolean into that integer depending
1089  ** on whether or not the file has been renamed, moved, or deleted since it
1090  ** was first opened.
1091  **
1092  ** <li>[[SQLITE_FCNTL_WIN32_GET_HANDLE]]
1093  ** The [SQLITE_FCNTL_WIN32_GET_HANDLE] opcode can be used to obtain the
1094  ** underlying native file handle associated with a file handle.  This file
1095  ** control interprets its argument as a pointer to a native file handle and
1096  ** writes the resulting value there.
1097  **
1098  ** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]]
1099  ** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging.  This
1100  ** opcode causes the xFileControl method to swap the file handle with the one
1101  ** pointed to by the pArg argument.  This capability is used during testing
1102  ** and only needs to be supported when SQLITE_TEST is defined.
1103  **
1104  ** <li>[[SQLITE_FCNTL_NULL_IO]]
1105  ** The [SQLITE_FCNTL_NULL_IO] opcode sets the low-level file descriptor
1106  ** or file handle for the [sqlite3_file] object such that it will no longer
1107  ** read or write to the database file.
1108  **
1109  ** <li>[[SQLITE_FCNTL_WAL_BLOCK]]
1110  ** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might
1111  ** be advantageous to block on the next WAL lock if the lock is not immediately
1112  ** available.  The WAL subsystem issues this signal during rare
1113  ** circumstances in order to fix a problem with priority inversion.
1114  ** Applications should <em>not</em> use this file-control.
1115  **
1116  ** <li>[[SQLITE_FCNTL_ZIPVFS]]
1117  ** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other
1118  ** VFS should return SQLITE_NOTFOUND for this opcode.
1119  **
1120  ** <li>[[SQLITE_FCNTL_RBU]]
1121  ** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
1122  ** the RBU extension only.  All other VFS should return SQLITE_NOTFOUND for
1123  ** this opcode.
1124  **
1125  ** <li>[[SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]]
1126  ** If the [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] opcode returns SQLITE_OK, then
1127  ** the file descriptor is placed in "batch write mode", which
1128  ** means all subsequent write operations will be deferred and done
1129  ** atomically at the next [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE].  Systems
1130  ** that do not support batch atomic writes will return SQLITE_NOTFOUND.
1131  ** ^Following a successful SQLITE_FCNTL_BEGIN_ATOMIC_WRITE and prior to
1132  ** the closing [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] or
1133  ** [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE], SQLite will make
1134  ** no VFS interface calls on the same [sqlite3_file] file descriptor
1135  ** except for calls to the xWrite method and the xFileControl method
1136  ** with [SQLITE_FCNTL_SIZE_HINT].
1137  **
1138  ** <li>[[SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]]
1139  ** The [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] opcode causes all write
1140  ** operations since the previous successful call to
1141  ** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be performed atomically.
1142  ** This file control returns [SQLITE_OK] if and only if the writes were
1143  ** all performed successfully and have been committed to persistent storage.
1144  ** ^Regardless of whether or not it is successful, this file control takes
1145  ** the file descriptor out of batch write mode so that all subsequent
1146  ** write operations are independent.
1147  ** ^SQLite will never invoke SQLITE_FCNTL_COMMIT_ATOMIC_WRITE without
1148  ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
1149  **
1150  ** <li>[[SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE]]
1151  ** The [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE] opcode causes all write
1152  ** operations since the previous successful call to
1153  ** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be rolled back.
1154  ** ^This file control takes the file descriptor out of batch write mode
1155  ** so that all subsequent write operations are independent.
1156  ** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without
1157  ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
1158  **
1159  ** <li>[[SQLITE_FCNTL_LOCK_TIMEOUT]]
1160  ** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode is used to configure a VFS
1161  ** to block for up to M milliseconds before failing when attempting to
1162  ** obtain a file lock using the xLock or xShmLock methods of the VFS.
1163  ** The parameter is a pointer to a 32-bit signed integer that contains
1164  ** the value that M is to be set to. Before returning, the 32-bit signed
1165  ** integer is overwritten with the previous value of M.
1166  **
1167  ** <li>[[SQLITE_FCNTL_BLOCK_ON_CONNECT]]
1168  ** The [SQLITE_FCNTL_BLOCK_ON_CONNECT] opcode is used to configure the
1169  ** VFS to block when taking a SHARED lock to connect to a wal mode database.
1170  ** This is used to implement the functionality associated with
1171  ** SQLITE_SETLK_BLOCK_ON_CONNECT.
1172  **
1173  ** <li>[[SQLITE_FCNTL_DATA_VERSION]]
1174  ** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to
1175  ** a database file.  The argument is a pointer to a 32-bit unsigned integer.
1176  ** The "data version" for the pager is written into the pointer.  The
1177  ** "data version" changes whenever any change occurs to the corresponding
1178  ** database file, either through SQL statements on the same database
1179  ** connection or through transactions committed by separate database
1180  ** connections possibly in other processes. The [sqlite3_total_changes()]
1181  ** interface can be used to find if any database on the connection has changed,
1182  ** but that interface responds to changes on TEMP as well as MAIN and does
1183  ** not provide a mechanism to detect changes to MAIN only.  Also, the
1184  ** [sqlite3_total_changes()] interface responds to internal changes only and
1185  ** omits changes made by other database connections.  The
1186  ** [PRAGMA data_version] command provides a mechanism to detect changes to
1187  ** a single attached database that occur due to other database connections,
1188  ** but omits changes implemented by the database connection on which it is
1189  ** called.  This file control is the only mechanism to detect changes that
1190  ** happen either internally or externally and that are associated with
1191  ** a particular attached database.
1192  **
1193  ** <li>[[SQLITE_FCNTL_CKPT_START]]
1194  ** The [SQLITE_FCNTL_CKPT_START] opcode is invoked from within a checkpoint
1195  ** in wal mode before the client starts to copy pages from the wal
1196  ** file to the database file.
1197  **
1198  ** <li>[[SQLITE_FCNTL_CKPT_DONE]]
1199  ** The [SQLITE_FCNTL_CKPT_DONE] opcode is invoked from within a checkpoint
1200  ** in wal mode after the client has finished copying pages from the wal
1201  ** file to the database file, but before the *-shm file is updated to
1202  ** record the fact that the pages have been checkpointed.
1203  **
1204  ** <li>[[SQLITE_FCNTL_EXTERNAL_READER]]
1205  ** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect
1206  ** whether or not there is a database client in another process with a wal-mode
1207  ** transaction open on the database or not. It is only available on unix.The
1208  ** (void*) argument passed with this file-control should be a pointer to a
1209  ** value of type (int). The integer value is set to 1 if the database is a wal
1210  ** mode database and there exists at least one client in another process that
1211  ** currently has an SQL transaction open on the database. It is set to 0 if
1212  ** the database is not a wal-mode db, or if there is no such connection in any
1213  ** other process. This opcode cannot be used to detect transactions opened
1214  ** by clients within the current process, only within other processes.
1215  **
1216  ** <li>[[SQLITE_FCNTL_CKSM_FILE]]
1217  ** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use internally by the
1218  ** [checksum VFS shim] only.
1219  **
1220  ** <li>[[SQLITE_FCNTL_RESET_CACHE]]
1221  ** If there is currently no transaction open on the database, and the
1222  ** database is not a temp db, then the [SQLITE_FCNTL_RESET_CACHE] file-control
1223  ** purges the contents of the in-memory page cache. If there is an open
1224  ** transaction, or if the db is a temp-db, this opcode is a no-op, not an error.
1225  ** </ul>
1226  */
1227  #define SQLITE_FCNTL_LOCKSTATE               1
1228  #define SQLITE_FCNTL_GET_LOCKPROXYFILE       2
1229  #define SQLITE_FCNTL_SET_LOCKPROXYFILE       3
1230  #define SQLITE_FCNTL_LAST_ERRNO              4
1231  #define SQLITE_FCNTL_SIZE_HINT               5
1232  #define SQLITE_FCNTL_CHUNK_SIZE              6
1233  #define SQLITE_FCNTL_FILE_POINTER            7
1234  #define SQLITE_FCNTL_SYNC_OMITTED            8
1235  #define SQLITE_FCNTL_WIN32_AV_RETRY          9
1236  #define SQLITE_FCNTL_PERSIST_WAL            10
1237  #define SQLITE_FCNTL_OVERWRITE              11
1238  #define SQLITE_FCNTL_VFSNAME                12
1239  #define SQLITE_FCNTL_POWERSAFE_OVERWRITE    13
1240  #define SQLITE_FCNTL_PRAGMA                 14
1241  #define SQLITE_FCNTL_BUSYHANDLER            15
1242  #define SQLITE_FCNTL_TEMPFILENAME           16
1243  #define SQLITE_FCNTL_MMAP_SIZE              18
1244  #define SQLITE_FCNTL_TRACE                  19
1245  #define SQLITE_FCNTL_HAS_MOVED              20
1246  #define SQLITE_FCNTL_SYNC                   21
1247  #define SQLITE_FCNTL_COMMIT_PHASETWO        22
1248  #define SQLITE_FCNTL_WIN32_SET_HANDLE       23
1249  #define SQLITE_FCNTL_WAL_BLOCK              24
1250  #define SQLITE_FCNTL_ZIPVFS                 25
1251  #define SQLITE_FCNTL_RBU                    26
1252  #define SQLITE_FCNTL_VFS_POINTER            27
1253  #define SQLITE_FCNTL_JOURNAL_POINTER        28
1254  #define SQLITE_FCNTL_WIN32_GET_HANDLE       29
1255  #define SQLITE_FCNTL_PDB                    30
1256  #define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE     31
1257  #define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE    32
1258  #define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE  33
1259  #define SQLITE_FCNTL_LOCK_TIMEOUT           34
1260  #define SQLITE_FCNTL_DATA_VERSION           35
1261  #define SQLITE_FCNTL_SIZE_LIMIT             36
1262  #define SQLITE_FCNTL_CKPT_DONE              37
1263  #define SQLITE_FCNTL_RESERVE_BYTES          38
1264  #define SQLITE_FCNTL_CKPT_START             39
1265  #define SQLITE_FCNTL_EXTERNAL_READER        40
1266  #define SQLITE_FCNTL_CKSM_FILE              41
1267  #define SQLITE_FCNTL_RESET_CACHE            42
1268  #define SQLITE_FCNTL_NULL_IO                43
1269  #define SQLITE_FCNTL_BLOCK_ON_CONNECT       44
1270  
1271  /* deprecated names */
1272  #define SQLITE_GET_LOCKPROXYFILE      SQLITE_FCNTL_GET_LOCKPROXYFILE
1273  #define SQLITE_SET_LOCKPROXYFILE      SQLITE_FCNTL_SET_LOCKPROXYFILE
1274  #define SQLITE_LAST_ERRNO             SQLITE_FCNTL_LAST_ERRNO
1275  
1276  
1277  /*
1278  ** CAPI3REF: Mutex Handle
1279  **
1280  ** The mutex module within SQLite defines [sqlite3_mutex] to be an
1281  ** abstract type for a mutex object.  The SQLite core never looks
1282  ** at the internal representation of an [sqlite3_mutex].  It only
1283  ** deals with pointers to the [sqlite3_mutex] object.
1284  **
1285  ** Mutexes are created using [sqlite3_mutex_alloc()].
1286  */
1287  typedef struct sqlite3_mutex sqlite3_mutex;
1288  
1289  /*
1290  ** CAPI3REF: Loadable Extension Thunk
1291  **
1292  ** A pointer to the opaque sqlite3_api_routines structure is passed as
1293  ** the third parameter to entry points of [loadable extensions].  This
1294  ** structure must be typedefed in order to work around compiler warnings
1295  ** on some platforms.
1296  */
1297  typedef struct sqlite3_api_routines sqlite3_api_routines;
1298  
1299  /*
1300  ** CAPI3REF: File Name
1301  **
1302  ** Type [sqlite3_filename] is used by SQLite to pass filenames to the
1303  ** xOpen method of a [VFS]. It may be cast to (const char*) and treated
1304  ** as a normal, nul-terminated, UTF-8 buffer containing the filename, but
1305  ** may also be passed to special APIs such as:
1306  **
1307  ** <ul>
1308  ** <li>  sqlite3_filename_database()
1309  ** <li>  sqlite3_filename_journal()
1310  ** <li>  sqlite3_filename_wal()
1311  ** <li>  sqlite3_uri_parameter()
1312  ** <li>  sqlite3_uri_boolean()
1313  ** <li>  sqlite3_uri_int64()
1314  ** <li>  sqlite3_uri_key()
1315  ** </ul>
1316  */
1317  typedef const char *sqlite3_filename;
1318  
1319  /*
1320  ** CAPI3REF: OS Interface Object
1321  **
1322  ** An instance of the sqlite3_vfs object defines the interface between
1323  ** the SQLite core and the underlying operating system.  The "vfs"
1324  ** in the name of the object stands for "virtual file system".  See
1325  ** the [VFS | VFS documentation] for further information.
1326  **
1327  ** The VFS interface is sometimes extended by adding new methods onto
1328  ** the end.  Each time such an extension occurs, the iVersion field
1329  ** is incremented.  The iVersion value started out as 1 in
1330  ** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 2
1331  ** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased
1332  ** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6].  Additional fields
1333  ** may be appended to the sqlite3_vfs object and the iVersion value
1334  ** may increase again in future versions of SQLite.
1335  ** Note that due to an oversight, the structure
1336  ** of the sqlite3_vfs object changed in the transition from
1337  ** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0]
1338  ** and yet the iVersion field was not increased.
1339  **
1340  ** The szOsFile field is the size of the subclassed [sqlite3_file]
1341  ** structure used by this VFS.  mxPathname is the maximum length of
1342  ** a pathname in this VFS.
1343  **
1344  ** Registered sqlite3_vfs objects are kept on a linked list formed by
1345  ** the pNext pointer.  The [sqlite3_vfs_register()]
1346  ** and [sqlite3_vfs_unregister()] interfaces manage this list
1347  ** in a thread-safe way.  The [sqlite3_vfs_find()] interface
1348  ** searches the list.  Neither the application code nor the VFS
1349  ** implementation should use the pNext pointer.
1350  **
1351  ** The pNext field is the only field in the sqlite3_vfs
1352  ** structure that SQLite will ever modify.  SQLite will only access
1353  ** or modify this field while holding a particular static mutex.
1354  ** The application should never modify anything within the sqlite3_vfs
1355  ** object once the object has been registered.
1356  **
1357  ** The zName field holds the name of the VFS module.  The name must
1358  ** be unique across all VFS modules.
1359  **
1360  ** [[sqlite3_vfs.xOpen]]
1361  ** ^SQLite guarantees that the zFilename parameter to xOpen
1362  ** is either a NULL pointer or string obtained
1363  ** from xFullPathname() with an optional suffix added.
1364  ** ^If a suffix is added to the zFilename parameter, it will
1365  ** consist of a single "-" character followed by no more than
1366  ** 11 alphanumeric and/or "-" characters.
1367  ** ^SQLite further guarantees that
1368  ** the string will be valid and unchanged until xClose() is
1369  ** called. Because of the previous sentence,
1370  ** the [sqlite3_file] can safely store a pointer to the
1371  ** filename if it needs to remember the filename for some reason.
1372  ** If the zFilename parameter to xOpen is a NULL pointer then xOpen
1373  ** must invent its own temporary name for the file.  ^Whenever the
1374  ** xFilename parameter is NULL it will also be the case that the
1375  ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].
1376  **
1377  ** The flags argument to xOpen() includes all bits set in
1378  ** the flags argument to [sqlite3_open_v2()].  Or if [sqlite3_open()]
1379  ** or [sqlite3_open16()] is used, then flags includes at least
1380  ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].
1381  ** If xOpen() opens a file read-only then it sets *pOutFlags to
1382  ** include [SQLITE_OPEN_READONLY].  Other bits in *pOutFlags may be set.
1383  **
1384  ** ^(SQLite will also add one of the following flags to the xOpen()
1385  ** call, depending on the object being opened:
1386  **
1387  ** <ul>
1388  ** <li>  [SQLITE_OPEN_MAIN_DB]
1389  ** <li>  [SQLITE_OPEN_MAIN_JOURNAL]
1390  ** <li>  [SQLITE_OPEN_TEMP_DB]
1391  ** <li>  [SQLITE_OPEN_TEMP_JOURNAL]
1392  ** <li>  [SQLITE_OPEN_TRANSIENT_DB]
1393  ** <li>  [SQLITE_OPEN_SUBJOURNAL]
1394  ** <li>  [SQLITE_OPEN_SUPER_JOURNAL]
1395  ** <li>  [SQLITE_OPEN_WAL]
1396  ** </ul>)^
1397  **
1398  ** The file I/O implementation can use the object type flags to
1399  ** change the way it deals with files.  For example, an application
1400  ** that does not care about crash recovery or rollback might make
1401  ** the open of a journal file a no-op.  Writes to this journal would
1402  ** also be no-ops, and any attempt to read the journal would return
1403  ** SQLITE_IOERR.  Or the implementation might recognize that a database
1404  ** file will be doing page-aligned sector reads and writes in a random
1405  ** order and set up its I/O subsystem accordingly.
1406  **
1407  ** SQLite might also add one of the following flags to the xOpen method:
1408  **
1409  ** <ul>
1410  ** <li> [SQLITE_OPEN_DELETEONCLOSE]
1411  ** <li> [SQLITE_OPEN_EXCLUSIVE]
1412  ** </ul>
1413  **
1414  ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be
1415  ** deleted when it is closed.  ^The [SQLITE_OPEN_DELETEONCLOSE]
1416  ** will be set for TEMP databases and their journals, transient
1417  ** databases, and subjournals.
1418  **
1419  ** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction
1420  ** with the [SQLITE_OPEN_CREATE] flag, which are both directly
1421  ** analogous to the O_EXCL and O_CREAT flags of the POSIX open()
1422  ** API.  The SQLITE_OPEN_EXCLUSIVE flag, when paired with the
1423  ** SQLITE_OPEN_CREATE, is used to indicate that file should always
1424  ** be created, and that it is an error if it already exists.
1425  ** It is <i>not</i> used to indicate the file should be opened
1426  ** for exclusive access.
1427  **
1428  ** ^At least szOsFile bytes of memory are allocated by SQLite
1429  ** to hold the [sqlite3_file] structure passed as the third
1430  ** argument to xOpen.  The xOpen method does not have to
1431  ** allocate the structure; it should just fill it in.  Note that
1432  ** the xOpen method must set the sqlite3_file.pMethods to either
1433  ** a valid [sqlite3_io_methods] object or to NULL.  xOpen must do
1434  ** this even if the open fails.  SQLite expects that the sqlite3_file.pMethods
1435  ** element will be valid after xOpen returns regardless of the success
1436  ** or failure of the xOpen call.
1437  **
1438  ** [[sqlite3_vfs.xAccess]]
1439  ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]
1440  ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to
1441  ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]
1442  ** to test whether a file is at least readable.  The SQLITE_ACCESS_READ
1443  ** flag is never actually used and is not implemented in the built-in
1444  ** VFSes of SQLite.  The file is named by the second argument and can be a
1445  ** directory. The xAccess method returns [SQLITE_OK] on success or some
1446  ** non-zero error code if there is an I/O error or if the name of
1447  ** the file given in the second argument is illegal.  If SQLITE_OK
1448  ** is returned, then non-zero or zero is written into *pResOut to indicate
1449  ** whether or not the file is accessible.
1450  **
1451  ** ^SQLite will always allocate at least mxPathname+1 bytes for the
1452  ** output buffer xFullPathname.  The exact size of the output buffer
1453  ** is also passed as a parameter to both  methods. If the output buffer
1454  ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
1455  ** handled as a fatal error by SQLite, vfs implementations should endeavor
1456  ** to prevent this by setting mxPathname to a sufficiently large value.
1457  **
1458  ** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
1459  ** interfaces are not strictly a part of the filesystem, but they are
1460  ** included in the VFS structure for completeness.
1461  ** The xRandomness() function attempts to return nBytes bytes
1462  ** of good-quality randomness into zOut.  The return value is
1463  ** the actual number of bytes of randomness obtained.
1464  ** The xSleep() method causes the calling thread to sleep for at
1465  ** least the number of microseconds given.  ^The xCurrentTime()
1466  ** method returns a Julian Day Number for the current date and time as
1467  ** a floating point value.
1468  ** ^The xCurrentTimeInt64() method returns, as an integer, the Julian
1469  ** Day Number multiplied by 86400000 (the number of milliseconds in
1470  ** a 24-hour day).
1471  ** ^SQLite will use the xCurrentTimeInt64() method to get the current
1472  ** date and time if that method is available (if iVersion is 2 or
1473  ** greater and the function pointer is not NULL) and will fall back
1474  ** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
1475  **
1476  ** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces
1477  ** are not used by the SQLite core.  These optional interfaces are provided
1478  ** by some VFSes to facilitate testing of the VFS code. By overriding
1479  ** system calls with functions under its control, a test program can
1480  ** simulate faults and error conditions that would otherwise be difficult
1481  ** or impossible to induce.  The set of system calls that can be overridden
1482  ** varies from one VFS to another, and from one version of the same VFS to the
1483  ** next.  Applications that use these interfaces must be prepared for any
1484  ** or all of these interfaces to be NULL or for their behavior to change
1485  ** from one release to the next.  Applications must not attempt to access
1486  ** any of these methods if the iVersion of the VFS is less than 3.
1487  */
1488  typedef struct sqlite3_vfs sqlite3_vfs;
1489  typedef void (*sqlite3_syscall_ptr)(void);
1490  struct sqlite3_vfs {
1491    int iVersion;            /* Structure version number (currently 3) */
1492    int szOsFile;            /* Size of subclassed sqlite3_file */
1493    int mxPathname;          /* Maximum file pathname length */
1494    sqlite3_vfs *pNext;      /* Next registered VFS */
1495    const char *zName;       /* Name of this virtual file system */
1496    void *pAppData;          /* Pointer to application-specific data */
1497    int (*xOpen)(sqlite3_vfs*, sqlite3_filename zName, sqlite3_file*,
1498                 int flags, int *pOutFlags);
1499    int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
1500    int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);
1501    int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
1502    void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
1503    void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
1504    void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void);
1505    void (*xDlClose)(sqlite3_vfs*, void*);
1506    int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);
1507    int (*xSleep)(sqlite3_vfs*, int microseconds);
1508    int (*xCurrentTime)(sqlite3_vfs*, double*);
1509    int (*xGetLastError)(sqlite3_vfs*, int, char *);
1510    /*
1511    ** The methods above are in version 1 of the sqlite_vfs object
1512    ** definition.  Those that follow are added in version 2 or later
1513    */
1514    int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
1515    /*
1516    ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
1517    ** Those below are for version 3 and greater.
1518    */
1519    int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr);
1520    sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName);
1521    const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName);
1522    /*
1523    ** The methods above are in versions 1 through 3 of the sqlite_vfs object.
1524    ** New fields may be appended in future versions.  The iVersion
1525    ** value will increment whenever this happens.
1526    */
1527  };
1528  
1529  /*
1530  ** CAPI3REF: Flags for the xAccess VFS method
1531  **
1532  ** These integer constants can be used as the third parameter to
1533  ** the xAccess method of an [sqlite3_vfs] object.  They determine
1534  ** what kind of permissions the xAccess method is looking for.
1535  ** With SQLITE_ACCESS_EXISTS, the xAccess method
1536  ** simply checks whether the file exists.
1537  ** With SQLITE_ACCESS_READWRITE, the xAccess method
1538  ** checks whether the named directory is both readable and writable
1539  ** (in other words, if files can be added, removed, and renamed within
1540  ** the directory).
1541  ** The SQLITE_ACCESS_READWRITE constant is currently used only by the
1542  ** [temp_store_directory pragma], though this could change in a future
1543  ** release of SQLite.
1544  ** With SQLITE_ACCESS_READ, the xAccess method
1545  ** checks whether the file is readable.  The SQLITE_ACCESS_READ constant is
1546  ** currently unused, though it might be used in a future release of
1547  ** SQLite.
1548  */
1549  #define SQLITE_ACCESS_EXISTS    0
1550  #define SQLITE_ACCESS_READWRITE 1   /* Used by PRAGMA temp_store_directory */
1551  #define SQLITE_ACCESS_READ      2   /* Unused */
1552  
1553  /*
1554  ** CAPI3REF: Flags for the xShmLock VFS method
1555  **
1556  ** These integer constants define the various locking operations
1557  ** allowed by the xShmLock method of [sqlite3_io_methods].  The
1558  ** following are the only legal combinations of flags to the
1559  ** xShmLock method:
1560  **
1561  ** <ul>
1562  ** <li>  SQLITE_SHM_LOCK | SQLITE_SHM_SHARED
1563  ** <li>  SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE
1564  ** <li>  SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED
1565  ** <li>  SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE
1566  ** </ul>
1567  **
1568  ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as
1569  ** was given on the corresponding lock.
1570  **
1571  ** The xShmLock method can transition between unlocked and SHARED or
1572  ** between unlocked and EXCLUSIVE.  It cannot transition between SHARED
1573  ** and EXCLUSIVE.
1574  */
1575  #define SQLITE_SHM_UNLOCK       1
1576  #define SQLITE_SHM_LOCK         2
1577  #define SQLITE_SHM_SHARED       4
1578  #define SQLITE_SHM_EXCLUSIVE    8
1579  
1580  /*
1581  ** CAPI3REF: Maximum xShmLock index
1582  **
1583  ** The xShmLock method on [sqlite3_io_methods] may use values
1584  ** between 0 and this upper bound as its "offset" argument.
1585  ** The SQLite core will never attempt to acquire or release a
1586  ** lock outside of this range
1587  */
1588  #define SQLITE_SHM_NLOCK        8
1589  
1590  
1591  /*
1592  ** CAPI3REF: Initialize The SQLite Library
1593  **
1594  ** ^The sqlite3_initialize() routine initializes the
1595  ** SQLite library.  ^The sqlite3_shutdown() routine
1596  ** deallocates any resources that were allocated by sqlite3_initialize().
1597  ** These routines are designed to aid in process initialization and
1598  ** shutdown on embedded systems.  Workstation applications using
1599  ** SQLite normally do not need to invoke either of these routines.
1600  **
1601  ** A call to sqlite3_initialize() is an "effective" call if it is
1602  ** the first time sqlite3_initialize() is invoked during the lifetime of
1603  ** the process, or if it is the first time sqlite3_initialize() is invoked
1604  ** following a call to sqlite3_shutdown().  ^(Only an effective call
1605  ** of sqlite3_initialize() does any initialization.  All other calls
1606  ** are harmless no-ops.)^
1607  **
1608  ** A call to sqlite3_shutdown() is an "effective" call if it is the first
1609  ** call to sqlite3_shutdown() since the last sqlite3_initialize().  ^(Only
1610  ** an effective call to sqlite3_shutdown() does any deinitialization.
1611  ** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^
1612  **
1613  ** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown()
1614  ** is not.  The sqlite3_shutdown() interface must only be called from a
1615  ** single thread.  All open [database connections] must be closed and all
1616  ** other SQLite resources must be deallocated prior to invoking
1617  ** sqlite3_shutdown().
1618  **
1619  ** Among other things, ^sqlite3_initialize() will invoke
1620  ** sqlite3_os_init().  Similarly, ^sqlite3_shutdown()
1621  ** will invoke sqlite3_os_end().
1622  **
1623  ** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success.
1624  ** ^If for some reason, sqlite3_initialize() is unable to initialize
1625  ** the library (perhaps it is unable to allocate a needed resource such
1626  ** as a mutex) it returns an [error code] other than [SQLITE_OK].
1627  **
1628  ** ^The sqlite3_initialize() routine is called internally by many other
1629  ** SQLite interfaces so that an application usually does not need to
1630  ** invoke sqlite3_initialize() directly.  For example, [sqlite3_open()]
1631  ** calls sqlite3_initialize() so the SQLite library will be automatically
1632  ** initialized when [sqlite3_open()] is called if it has not be initialized
1633  ** already.  ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
1634  ** compile-time option, then the automatic calls to sqlite3_initialize()
1635  ** are omitted and the application must call sqlite3_initialize() directly
1636  ** prior to using any other SQLite interface.  For maximum portability,
1637  ** it is recommended that applications always invoke sqlite3_initialize()
1638  ** directly prior to using any other SQLite interface.  Future releases
1639  ** of SQLite may require this.  In other words, the behavior exhibited
1640  ** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the
1641  ** default behavior in some future release of SQLite.
1642  **
1643  ** The sqlite3_os_init() routine does operating-system specific
1644  ** initialization of the SQLite library.  The sqlite3_os_end()
1645  ** routine undoes the effect of sqlite3_os_init().  Typical tasks
1646  ** performed by these routines include allocation or deallocation
1647  ** of static resources, initialization of global variables,
1648  ** setting up a default [sqlite3_vfs] module, or setting up
1649  ** a default configuration using [sqlite3_config()].
1650  **
1651  ** The application should never invoke either sqlite3_os_init()
1652  ** or sqlite3_os_end() directly.  The application should only invoke
1653  ** sqlite3_initialize() and sqlite3_shutdown().  The sqlite3_os_init()
1654  ** interface is called automatically by sqlite3_initialize() and
1655  ** sqlite3_os_end() is called by sqlite3_shutdown().  Appropriate
1656  ** implementations for sqlite3_os_init() and sqlite3_os_end()
1657  ** are built into SQLite when it is compiled for Unix, Windows, or OS/2.
1658  ** When [custom builds | built for other platforms]
1659  ** (using the [SQLITE_OS_OTHER=1] compile-time
1660  ** option) the application must supply a suitable implementation for
1661  ** sqlite3_os_init() and sqlite3_os_end().  An application-supplied
1662  ** implementation of sqlite3_os_init() or sqlite3_os_end()
1663  ** must return [SQLITE_OK] on success and some other [error code] upon
1664  ** failure.
1665  */
1666  SQLITE_API int sqlite3_initialize(void);
1667  SQLITE_API int sqlite3_shutdown(void);
1668  SQLITE_API int sqlite3_os_init(void);
1669  SQLITE_API int sqlite3_os_end(void);
1670  
1671  /*
1672  ** CAPI3REF: Configuring The SQLite Library
1673  **
1674  ** The sqlite3_config() interface is used to make global configuration
1675  ** changes to SQLite in order to tune SQLite to the specific needs of
1676  ** the application.  The default configuration is recommended for most
1677  ** applications and so this routine is usually not necessary.  It is
1678  ** provided to support rare applications with unusual needs.
1679  **
1680  ** <b>The sqlite3_config() interface is not threadsafe. The application
1681  ** must ensure that no other SQLite interfaces are invoked by other
1682  ** threads while sqlite3_config() is running.</b>
1683  **
1684  ** The first argument to sqlite3_config() is an integer
1685  ** [configuration option] that determines
1686  ** what property of SQLite is to be configured.  Subsequent arguments
1687  ** vary depending on the [configuration option]
1688  ** in the first argument.
1689  **
1690  ** For most configuration options, the sqlite3_config() interface
1691  ** may only be invoked prior to library initialization using
1692  ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].
1693  ** The exceptional configuration options that may be invoked at any time
1694  ** are called "anytime configuration options".
1695  ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before
1696  ** [sqlite3_shutdown()] with a first argument that is not an anytime
1697  ** configuration option, then the sqlite3_config() call will return SQLITE_MISUSE.
1698  ** Note, however, that ^sqlite3_config() can be called as part of the
1699  ** implementation of an application-defined [sqlite3_os_init()].
1700  **
1701  ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
1702  ** ^If the option is unknown or SQLite is unable to set the option
1703  ** then this routine returns a non-zero [error code].
1704  */
1705  SQLITE_API int sqlite3_config(int, ...);
1706  
1707  /*
1708  ** CAPI3REF: Configure database connections
1709  ** METHOD: sqlite3
1710  **
1711  ** The sqlite3_db_config() interface is used to make configuration
1712  ** changes to a [database connection].  The interface is similar to
1713  ** [sqlite3_config()] except that the changes apply to a single
1714  ** [database connection] (specified in the first argument).
1715  **
1716  ** The second argument to sqlite3_db_config(D,V,...)  is the
1717  ** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code
1718  ** that indicates what aspect of the [database connection] is being configured.
1719  ** Subsequent arguments vary depending on the configuration verb.
1720  **
1721  ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
1722  ** the call is considered successful.
1723  */
1724  SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);
1725  
1726  /*
1727  ** CAPI3REF: Memory Allocation Routines
1728  **
1729  ** An instance of this object defines the interface between SQLite
1730  ** and low-level memory allocation routines.
1731  **
1732  ** This object is used in only one place in the SQLite interface.
1733  ** A pointer to an instance of this object is the argument to
1734  ** [sqlite3_config()] when the configuration option is
1735  ** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC].
1736  ** By creating an instance of this object
1737  ** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC])
1738  ** during configuration, an application can specify an alternative
1739  ** memory allocation subsystem for SQLite to use for all of its
1740  ** dynamic memory needs.
1741  **
1742  ** Note that SQLite comes with several [built-in memory allocators]
1743  ** that are perfectly adequate for the overwhelming majority of applications
1744  ** and that this object is only useful to a tiny minority of applications
1745  ** with specialized memory allocation requirements.  This object is
1746  ** also used during testing of SQLite in order to specify an alternative
1747  ** memory allocator that simulates memory out-of-memory conditions in
1748  ** order to verify that SQLite recovers gracefully from such
1749  ** conditions.
1750  **
1751  ** The xMalloc, xRealloc, and xFree methods must work like the
1752  ** malloc(), realloc() and free() functions from the standard C library.
1753  ** ^SQLite guarantees that the second argument to
1754  ** xRealloc is always a value returned by a prior call to xRoundup.
1755  **
1756  ** xSize should return the allocated size of a memory allocation
1757  ** previously obtained from xMalloc or xRealloc.  The allocated size
1758  ** is always at least as big as the requested size but may be larger.
1759  **
1760  ** The xRoundup method returns what would be the allocated size of
1761  ** a memory allocation given a particular requested size.  Most memory
1762  ** allocators round up memory allocations at least to the next multiple
1763  ** of 8.  Some allocators round up to a larger multiple or to a power of 2.
1764  ** Every memory allocation request coming in through [sqlite3_malloc()]
1765  ** or [sqlite3_realloc()] first calls xRoundup.  If xRoundup returns 0,
1766  ** that causes the corresponding memory allocation to fail.
1767  **
1768  ** The xInit method initializes the memory allocator.  For example,
1769  ** it might allocate any required mutexes or initialize internal data
1770  ** structures.  The xShutdown method is invoked (indirectly) by
1771  ** [sqlite3_shutdown()] and should deallocate any resources acquired
1772  ** by xInit.  The pAppData pointer is used as the only parameter to
1773  ** xInit and xShutdown.
1774  **
1775  ** SQLite holds the [SQLITE_MUTEX_STATIC_MAIN] mutex when it invokes
1776  ** the xInit method, so the xInit method need not be threadsafe.  The
1777  ** xShutdown method is only called from [sqlite3_shutdown()] so it does
1778  ** not need to be threadsafe either.  For all other methods, SQLite
1779  ** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the
1780  ** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which
1781  ** it is by default) and so the methods are automatically serialized.
1782  ** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other
1783  ** methods must be threadsafe or else make their own arrangements for
1784  ** serialization.
1785  **
1786  ** SQLite will never invoke xInit() more than once without an intervening
1787  ** call to xShutdown().
1788  */
1789  typedef struct sqlite3_mem_methods sqlite3_mem_methods;
1790  struct sqlite3_mem_methods {
1791    void *(*xMalloc)(int);         /* Memory allocation function */
1792    void (*xFree)(void*);          /* Free a prior allocation */
1793    void *(*xRealloc)(void*,int);  /* Resize an allocation */
1794    int (*xSize)(void*);           /* Return the size of an allocation */
1795    int (*xRoundup)(int);          /* Round up request size to allocation size */
1796    int (*xInit)(void*);           /* Initialize the memory allocator */
1797    void (*xShutdown)(void*);      /* Deinitialize the memory allocator */
1798    void *pAppData;                /* Argument to xInit() and xShutdown() */
1799  };
1800  
1801  /*
1802  ** CAPI3REF: Configuration Options
1803  ** KEYWORDS: {configuration option}
1804  **
1805  ** These constants are the available integer configuration options that
1806  ** can be passed as the first argument to the [sqlite3_config()] interface.
1807  **
1808  ** Most of the configuration options for sqlite3_config()
1809  ** will only work if invoked prior to [sqlite3_initialize()] or after
1810  ** [sqlite3_shutdown()].  The few exceptions to this rule are called
1811  ** "anytime configuration options".
1812  ** ^Calling [sqlite3_config()] with a first argument that is not an
1813  ** anytime configuration option in between calls to [sqlite3_initialize()] and
1814  ** [sqlite3_shutdown()] is a no-op that returns SQLITE_MISUSE.
1815  **
1816  ** The set of anytime configuration options can change (by insertions
1817  ** and/or deletions) from one release of SQLite to the next.
1818  ** As of SQLite version 3.42.0, the complete set of anytime configuration
1819  ** options is:
1820  ** <ul>
1821  ** <li> SQLITE_CONFIG_LOG
1822  ** <li> SQLITE_CONFIG_PCACHE_HDRSZ
1823  ** </ul>
1824  **
1825  ** New configuration options may be added in future releases of SQLite.
1826  ** Existing configuration options might be discontinued.  Applications
1827  ** should check the return code from [sqlite3_config()] to make sure that
1828  ** the call worked.  The [sqlite3_config()] interface will return a
1829  ** non-zero [error code] if a discontinued or unsupported configuration option
1830  ** is invoked.
1831  **
1832  ** <dl>
1833  ** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt>
1834  ** <dd>There are no arguments to this option.  ^This option sets the
1835  ** [threading mode] to Single-thread.  In other words, it disables
1836  ** all mutexing and puts SQLite into a mode where it can only be used
1837  ** by a single thread.   ^If SQLite is compiled with
1838  ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1839  ** it is not possible to change the [threading mode] from its default
1840  ** value of Single-thread and so [sqlite3_config()] will return
1841  ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD
1842  ** configuration option.</dd>
1843  **
1844  ** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt>
1845  ** <dd>There are no arguments to this option.  ^This option sets the
1846  ** [threading mode] to Multi-thread.  In other words, it disables
1847  ** mutexing on [database connection] and [prepared statement] objects.
1848  ** The application is responsible for serializing access to
1849  ** [database connections] and [prepared statements].  But other mutexes
1850  ** are enabled so that SQLite will be safe to use in a multi-threaded
1851  ** environment as long as no two threads attempt to use the same
1852  ** [database connection] at the same time.  ^If SQLite is compiled with
1853  ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1854  ** it is not possible to set the Multi-thread [threading mode] and
1855  ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1856  ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>
1857  **
1858  ** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt>
1859  ** <dd>There are no arguments to this option.  ^This option sets the
1860  ** [threading mode] to Serialized. In other words, this option enables
1861  ** all mutexes including the recursive
1862  ** mutexes on [database connection] and [prepared statement] objects.
1863  ** In this mode (which is the default when SQLite is compiled with
1864  ** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access
1865  ** to [database connections] and [prepared statements] so that the
1866  ** application is free to use the same [database connection] or the
1867  ** same [prepared statement] in different threads at the same time.
1868  ** ^If SQLite is compiled with
1869  ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1870  ** it is not possible to set the Serialized [threading mode] and
1871  ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1872  ** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
1873  **
1874  ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
1875  ** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is
1876  ** a pointer to an instance of the [sqlite3_mem_methods] structure.
1877  ** The argument specifies
1878  ** alternative low-level memory allocation routines to be used in place of
1879  ** the memory allocation routines built into SQLite.)^ ^SQLite makes
1880  ** its own private copy of the content of the [sqlite3_mem_methods] structure
1881  ** before the [sqlite3_config()] call returns.</dd>
1882  **
1883  ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
1884  ** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
1885  ** is a pointer to an instance of the [sqlite3_mem_methods] structure.
1886  ** The [sqlite3_mem_methods]
1887  ** structure is filled with the currently defined memory allocation routines.)^
1888  ** This option can be used to overload the default memory allocation
1889  ** routines with a wrapper that simulations memory allocation failure or
1890  ** tracks memory usage, for example. </dd>
1891  **
1892  ** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt>
1893  ** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes single argument of
1894  ** type int, interpreted as a boolean, which if true provides a hint to
1895  ** SQLite that it should avoid large memory allocations if possible.
1896  ** SQLite will run faster if it is free to make large memory allocations,
1897  ** but some application might prefer to run slower in exchange for
1898  ** guarantees about memory fragmentation that are possible if large
1899  ** allocations are avoided.  This hint is normally off.
1900  ** </dd>
1901  **
1902  ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1903  ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
1904  ** interpreted as a boolean, which enables or disables the collection of
1905  ** memory allocation statistics. ^(When memory allocation statistics are
1906  ** disabled, the following SQLite interfaces become non-operational:
1907  **   <ul>
1908  **   <li> [sqlite3_hard_heap_limit64()]
1909  **   <li> [sqlite3_memory_used()]
1910  **   <li> [sqlite3_memory_highwater()]
1911  **   <li> [sqlite3_soft_heap_limit64()]
1912  **   <li> [sqlite3_status64()]
1913  **   </ul>)^
1914  ** ^Memory allocation statistics are enabled by default unless SQLite is
1915  ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1916  ** allocation statistics are disabled by default.
1917  ** </dd>
1918  **
1919  ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
1920  ** <dd> The SQLITE_CONFIG_SCRATCH option is no longer used.
1921  ** </dd>
1922  **
1923  ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
1924  ** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool
1925  ** that SQLite can use for the database page cache with the default page
1926  ** cache implementation.
1927  ** This configuration option is a no-op if an application-defined page
1928  ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2].
1929  ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
1930  ** 8-byte aligned memory (pMem), the size of each page cache line (sz),
1931  ** and the number of cache lines (N).
1932  ** The sz argument should be the size of the largest database page
1933  ** (a power of two between 512 and 65536) plus some extra bytes for each
1934  ** page header.  ^The number of extra bytes needed by the page header
1935  ** can be determined using [SQLITE_CONFIG_PCACHE_HDRSZ].
1936  ** ^It is harmless, apart from the wasted memory,
1937  ** for the sz parameter to be larger than necessary.  The pMem
1938  ** argument must be either a NULL pointer or a pointer to an 8-byte
1939  ** aligned block of memory of at least sz*N bytes, otherwise
1940  ** subsequent behavior is undefined.
1941  ** ^When pMem is not NULL, SQLite will strive to use the memory provided
1942  ** to satisfy page cache needs, falling back to [sqlite3_malloc()] if
1943  ** a page cache line is larger than sz bytes or if all of the pMem buffer
1944  ** is exhausted.
1945  ** ^If pMem is NULL and N is non-zero, then each database connection
1946  ** does an initial bulk allocation for page cache memory
1947  ** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or
1948  ** of -1024*N bytes if N is negative, . ^If additional
1949  ** page cache memory is needed beyond what is provided by the initial
1950  ** allocation, then SQLite goes to [sqlite3_malloc()] separately for each
1951  ** additional cache line. </dd>
1952  **
1953  ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
1954  ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
1955  ** that SQLite will use for all of its dynamic memory allocation needs
1956  ** beyond those provided for by [SQLITE_CONFIG_PAGECACHE].
1957  ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
1958  ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
1959  ** [SQLITE_ERROR] if invoked otherwise.
1960  ** ^There are three arguments to SQLITE_CONFIG_HEAP:
1961  ** An 8-byte aligned pointer to the memory,
1962  ** the number of bytes in the memory buffer, and the minimum allocation size.
1963  ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
1964  ** to using its default memory allocator (the system malloc() implementation),
1965  ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC].  ^If the
1966  ** memory pointer is not NULL then the alternative memory
1967  ** allocator is engaged to handle all of SQLites memory allocation needs.
1968  ** The first pointer (the memory pointer) must be aligned to an 8-byte
1969  ** boundary or subsequent behavior of SQLite will be undefined.
1970  ** The minimum allocation size is capped at 2**12. Reasonable values
1971  ** for the minimum allocation size are 2**5 through 2**8.</dd>
1972  **
1973  ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
1974  ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
1975  ** pointer to an instance of the [sqlite3_mutex_methods] structure.
1976  ** The argument specifies alternative low-level mutex routines to be used
1977  ** in place the mutex routines built into SQLite.)^  ^SQLite makes a copy of
1978  ** the content of the [sqlite3_mutex_methods] structure before the call to
1979  ** [sqlite3_config()] returns. ^If SQLite is compiled with
1980  ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1981  ** the entire mutexing subsystem is omitted from the build and hence calls to
1982  ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
1983  ** return [SQLITE_ERROR].</dd>
1984  **
1985  ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
1986  ** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which
1987  ** is a pointer to an instance of the [sqlite3_mutex_methods] structure.  The
1988  ** [sqlite3_mutex_methods]
1989  ** structure is filled with the currently defined mutex routines.)^
1990  ** This option can be used to overload the default mutex allocation
1991  ** routines with a wrapper used to track mutex usage for performance
1992  ** profiling or testing, for example.   ^If SQLite is compiled with
1993  ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1994  ** the entire mutexing subsystem is omitted from the build and hence calls to
1995  ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
1996  ** return [SQLITE_ERROR].</dd>
1997  **
1998  ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1999  ** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
2000  ** the default size of [lookaside memory] on each [database connection].
2001  ** The first argument is the
2002  ** size of each lookaside buffer slot ("sz") and the second is the number of
2003  ** slots allocated to each database connection ("cnt").)^
2004  ** ^(SQLITE_CONFIG_LOOKASIDE sets the <i>default</i> lookaside size.
2005  ** The [SQLITE_DBCONFIG_LOOKASIDE] option to [sqlite3_db_config()] can
2006  ** be used to change the lookaside configuration on individual connections.)^
2007  ** The [-DSQLITE_DEFAULT_LOOKASIDE] option can be used to change the
2008  ** default lookaside configuration at compile-time.
2009  ** </dd>
2010  **
2011  ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
2012  ** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is
2013  ** a pointer to an [sqlite3_pcache_methods2] object.  This object specifies
2014  ** the interface to a custom page cache implementation.)^
2015  ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
2016  **
2017  ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
2018  ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
2019  ** is a pointer to an [sqlite3_pcache_methods2] object.  SQLite copies of
2020  ** the current page cache implementation into that object.)^ </dd>
2021  **
2022  ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
2023  ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
2024  ** global [error log].
2025  ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
2026  ** function with a call signature of void(*)(void*,int,const char*),
2027  ** and a pointer to void. ^If the function pointer is not NULL, it is
2028  ** invoked by [sqlite3_log()] to process each logging event.  ^If the
2029  ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.
2030  ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is
2031  ** passed through as the first parameter to the application-defined logger
2032  ** function whenever that function is invoked.  ^The second parameter to
2033  ** the logger function is a copy of the first parameter to the corresponding
2034  ** [sqlite3_log()] call and is intended to be a [result code] or an
2035  ** [extended result code].  ^The third parameter passed to the logger is
2036  ** log message after formatting via [sqlite3_snprintf()].
2037  ** The SQLite logging interface is not reentrant; the logger function
2038  ** supplied by the application must not invoke any SQLite interface.
2039  ** In a multi-threaded application, the application-defined logger
2040  ** function must be threadsafe. </dd>
2041  **
2042  ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
2043  ** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int.
2044  ** If non-zero, then URI handling is globally enabled. If the parameter is zero,
2045  ** then URI handling is globally disabled.)^ ^If URI handling is globally
2046  ** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()],
2047  ** [sqlite3_open16()] or
2048  ** specified as part of [ATTACH] commands are interpreted as URIs, regardless
2049  ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
2050  ** connection is opened. ^If it is globally disabled, filenames are
2051  ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
2052  ** database connection is opened. ^(By default, URI handling is globally
2053  ** disabled. The default value may be changed by compiling with the
2054  ** [SQLITE_USE_URI] symbol defined.)^
2055  **
2056  ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
2057  ** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer
2058  ** argument which is interpreted as a boolean in order to enable or disable
2059  ** the use of covering indices for full table scans in the query optimizer.
2060  ** ^The default setting is determined
2061  ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
2062  ** if that compile-time option is omitted.
2063  ** The ability to disable the use of covering indices for full table scans
2064  ** is because some incorrectly coded legacy applications might malfunction
2065  ** when the optimization is enabled.  Providing the ability to
2066  ** disable the optimization allows the older, buggy application code to work
2067  ** without change even with newer versions of SQLite.
2068  **
2069  ** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]]
2070  ** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE
2071  ** <dd> These options are obsolete and should not be used by new code.
2072  ** They are retained for backwards compatibility but are now no-ops.
2073  ** </dd>
2074  **
2075  ** [[SQLITE_CONFIG_SQLLOG]]
2076  ** <dt>SQLITE_CONFIG_SQLLOG
2077  ** <dd>This option is only available if sqlite is compiled with the
2078  ** [SQLITE_ENABLE_SQLLOG] pre-processor macro defined. The first argument should
2079  ** be a pointer to a function of type void(*)(void*,sqlite3*,const char*, int).
2080  ** The second should be of type (void*). The callback is invoked by the library
2081  ** in three separate circumstances, identified by the value passed as the
2082  ** fourth parameter. If the fourth parameter is 0, then the database connection
2083  ** passed as the second argument has just been opened. The third argument
2084  ** points to a buffer containing the name of the main database file. If the
2085  ** fourth parameter is 1, then the SQL statement that the third parameter
2086  ** points to has just been executed. Or, if the fourth parameter is 2, then
2087  ** the connection being passed as the second parameter is being closed. The
2088  ** third parameter is passed NULL In this case.  An example of using this
2089  ** configuration option can be seen in the "test_sqllog.c" source file in
2090  ** the canonical SQLite source tree.</dd>
2091  **
2092  ** [[SQLITE_CONFIG_MMAP_SIZE]]
2093  ** <dt>SQLITE_CONFIG_MMAP_SIZE
2094  ** <dd>^SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values
2095  ** that are the default mmap size limit (the default setting for
2096  ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
2097  ** ^The default setting can be overridden by each database connection using
2098  ** either the [PRAGMA mmap_size] command, or by using the
2099  ** [SQLITE_FCNTL_MMAP_SIZE] file control.  ^(The maximum allowed mmap size
2100  ** will be silently truncated if necessary so that it does not exceed the
2101  ** compile-time maximum mmap size set by the
2102  ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
2103  ** ^If either argument to this option is negative, then that argument is
2104  ** changed to its compile-time default.
2105  **
2106  ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
2107  ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
2108  ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
2109  ** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro
2110  ** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
2111  ** that specifies the maximum size of the created heap.
2112  **
2113  ** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
2114  ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
2115  ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
2116  ** is a pointer to an integer and writes into that integer the number of extra
2117  ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
2118  ** The amount of extra space required can change depending on the compiler,
2119  ** target platform, and SQLite version.
2120  **
2121  ** [[SQLITE_CONFIG_PMASZ]]
2122  ** <dt>SQLITE_CONFIG_PMASZ
2123  ** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which
2124  ** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded
2125  ** sorter to that integer.  The default minimum PMA Size is set by the
2126  ** [SQLITE_SORTER_PMASZ] compile-time option.  New threads are launched
2127  ** to help with sort operations when multithreaded sorting
2128  ** is enabled (using the [PRAGMA threads] command) and the amount of content
2129  ** to be sorted exceeds the page size times the minimum of the
2130  ** [PRAGMA cache_size] setting and this value.
2131  **
2132  ** [[SQLITE_CONFIG_STMTJRNL_SPILL]]
2133  ** <dt>SQLITE_CONFIG_STMTJRNL_SPILL
2134  ** <dd>^The SQLITE_CONFIG_STMTJRNL_SPILL option takes a single parameter which
2135  ** becomes the [statement journal] spill-to-disk threshold.
2136  ** [Statement journals] are held in memory until their size (in bytes)
2137  ** exceeds this threshold, at which point they are written to disk.
2138  ** Or if the threshold is -1, statement journals are always held
2139  ** exclusively in memory.
2140  ** Since many statement journals never become large, setting the spill
2141  ** threshold to a value such as 64KiB can greatly reduce the amount of
2142  ** I/O required to support statement rollback.
2143  ** The default value for this setting is controlled by the
2144  ** [SQLITE_STMTJRNL_SPILL] compile-time option.
2145  **
2146  ** [[SQLITE_CONFIG_SORTERREF_SIZE]]
2147  ** <dt>SQLITE_CONFIG_SORTERREF_SIZE
2148  ** <dd>The SQLITE_CONFIG_SORTERREF_SIZE option accepts a single parameter
2149  ** of type (int) - the new value of the sorter-reference size threshold.
2150  ** Usually, when SQLite uses an external sort to order records according
2151  ** to an ORDER BY clause, all fields required by the caller are present in the
2152  ** sorted records. However, if SQLite determines based on the declared type
2153  ** of a table column that its values are likely to be very large - larger
2154  ** than the configured sorter-reference size threshold - then a reference
2155  ** is stored in each sorted record and the required column values loaded
2156  ** from the database as records are returned in sorted order. The default
2157  ** value for this option is to never use this optimization. Specifying a
2158  ** negative value for this option restores the default behavior.
2159  ** This option is only available if SQLite is compiled with the
2160  ** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option.
2161  **
2162  ** [[SQLITE_CONFIG_MEMDB_MAXSIZE]]
2163  ** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE
2164  ** <dd>The SQLITE_CONFIG_MEMDB_MAXSIZE option accepts a single parameter
2165  ** [sqlite3_int64] parameter which is the default maximum size for an in-memory
2166  ** database created using [sqlite3_deserialize()].  This default maximum
2167  ** size can be adjusted up or down for individual databases using the
2168  ** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control].  If this
2169  ** configuration setting is never used, then the default maximum is determined
2170  ** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option.  If that
2171  ** compile-time option is not set, then the default maximum is 1073741824.
2172  **
2173  ** [[SQLITE_CONFIG_ROWID_IN_VIEW]]
2174  ** <dt>SQLITE_CONFIG_ROWID_IN_VIEW
2175  ** <dd>The SQLITE_CONFIG_ROWID_IN_VIEW option enables or disables the ability
2176  ** for VIEWs to have a ROWID.  The capability can only be enabled if SQLite is
2177  ** compiled with -DSQLITE_ALLOW_ROWID_IN_VIEW, in which case the capability
2178  ** defaults to on.  This configuration option queries the current setting or
2179  ** changes the setting to off or on.  The argument is a pointer to an integer.
2180  ** If that integer initially holds a value of 1, then the ability for VIEWs to
2181  ** have ROWIDs is activated.  If the integer initially holds zero, then the
2182  ** ability is deactivated.  Any other initial value for the integer leaves the
2183  ** setting unchanged.  After changes, if any, the integer is written with
2184  ** a 1 or 0, if the ability for VIEWs to have ROWIDs is on or off.  If SQLite
2185  ** is compiled without -DSQLITE_ALLOW_ROWID_IN_VIEW (which is the usual and
2186  ** recommended case) then the integer is always filled with zero, regardless
2187  ** if its initial value.
2188  ** </dl>
2189  */
2190  #define SQLITE_CONFIG_SINGLETHREAD         1  /* nil */
2191  #define SQLITE_CONFIG_MULTITHREAD          2  /* nil */
2192  #define SQLITE_CONFIG_SERIALIZED           3  /* nil */
2193  #define SQLITE_CONFIG_MALLOC               4  /* sqlite3_mem_methods* */
2194  #define SQLITE_CONFIG_GETMALLOC            5  /* sqlite3_mem_methods* */
2195  #define SQLITE_CONFIG_SCRATCH              6  /* No longer used */
2196  #define SQLITE_CONFIG_PAGECACHE            7  /* void*, int sz, int N */
2197  #define SQLITE_CONFIG_HEAP                 8  /* void*, int nByte, int min */
2198  #define SQLITE_CONFIG_MEMSTATUS            9  /* boolean */
2199  #define SQLITE_CONFIG_MUTEX               10  /* sqlite3_mutex_methods* */
2200  #define SQLITE_CONFIG_GETMUTEX            11  /* sqlite3_mutex_methods* */
2201  /* previously SQLITE_CONFIG_CHUNKALLOC    12 which is now unused. */
2202  #define SQLITE_CONFIG_LOOKASIDE           13  /* int int */
2203  #define SQLITE_CONFIG_PCACHE              14  /* no-op */
2204  #define SQLITE_CONFIG_GETPCACHE           15  /* no-op */
2205  #define SQLITE_CONFIG_LOG                 16  /* xFunc, void* */
2206  #define SQLITE_CONFIG_URI                 17  /* int */
2207  #define SQLITE_CONFIG_PCACHE2             18  /* sqlite3_pcache_methods2* */
2208  #define SQLITE_CONFIG_GETPCACHE2          19  /* sqlite3_pcache_methods2* */
2209  #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20  /* int */
2210  #define SQLITE_CONFIG_SQLLOG              21  /* xSqllog, void* */
2211  #define SQLITE_CONFIG_MMAP_SIZE           22  /* sqlite3_int64, sqlite3_int64 */
2212  #define SQLITE_CONFIG_WIN32_HEAPSIZE      23  /* int nByte */
2213  #define SQLITE_CONFIG_PCACHE_HDRSZ        24  /* int *psz */
2214  #define SQLITE_CONFIG_PMASZ               25  /* unsigned int szPma */
2215  #define SQLITE_CONFIG_STMTJRNL_SPILL      26  /* int nByte */
2216  #define SQLITE_CONFIG_SMALL_MALLOC        27  /* boolean */
2217  #define SQLITE_CONFIG_SORTERREF_SIZE      28  /* int nByte */
2218  #define SQLITE_CONFIG_MEMDB_MAXSIZE       29  /* sqlite3_int64 */
2219  #define SQLITE_CONFIG_ROWID_IN_VIEW       30  /* int* */
2220  
2221  /*
2222  ** CAPI3REF: Database Connection Configuration Options
2223  **
2224  ** These constants are the available integer configuration options that
2225  ** can be passed as the second parameter to the [sqlite3_db_config()] interface.
2226  **
2227  ** The [sqlite3_db_config()] interface is a var-args functions.  It takes a
2228  ** variable number of parameters, though always at least two.  The number of
2229  ** parameters passed into sqlite3_db_config() depends on which of these
2230  ** constants is given as the second parameter.  This documentation page
2231  ** refers to parameters beyond the second as "arguments".  Thus, when this
2232  ** page says "the N-th argument" it means "the N-th parameter past the
2233  ** configuration option" or "the (N+2)-th parameter to sqlite3_db_config()".
2234  **
2235  ** New configuration options may be added in future releases of SQLite.
2236  ** Existing configuration options might be discontinued.  Applications
2237  ** should check the return code from [sqlite3_db_config()] to make sure that
2238  ** the call worked.  ^The [sqlite3_db_config()] interface will return a
2239  ** non-zero [error code] if a discontinued or unsupported configuration option
2240  ** is invoked.
2241  **
2242  ** <dl>
2243  ** [[SQLITE_DBCONFIG_LOOKASIDE]]
2244  ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
2245  ** <dd> The SQLITE_DBCONFIG_LOOKASIDE option is used to adjust the
2246  ** configuration of the [lookaside memory allocator] within a database
2247  ** connection.
2248  ** The arguments to the SQLITE_DBCONFIG_LOOKASIDE option are <i>not</i>
2249  ** in the [DBCONFIG arguments|usual format].
2250  ** The SQLITE_DBCONFIG_LOOKASIDE option takes three arguments, not two,
2251  ** so that a call to [sqlite3_db_config()] that uses SQLITE_DBCONFIG_LOOKASIDE
2252  ** should have a total of five parameters.
2253  ** <ol>
2254  ** <li><p>The first argument ("buf") is a
2255  ** pointer to a memory buffer to use for lookaside memory.
2256  ** The first argument may be NULL in which case SQLite will allocate the
2257  ** lookaside buffer itself using [sqlite3_malloc()].
2258  ** <li><P>The second argument ("sz") is the
2259  ** size of each lookaside buffer slot.  Lookaside is disabled if "sz"
2260  ** is less than 8.  The "sz" argument should be a multiple of 8 less than
2261  ** 65536.  If "sz" does not meet this constraint, it is reduced in size until
2262  ** it does.
2263  ** <li><p>The third argument ("cnt") is the number of slots. Lookaside is disabled
2264  ** if "cnt"is less than 1.  The "cnt" value will be reduced, if necessary, so
2265  ** that the product of "sz" and "cnt" does not exceed 2,147,418,112.  The "cnt"
2266  ** parameter is usually chosen so that the product of "sz" and "cnt" is less
2267  ** than 1,000,000.
2268  ** </ol>
2269  ** <p>If the "buf" argument is not NULL, then it must
2270  ** point to a memory buffer with a size that is greater than
2271  ** or equal to the product of "sz" and "cnt".
2272  ** The buffer must be aligned to an 8-byte boundary.
2273  ** The lookaside memory
2274  ** configuration for a database connection can only be changed when that
2275  ** connection is not currently using lookaside memory, or in other words
2276  ** when the value returned by [SQLITE_DBSTATUS_LOOKASIDE_USED] is zero.
2277  ** Any attempt to change the lookaside memory configuration when lookaside
2278  ** memory is in use leaves the configuration unchanged and returns
2279  ** [SQLITE_BUSY].
2280  ** If the "buf" argument is NULL and an attempt
2281  ** to allocate memory based on "sz" and "cnt" fails, then
2282  ** lookaside is silently disabled.
2283  ** <p>
2284  ** The [SQLITE_CONFIG_LOOKASIDE] configuration option can be used to set the
2285  ** default lookaside configuration at initialization.  The
2286  ** [-DSQLITE_DEFAULT_LOOKASIDE] option can be used to set the default lookaside
2287  ** configuration at compile-time.  Typical values for lookaside are 1200 for
2288  ** "sz" and 40 to 100 for "cnt".
2289  ** </dd>
2290  **
2291  ** [[SQLITE_DBCONFIG_ENABLE_FKEY]]
2292  ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
2293  ** <dd> ^This option is used to enable or disable the enforcement of
2294  ** [foreign key constraints].  This is the same setting that is
2295  ** enabled or disabled by the [PRAGMA foreign_keys] statement.
2296  ** The first argument is an integer which is 0 to disable FK enforcement,
2297  ** positive to enable FK enforcement or negative to leave FK enforcement
2298  ** unchanged.  The second parameter is a pointer to an integer into which
2299  ** is written 0 or 1 to indicate whether FK enforcement is off or on
2300  ** following this call.  The second parameter may be a NULL pointer, in
2301  ** which case the FK enforcement setting is not reported back. </dd>
2302  **
2303  ** [[SQLITE_DBCONFIG_ENABLE_TRIGGER]]
2304  ** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>
2305  ** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
2306  ** There should be two additional arguments.
2307  ** The first argument is an integer which is 0 to disable triggers,
2308  ** positive to enable triggers or negative to leave the setting unchanged.
2309  ** The second parameter is a pointer to an integer into which
2310  ** is written 0 or 1 to indicate whether triggers are disabled or enabled
2311  ** following this call.  The second parameter may be a NULL pointer, in
2312  ** which case the trigger setting is not reported back.
2313  **
2314  ** <p>Originally this option disabled all triggers.  ^(However, since
2315  ** SQLite version 3.35.0, TEMP triggers are still allowed even if
2316  ** this option is off.  So, in other words, this option now only disables
2317  ** triggers in the main database schema or in the schemas of [ATTACH]-ed
2318  ** databases.)^ </dd>
2319  **
2320  ** [[SQLITE_DBCONFIG_ENABLE_VIEW]]
2321  ** <dt>SQLITE_DBCONFIG_ENABLE_VIEW</dt>
2322  ** <dd> ^This option is used to enable or disable [CREATE VIEW | views].
2323  ** There must be two additional arguments.
2324  ** The first argument is an integer which is 0 to disable views,
2325  ** positive to enable views or negative to leave the setting unchanged.
2326  ** The second parameter is a pointer to an integer into which
2327  ** is written 0 or 1 to indicate whether views are disabled or enabled
2328  ** following this call.  The second parameter may be a NULL pointer, in
2329  ** which case the view setting is not reported back.
2330  **
2331  ** <p>Originally this option disabled all views.  ^(However, since
2332  ** SQLite version 3.35.0, TEMP views are still allowed even if
2333  ** this option is off.  So, in other words, this option now only disables
2334  ** views in the main database schema or in the schemas of ATTACH-ed
2335  ** databases.)^ </dd>
2336  **
2337  ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
2338  ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
2339  ** <dd> ^This option is used to enable or disable the
2340  ** [fts3_tokenizer()] function which is part of the
2341  ** [FTS3] full-text search engine extension.
2342  ** There must be two additional arguments.
2343  ** The first argument is an integer which is 0 to disable fts3_tokenizer() or
2344  ** positive to enable fts3_tokenizer() or negative to leave the setting
2345  ** unchanged.
2346  ** The second parameter is a pointer to an integer into which
2347  ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
2348  ** following this call.  The second parameter may be a NULL pointer, in
2349  ** which case the new setting is not reported back. </dd>
2350  **
2351  ** [[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION]]
2352  ** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
2353  ** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
2354  ** interface independently of the [load_extension()] SQL function.
2355  ** The [sqlite3_enable_load_extension()] API enables or disables both the
2356  ** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
2357  ** There must be two additional arguments.
2358  ** When the first argument to this interface is 1, then only the C-API is
2359  ** enabled and the SQL function remains disabled.  If the first argument to
2360  ** this interface is 0, then both the C-API and the SQL function are disabled.
2361  ** If the first argument is -1, then no changes are made to state of either the
2362  ** C-API or the SQL function.
2363  ** The second parameter is a pointer to an integer into which
2364  ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
2365  ** is disabled or enabled following this call.  The second parameter may
2366  ** be a NULL pointer, in which case the new setting is not reported back.
2367  ** </dd>
2368  **
2369  ** [[SQLITE_DBCONFIG_MAINDBNAME]] <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
2370  ** <dd> ^This option is used to change the name of the "main" database
2371  ** schema.  This option does not follow the
2372  ** [DBCONFIG arguments|usual SQLITE_DBCONFIG argument format].
2373  ** This option takes exactly one additional argument so that the
2374  ** [sqlite3_db_config()] call has a total of three parameters.  The
2375  ** extra argument must be a pointer to a constant UTF8 string which
2376  ** will become the new schema name in place of "main".  ^SQLite does
2377  ** not make a copy of the new main schema name string, so the application
2378  ** must ensure that the argument passed into SQLITE_DBCONFIG MAINDBNAME
2379  ** is unchanged until after the database connection closes.
2380  ** </dd>
2381  **
2382  ** [[SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE]]
2383  ** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>
2384  ** <dd> Usually, when a database in [WAL mode] is closed or detached from a
2385  ** database handle, SQLite checks if if there are other connections to the
2386  ** same database, and if there are no other database connection (if the
2387  ** connection being closed is the last open connection to the database),
2388  ** then SQLite performs a [checkpoint] before closing the connection and
2389  ** deletes the WAL file.  The SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE option can
2390  ** be used to override that behavior. The first argument passed to this
2391  ** operation (the third parameter to [sqlite3_db_config()]) is an integer
2392  ** which is positive to disable checkpoints-on-close, or zero (the default)
2393  ** to enable them, and negative to leave the setting unchanged.
2394  ** The second argument (the fourth parameter) is a pointer to an integer
2395  ** into which is written 0 or 1 to indicate whether checkpoints-on-close
2396  ** have been disabled - 0 if they are not disabled, 1 if they are.
2397  ** </dd>
2398  **
2399  ** [[SQLITE_DBCONFIG_ENABLE_QPSG]] <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
2400  ** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates
2401  ** the [query planner stability guarantee] (QPSG).  When the QPSG is active,
2402  ** a single SQL query statement will always use the same algorithm regardless
2403  ** of values of [bound parameters].)^ The QPSG disables some query optimizations
2404  ** that look at the values of bound parameters, which can make some queries
2405  ** slower.  But the QPSG has the advantage of more predictable behavior.  With
2406  ** the QPSG active, SQLite will always use the same query plan in the field as
2407  ** was used during testing in the lab.
2408  ** The first argument to this setting is an integer which is 0 to disable
2409  ** the QPSG, positive to enable QPSG, or negative to leave the setting
2410  ** unchanged. The second parameter is a pointer to an integer into which
2411  ** is written 0 or 1 to indicate whether the QPSG is disabled or enabled
2412  ** following this call.
2413  ** </dd>
2414  **
2415  ** [[SQLITE_DBCONFIG_TRIGGER_EQP]] <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt>
2416  ** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not
2417  ** include output for any operations performed by trigger programs. This
2418  ** option is used to set or clear (the default) a flag that governs this
2419  ** behavior. The first parameter passed to this operation is an integer -
2420  ** positive to enable output for trigger programs, or zero to disable it,
2421  ** or negative to leave the setting unchanged.
2422  ** The second parameter is a pointer to an integer into which is written
2423  ** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if
2424  ** it is not disabled, 1 if it is.
2425  ** </dd>
2426  **
2427  ** [[SQLITE_DBCONFIG_RESET_DATABASE]] <dt>SQLITE_DBCONFIG_RESET_DATABASE</dt>
2428  ** <dd> Set the SQLITE_DBCONFIG_RESET_DATABASE flag and then run
2429  ** [VACUUM] in order to reset a database back to an empty database
2430  ** with no schema and no content. The following process works even for
2431  ** a badly corrupted database file:
2432  ** <ol>
2433  ** <li> If the database connection is newly opened, make sure it has read the
2434  **      database schema by preparing then discarding some query against the
2435  **      database, or calling sqlite3_table_column_metadata(), ignoring any
2436  **      errors.  This step is only necessary if the application desires to keep
2437  **      the database in WAL mode after the reset if it was in WAL mode before
2438  **      the reset.
2439  ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0);
2440  ** <li> [sqlite3_exec](db, "[VACUUM]", 0, 0, 0);
2441  ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
2442  ** </ol>
2443  ** Because resetting a database is destructive and irreversible, the
2444  ** process requires the use of this obscure API and multiple steps to
2445  ** help ensure that it does not happen by accident. Because this
2446  ** feature must be capable of resetting corrupt databases, and
2447  ** shutting down virtual tables may require access to that corrupt
2448  ** storage, the library must abandon any installed virtual tables
2449  ** without calling their xDestroy() methods.
2450  **
2451  ** [[SQLITE_DBCONFIG_DEFENSIVE]] <dt>SQLITE_DBCONFIG_DEFENSIVE</dt>
2452  ** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the
2453  ** "defensive" flag for a database connection.  When the defensive
2454  ** flag is enabled, language features that allow ordinary SQL to
2455  ** deliberately corrupt the database file are disabled.  The disabled
2456  ** features include but are not limited to the following:
2457  ** <ul>
2458  ** <li> The [PRAGMA writable_schema=ON] statement.
2459  ** <li> The [PRAGMA journal_mode=OFF] statement.
2460  ** <li> The [PRAGMA schema_version=N] statement.
2461  ** <li> Writes to the [sqlite_dbpage] virtual table.
2462  ** <li> Direct writes to [shadow tables].
2463  ** </ul>
2464  ** </dd>
2465  **
2466  ** [[SQLITE_DBCONFIG_WRITABLE_SCHEMA]] <dt>SQLITE_DBCONFIG_WRITABLE_SCHEMA</dt>
2467  ** <dd>The SQLITE_DBCONFIG_WRITABLE_SCHEMA option activates or deactivates the
2468  ** "writable_schema" flag. This has the same effect and is logically equivalent
2469  ** to setting [PRAGMA writable_schema=ON] or [PRAGMA writable_schema=OFF].
2470  ** The first argument to this setting is an integer which is 0 to disable
2471  ** the writable_schema, positive to enable writable_schema, or negative to
2472  ** leave the setting unchanged. The second parameter is a pointer to an
2473  ** integer into which is written 0 or 1 to indicate whether the writable_schema
2474  ** is enabled or disabled following this call.
2475  ** </dd>
2476  **
2477  ** [[SQLITE_DBCONFIG_LEGACY_ALTER_TABLE]]
2478  ** <dt>SQLITE_DBCONFIG_LEGACY_ALTER_TABLE</dt>
2479  ** <dd>The SQLITE_DBCONFIG_LEGACY_ALTER_TABLE option activates or deactivates
2480  ** the legacy behavior of the [ALTER TABLE RENAME] command such it
2481  ** behaves as it did prior to [version 3.24.0] (2018-06-04).  See the
2482  ** "Compatibility Notice" on the [ALTER TABLE RENAME documentation] for
2483  ** additional information. This feature can also be turned on and off
2484  ** using the [PRAGMA legacy_alter_table] statement.
2485  ** </dd>
2486  **
2487  ** [[SQLITE_DBCONFIG_DQS_DML]]
2488  ** <dt>SQLITE_DBCONFIG_DQS_DML</dt>
2489  ** <dd>The SQLITE_DBCONFIG_DQS_DML option activates or deactivates
2490  ** the legacy [double-quoted string literal] misfeature for DML statements
2491  ** only, that is DELETE, INSERT, SELECT, and UPDATE statements. The
2492  ** default value of this setting is determined by the [-DSQLITE_DQS]
2493  ** compile-time option.
2494  ** </dd>
2495  **
2496  ** [[SQLITE_DBCONFIG_DQS_DDL]]
2497  ** <dt>SQLITE_DBCONFIG_DQS_DDL</dt>
2498  ** <dd>The SQLITE_DBCONFIG_DQS option activates or deactivates
2499  ** the legacy [double-quoted string literal] misfeature for DDL statements,
2500  ** such as CREATE TABLE and CREATE INDEX. The
2501  ** default value of this setting is determined by the [-DSQLITE_DQS]
2502  ** compile-time option.
2503  ** </dd>
2504  **
2505  ** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
2506  ** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</dt>
2507  ** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to
2508  ** assume that database schemas are untainted by malicious content.
2509  ** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
2510  ** takes additional defensive steps to protect the application from harm
2511  ** including:
2512  ** <ul>
2513  ** <li> Prohibit the use of SQL functions inside triggers, views,
2514  ** CHECK constraints, DEFAULT clauses, expression indexes,
2515  ** partial indexes, or generated columns
2516  ** unless those functions are tagged with [SQLITE_INNOCUOUS].
2517  ** <li> Prohibit the use of virtual tables inside of triggers or views
2518  ** unless those virtual tables are tagged with [SQLITE_VTAB_INNOCUOUS].
2519  ** </ul>
2520  ** This setting defaults to "on" for legacy compatibility, however
2521  ** all applications are advised to turn it off if possible. This setting
2522  ** can also be controlled using the [PRAGMA trusted_schema] statement.
2523  ** </dd>
2524  **
2525  ** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
2526  ** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</dt>
2527  ** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
2528  ** the legacy file format flag.  When activated, this flag causes all newly
2529  ** created database file to have a schema format version number (the 4-byte
2530  ** integer found at offset 44 into the database header) of 1.  This in turn
2531  ** means that the resulting database file will be readable and writable by
2532  ** any SQLite version back to 3.0.0 ([dateof:3.0.0]).  Without this setting,
2533  ** newly created databases are generally not understandable by SQLite versions
2534  ** prior to 3.3.0 ([dateof:3.3.0]).  As these words are written, there
2535  ** is now scarcely any need to generate database files that are compatible
2536  ** all the way back to version 3.0.0, and so this setting is of little
2537  ** practical use, but is provided so that SQLite can continue to claim the
2538  ** ability to generate new database files that are compatible with  version
2539  ** 3.0.0.
2540  ** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on,
2541  ** the [VACUUM] command will fail with an obscure error when attempting to
2542  ** process a table with generated columns and a descending index.  This is
2543  ** not considered a bug since SQLite versions 3.3.0 and earlier do not support
2544  ** either generated columns or descending indexes.
2545  ** </dd>
2546  **
2547  ** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]]
2548  ** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt>
2549  ** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in
2550  ** SQLITE_ENABLE_STMT_SCANSTATUS builds. In this case, it sets or clears
2551  ** a flag that enables collection of the sqlite3_stmt_scanstatus_v2()
2552  ** statistics. For statistics to be collected, the flag must be set on
2553  ** the database handle both when the SQL statement is prepared and when it
2554  ** is stepped. The flag is set (collection of statistics is enabled)
2555  ** by default. <p>This option takes two arguments: an integer and a pointer to
2556  ** an integer..  The first argument is 1, 0, or -1 to enable, disable, or
2557  ** leave unchanged the statement scanstatus option.  If the second argument
2558  ** is not NULL, then the value of the statement scanstatus setting after
2559  ** processing the first argument is written into the integer that the second
2560  ** argument points to.
2561  ** </dd>
2562  **
2563  ** [[SQLITE_DBCONFIG_REVERSE_SCANORDER]]
2564  ** <dt>SQLITE_DBCONFIG_REVERSE_SCANORDER</dt>
2565  ** <dd>The SQLITE_DBCONFIG_REVERSE_SCANORDER option changes the default order
2566  ** in which tables and indexes are scanned so that the scans start at the end
2567  ** and work toward the beginning rather than starting at the beginning and
2568  ** working toward the end. Setting SQLITE_DBCONFIG_REVERSE_SCANORDER is the
2569  ** same as setting [PRAGMA reverse_unordered_selects]. <p>This option takes
2570  ** two arguments which are an integer and a pointer to an integer.  The first
2571  ** argument is 1, 0, or -1 to enable, disable, or leave unchanged the
2572  ** reverse scan order flag, respectively.  If the second argument is not NULL,
2573  ** then 0 or 1 is written into the integer that the second argument points to
2574  ** depending on if the reverse scan order flag is set after processing the
2575  ** first argument.
2576  ** </dd>
2577  **
2578  ** [[SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE]]
2579  ** <dt>SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE</dt>
2580  ** <dd>The SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE option enables or disables
2581  ** the ability of the [ATTACH DATABASE] SQL command to create a new database
2582  ** file if the database filed named in the ATTACH command does not already
2583  ** exist.  This ability of ATTACH to create a new database is enabled by
2584  ** default.  Applications can disable or reenable the ability for ATTACH to
2585  ** create new database files using this DBCONFIG option.<p>
2586  ** This option takes two arguments which are an integer and a pointer
2587  ** to an integer.  The first argument is 1, 0, or -1 to enable, disable, or
2588  ** leave unchanged the attach-create flag, respectively.  If the second
2589  ** argument is not NULL, then 0 or 1 is written into the integer that the
2590  ** second argument points to depending on if the attach-create flag is set
2591  ** after processing the first argument.
2592  ** </dd>
2593  **
2594  ** [[SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE]]
2595  ** <dt>SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE</dt>
2596  ** <dd>The SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE option enables or disables the
2597  ** ability of the [ATTACH DATABASE] SQL command to open a database for writing.
2598  ** This capability is enabled by default.  Applications can disable or
2599  ** reenable this capability using the current DBCONFIG option.  If the
2600  ** the this capability is disabled, the [ATTACH] command will still work,
2601  ** but the database will be opened read-only.  If this option is disabled,
2602  ** then the ability to create a new database using [ATTACH] is also disabled,
2603  ** regardless of the value of the [SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE]
2604  ** option.<p>
2605  ** This option takes two arguments which are an integer and a pointer
2606  ** to an integer.  The first argument is 1, 0, or -1 to enable, disable, or
2607  ** leave unchanged the ability to ATTACH another database for writing,
2608  ** respectively.  If the second argument is not NULL, then 0 or 1 is written
2609  ** into the integer to which the second argument points, depending on whether
2610  ** the ability to ATTACH a read/write database is enabled or disabled
2611  ** after processing the first argument.
2612  ** </dd>
2613  **
2614  ** [[SQLITE_DBCONFIG_ENABLE_COMMENTS]]
2615  ** <dt>SQLITE_DBCONFIG_ENABLE_COMMENTS</dt>
2616  ** <dd>The SQLITE_DBCONFIG_ENABLE_COMMENTS option enables or disables the
2617  ** ability to include comments in SQL text.  Comments are enabled by default.
2618  ** An application can disable or reenable comments in SQL text using this
2619  ** DBCONFIG option.<p>
2620  ** This option takes two arguments which are an integer and a pointer
2621  ** to an integer.  The first argument is 1, 0, or -1 to enable, disable, or
2622  ** leave unchanged the ability to use comments in SQL text,
2623  ** respectively.  If the second argument is not NULL, then 0 or 1 is written
2624  ** into the integer that the second argument points to depending on if
2625  ** comments are allowed in SQL text after processing the first argument.
2626  ** </dd>
2627  **
2628  ** </dl>
2629  **
2630  ** [[DBCONFIG arguments]] <h3>Arguments To SQLITE_DBCONFIG Options</h3>
2631  **
2632  ** <p>Most of the SQLITE_DBCONFIG options take two arguments, so that the
2633  ** overall call to [sqlite3_db_config()] has a total of four parameters.
2634  ** The first argument (the third parameter to sqlite3_db_config()) is a integer.
2635  ** The second argument is a pointer to an integer.  If the first argument is 1,
2636  ** then the option becomes enabled.  If the first integer argument is 0, then the
2637  ** option is disabled.  If the first argument is -1, then the option setting
2638  ** is unchanged.  The second argument, the pointer to an integer, may be NULL.
2639  ** If the second argument is not NULL, then a value of 0 or 1 is written into
2640  ** the integer to which the second argument points, depending on whether the
2641  ** setting is disabled or enabled after applying any changes specified by
2642  ** the first argument.
2643  **
2644  ** <p>While most SQLITE_DBCONFIG options use the argument format
2645  ** described in the previous paragraph, the [SQLITE_DBCONFIG_MAINDBNAME]
2646  ** and [SQLITE_DBCONFIG_LOOKASIDE] options are different.  See the
2647  ** documentation of those exceptional options for details.
2648  */
2649  #define SQLITE_DBCONFIG_MAINDBNAME            1000 /* const char* */
2650  #define SQLITE_DBCONFIG_LOOKASIDE             1001 /* void* int int */
2651  #define SQLITE_DBCONFIG_ENABLE_FKEY           1002 /* int int* */
2652  #define SQLITE_DBCONFIG_ENABLE_TRIGGER        1003 /* int int* */
2653  #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
2654  #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
2655  #define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE      1006 /* int int* */
2656  #define SQLITE_DBCONFIG_ENABLE_QPSG           1007 /* int int* */
2657  #define SQLITE_DBCONFIG_TRIGGER_EQP           1008 /* int int* */
2658  #define SQLITE_DBCONFIG_RESET_DATABASE        1009 /* int int* */
2659  #define SQLITE_DBCONFIG_DEFENSIVE             1010 /* int int* */
2660  #define SQLITE_DBCONFIG_WRITABLE_SCHEMA       1011 /* int int* */
2661  #define SQLITE_DBCONFIG_LEGACY_ALTER_TABLE    1012 /* int int* */
2662  #define SQLITE_DBCONFIG_DQS_DML               1013 /* int int* */
2663  #define SQLITE_DBCONFIG_DQS_DDL               1014 /* int int* */
2664  #define SQLITE_DBCONFIG_ENABLE_VIEW           1015 /* int int* */
2665  #define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT    1016 /* int int* */
2666  #define SQLITE_DBCONFIG_TRUSTED_SCHEMA        1017 /* int int* */
2667  #define SQLITE_DBCONFIG_STMT_SCANSTATUS       1018 /* int int* */
2668  #define SQLITE_DBCONFIG_REVERSE_SCANORDER     1019 /* int int* */
2669  #define SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE  1020 /* int int* */
2670  #define SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE   1021 /* int int* */
2671  #define SQLITE_DBCONFIG_ENABLE_COMMENTS       1022 /* int int* */
2672  #define SQLITE_DBCONFIG_MAX                   1022 /* Largest DBCONFIG */
2673  
2674  /*
2675  ** CAPI3REF: Enable Or Disable Extended Result Codes
2676  ** METHOD: sqlite3
2677  **
2678  ** ^The sqlite3_extended_result_codes() routine enables or disables the
2679  ** [extended result codes] feature of SQLite. ^The extended result
2680  ** codes are disabled by default for historical compatibility.
2681  */
2682  SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);
2683  
2684  /*
2685  ** CAPI3REF: Last Insert Rowid
2686  ** METHOD: sqlite3
2687  **
2688  ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)
2689  ** has a unique 64-bit signed
2690  ** integer key called the [ROWID | "rowid"]. ^The rowid is always available
2691  ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those
2692  ** names are not also used by explicitly declared columns. ^If
2693  ** the table has a column of type [INTEGER PRIMARY KEY] then that column
2694  ** is another alias for the rowid.
2695  **
2696  ** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of
2697  ** the most recent successful [INSERT] into a rowid table or [virtual table]
2698  ** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not
2699  ** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred
2700  ** on the database connection D, then sqlite3_last_insert_rowid(D) returns
2701  ** zero.
2702  **
2703  ** As well as being set automatically as rows are inserted into database
2704  ** tables, the value returned by this function may be set explicitly by
2705  ** [sqlite3_set_last_insert_rowid()]
2706  **
2707  ** Some virtual table implementations may INSERT rows into rowid tables as
2708  ** part of committing a transaction (e.g. to flush data accumulated in memory
2709  ** to disk). In this case subsequent calls to this function return the rowid
2710  ** associated with these internal INSERT operations, which leads to
2711  ** unintuitive results. Virtual table implementations that do write to rowid
2712  ** tables in this way can avoid this problem by restoring the original
2713  ** rowid value using [sqlite3_set_last_insert_rowid()] before returning
2714  ** control to the user.
2715  **
2716  ** ^(If an [INSERT] occurs within a trigger then this routine will
2717  ** return the [rowid] of the inserted row as long as the trigger is
2718  ** running. Once the trigger program ends, the value returned
2719  ** by this routine reverts to what it was before the trigger was fired.)^
2720  **
2721  ** ^An [INSERT] that fails due to a constraint violation is not a
2722  ** successful [INSERT] and does not change the value returned by this
2723  ** routine.  ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,
2724  ** and INSERT OR ABORT make no changes to the return value of this
2725  ** routine when their insertion fails.  ^(When INSERT OR REPLACE
2726  ** encounters a constraint violation, it does not fail.  The
2727  ** INSERT continues to completion after deleting rows that caused
2728  ** the constraint problem so INSERT OR REPLACE will always change
2729  ** the return value of this interface.)^
2730  **
2731  ** ^For the purposes of this routine, an [INSERT] is considered to
2732  ** be successful even if it is subsequently rolled back.
2733  **
2734  ** This function is accessible to SQL statements via the
2735  ** [last_insert_rowid() SQL function].
2736  **
2737  ** If a separate thread performs a new [INSERT] on the same
2738  ** database connection while the [sqlite3_last_insert_rowid()]
2739  ** function is running and thus changes the last insert [rowid],
2740  ** then the value returned by [sqlite3_last_insert_rowid()] is
2741  ** unpredictable and might not equal either the old or the new
2742  ** last insert [rowid].
2743  */
2744  SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
2745  
2746  /*
2747  ** CAPI3REF: Set the Last Insert Rowid value.
2748  ** METHOD: sqlite3
2749  **
2750  ** The sqlite3_set_last_insert_rowid(D, R) method allows the application to
2751  ** set the value returned by calling sqlite3_last_insert_rowid(D) to R
2752  ** without inserting a row into the database.
2753  */
2754  SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64);
2755  
2756  /*
2757  ** CAPI3REF: Count The Number Of Rows Modified
2758  ** METHOD: sqlite3
2759  **
2760  ** ^These functions return the number of rows modified, inserted or
2761  ** deleted by the most recently completed INSERT, UPDATE or DELETE
2762  ** statement on the database connection specified by the only parameter.
2763  ** The two functions are identical except for the type of the return value
2764  ** and that if the number of rows modified by the most recent INSERT, UPDATE,
2765  ** or DELETE is greater than the maximum value supported by type "int", then
2766  ** the return value of sqlite3_changes() is undefined. ^Executing any other
2767  ** type of SQL statement does not modify the value returned by these functions.
2768  ** For the purposes of this interface, a CREATE TABLE AS SELECT statement
2769  ** does not count as an INSERT, UPDATE or DELETE statement and hence the rows
2770  ** added to the new table by the CREATE TABLE AS SELECT statement are not
2771  ** counted.
2772  **
2773  ** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are
2774  ** considered - auxiliary changes caused by [CREATE TRIGGER | triggers],
2775  ** [foreign key actions] or [REPLACE] constraint resolution are not counted.
2776  **
2777  ** Changes to a view that are intercepted by
2778  ** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value
2779  ** returned by sqlite3_changes() immediately after an INSERT, UPDATE or
2780  ** DELETE statement run on a view is always zero. Only changes made to real
2781  ** tables are counted.
2782  **
2783  ** Things are more complicated if the sqlite3_changes() function is
2784  ** executed while a trigger program is running. This may happen if the
2785  ** program uses the [changes() SQL function], or if some other callback
2786  ** function invokes sqlite3_changes() directly. Essentially:
2787  **
2788  ** <ul>
2789  **   <li> ^(Before entering a trigger program the value returned by
2790  **        sqlite3_changes() function is saved. After the trigger program
2791  **        has finished, the original value is restored.)^
2792  **
2793  **   <li> ^(Within a trigger program each INSERT, UPDATE and DELETE
2794  **        statement sets the value returned by sqlite3_changes()
2795  **        upon completion as normal. Of course, this value will not include
2796  **        any changes performed by sub-triggers, as the sqlite3_changes()
2797  **        value will be saved and restored after each sub-trigger has run.)^
2798  ** </ul>
2799  **
2800  ** ^This means that if the changes() SQL function (or similar) is used
2801  ** by the first INSERT, UPDATE or DELETE statement within a trigger, it
2802  ** returns the value as set when the calling statement began executing.
2803  ** ^If it is used by the second or subsequent such statement within a trigger
2804  ** program, the value returned reflects the number of rows modified by the
2805  ** previous INSERT, UPDATE or DELETE statement within the same trigger.
2806  **
2807  ** If a separate thread makes changes on the same database connection
2808  ** while [sqlite3_changes()] is running then the value returned
2809  ** is unpredictable and not meaningful.
2810  **
2811  ** See also:
2812  ** <ul>
2813  ** <li> the [sqlite3_total_changes()] interface
2814  ** <li> the [count_changes pragma]
2815  ** <li> the [changes() SQL function]
2816  ** <li> the [data_version pragma]
2817  ** </ul>
2818  */
2819  SQLITE_API int sqlite3_changes(sqlite3*);
2820  SQLITE_API sqlite3_int64 sqlite3_changes64(sqlite3*);
2821  
2822  /*
2823  ** CAPI3REF: Total Number Of Rows Modified
2824  ** METHOD: sqlite3
2825  **
2826  ** ^These functions return the total number of rows inserted, modified or
2827  ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
2828  ** since the database connection was opened, including those executed as
2829  ** part of trigger programs. The two functions are identical except for the
2830  ** type of the return value and that if the number of rows modified by the
2831  ** connection exceeds the maximum value supported by type "int", then
2832  ** the return value of sqlite3_total_changes() is undefined. ^Executing
2833  ** any other type of SQL statement does not affect the value returned by
2834  ** sqlite3_total_changes().
2835  **
2836  ** ^Changes made as part of [foreign key actions] are included in the
2837  ** count, but those made as part of REPLACE constraint resolution are
2838  ** not. ^Changes to a view that are intercepted by INSTEAD OF triggers
2839  ** are not counted.
2840  **
2841  ** The [sqlite3_total_changes(D)] interface only reports the number
2842  ** of rows that changed due to SQL statement run against database
2843  ** connection D.  Any changes by other database connections are ignored.
2844  ** To detect changes against a database file from other database
2845  ** connections use the [PRAGMA data_version] command or the
2846  ** [SQLITE_FCNTL_DATA_VERSION] [file control].
2847  **
2848  ** If a separate thread makes changes on the same database connection
2849  ** while [sqlite3_total_changes()] is running then the value
2850  ** returned is unpredictable and not meaningful.
2851  **
2852  ** See also:
2853  ** <ul>
2854  ** <li> the [sqlite3_changes()] interface
2855  ** <li> the [count_changes pragma]
2856  ** <li> the [changes() SQL function]
2857  ** <li> the [data_version pragma]
2858  ** <li> the [SQLITE_FCNTL_DATA_VERSION] [file control]
2859  ** </ul>
2860  */
2861  SQLITE_API int sqlite3_total_changes(sqlite3*);
2862  SQLITE_API sqlite3_int64 sqlite3_total_changes64(sqlite3*);
2863  
2864  /*
2865  ** CAPI3REF: Interrupt A Long-Running Query
2866  ** METHOD: sqlite3
2867  **
2868  ** ^This function causes any pending database operation to abort and
2869  ** return at its earliest opportunity. This routine is typically
2870  ** called in response to a user action such as pressing "Cancel"
2871  ** or Ctrl-C where the user wants a long query operation to halt
2872  ** immediately.
2873  **
2874  ** ^It is safe to call this routine from a thread different from the
2875  ** thread that is currently running the database operation.  But it
2876  ** is not safe to call this routine with a [database connection] that
2877  ** is closed or might close before sqlite3_interrupt() returns.
2878  **
2879  ** ^If an SQL operation is very nearly finished at the time when
2880  ** sqlite3_interrupt() is called, then it might not have an opportunity
2881  ** to be interrupted and might continue to completion.
2882  **
2883  ** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT].
2884  ** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE
2885  ** that is inside an explicit transaction, then the entire transaction
2886  ** will be rolled back automatically.
2887  **
2888  ** ^The sqlite3_interrupt(D) call is in effect until all currently running
2889  ** SQL statements on [database connection] D complete.  ^Any new SQL statements
2890  ** that are started after the sqlite3_interrupt() call and before the
2891  ** running statement count reaches zero are interrupted as if they had been
2892  ** running prior to the sqlite3_interrupt() call.  ^New SQL statements
2893  ** that are started after the running statement count reaches zero are
2894  ** not effected by the sqlite3_interrupt().
2895  ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
2896  ** SQL statements is a no-op and has no effect on SQL statements
2897  ** that are started after the sqlite3_interrupt() call returns.
2898  **
2899  ** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether
2900  ** or not an interrupt is currently in effect for [database connection] D.
2901  ** It returns 1 if an interrupt is currently in effect, or 0 otherwise.
2902  */
2903  SQLITE_API void sqlite3_interrupt(sqlite3*);
2904  SQLITE_API int sqlite3_is_interrupted(sqlite3*);
2905  
2906  /*
2907  ** CAPI3REF: Determine If An SQL Statement Is Complete
2908  **
2909  ** These routines are useful during command-line input to determine if the
2910  ** currently entered text seems to form a complete SQL statement or
2911  ** if additional input is needed before sending the text into
2912  ** SQLite for parsing.  ^These routines return 1 if the input string
2913  ** appears to be a complete SQL statement.  ^A statement is judged to be
2914  ** complete if it ends with a semicolon token and is not a prefix of a
2915  ** well-formed CREATE TRIGGER statement.  ^Semicolons that are embedded within
2916  ** string literals or quoted identifier names or comments are not
2917  ** independent tokens (they are part of the token in which they are
2918  ** embedded) and thus do not count as a statement terminator.  ^Whitespace
2919  ** and comments that follow the final semicolon are ignored.
2920  **
2921  ** ^These routines return 0 if the statement is incomplete.  ^If a
2922  ** memory allocation fails, then SQLITE_NOMEM is returned.
2923  **
2924  ** ^These routines do not parse the SQL statements thus
2925  ** will not detect syntactically incorrect SQL.
2926  **
2927  ** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior
2928  ** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked
2929  ** automatically by sqlite3_complete16().  If that initialization fails,
2930  ** then the return value from sqlite3_complete16() will be non-zero
2931  ** regardless of whether or not the input SQL is complete.)^
2932  **
2933  ** The input to [sqlite3_complete()] must be a zero-terminated
2934  ** UTF-8 string.
2935  **
2936  ** The input to [sqlite3_complete16()] must be a zero-terminated
2937  ** UTF-16 string in native byte order.
2938  */
2939  SQLITE_API int sqlite3_complete(const char *sql);
2940  SQLITE_API int sqlite3_complete16(const void *sql);
2941  
2942  /*
2943  ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2944  ** KEYWORDS: {busy-handler callback} {busy handler}
2945  ** METHOD: sqlite3
2946  **
2947  ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
2948  ** that might be invoked with argument P whenever
2949  ** an attempt is made to access a database table associated with
2950  ** [database connection] D when another thread
2951  ** or process has the table locked.
2952  ** The sqlite3_busy_handler() interface is used to implement
2953  ** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout].
2954  **
2955  ** ^If the busy callback is NULL, then [SQLITE_BUSY]
2956  ** is returned immediately upon encountering the lock.  ^If the busy callback
2957  ** is not NULL, then the callback might be invoked with two arguments.
2958  **
2959  ** ^The first argument to the busy handler is a copy of the void* pointer which
2960  ** is the third argument to sqlite3_busy_handler().  ^The second argument to
2961  ** the busy handler callback is the number of times that the busy handler has
2962  ** been invoked previously for the same locking event.  ^If the
2963  ** busy callback returns 0, then no additional attempts are made to
2964  ** access the database and [SQLITE_BUSY] is returned
2965  ** to the application.
2966  ** ^If the callback returns non-zero, then another attempt
2967  ** is made to access the database and the cycle repeats.
2968  **
2969  ** The presence of a busy handler does not guarantee that it will be invoked
2970  ** when there is lock contention. ^If SQLite determines that invoking the busy
2971  ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]
2972  ** to the application instead of invoking the
2973  ** busy handler.
2974  ** Consider a scenario where one process is holding a read lock that
2975  ** it is trying to promote to a reserved lock and
2976  ** a second process is holding a reserved lock that it is trying
2977  ** to promote to an exclusive lock.  The first process cannot proceed
2978  ** because it is blocked by the second and the second process cannot
2979  ** proceed because it is blocked by the first.  If both processes
2980  ** invoke the busy handlers, neither will make any progress.  Therefore,
2981  ** SQLite returns [SQLITE_BUSY] for the first process, hoping that this
2982  ** will induce the first process to release its read lock and allow
2983  ** the second process to proceed.
2984  **
2985  ** ^The default busy callback is NULL.
2986  **
2987  ** ^(There can only be a single busy handler defined for each
2988  ** [database connection].  Setting a new busy handler clears any
2989  ** previously set handler.)^  ^Note that calling [sqlite3_busy_timeout()]
2990  ** or evaluating [PRAGMA busy_timeout=N] will change the
2991  ** busy handler and thus clear any previously set busy handler.
2992  **
2993  ** The busy callback should not take any actions which modify the
2994  ** database connection that invoked the busy handler.  In other words,
2995  ** the busy handler is not reentrant.  Any such actions
2996  ** result in undefined behavior.
2997  **
2998  ** A busy handler must not close the database connection
2999  ** or [prepared statement] that invoked the busy handler.
3000  */
3001  SQLITE_API int sqlite3_busy_handler(sqlite3*,int(*)(void*,int),void*);
3002  
3003  /*
3004  ** CAPI3REF: Set A Busy Timeout
3005  ** METHOD: sqlite3
3006  **
3007  ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps
3008  ** for a specified amount of time when a table is locked.  ^The handler
3009  ** will sleep multiple times until at least "ms" milliseconds of sleeping
3010  ** have accumulated.  ^After at least "ms" milliseconds of sleeping,
3011  ** the handler returns 0 which causes [sqlite3_step()] to return
3012  ** [SQLITE_BUSY].
3013  **
3014  ** ^Calling this routine with an argument less than or equal to zero
3015  ** turns off all busy handlers.
3016  **
3017  ** ^(There can only be a single busy handler for a particular
3018  ** [database connection] at any given moment.  If another busy handler
3019  ** was defined  (using [sqlite3_busy_handler()]) prior to calling
3020  ** this routine, that other busy handler is cleared.)^
3021  **
3022  ** See also:  [PRAGMA busy_timeout]
3023  */
3024  SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);
3025  
3026  /*
3027  ** CAPI3REF: Set the Setlk Timeout
3028  ** METHOD: sqlite3
3029  **
3030  ** This routine is only useful in SQLITE_ENABLE_SETLK_TIMEOUT builds. If
3031  ** the VFS supports blocking locks, it sets the timeout in ms used by
3032  ** eligible locks taken on wal mode databases by the specified database
3033  ** handle. In non-SQLITE_ENABLE_SETLK_TIMEOUT builds, or if the VFS does
3034  ** not support blocking locks, this function is a no-op.
3035  **
3036  ** Passing 0 to this function disables blocking locks altogether. Passing
3037  ** -1 to this function requests that the VFS blocks for a long time -
3038  ** indefinitely if possible. The results of passing any other negative value
3039  ** are undefined.
3040  **
3041  ** Internally, each SQLite database handle store two timeout values - the
3042  ** busy-timeout (used for rollback mode databases, or if the VFS does not
3043  ** support blocking locks) and the setlk-timeout (used for blocking locks
3044  ** on wal-mode databases). The sqlite3_busy_timeout() method sets both
3045  ** values, this function sets only the setlk-timeout value. Therefore,
3046  ** to configure separate busy-timeout and setlk-timeout values for a single
3047  ** database handle, call sqlite3_busy_timeout() followed by this function.
3048  **
3049  ** Whenever the number of connections to a wal mode database falls from
3050  ** 1 to 0, the last connection takes an exclusive lock on the database,
3051  ** then checkpoints and deletes the wal file. While it is doing this, any
3052  ** new connection that tries to read from the database fails with an
3053  ** SQLITE_BUSY error. Or, if the SQLITE_SETLK_BLOCK_ON_CONNECT flag is
3054  ** passed to this API, the new connection blocks until the exclusive lock
3055  ** has been released.
3056  */
3057  SQLITE_API int sqlite3_setlk_timeout(sqlite3*, int ms, int flags);
3058  
3059  /*
3060  ** CAPI3REF: Flags for sqlite3_setlk_timeout()
3061  */
3062  #define SQLITE_SETLK_BLOCK_ON_CONNECT 0x01
3063  
3064  /*
3065  ** CAPI3REF: Convenience Routines For Running Queries
3066  ** METHOD: sqlite3
3067  **
3068  ** This is a legacy interface that is preserved for backwards compatibility.
3069  ** Use of this interface is not recommended.
3070  **
3071  ** Definition: A <b>result table</b> is memory data structure created by the
3072  ** [sqlite3_get_table()] interface.  A result table records the
3073  ** complete query results from one or more queries.
3074  **
3075  ** The table conceptually has a number of rows and columns.  But
3076  ** these numbers are not part of the result table itself.  These
3077  ** numbers are obtained separately.  Let N be the number of rows
3078  ** and M be the number of columns.
3079  **
3080  ** A result table is an array of pointers to zero-terminated UTF-8 strings.
3081  ** There are (N+1)*M elements in the array.  The first M pointers point
3082  ** to zero-terminated strings that  contain the names of the columns.
3083  ** The remaining entries all point to query results.  NULL values result
3084  ** in NULL pointers.  All other values are in their UTF-8 zero-terminated
3085  ** string representation as returned by [sqlite3_column_text()].
3086  **
3087  ** A result table might consist of one or more memory allocations.
3088  ** It is not safe to pass a result table directly to [sqlite3_free()].
3089  ** A result table should be deallocated using [sqlite3_free_table()].
3090  **
3091  ** ^(As an example of the result table format, suppose a query result
3092  ** is as follows:
3093  **
3094  ** <blockquote><pre>
3095  **        Name        | Age
3096  **        -----------------------
3097  **        Alice       | 43
3098  **        Bob         | 28
3099  **        Cindy       | 21
3100  ** </pre></blockquote>
3101  **
3102  ** There are two columns (M==2) and three rows (N==3).  Thus the
3103  ** result table has 8 entries.  Suppose the result table is stored
3104  ** in an array named azResult.  Then azResult holds this content:
3105  **
3106  ** <blockquote><pre>
3107  **        azResult&#91;0] = "Name";
3108  **        azResult&#91;1] = "Age";
3109  **        azResult&#91;2] = "Alice";
3110  **        azResult&#91;3] = "43";
3111  **        azResult&#91;4] = "Bob";
3112  **        azResult&#91;5] = "28";
3113  **        azResult&#91;6] = "Cindy";
3114  **        azResult&#91;7] = "21";
3115  ** </pre></blockquote>)^
3116  **
3117  ** ^The sqlite3_get_table() function evaluates one or more
3118  ** semicolon-separated SQL statements in the zero-terminated UTF-8
3119  ** string of its 2nd parameter and returns a result table to the
3120  ** pointer given in its 3rd parameter.
3121  **
3122  ** After the application has finished with the result from sqlite3_get_table(),
3123  ** it must pass the result table pointer to sqlite3_free_table() in order to
3124  ** release the memory that was malloced.  Because of the way the
3125  ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling
3126  ** function must not try to call [sqlite3_free()] directly.  Only
3127  ** [sqlite3_free_table()] is able to release the memory properly and safely.
3128  **
3129  ** The sqlite3_get_table() interface is implemented as a wrapper around
3130  ** [sqlite3_exec()].  The sqlite3_get_table() routine does not have access
3131  ** to any internal data structures of SQLite.  It uses only the public
3132  ** interface defined here.  As a consequence, errors that occur in the
3133  ** wrapper layer outside of the internal [sqlite3_exec()] call are not
3134  ** reflected in subsequent calls to [sqlite3_errcode()] or
3135  ** [sqlite3_errmsg()].
3136  */
3137  SQLITE_API int sqlite3_get_table(
3138    sqlite3 *db,          /* An open database */
3139    const char *zSql,     /* SQL to be evaluated */
3140    char ***pazResult,    /* Results of the query */
3141    int *pnRow,           /* Number of result rows written here */
3142    int *pnColumn,        /* Number of result columns written here */
3143    char **pzErrmsg       /* Error msg written here */
3144  );
3145  SQLITE_API void sqlite3_free_table(char **result);
3146  
3147  /*
3148  ** CAPI3REF: Formatted String Printing Functions
3149  **
3150  ** These routines are work-alikes of the "printf()" family of functions
3151  ** from the standard C library.
3152  ** These routines understand most of the common formatting options from
3153  ** the standard library printf()
3154  ** plus some additional non-standard formats ([%q], [%Q], [%w], and [%z]).
3155  ** See the [built-in printf()] documentation for details.
3156  **
3157  ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their
3158  ** results into memory obtained from [sqlite3_malloc64()].
3159  ** The strings returned by these two routines should be
3160  ** released by [sqlite3_free()].  ^Both routines return a
3161  ** NULL pointer if [sqlite3_malloc64()] is unable to allocate enough
3162  ** memory to hold the resulting string.
3163  **
3164  ** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from
3165  ** the standard C library.  The result is written into the
3166  ** buffer supplied as the second parameter whose size is given by
3167  ** the first parameter. Note that the order of the
3168  ** first two parameters is reversed from snprintf().)^  This is an
3169  ** historical accident that cannot be fixed without breaking
3170  ** backwards compatibility.  ^(Note also that sqlite3_snprintf()
3171  ** returns a pointer to its buffer instead of the number of
3172  ** characters actually written into the buffer.)^  We admit that
3173  ** the number of characters written would be a more useful return
3174  ** value but we cannot change the implementation of sqlite3_snprintf()
3175  ** now without breaking compatibility.
3176  **
3177  ** ^As long as the buffer size is greater than zero, sqlite3_snprintf()
3178  ** guarantees that the buffer is always zero-terminated.  ^The first
3179  ** parameter "n" is the total size of the buffer, including space for
3180  ** the zero terminator.  So the longest string that can be completely
3181  ** written will be n-1 characters.
3182  **
3183  ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
3184  **
3185  ** See also:  [built-in printf()], [printf() SQL function]
3186  */
3187  SQLITE_API char *sqlite3_mprintf(const char*,...);
3188  SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
3189  SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
3190  SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
3191  
3192  /*
3193  ** CAPI3REF: Memory Allocation Subsystem
3194  **
3195  ** The SQLite core uses these three routines for all of its own
3196  ** internal memory allocation needs. "Core" in the previous sentence
3197  ** does not include operating-system specific [VFS] implementation.  The
3198  ** Windows VFS uses native malloc() and free() for some operations.
3199  **
3200  ** ^The sqlite3_malloc() routine returns a pointer to a block
3201  ** of memory at least N bytes in length, where N is the parameter.
3202  ** ^If sqlite3_malloc() is unable to obtain sufficient free
3203  ** memory, it returns a NULL pointer.  ^If the parameter N to
3204  ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns
3205  ** a NULL pointer.
3206  **
3207  ** ^The sqlite3_malloc64(N) routine works just like
3208  ** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead
3209  ** of a signed 32-bit integer.
3210  **
3211  ** ^Calling sqlite3_free() with a pointer previously returned
3212  ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so
3213  ** that it might be reused.  ^The sqlite3_free() routine is
3214  ** a no-op if is called with a NULL pointer.  Passing a NULL pointer
3215  ** to sqlite3_free() is harmless.  After being freed, memory
3216  ** should neither be read nor written.  Even reading previously freed
3217  ** memory might result in a segmentation fault or other severe error.
3218  ** Memory corruption, a segmentation fault, or other severe error
3219  ** might result if sqlite3_free() is called with a non-NULL pointer that
3220  ** was not obtained from sqlite3_malloc() or sqlite3_realloc().
3221  **
3222  ** ^The sqlite3_realloc(X,N) interface attempts to resize a
3223  ** prior memory allocation X to be at least N bytes.
3224  ** ^If the X parameter to sqlite3_realloc(X,N)
3225  ** is a NULL pointer then its behavior is identical to calling
3226  ** sqlite3_malloc(N).
3227  ** ^If the N parameter to sqlite3_realloc(X,N) is zero or
3228  ** negative then the behavior is exactly the same as calling
3229  ** sqlite3_free(X).
3230  ** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation
3231  ** of at least N bytes in size or NULL if insufficient memory is available.
3232  ** ^If M is the size of the prior allocation, then min(N,M) bytes
3233  ** of the prior allocation are copied into the beginning of buffer returned
3234  ** by sqlite3_realloc(X,N) and the prior allocation is freed.
3235  ** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the
3236  ** prior allocation is not freed.
3237  **
3238  ** ^The sqlite3_realloc64(X,N) interfaces works the same as
3239  ** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead
3240  ** of a 32-bit signed integer.
3241  **
3242  ** ^If X is a memory allocation previously obtained from sqlite3_malloc(),
3243  ** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then
3244  ** sqlite3_msize(X) returns the size of that memory allocation in bytes.
3245  ** ^The value returned by sqlite3_msize(X) might be larger than the number
3246  ** of bytes requested when X was allocated.  ^If X is a NULL pointer then
3247  ** sqlite3_msize(X) returns zero.  If X points to something that is not
3248  ** the beginning of memory allocation, or if it points to a formerly
3249  ** valid memory allocation that has now been freed, then the behavior
3250  ** of sqlite3_msize(X) is undefined and possibly harmful.
3251  **
3252  ** ^The memory returned by sqlite3_malloc(), sqlite3_realloc(),
3253  ** sqlite3_malloc64(), and sqlite3_realloc64()
3254  ** is always aligned to at least an 8 byte boundary, or to a
3255  ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time
3256  ** option is used.
3257  **
3258  ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]
3259  ** must be either NULL or else pointers obtained from a prior
3260  ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have
3261  ** not yet been released.
3262  **
3263  ** The application must not read or write any part of
3264  ** a block of memory after it has been released using
3265  ** [sqlite3_free()] or [sqlite3_realloc()].
3266  */
3267  SQLITE_API void *sqlite3_malloc(int);
3268  SQLITE_API void *sqlite3_malloc64(sqlite3_uint64);
3269  SQLITE_API void *sqlite3_realloc(void*, int);
3270  SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64);
3271  SQLITE_API void sqlite3_free(void*);
3272  SQLITE_API sqlite3_uint64 sqlite3_msize(void*);
3273  
3274  /*
3275  ** CAPI3REF: Memory Allocator Statistics
3276  **
3277  ** SQLite provides these two interfaces for reporting on the status
3278  ** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()]
3279  ** routines, which form the built-in memory allocation subsystem.
3280  **
3281  ** ^The [sqlite3_memory_used()] routine returns the number of bytes
3282  ** of memory currently outstanding (malloced but not freed).
3283  ** ^The [sqlite3_memory_highwater()] routine returns the maximum
3284  ** value of [sqlite3_memory_used()] since the high-water mark
3285  ** was last reset.  ^The values returned by [sqlite3_memory_used()] and
3286  ** [sqlite3_memory_highwater()] include any overhead
3287  ** added by SQLite in its implementation of [sqlite3_malloc()],
3288  ** but not overhead added by the any underlying system library
3289  ** routines that [sqlite3_malloc()] may call.
3290  **
3291  ** ^The memory high-water mark is reset to the current value of
3292  ** [sqlite3_memory_used()] if and only if the parameter to
3293  ** [sqlite3_memory_highwater()] is true.  ^The value returned
3294  ** by [sqlite3_memory_highwater(1)] is the high-water mark
3295  ** prior to the reset.
3296  */
3297  SQLITE_API sqlite3_int64 sqlite3_memory_used(void);
3298  SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag);
3299  
3300  /*
3301  ** CAPI3REF: Pseudo-Random Number Generator
3302  **
3303  ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to
3304  ** select random [ROWID | ROWIDs] when inserting new records into a table that
3305  ** already uses the largest possible [ROWID].  The PRNG is also used for
3306  ** the built-in random() and randomblob() SQL functions.  This interface allows
3307  ** applications to access the same PRNG for other purposes.
3308  **
3309  ** ^A call to this routine stores N bytes of randomness into buffer P.
3310  ** ^The P parameter can be a NULL pointer.
3311  **
3312  ** ^If this routine has not been previously called or if the previous
3313  ** call had N less than one or a NULL pointer for P, then the PRNG is
3314  ** seeded using randomness obtained from the xRandomness method of
3315  ** the default [sqlite3_vfs] object.
3316  ** ^If the previous call to this routine had an N of 1 or more and a
3317  ** non-NULL P then the pseudo-randomness is generated
3318  ** internally and without recourse to the [sqlite3_vfs] xRandomness
3319  ** method.
3320  */
3321  SQLITE_API void sqlite3_randomness(int N, void *P);
3322  
3323  /*
3324  ** CAPI3REF: Compile-Time Authorization Callbacks
3325  ** METHOD: sqlite3
3326  ** KEYWORDS: {authorizer callback}
3327  **
3328  ** ^This routine registers an authorizer callback with a particular
3329  ** [database connection], supplied in the first argument.
3330  ** ^The authorizer callback is invoked as SQL statements are being compiled
3331  ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
3332  ** [sqlite3_prepare_v3()], [sqlite3_prepare16()], [sqlite3_prepare16_v2()],
3333  ** and [sqlite3_prepare16_v3()].  ^At various
3334  ** points during the compilation process, as logic is being created
3335  ** to perform various actions, the authorizer callback is invoked to
3336  ** see if those actions are allowed.  ^The authorizer callback should
3337  ** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the
3338  ** specific action but allow the SQL statement to continue to be
3339  ** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be
3340  ** rejected with an error.  ^If the authorizer callback returns
3341  ** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY]
3342  ** then the [sqlite3_prepare_v2()] or equivalent call that triggered
3343  ** the authorizer will fail with an error message.
3344  **
3345  ** When the callback returns [SQLITE_OK], that means the operation
3346  ** requested is ok.  ^When the callback returns [SQLITE_DENY], the
3347  ** [sqlite3_prepare_v2()] or equivalent call that triggered the
3348  ** authorizer will fail with an error message explaining that
3349  ** access is denied.
3350  **
3351  ** ^The first parameter to the authorizer callback is a copy of the third
3352  ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
3353  ** to the callback is an integer [SQLITE_COPY | action code] that specifies
3354  ** the particular action to be authorized. ^The third through sixth parameters
3355  ** to the callback are either NULL pointers or zero-terminated strings
3356  ** that contain additional details about the action to be authorized.
3357  ** Applications must always be prepared to encounter a NULL pointer in any
3358  ** of the third through the sixth parameters of the authorization callback.
3359  **
3360  ** ^If the action code is [SQLITE_READ]
3361  ** and the callback returns [SQLITE_IGNORE] then the
3362  ** [prepared statement] statement is constructed to substitute
3363  ** a NULL value in place of the table column that would have
3364  ** been read if [SQLITE_OK] had been returned.  The [SQLITE_IGNORE]
3365  ** return can be used to deny an untrusted user access to individual
3366  ** columns of a table.
3367  ** ^When a table is referenced by a [SELECT] but no column values are
3368  ** extracted from that table (for example in a query like
3369  ** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback
3370  ** is invoked once for that table with a column name that is an empty string.
3371  ** ^If the action code is [SQLITE_DELETE] and the callback returns
3372  ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
3373  ** [truncate optimization] is disabled and all rows are deleted individually.
3374  **
3375  ** An authorizer is used when [sqlite3_prepare | preparing]
3376  ** SQL statements from an untrusted source, to ensure that the SQL statements
3377  ** do not try to access data they are not allowed to see, or that they do not
3378  ** try to execute malicious statements that damage the database.  For
3379  ** example, an application may allow a user to enter arbitrary
3380  ** SQL queries for evaluation by a database.  But the application does
3381  ** not want the user to be able to make arbitrary changes to the
3382  ** database.  An authorizer could then be put in place while the
3383  ** user-entered SQL is being [sqlite3_prepare | prepared] that
3384  ** disallows everything except [SELECT] statements.
3385  **
3386  ** Applications that need to process SQL from untrusted sources
3387  ** might also consider lowering resource limits using [sqlite3_limit()]
3388  ** and limiting database size using the [max_page_count] [PRAGMA]
3389  ** in addition to using an authorizer.
3390  **
3391  ** ^(Only a single authorizer can be in place on a database connection
3392  ** at a time.  Each call to sqlite3_set_authorizer overrides the
3393  ** previous call.)^  ^Disable the authorizer by installing a NULL callback.
3394  ** The authorizer is disabled by default.
3395  **
3396  ** The authorizer callback must not do anything that will modify
3397  ** the database connection that invoked the authorizer callback.
3398  ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
3399  ** database connections for the meaning of "modify" in this paragraph.
3400  **
3401  ** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the
3402  ** statement might be re-prepared during [sqlite3_step()] due to a
3403  ** schema change.  Hence, the application should ensure that the
3404  ** correct authorizer callback remains in place during the [sqlite3_step()].
3405  **
3406  ** ^Note that the authorizer callback is invoked only during
3407  ** [sqlite3_prepare()] or its variants.  Authorization is not
3408  ** performed during statement evaluation in [sqlite3_step()], unless
3409  ** as stated in the previous paragraph, sqlite3_step() invokes
3410  ** sqlite3_prepare_v2() to reprepare a statement after a schema change.
3411  */
3412  SQLITE_API int sqlite3_set_authorizer(
3413    sqlite3*,
3414    int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
3415    void *pUserData
3416  );
3417  
3418  /*
3419  ** CAPI3REF: Authorizer Return Codes
3420  **
3421  ** The [sqlite3_set_authorizer | authorizer callback function] must
3422  ** return either [SQLITE_OK] or one of these two constants in order
3423  ** to signal SQLite whether or not the action is permitted.  See the
3424  ** [sqlite3_set_authorizer | authorizer documentation] for additional
3425  ** information.
3426  **
3427  ** Note that SQLITE_IGNORE is also used as a [conflict resolution mode]
3428  ** returned from the [sqlite3_vtab_on_conflict()] interface.
3429  */
3430  #define SQLITE_DENY   1   /* Abort the SQL statement with an error */
3431  #define SQLITE_IGNORE 2   /* Don't allow access, but don't generate an error */
3432  
3433  /*
3434  ** CAPI3REF: Authorizer Action Codes
3435  **
3436  ** The [sqlite3_set_authorizer()] interface registers a callback function
3437  ** that is invoked to authorize certain SQL statement actions.  The
3438  ** second parameter to the callback is an integer code that specifies
3439  ** what action is being authorized.  These are the integer action codes that
3440  ** the authorizer callback may be passed.
3441  **
3442  ** These action code values signify what kind of operation is to be
3443  ** authorized.  The 3rd and 4th parameters to the authorization
3444  ** callback function will be parameters or NULL depending on which of these
3445  ** codes is used as the second parameter.  ^(The 5th parameter to the
3446  ** authorizer callback is the name of the database ("main", "temp",
3447  ** etc.) if applicable.)^  ^The 6th parameter to the authorizer callback
3448  ** is the name of the inner-most trigger or view that is responsible for
3449  ** the access attempt or NULL if this access attempt is directly from
3450  ** top-level SQL code.
3451  */
3452  /******************************************* 3rd ************ 4th ***********/
3453  #define SQLITE_CREATE_INDEX          1   /* Index Name      Table Name      */
3454  #define SQLITE_CREATE_TABLE          2   /* Table Name      NULL            */
3455  #define SQLITE_CREATE_TEMP_INDEX     3   /* Index Name      Table Name      */
3456  #define SQLITE_CREATE_TEMP_TABLE     4   /* Table Name      NULL            */
3457  #define SQLITE_CREATE_TEMP_TRIGGER   5   /* Trigger Name    Table Name      */
3458  #define SQLITE_CREATE_TEMP_VIEW      6   /* View Name       NULL            */
3459  #define SQLITE_CREATE_TRIGGER        7   /* Trigger Name    Table Name      */
3460  #define SQLITE_CREATE_VIEW           8   /* View Name       NULL            */
3461  #define SQLITE_DELETE                9   /* Table Name      NULL            */
3462  #define SQLITE_DROP_INDEX           10   /* Index Name      Table Name      */
3463  #define SQLITE_DROP_TABLE           11   /* Table Name      NULL            */
3464  #define SQLITE_DROP_TEMP_INDEX      12   /* Index Name      Table Name      */
3465  #define SQLITE_DROP_TEMP_TABLE      13   /* Table Name      NULL            */
3466  #define SQLITE_DROP_TEMP_TRIGGER    14   /* Trigger Name    Table Name      */
3467  #define SQLITE_DROP_TEMP_VIEW       15   /* View Name       NULL            */
3468  #define SQLITE_DROP_TRIGGER         16   /* Trigger Name    Table Name      */
3469  #define SQLITE_DROP_VIEW            17   /* View Name       NULL            */
3470  #define SQLITE_INSERT               18   /* Table Name      NULL            */
3471  #define SQLITE_PRAGMA               19   /* Pragma Name     1st arg or NULL */
3472  #define SQLITE_READ                 20   /* Table Name      Column Name     */
3473  #define SQLITE_SELECT               21   /* NULL            NULL            */
3474  #define SQLITE_TRANSACTION          22   /* Operation       NULL            */
3475  #define SQLITE_UPDATE               23   /* Table Name      Column Name     */
3476  #define SQLITE_ATTACH               24   /* Filename        NULL            */
3477  #define SQLITE_DETACH               25   /* Database Name   NULL            */
3478  #define SQLITE_ALTER_TABLE          26   /* Database Name   Table Name      */
3479  #define SQLITE_REINDEX              27   /* Index Name      NULL            */
3480  #define SQLITE_ANALYZE              28   /* Table Name      NULL            */
3481  #define SQLITE_CREATE_VTABLE        29   /* Table Name      Module Name     */
3482  #define SQLITE_DROP_VTABLE          30   /* Table Name      Module Name     */
3483  #define SQLITE_FUNCTION             31   /* NULL            Function Name   */
3484  #define SQLITE_SAVEPOINT            32   /* Operation       Savepoint Name  */
3485  #define SQLITE_COPY                  0   /* No longer used */
3486  #define SQLITE_RECURSIVE            33   /* NULL            NULL            */
3487  
3488  /*
3489  ** CAPI3REF: Deprecated Tracing And Profiling Functions
3490  ** DEPRECATED
3491  **
3492  ** These routines are deprecated. Use the [sqlite3_trace_v2()] interface
3493  ** instead of the routines described here.
3494  **
3495  ** These routines register callback functions that can be used for
3496  ** tracing and profiling the execution of SQL statements.
3497  **
3498  ** ^The callback function registered by sqlite3_trace() is invoked at
3499  ** various times when an SQL statement is being run by [sqlite3_step()].
3500  ** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the
3501  ** SQL statement text as the statement first begins executing.
3502  ** ^(Additional sqlite3_trace() callbacks might occur
3503  ** as each triggered subprogram is entered.  The callbacks for triggers
3504  ** contain a UTF-8 SQL comment that identifies the trigger.)^
3505  **
3506  ** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit
3507  ** the length of [bound parameter] expansion in the output of sqlite3_trace().
3508  **
3509  ** ^The callback function registered by sqlite3_profile() is invoked
3510  ** as each SQL statement finishes.  ^The profile callback contains
3511  ** the original statement text and an estimate of wall-clock time
3512  ** of how long that statement took to run.  ^The profile callback
3513  ** time is in units of nanoseconds, however the current implementation
3514  ** is only capable of millisecond resolution so the six least significant
3515  ** digits in the time are meaningless.  Future versions of SQLite
3516  ** might provide greater resolution on the profiler callback.  Invoking
3517  ** either [sqlite3_trace()] or [sqlite3_trace_v2()] will cancel the
3518  ** profile callback.
3519  */
3520  SQLITE_API SQLITE_DEPRECATED void *sqlite3_trace(sqlite3*,
3521     void(*xTrace)(void*,const char*), void*);
3522  SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3*,
3523     void(*xProfile)(void*,const char*,sqlite3_uint64), void*);
3524  
3525  /*
3526  ** CAPI3REF: SQL Trace Event Codes
3527  ** KEYWORDS: SQLITE_TRACE
3528  **
3529  ** These constants identify classes of events that can be monitored
3530  ** using the [sqlite3_trace_v2()] tracing logic.  The M argument
3531  ** to [sqlite3_trace_v2(D,M,X,P)] is an OR-ed combination of one or more of
3532  ** the following constants.  ^The first argument to the trace callback
3533  ** is one of the following constants.
3534  **
3535  ** New tracing constants may be added in future releases.
3536  **
3537  ** ^A trace callback has four arguments: xCallback(T,C,P,X).
3538  ** ^The T argument is one of the integer type codes above.
3539  ** ^The C argument is a copy of the context pointer passed in as the
3540  ** fourth argument to [sqlite3_trace_v2()].
3541  ** The P and X arguments are pointers whose meanings depend on T.
3542  **
3543  ** <dl>
3544  ** [[SQLITE_TRACE_STMT]] <dt>SQLITE_TRACE_STMT</dt>
3545  ** <dd>^An SQLITE_TRACE_STMT callback is invoked when a prepared statement
3546  ** first begins running and possibly at other times during the
3547  ** execution of the prepared statement, such as at the start of each
3548  ** trigger subprogram. ^The P argument is a pointer to the
3549  ** [prepared statement]. ^The X argument is a pointer to a string which
3550  ** is the unexpanded SQL text of the prepared statement or an SQL comment
3551  ** that indicates the invocation of a trigger.  ^The callback can compute
3552  ** the same text that would have been returned by the legacy [sqlite3_trace()]
3553  ** interface by using the X argument when X begins with "--" and invoking
3554  ** [sqlite3_expanded_sql(P)] otherwise.
3555  **
3556  ** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt>
3557  ** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same
3558  ** information as is provided by the [sqlite3_profile()] callback.
3559  ** ^The P argument is a pointer to the [prepared statement] and the
3560  ** X argument points to a 64-bit integer which is approximately
3561  ** the number of nanoseconds that the prepared statement took to run.
3562  ** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.
3563  **
3564  ** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt>
3565  ** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared
3566  ** statement generates a single row of result.
3567  ** ^The P argument is a pointer to the [prepared statement] and the
3568  ** X argument is unused.
3569  **
3570  ** [[SQLITE_TRACE_CLOSE]] <dt>SQLITE_TRACE_CLOSE</dt>
3571  ** <dd>^An SQLITE_TRACE_CLOSE callback is invoked when a database
3572  ** connection closes.
3573  ** ^The P argument is a pointer to the [database connection] object
3574  ** and the X argument is unused.
3575  ** </dl>
3576  */
3577  #define SQLITE_TRACE_STMT       0x01
3578  #define SQLITE_TRACE_PROFILE    0x02
3579  #define SQLITE_TRACE_ROW        0x04
3580  #define SQLITE_TRACE_CLOSE      0x08
3581  
3582  /*
3583  ** CAPI3REF: SQL Trace Hook
3584  ** METHOD: sqlite3
3585  **
3586  ** ^The sqlite3_trace_v2(D,M,X,P) interface registers a trace callback
3587  ** function X against [database connection] D, using property mask M
3588  ** and context pointer P.  ^If the X callback is
3589  ** NULL or if the M mask is zero, then tracing is disabled.  The
3590  ** M argument should be the bitwise OR-ed combination of
3591  ** zero or more [SQLITE_TRACE] constants.
3592  **
3593  ** ^Each call to either sqlite3_trace(D,X,P) or sqlite3_trace_v2(D,M,X,P)
3594  ** overrides (cancels) all prior calls to sqlite3_trace(D,X,P) or
3595  ** sqlite3_trace_v2(D,M,X,P) for the [database connection] D.  Each
3596  ** database connection may have at most one trace callback.
3597  **
3598  ** ^The X callback is invoked whenever any of the events identified by
3599  ** mask M occur.  ^The integer return value from the callback is currently
3600  ** ignored, though this may change in future releases.  Callback
3601  ** implementations should return zero to ensure future compatibility.
3602  **
3603  ** ^A trace callback is invoked with four arguments: callback(T,C,P,X).
3604  ** ^The T argument is one of the [SQLITE_TRACE]
3605  ** constants to indicate why the callback was invoked.
3606  ** ^The C argument is a copy of the context pointer.
3607  ** The P and X arguments are pointers whose meanings depend on T.
3608  **
3609  ** The sqlite3_trace_v2() interface is intended to replace the legacy
3610  ** interfaces [sqlite3_trace()] and [sqlite3_profile()], both of which
3611  ** are deprecated.
3612  */
3613  SQLITE_API int sqlite3_trace_v2(
3614    sqlite3*,
3615    unsigned uMask,
3616    int(*xCallback)(unsigned,void*,void*,void*),
3617    void *pCtx
3618  );
3619  
3620  /*
3621  ** CAPI3REF: Query Progress Callbacks
3622  ** METHOD: sqlite3
3623  **
3624  ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
3625  ** function X to be invoked periodically during long running calls to
3626  ** [sqlite3_step()] and [sqlite3_prepare()] and similar for
3627  ** database connection D.  An example use for this
3628  ** interface is to keep a GUI updated during a large query.
3629  **
3630  ** ^The parameter P is passed through as the only parameter to the
3631  ** callback function X.  ^The parameter N is the approximate number of
3632  ** [virtual machine instructions] that are evaluated between successive
3633  ** invocations of the callback X.  ^If N is less than one then the progress
3634  ** handler is disabled.
3635  **
3636  ** ^Only a single progress handler may be defined at one time per
3637  ** [database connection]; setting a new progress handler cancels the
3638  ** old one.  ^Setting parameter X to NULL disables the progress handler.
3639  ** ^The progress handler is also disabled by setting N to a value less
3640  ** than 1.
3641  **
3642  ** ^If the progress callback returns non-zero, the operation is
3643  ** interrupted.  This feature can be used to implement a
3644  ** "Cancel" button on a GUI progress dialog box.
3645  **
3646  ** The progress handler callback must not do anything that will modify
3647  ** the database connection that invoked the progress handler.
3648  ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
3649  ** database connections for the meaning of "modify" in this paragraph.
3650  **
3651  ** The progress handler callback would originally only be invoked from the
3652  ** bytecode engine.  It still might be invoked during [sqlite3_prepare()]
3653  ** and similar because those routines might force a reparse of the schema
3654  ** which involves running the bytecode engine.  However, beginning with
3655  ** SQLite version 3.41.0, the progress handler callback might also be
3656  ** invoked directly from [sqlite3_prepare()] while analyzing and generating
3657  ** code for complex queries.
3658  */
3659  SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
3660  
3661  /*
3662  ** CAPI3REF: Opening A New Database Connection
3663  ** CONSTRUCTOR: sqlite3
3664  **
3665  ** ^These routines open an SQLite database file as specified by the
3666  ** filename argument. ^The filename argument is interpreted as UTF-8 for
3667  ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte
3668  ** order for sqlite3_open16(). ^(A [database connection] handle is usually
3669  ** returned in *ppDb, even if an error occurs.  The only exception is that
3670  ** if SQLite is unable to allocate memory to hold the [sqlite3] object,
3671  ** a NULL will be written into *ppDb instead of a pointer to the [sqlite3]
3672  ** object.)^ ^(If the database is opened (and/or created) successfully, then
3673  ** [SQLITE_OK] is returned.  Otherwise an [error code] is returned.)^ ^The
3674  ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain
3675  ** an English language description of the error following a failure of any
3676  ** of the sqlite3_open() routines.
3677  **
3678  ** ^The default encoding will be UTF-8 for databases created using
3679  ** sqlite3_open() or sqlite3_open_v2().  ^The default encoding for databases
3680  ** created using sqlite3_open16() will be UTF-16 in the native byte order.
3681  **
3682  ** Whether or not an error occurs when it is opened, resources
3683  ** associated with the [database connection] handle should be released by
3684  ** passing it to [sqlite3_close()] when it is no longer required.
3685  **
3686  ** The sqlite3_open_v2() interface works like sqlite3_open()
3687  ** except that it accepts two additional parameters for additional control
3688  ** over the new database connection.  ^(The flags parameter to
3689  ** sqlite3_open_v2() must include, at a minimum, one of the following
3690  ** three flag combinations:)^
3691  **
3692  ** <dl>
3693  ** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
3694  ** <dd>The database is opened in read-only mode.  If the database does
3695  ** not already exist, an error is returned.</dd>)^
3696  **
3697  ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
3698  ** <dd>The database is opened for reading and writing if possible, or
3699  ** reading only if the file is write protected by the operating
3700  ** system.  In either case the database must already exist, otherwise
3701  ** an error is returned.  For historical reasons, if opening in
3702  ** read-write mode fails due to OS-level permissions, an attempt is
3703  ** made to open it in read-only mode. [sqlite3_db_readonly()] can be
3704  ** used to determine whether the database is actually
3705  ** read-write.</dd>)^
3706  **
3707  ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
3708  ** <dd>The database is opened for reading and writing, and is created if
3709  ** it does not already exist. This is the behavior that is always used for
3710  ** sqlite3_open() and sqlite3_open16().</dd>)^
3711  ** </dl>
3712  **
3713  ** In addition to the required flags, the following optional flags are
3714  ** also supported:
3715  **
3716  ** <dl>
3717  ** ^(<dt>[SQLITE_OPEN_URI]</dt>
3718  ** <dd>The filename can be interpreted as a URI if this flag is set.</dd>)^
3719  **
3720  ** ^(<dt>[SQLITE_OPEN_MEMORY]</dt>
3721  ** <dd>The database will be opened as an in-memory database.  The database
3722  ** is named by the "filename" argument for the purposes of cache-sharing,
3723  ** if shared cache mode is enabled, but the "filename" is otherwise ignored.
3724  ** </dd>)^
3725  **
3726  ** ^(<dt>[SQLITE_OPEN_NOMUTEX]</dt>
3727  ** <dd>The new database connection will use the "multi-thread"
3728  ** [threading mode].)^  This means that separate threads are allowed
3729  ** to use SQLite at the same time, as long as each thread is using
3730  ** a different [database connection].
3731  **
3732  ** ^(<dt>[SQLITE_OPEN_FULLMUTEX]</dt>
3733  ** <dd>The new database connection will use the "serialized"
3734  ** [threading mode].)^  This means the multiple threads can safely
3735  ** attempt to use the same database connection at the same time.
3736  ** (Mutexes will block any actual concurrency, but in this mode
3737  ** there is no harm in trying.)
3738  **
3739  ** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt>
3740  ** <dd>The database is opened [shared cache] enabled, overriding
3741  ** the default shared cache setting provided by
3742  ** [sqlite3_enable_shared_cache()].)^
3743  ** The [use of shared cache mode is discouraged] and hence shared cache
3744  ** capabilities may be omitted from many builds of SQLite.  In such cases,
3745  ** this option is a no-op.
3746  **
3747  ** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>
3748  ** <dd>The database is opened [shared cache] disabled, overriding
3749  ** the default shared cache setting provided by
3750  ** [sqlite3_enable_shared_cache()].)^
3751  **
3752  ** [[OPEN_EXRESCODE]] ^(<dt>[SQLITE_OPEN_EXRESCODE]</dt>
3753  ** <dd>The database connection comes up in "extended result code mode".
3754  ** In other words, the database behaves as if
3755  ** [sqlite3_extended_result_codes(db,1)] were called on the database
3756  ** connection as soon as the connection is created. In addition to setting
3757  ** the extended result code mode, this flag also causes [sqlite3_open_v2()]
3758  ** to return an extended result code.</dd>
3759  **
3760  ** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>
3761  ** <dd>The database filename is not allowed to contain a symbolic link</dd>
3762  ** </dl>)^
3763  **
3764  ** If the 3rd parameter to sqlite3_open_v2() is not one of the
3765  ** required combinations shown above optionally combined with other
3766  ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
3767  ** then the behavior is undefined.  Historic versions of SQLite
3768  ** have silently ignored surplus bits in the flags parameter to
3769  ** sqlite3_open_v2(), however that behavior might not be carried through
3770  ** into future versions of SQLite and so applications should not rely
3771  ** upon it.  Note in particular that the SQLITE_OPEN_EXCLUSIVE flag is a no-op
3772  ** for sqlite3_open_v2().  The SQLITE_OPEN_EXCLUSIVE does *not* cause
3773  ** the open to fail if the database already exists.  The SQLITE_OPEN_EXCLUSIVE
3774  ** flag is intended for use by the [sqlite3_vfs|VFS interface] only, and not
3775  ** by sqlite3_open_v2().
3776  **
3777  ** ^The fourth parameter to sqlite3_open_v2() is the name of the
3778  ** [sqlite3_vfs] object that defines the operating system interface that
3779  ** the new database connection should use.  ^If the fourth parameter is
3780  ** a NULL pointer then the default [sqlite3_vfs] object is used.
3781  **
3782  ** ^If the filename is ":memory:", then a private, temporary in-memory database
3783  ** is created for the connection.  ^This in-memory database will vanish when
3784  ** the database connection is closed.  Future versions of SQLite might
3785  ** make use of additional special filenames that begin with the ":" character.
3786  ** It is recommended that when a database filename actually does begin with
3787  ** a ":" character you should prefix the filename with a pathname such as
3788  ** "./" to avoid ambiguity.
3789  **
3790  ** ^If the filename is an empty string, then a private, temporary
3791  ** on-disk database will be created.  ^This private database will be
3792  ** automatically deleted as soon as the database connection is closed.
3793  **
3794  ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
3795  **
3796  ** ^If [URI filename] interpretation is enabled, and the filename argument
3797  ** begins with "file:", then the filename is interpreted as a URI. ^URI
3798  ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
3799  ** set in the third argument to sqlite3_open_v2(), or if it has
3800  ** been enabled globally using the [SQLITE_CONFIG_URI] option with the
3801  ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
3802  ** URI filename interpretation is turned off
3803  ** by default, but future releases of SQLite might enable URI filename
3804  ** interpretation by default.  See "[URI filenames]" for additional
3805  ** information.
3806  **
3807  ** URI filenames are parsed according to RFC 3986. ^If the URI contains an
3808  ** authority, then it must be either an empty string or the string
3809  ** "localhost". ^If the authority is not an empty string or "localhost", an
3810  ** error is returned to the caller. ^The fragment component of a URI, if
3811  ** present, is ignored.
3812  **
3813  ** ^SQLite uses the path component of the URI as the name of the disk file
3814  ** which contains the database. ^If the path begins with a '/' character,
3815  ** then it is interpreted as an absolute path. ^If the path does not begin
3816  ** with a '/' (meaning that the authority section is omitted from the URI)
3817  ** then the path is interpreted as a relative path.
3818  ** ^(On windows, the first component of an absolute path
3819  ** is a drive specification (e.g. "C:").)^
3820  **
3821  ** [[core URI query parameters]]
3822  ** The query component of a URI may contain parameters that are interpreted
3823  ** either by SQLite itself, or by a [VFS | custom VFS implementation].
3824  ** SQLite and its built-in [VFSes] interpret the
3825  ** following query parameters:
3826  **
3827  ** <ul>
3828  **   <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of
3829  **     a VFS object that provides the operating system interface that should
3830  **     be used to access the database file on disk. ^If this option is set to
3831  **     an empty string the default VFS object is used. ^Specifying an unknown
3832  **     VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is
3833  **     present, then the VFS specified by the option takes precedence over
3834  **     the value passed as the fourth parameter to sqlite3_open_v2().
3835  **
3836  **   <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",
3837  **     "rwc", or "memory". Attempting to set it to any other value is
3838  **     an error)^.
3839  **     ^If "ro" is specified, then the database is opened for read-only
3840  **     access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the
3841  **     third argument to sqlite3_open_v2(). ^If the mode option is set to
3842  **     "rw", then the database is opened for read-write (but not create)
3843  **     access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had
3844  **     been set. ^Value "rwc" is equivalent to setting both
3845  **     SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE.  ^If the mode option is
3846  **     set to "memory" then a pure [in-memory database] that never reads
3847  **     or writes from disk is used. ^It is an error to specify a value for
3848  **     the mode parameter that is less restrictive than that specified by
3849  **     the flags passed in the third parameter to sqlite3_open_v2().
3850  **
3851  **   <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or
3852  **     "private". ^Setting it to "shared" is equivalent to setting the
3853  **     SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to
3854  **     sqlite3_open_v2(). ^Setting the cache parameter to "private" is
3855  **     equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.
3856  **     ^If sqlite3_open_v2() is used and the "cache" parameter is present in
3857  **     a URI filename, its value overrides any behavior requested by setting
3858  **     SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.
3859  **
3860  **  <li> <b>psow</b>: ^The psow parameter indicates whether or not the
3861  **     [powersafe overwrite] property does or does not apply to the
3862  **     storage media on which the database file resides.
3863  **
3864  **  <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter
3865  **     which if set disables file locking in rollback journal modes.  This
3866  **     is useful for accessing a database on a filesystem that does not
3867  **     support locking.  Caution:  Database corruption might result if two
3868  **     or more processes write to the same database and any one of those
3869  **     processes uses nolock=1.
3870  **
3871  **  <li> <b>immutable</b>: ^The immutable parameter is a boolean query
3872  **     parameter that indicates that the database file is stored on
3873  **     read-only media.  ^When immutable is set, SQLite assumes that the
3874  **     database file cannot be changed, even by a process with higher
3875  **     privilege, and so the database is opened read-only and all locking
3876  **     and change detection is disabled.  Caution: Setting the immutable
3877  **     property on a database file that does in fact change can result
3878  **     in incorrect query results and/or [SQLITE_CORRUPT] errors.
3879  **     See also: [SQLITE_IOCAP_IMMUTABLE].
3880  **
3881  ** </ul>
3882  **
3883  ** ^Specifying an unknown parameter in the query component of a URI is not an
3884  ** error.  Future versions of SQLite might understand additional query
3885  ** parameters.  See "[query parameters with special meaning to SQLite]" for
3886  ** additional information.
3887  **
3888  ** [[URI filename examples]] <h3>URI filename examples</h3>
3889  **
3890  ** <table border="1" align=center cellpadding=5>
3891  ** <tr><th> URI filenames <th> Results
3892  ** <tr><td> file:data.db <td>
3893  **          Open the file "data.db" in the current directory.
3894  ** <tr><td> file:/home/fred/data.db<br>
3895  **          file:///home/fred/data.db <br>
3896  **          file://localhost/home/fred/data.db <br> <td>
3897  **          Open the database file "/home/fred/data.db".
3898  ** <tr><td> file://darkstar/home/fred/data.db <td>
3899  **          An error. "darkstar" is not a recognized authority.
3900  ** <tr><td style="white-space:nowrap">
3901  **          file:///C:/Documents%20and%20Settings/fred/Desktop/data.db
3902  **     <td> Windows only: Open the file "data.db" on fred's desktop on drive
3903  **          C:. Note that the %20 escaping in this example is not strictly
3904  **          necessary - space characters can be used literally
3905  **          in URI filenames.
3906  ** <tr><td> file:data.db?mode=ro&cache=private <td>
3907  **          Open file "data.db" in the current directory for read-only access.
3908  **          Regardless of whether or not shared-cache mode is enabled by
3909  **          default, use a private cache.
3910  ** <tr><td> file:/home/fred/data.db?vfs=unix-dotfile <td>
3911  **          Open file "/home/fred/data.db". Use the special VFS "unix-dotfile"
3912  **          that uses dot-files in place of posix advisory locking.
3913  ** <tr><td> file:data.db?mode=readonly <td>
3914  **          An error. "readonly" is not a valid option for the "mode" parameter.
3915  **          Use "ro" instead:  "file:data.db?mode=ro".
3916  ** </table>
3917  **
3918  ** ^URI hexadecimal escape sequences (%HH) are supported within the path and
3919  ** query components of a URI. A hexadecimal escape sequence consists of a
3920  ** percent sign - "%" - followed by exactly two hexadecimal digits
3921  ** specifying an octet value. ^Before the path or query components of a
3922  ** URI filename are interpreted, they are encoded using UTF-8 and all
3923  ** hexadecimal escape sequences replaced by a single byte containing the
3924  ** corresponding octet. If this process generates an invalid UTF-8 encoding,
3925  ** the results are undefined.
3926  **
3927  ** <b>Note to Windows users:</b>  The encoding used for the filename argument
3928  ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever
3929  ** codepage is currently defined.  Filenames containing international
3930  ** characters must be converted to UTF-8 prior to passing them into
3931  ** sqlite3_open() or sqlite3_open_v2().
3932  **
3933  ** <b>Note to Windows Runtime users:</b>  The temporary directory must be set
3934  ** prior to calling sqlite3_open() or sqlite3_open_v2().  Otherwise, various
3935  ** features that require the use of temporary files may fail.
3936  **
3937  ** See also: [sqlite3_temp_directory]
3938  */
3939  SQLITE_API int sqlite3_open(
3940    const char *filename,   /* Database filename (UTF-8) */
3941    sqlite3 **ppDb          /* OUT: SQLite db handle */
3942  );
3943  SQLITE_API int sqlite3_open16(
3944    const void *filename,   /* Database filename (UTF-16) */
3945    sqlite3 **ppDb          /* OUT: SQLite db handle */
3946  );
3947  SQLITE_API int sqlite3_open_v2(
3948    const char *filename,   /* Database filename (UTF-8) */
3949    sqlite3 **ppDb,         /* OUT: SQLite db handle */
3950    int flags,              /* Flags */
3951    const char *zVfs        /* Name of VFS module to use */
3952  );
3953  
3954  /*
3955  ** CAPI3REF: Obtain Values For URI Parameters
3956  **
3957  ** These are utility routines, useful to [VFS|custom VFS implementations],
3958  ** that check if a database file was a URI that contained a specific query
3959  ** parameter, and if so obtains the value of that query parameter.
3960  **
3961  ** The first parameter to these interfaces (hereafter referred to
3962  ** as F) must be one of:
3963  ** <ul>
3964  ** <li> A database filename pointer created by the SQLite core and
3965  ** passed into the xOpen() method of a VFS implementation, or
3966  ** <li> A filename obtained from [sqlite3_db_filename()], or
3967  ** <li> A new filename constructed using [sqlite3_create_filename()].
3968  ** </ul>
3969  ** If the F parameter is not one of the above, then the behavior is
3970  ** undefined and probably undesirable.  Older versions of SQLite were
3971  ** more tolerant of invalid F parameters than newer versions.
3972  **
3973  ** If F is a suitable filename (as described in the previous paragraph)
3974  ** and if P is the name of the query parameter, then
3975  ** sqlite3_uri_parameter(F,P) returns the value of the P
3976  ** parameter if it exists or a NULL pointer if P does not appear as a
3977  ** query parameter on F.  If P is a query parameter of F and it
3978  ** has no explicit value, then sqlite3_uri_parameter(F,P) returns
3979  ** a pointer to an empty string.
3980  **
3981  ** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean
3982  ** parameter and returns true (1) or false (0) according to the value
3983  ** of P.  The sqlite3_uri_boolean(F,P,B) routine returns true (1) if the
3984  ** value of query parameter P is one of "yes", "true", or "on" in any
3985  ** case or if the value begins with a non-zero number.  The
3986  ** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of
3987  ** query parameter P is one of "no", "false", or "off" in any case or
3988  ** if the value begins with a numeric zero.  If P is not a query
3989  ** parameter on F or if the value of P does not match any of the
3990  ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).
3991  **
3992  ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
3993  ** 64-bit signed integer and returns that integer, or D if P does not
3994  ** exist.  If the value of P is something other than an integer, then
3995  ** zero is returned.
3996  **
3997  ** The sqlite3_uri_key(F,N) returns a pointer to the name (not
3998  ** the value) of the N-th query parameter for filename F, or a NULL
3999  ** pointer if N is less than zero or greater than the number of query
4000  ** parameters minus 1.  The N value is zero-based so N should be 0 to obtain
4001  ** the name of the first query parameter, 1 for the second parameter, and
4002  ** so forth.
4003  **
4004  ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
4005  ** sqlite3_uri_boolean(F,P,B) returns B.  If F is not a NULL pointer and
4006  ** is not a database file pathname pointer that the SQLite core passed
4007  ** into the xOpen VFS method, then the behavior of this routine is undefined
4008  ** and probably undesirable.
4009  **
4010  ** Beginning with SQLite [version 3.31.0] ([dateof:3.31.0]) the input F
4011  ** parameter can also be the name of a rollback journal file or WAL file
4012  ** in addition to the main database file.  Prior to version 3.31.0, these
4013  ** routines would only work if F was the name of the main database file.
4014  ** When the F parameter is the name of the rollback journal or WAL file,
4015  ** it has access to all the same query parameters as were found on the
4016  ** main database file.
4017  **
4018  ** See the [URI filename] documentation for additional information.
4019  */
4020  SQLITE_API const char *sqlite3_uri_parameter(sqlite3_filename z, const char *zParam);
4021  SQLITE_API int sqlite3_uri_boolean(sqlite3_filename z, const char *zParam, int bDefault);
4022  SQLITE_API sqlite3_int64 sqlite3_uri_int64(sqlite3_filename, const char*, sqlite3_int64);
4023  SQLITE_API const char *sqlite3_uri_key(sqlite3_filename z, int N);
4024  
4025  /*
4026  ** CAPI3REF:  Translate filenames
4027  **
4028  ** These routines are available to [VFS|custom VFS implementations] for
4029  ** translating filenames between the main database file, the journal file,
4030  ** and the WAL file.
4031  **
4032  ** If F is the name of an sqlite database file, journal file, or WAL file
4033  ** passed by the SQLite core into the VFS, then sqlite3_filename_database(F)
4034  ** returns the name of the corresponding database file.
4035  **
4036  ** If F is the name of an sqlite database file, journal file, or WAL file
4037  ** passed by the SQLite core into the VFS, or if F is a database filename
4038  ** obtained from [sqlite3_db_filename()], then sqlite3_filename_journal(F)
4039  ** returns the name of the corresponding rollback journal file.
4040  **
4041  ** If F is the name of an sqlite database file, journal file, or WAL file
4042  ** that was passed by the SQLite core into the VFS, or if F is a database
4043  ** filename obtained from [sqlite3_db_filename()], then
4044  ** sqlite3_filename_wal(F) returns the name of the corresponding
4045  ** WAL file.
4046  **
4047  ** In all of the above, if F is not the name of a database, journal or WAL
4048  ** filename passed into the VFS from the SQLite core and F is not the
4049  ** return value from [sqlite3_db_filename()], then the result is
4050  ** undefined and is likely a memory access violation.
4051  */
4052  SQLITE_API const char *sqlite3_filename_database(sqlite3_filename);
4053  SQLITE_API const char *sqlite3_filename_journal(sqlite3_filename);
4054  SQLITE_API const char *sqlite3_filename_wal(sqlite3_filename);
4055  
4056  /*
4057  ** CAPI3REF:  Database File Corresponding To A Journal
4058  **
4059  ** ^If X is the name of a rollback or WAL-mode journal file that is
4060  ** passed into the xOpen method of [sqlite3_vfs], then
4061  ** sqlite3_database_file_object(X) returns a pointer to the [sqlite3_file]
4062  ** object that represents the main database file.
4063  **
4064  ** This routine is intended for use in custom [VFS] implementations
4065  ** only.  It is not a general-purpose interface.
4066  ** The argument sqlite3_file_object(X) must be a filename pointer that
4067  ** has been passed into [sqlite3_vfs].xOpen method where the
4068  ** flags parameter to xOpen contains one of the bits
4069  ** [SQLITE_OPEN_MAIN_JOURNAL] or [SQLITE_OPEN_WAL].  Any other use
4070  ** of this routine results in undefined and probably undesirable
4071  ** behavior.
4072  */
4073  SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*);
4074  
4075  /*
4076  ** CAPI3REF: Create and Destroy VFS Filenames
4077  **
4078  ** These interfaces are provided for use by [VFS shim] implementations and
4079  ** are not useful outside of that context.
4080  **
4081  ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of
4082  ** database filename D with corresponding journal file J and WAL file W and
4083  ** an array P of N URI Key/Value pairs.  The result from
4084  ** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that
4085  ** is safe to pass to routines like:
4086  ** <ul>
4087  ** <li> [sqlite3_uri_parameter()],
4088  ** <li> [sqlite3_uri_boolean()],
4089  ** <li> [sqlite3_uri_int64()],
4090  ** <li> [sqlite3_uri_key()],
4091  ** <li> [sqlite3_filename_database()],
4092  ** <li> [sqlite3_filename_journal()], or
4093  ** <li> [sqlite3_filename_wal()].
4094  ** </ul>
4095  ** If a memory allocation error occurs, sqlite3_create_filename() might
4096  ** return a NULL pointer.  The memory obtained from sqlite3_create_filename(X)
4097  ** must be released by a corresponding call to sqlite3_free_filename(Y).
4098  **
4099  ** The P parameter in sqlite3_create_filename(D,J,W,N,P) should be an array
4100  ** of 2*N pointers to strings.  Each pair of pointers in this array corresponds
4101  ** to a key and value for a query parameter.  The P parameter may be a NULL
4102  ** pointer if N is zero.  None of the 2*N pointers in the P array may be
4103  ** NULL pointers and key pointers should not be empty strings.
4104  ** None of the D, J, or W parameters to sqlite3_create_filename(D,J,W,N,P) may
4105  ** be NULL pointers, though they can be empty strings.
4106  **
4107  ** The sqlite3_free_filename(Y) routine releases a memory allocation
4108  ** previously obtained from sqlite3_create_filename().  Invoking
4109  ** sqlite3_free_filename(Y) where Y is a NULL pointer is a harmless no-op.
4110  **
4111  ** If the Y parameter to sqlite3_free_filename(Y) is anything other
4112  ** than a NULL pointer or a pointer previously acquired from
4113  ** sqlite3_create_filename(), then bad things such as heap
4114  ** corruption or segfaults may occur. The value Y should not be
4115  ** used again after sqlite3_free_filename(Y) has been called.  This means
4116  ** that if the [sqlite3_vfs.xOpen()] method of a VFS has been called using Y,
4117  ** then the corresponding [sqlite3_module.xClose() method should also be
4118  ** invoked prior to calling sqlite3_free_filename(Y).
4119  */
4120  SQLITE_API sqlite3_filename sqlite3_create_filename(
4121    const char *zDatabase,
4122    const char *zJournal,
4123    const char *zWal,
4124    int nParam,
4125    const char **azParam
4126  );
4127  SQLITE_API void sqlite3_free_filename(sqlite3_filename);
4128  
4129  /*
4130  ** CAPI3REF: Error Codes And Messages
4131  ** METHOD: sqlite3
4132  **
4133  ** ^If the most recent sqlite3_* API call associated with
4134  ** [database connection] D failed, then the sqlite3_errcode(D) interface
4135  ** returns the numeric [result code] or [extended result code] for that
4136  ** API call.
4137  ** ^The sqlite3_extended_errcode()
4138  ** interface is the same except that it always returns the
4139  ** [extended result code] even when extended result codes are
4140  ** disabled.
4141  **
4142  ** The values returned by sqlite3_errcode() and/or
4143  ** sqlite3_extended_errcode() might change with each API call.
4144  ** Except, there are some interfaces that are guaranteed to never
4145  ** change the value of the error code.  The error-code preserving
4146  ** interfaces include the following:
4147  **
4148  ** <ul>
4149  ** <li> sqlite3_errcode()
4150  ** <li> sqlite3_extended_errcode()
4151  ** <li> sqlite3_errmsg()
4152  ** <li> sqlite3_errmsg16()
4153  ** <li> sqlite3_error_offset()
4154  ** </ul>
4155  **
4156  ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
4157  ** text that describes the error, as either UTF-8 or UTF-16 respectively,
4158  ** or NULL if no error message is available.
4159  ** (See how SQLite handles [invalid UTF] for exceptions to this rule.)
4160  ** ^(Memory to hold the error message string is managed internally.
4161  ** The application does not need to worry about freeing the result.
4162  ** However, the error string might be overwritten or deallocated by
4163  ** subsequent calls to other SQLite interface functions.)^
4164  **
4165  ** ^The sqlite3_errstr(E) interface returns the English-language text
4166  ** that describes the [result code] E, as UTF-8, or NULL if E is not an
4167  ** result code for which a text error message is available.
4168  ** ^(Memory to hold the error message string is managed internally
4169  ** and must not be freed by the application)^.
4170  **
4171  ** ^If the most recent error references a specific token in the input
4172  ** SQL, the sqlite3_error_offset() interface returns the byte offset
4173  ** of the start of that token.  ^The byte offset returned by
4174  ** sqlite3_error_offset() assumes that the input SQL is UTF8.
4175  ** ^If the most recent error does not reference a specific token in the input
4176  ** SQL, then the sqlite3_error_offset() function returns -1.
4177  **
4178  ** When the serialized [threading mode] is in use, it might be the
4179  ** case that a second error occurs on a separate thread in between
4180  ** the time of the first error and the call to these interfaces.
4181  ** When that happens, the second error will be reported since these
4182  ** interfaces always report the most recent result.  To avoid
4183  ** this, each thread can obtain exclusive use of the [database connection] D
4184  ** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning
4185  ** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after
4186  ** all calls to the interfaces listed here are completed.
4187  **
4188  ** If an interface fails with SQLITE_MISUSE, that means the interface
4189  ** was invoked incorrectly by the application.  In that case, the
4190  ** error code and message may or may not be set.
4191  */
4192  SQLITE_API int sqlite3_errcode(sqlite3 *db);
4193  SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);
4194  SQLITE_API const char *sqlite3_errmsg(sqlite3*);
4195  SQLITE_API const void *sqlite3_errmsg16(sqlite3*);
4196  SQLITE_API const char *sqlite3_errstr(int);
4197  SQLITE_API int sqlite3_error_offset(sqlite3 *db);
4198  
4199  /*
4200  ** CAPI3REF: Prepared Statement Object
4201  ** KEYWORDS: {prepared statement} {prepared statements}
4202  **
4203  ** An instance of this object represents a single SQL statement that
4204  ** has been compiled into binary form and is ready to be evaluated.
4205  **
4206  ** Think of each SQL statement as a separate computer program.  The
4207  ** original SQL text is source code.  A prepared statement object
4208  ** is the compiled object code.  All SQL must be converted into a
4209  ** prepared statement before it can be run.
4210  **
4211  ** The life-cycle of a prepared statement object usually goes like this:
4212  **
4213  ** <ol>
4214  ** <li> Create the prepared statement object using [sqlite3_prepare_v2()].
4215  ** <li> Bind values to [parameters] using the sqlite3_bind_*()
4216  **      interfaces.
4217  ** <li> Run the SQL by calling [sqlite3_step()] one or more times.
4218  ** <li> Reset the prepared statement using [sqlite3_reset()] then go back
4219  **      to step 2.  Do this zero or more times.
4220  ** <li> Destroy the object using [sqlite3_finalize()].
4221  ** </ol>
4222  */
4223  typedef struct sqlite3_stmt sqlite3_stmt;
4224  
4225  /*
4226  ** CAPI3REF: Run-time Limits
4227  ** METHOD: sqlite3
4228  **
4229  ** ^(This interface allows the size of various constructs to be limited
4230  ** on a connection by connection basis.  The first parameter is the
4231  ** [database connection] whose limit is to be set or queried.  The
4232  ** second parameter is one of the [limit categories] that define a
4233  ** class of constructs to be size limited.  The third parameter is the
4234  ** new limit for that construct.)^
4235  **
4236  ** ^If the new limit is a negative number, the limit is unchanged.
4237  ** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a
4238  ** [limits | hard upper bound]
4239  ** set at compile-time by a C preprocessor macro called
4240  ** [limits | SQLITE_MAX_<i>NAME</i>].
4241  ** (The "_LIMIT_" in the name is changed to "_MAX_".))^
4242  ** ^Attempts to increase a limit above its hard upper bound are
4243  ** silently truncated to the hard upper bound.
4244  **
4245  ** ^Regardless of whether or not the limit was changed, the
4246  ** [sqlite3_limit()] interface returns the prior value of the limit.
4247  ** ^Hence, to find the current value of a limit without changing it,
4248  ** simply invoke this interface with the third parameter set to -1.
4249  **
4250  ** Run-time limits are intended for use in applications that manage
4251  ** both their own internal database and also databases that are controlled
4252  ** by untrusted external sources.  An example application might be a
4253  ** web browser that has its own databases for storing history and
4254  ** separate databases controlled by JavaScript applications downloaded
4255  ** off the Internet.  The internal databases can be given the
4256  ** large, default limits.  Databases managed by external sources can
4257  ** be given much smaller limits designed to prevent a denial of service
4258  ** attack.  Developers might also want to use the [sqlite3_set_authorizer()]
4259  ** interface to further control untrusted SQL.  The size of the database
4260  ** created by an untrusted script can be contained using the
4261  ** [max_page_count] [PRAGMA].
4262  **
4263  ** New run-time limit categories may be added in future releases.
4264  */
4265  SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
4266  
4267  /*
4268  ** CAPI3REF: Run-Time Limit Categories
4269  ** KEYWORDS: {limit category} {*limit categories}
4270  **
4271  ** These constants define various performance limits
4272  ** that can be lowered at run-time using [sqlite3_limit()].
4273  ** The synopsis of the meanings of the various limits is shown below.
4274  ** Additional information is available at [limits | Limits in SQLite].
4275  **
4276  ** <dl>
4277  ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>
4278  ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^
4279  **
4280  ** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>
4281  ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^
4282  **
4283  ** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt>
4284  ** <dd>The maximum number of columns in a table definition or in the
4285  ** result set of a [SELECT] or the maximum number of columns in an index
4286  ** or in an ORDER BY or GROUP BY clause.</dd>)^
4287  **
4288  ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
4289  ** <dd>The maximum depth of the parse tree on any expression.</dd>)^
4290  **
4291  ** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
4292  ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^
4293  **
4294  ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>
4295  ** <dd>The maximum number of instructions in a virtual machine program
4296  ** used to implement an SQL statement.  If [sqlite3_prepare_v2()] or
4297  ** the equivalent tries to allocate space for more than this many opcodes
4298  ** in a single prepared statement, an SQLITE_NOMEM error is returned.</dd>)^
4299  **
4300  ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
4301  ** <dd>The maximum number of arguments on a function.</dd>)^
4302  **
4303  ** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>
4304  ** <dd>The maximum number of [ATTACH | attached databases].)^</dd>
4305  **
4306  ** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]]
4307  ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
4308  ** <dd>The maximum length of the pattern argument to the [LIKE] or
4309  ** [GLOB] operators.</dd>)^
4310  **
4311  ** [[SQLITE_LIMIT_VARIABLE_NUMBER]]
4312  ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
4313  ** <dd>The maximum index number of any [parameter] in an SQL statement.)^
4314  **
4315  ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>
4316  ** <dd>The maximum depth of recursion for triggers.</dd>)^
4317  **
4318  ** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>
4319  ** <dd>The maximum number of auxiliary worker threads that a single
4320  ** [prepared statement] may start.</dd>)^
4321  ** </dl>
4322  */
4323  #define SQLITE_LIMIT_LENGTH                    0
4324  #define SQLITE_LIMIT_SQL_LENGTH                1
4325  #define SQLITE_LIMIT_COLUMN                    2
4326  #define SQLITE_LIMIT_EXPR_DEPTH                3
4327  #define SQLITE_LIMIT_COMPOUND_SELECT           4
4328  #define SQLITE_LIMIT_VDBE_OP                   5
4329  #define SQLITE_LIMIT_FUNCTION_ARG              6
4330  #define SQLITE_LIMIT_ATTACHED                  7
4331  #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH       8
4332  #define SQLITE_LIMIT_VARIABLE_NUMBER           9
4333  #define SQLITE_LIMIT_TRIGGER_DEPTH            10
4334  #define SQLITE_LIMIT_WORKER_THREADS           11
4335  
4336  /*
4337  ** CAPI3REF: Prepare Flags
4338  **
4339  ** These constants define various flags that can be passed into
4340  ** "prepFlags" parameter of the [sqlite3_prepare_v3()] and
4341  ** [sqlite3_prepare16_v3()] interfaces.
4342  **
4343  ** New flags may be added in future releases of SQLite.
4344  **
4345  ** <dl>
4346  ** [[SQLITE_PREPARE_PERSISTENT]] ^(<dt>SQLITE_PREPARE_PERSISTENT</dt>
4347  ** <dd>The SQLITE_PREPARE_PERSISTENT flag is a hint to the query planner
4348  ** that the prepared statement will be retained for a long time and
4349  ** probably reused many times.)^ ^Without this flag, [sqlite3_prepare_v3()]
4350  ** and [sqlite3_prepare16_v3()] assume that the prepared statement will
4351  ** be used just once or at most a few times and then destroyed using
4352  ** [sqlite3_finalize()] relatively soon. The current implementation acts
4353  ** on this hint by avoiding the use of [lookaside memory] so as not to
4354  ** deplete the limited store of lookaside memory. Future versions of
4355  ** SQLite may act on this hint differently.
4356  **
4357  ** [[SQLITE_PREPARE_NORMALIZE]] <dt>SQLITE_PREPARE_NORMALIZE</dt>
4358  ** <dd>The SQLITE_PREPARE_NORMALIZE flag is a no-op. This flag used
4359  ** to be required for any prepared statement that wanted to use the
4360  ** [sqlite3_normalized_sql()] interface.  However, the
4361  ** [sqlite3_normalized_sql()] interface is now available to all
4362  ** prepared statements, regardless of whether or not they use this
4363  ** flag.
4364  **
4365  ** [[SQLITE_PREPARE_NO_VTAB]] <dt>SQLITE_PREPARE_NO_VTAB</dt>
4366  ** <dd>The SQLITE_PREPARE_NO_VTAB flag causes the SQL compiler
4367  ** to return an error (error code SQLITE_ERROR) if the statement uses
4368  ** any virtual tables.
4369  **
4370  ** [[SQLITE_PREPARE_DONT_LOG]] <dt>SQLITE_PREPARE_DONT_LOG</dt>
4371  ** <dd>The SQLITE_PREPARE_DONT_LOG flag prevents SQL compiler
4372  ** errors from being sent to the error log defined by
4373  ** [SQLITE_CONFIG_LOG].  This can be used, for example, to do test
4374  ** compiles to see if some SQL syntax is well-formed, without generating
4375  ** messages on the global error log when it is not.  If the test compile
4376  ** fails, the sqlite3_prepare_v3() call returns the same error indications
4377  ** with or without this flag; it just omits the call to [sqlite3_log()] that
4378  ** logs the error.
4379  ** </dl>
4380  */
4381  #define SQLITE_PREPARE_PERSISTENT              0x01
4382  #define SQLITE_PREPARE_NORMALIZE               0x02
4383  #define SQLITE_PREPARE_NO_VTAB                 0x04
4384  #define SQLITE_PREPARE_DONT_LOG                0x10
4385  
4386  /*
4387  ** CAPI3REF: Compiling An SQL Statement
4388  ** KEYWORDS: {SQL statement compiler}
4389  ** METHOD: sqlite3
4390  ** CONSTRUCTOR: sqlite3_stmt
4391  **
4392  ** To execute an SQL statement, it must first be compiled into a byte-code
4393  ** program using one of these routines.  Or, in other words, these routines
4394  ** are constructors for the [prepared statement] object.
4395  **
4396  ** The preferred routine to use is [sqlite3_prepare_v2()].  The
4397  ** [sqlite3_prepare()] interface is legacy and should be avoided.
4398  ** [sqlite3_prepare_v3()] has an extra "prepFlags" option that is used
4399  ** for special purposes.
4400  **
4401  ** The use of the UTF-8 interfaces is preferred, as SQLite currently
4402  ** does all parsing using UTF-8.  The UTF-16 interfaces are provided
4403  ** as a convenience.  The UTF-16 interfaces work by converting the
4404  ** input text into UTF-8, then invoking the corresponding UTF-8 interface.
4405  **
4406  ** The first argument, "db", is a [database connection] obtained from a
4407  ** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or
4408  ** [sqlite3_open16()].  The database connection must not have been closed.
4409  **
4410  ** The second argument, "zSql", is the statement to be compiled, encoded
4411  ** as either UTF-8 or UTF-16.  The sqlite3_prepare(), sqlite3_prepare_v2(),
4412  ** and sqlite3_prepare_v3()
4413  ** interfaces use UTF-8, and sqlite3_prepare16(), sqlite3_prepare16_v2(),
4414  ** and sqlite3_prepare16_v3() use UTF-16.
4415  **
4416  ** ^If the nByte argument is negative, then zSql is read up to the
4417  ** first zero terminator. ^If nByte is positive, then it is the maximum
4418  ** number of bytes read from zSql.  When nByte is positive, zSql is read
4419  ** up to the first zero terminator or until the nByte bytes have been read,
4420  ** whichever comes first.  ^If nByte is zero, then no prepared
4421  ** statement is generated.
4422  ** If the caller knows that the supplied string is nul-terminated, then
4423  ** there is a small performance advantage to passing an nByte parameter that
4424  ** is the number of bytes in the input string <i>including</i>
4425  ** the nul-terminator.
4426  ** Note that nByte measure the length of the input in bytes, not
4427  ** characters, even for the UTF-16 interfaces.
4428  **
4429  ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
4430  ** past the end of the first SQL statement in zSql.  These routines only
4431  ** compile the first statement in zSql, so *pzTail is left pointing to
4432  ** what remains uncompiled.
4433  **
4434  ** ^*ppStmt is left pointing to a compiled [prepared statement] that can be
4435  ** executed using [sqlite3_step()].  ^If there is an error, *ppStmt is set
4436  ** to NULL.  ^If the input text contains no SQL (if the input is an empty
4437  ** string or a comment) then *ppStmt is set to NULL.
4438  ** The calling procedure is responsible for deleting the compiled
4439  ** SQL statement using [sqlite3_finalize()] after it has finished with it.
4440  ** ppStmt may not be NULL.
4441  **
4442  ** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK];
4443  ** otherwise an [error code] is returned.
4444  **
4445  ** The sqlite3_prepare_v2(), sqlite3_prepare_v3(), sqlite3_prepare16_v2(),
4446  ** and sqlite3_prepare16_v3() interfaces are recommended for all new programs.
4447  ** The older interfaces (sqlite3_prepare() and sqlite3_prepare16())
4448  ** are retained for backwards compatibility, but their use is discouraged.
4449  ** ^In the "vX" interfaces, the prepared statement
4450  ** that is returned (the [sqlite3_stmt] object) contains a copy of the
4451  ** original SQL text. This causes the [sqlite3_step()] interface to
4452  ** behave differently in three ways:
4453  **
4454  ** <ol>
4455  ** <li>
4456  ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it
4457  ** always used to do, [sqlite3_step()] will automatically recompile the SQL
4458  ** statement and try to run it again. As many as [SQLITE_MAX_SCHEMA_RETRY]
4459  ** retries will occur before sqlite3_step() gives up and returns an error.
4460  ** </li>
4461  **
4462  ** <li>
4463  ** ^When an error occurs, [sqlite3_step()] will return one of the detailed
4464  ** [error codes] or [extended error codes].  ^The legacy behavior was that
4465  ** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code
4466  ** and the application would have to make a second call to [sqlite3_reset()]
4467  ** in order to find the underlying cause of the problem. With the "v2" prepare
4468  ** interfaces, the underlying reason for the error is returned immediately.
4469  ** </li>
4470  **
4471  ** <li>
4472  ** ^If the specific value bound to a [parameter | host parameter] in the
4473  ** WHERE clause might influence the choice of query plan for a statement,
4474  ** then the statement will be automatically recompiled, as if there had been
4475  ** a schema change, on the first [sqlite3_step()] call following any change
4476  ** to the [sqlite3_bind_text | bindings] of that [parameter].
4477  ** ^The specific value of a WHERE-clause [parameter] might influence the
4478  ** choice of query plan if the parameter is the left-hand side of a [LIKE]
4479  ** or [GLOB] operator or if the parameter is compared to an indexed column
4480  ** and the [SQLITE_ENABLE_STAT4] compile-time option is enabled.
4481  ** </li>
4482  ** </ol>
4483  **
4484  ** <p>^sqlite3_prepare_v3() differs from sqlite3_prepare_v2() only in having
4485  ** the extra prepFlags parameter, which is a bit array consisting of zero or
4486  ** more of the [SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_*] flags.  ^The
4487  ** sqlite3_prepare_v2() interface works exactly the same as
4488  ** sqlite3_prepare_v3() with a zero prepFlags parameter.
4489  */
4490  SQLITE_API int sqlite3_prepare(
4491    sqlite3 *db,            /* Database handle */
4492    const char *zSql,       /* SQL statement, UTF-8 encoded */
4493    int nByte,              /* Maximum length of zSql in bytes. */
4494    sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
4495    const char **pzTail     /* OUT: Pointer to unused portion of zSql */
4496  );
4497  SQLITE_API int sqlite3_prepare_v2(
4498    sqlite3 *db,            /* Database handle */
4499    const char *zSql,       /* SQL statement, UTF-8 encoded */
4500    int nByte,              /* Maximum length of zSql in bytes. */
4501    sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
4502    const char **pzTail     /* OUT: Pointer to unused portion of zSql */
4503  );
4504  SQLITE_API int sqlite3_prepare_v3(
4505    sqlite3 *db,            /* Database handle */
4506    const char *zSql,       /* SQL statement, UTF-8 encoded */
4507    int nByte,              /* Maximum length of zSql in bytes. */
4508    unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */
4509    sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
4510    const char **pzTail     /* OUT: Pointer to unused portion of zSql */
4511  );
4512  SQLITE_API int sqlite3_prepare16(
4513    sqlite3 *db,            /* Database handle */
4514    const void *zSql,       /* SQL statement, UTF-16 encoded */
4515    int nByte,              /* Maximum length of zSql in bytes. */
4516    sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
4517    const void **pzTail     /* OUT: Pointer to unused portion of zSql */
4518  );
4519  SQLITE_API int sqlite3_prepare16_v2(
4520    sqlite3 *db,            /* Database handle */
4521    const void *zSql,       /* SQL statement, UTF-16 encoded */
4522    int nByte,              /* Maximum length of zSql in bytes. */
4523    sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
4524    const void **pzTail     /* OUT: Pointer to unused portion of zSql */
4525  );
4526  SQLITE_API int sqlite3_prepare16_v3(
4527    sqlite3 *db,            /* Database handle */
4528    const void *zSql,       /* SQL statement, UTF-16 encoded */
4529    int nByte,              /* Maximum length of zSql in bytes. */
4530    unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */
4531    sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
4532    const void **pzTail     /* OUT: Pointer to unused portion of zSql */
4533  );
4534  
4535  /*
4536  ** CAPI3REF: Retrieving Statement SQL
4537  ** METHOD: sqlite3_stmt
4538  **
4539  ** ^The sqlite3_sql(P) interface returns a pointer to a copy of the UTF-8
4540  ** SQL text used to create [prepared statement] P if P was
4541  ** created by [sqlite3_prepare_v2()], [sqlite3_prepare_v3()],
4542  ** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()].
4543  ** ^The sqlite3_expanded_sql(P) interface returns a pointer to a UTF-8
4544  ** string containing the SQL text of prepared statement P with
4545  ** [bound parameters] expanded.
4546  ** ^The sqlite3_normalized_sql(P) interface returns a pointer to a UTF-8
4547  ** string containing the normalized SQL text of prepared statement P.  The
4548  ** semantics used to normalize a SQL statement are unspecified and subject
4549  ** to change.  At a minimum, literal values will be replaced with suitable
4550  ** placeholders.
4551  **
4552  ** ^(For example, if a prepared statement is created using the SQL
4553  ** text "SELECT $abc,:xyz" and if parameter $abc is bound to integer 2345
4554  ** and parameter :xyz is unbound, then sqlite3_sql() will return
4555  ** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()
4556  ** will return "SELECT 2345,NULL".)^
4557  **
4558  ** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory
4559  ** is available to hold the result, or if the result would exceed the
4560  ** the maximum string length determined by the [SQLITE_LIMIT_LENGTH].
4561  **
4562  ** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of
4563  ** bound parameter expansions.  ^The [SQLITE_OMIT_TRACE] compile-time
4564  ** option causes sqlite3_expanded_sql() to always return NULL.
4565  **
4566  ** ^The strings returned by sqlite3_sql(P) and sqlite3_normalized_sql(P)
4567  ** are managed by SQLite and are automatically freed when the prepared
4568  ** statement is finalized.
4569  ** ^The string returned by sqlite3_expanded_sql(P), on the other hand,
4570  ** is obtained from [sqlite3_malloc()] and must be freed by the application
4571  ** by passing it to [sqlite3_free()].
4572  **
4573  ** ^The sqlite3_normalized_sql() interface is only available if
4574  ** the [SQLITE_ENABLE_NORMALIZE] compile-time option is defined.
4575  */
4576  SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);
4577  SQLITE_API char *sqlite3_expanded_sql(sqlite3_stmt *pStmt);
4578  #ifdef SQLITE_ENABLE_NORMALIZE
4579  SQLITE_API const char *sqlite3_normalized_sql(sqlite3_stmt *pStmt);
4580  #endif
4581  
4582  /*
4583  ** CAPI3REF: Determine If An SQL Statement Writes The Database
4584  ** METHOD: sqlite3_stmt
4585  **
4586  ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if
4587  ** and only if the [prepared statement] X makes no direct changes to
4588  ** the content of the database file.
4589  **
4590  ** Note that [application-defined SQL functions] or
4591  ** [virtual tables] might change the database indirectly as a side effect.
4592  ** ^(For example, if an application defines a function "eval()" that
4593  ** calls [sqlite3_exec()], then the following SQL statement would
4594  ** change the database file through side-effects:
4595  **
4596  ** <blockquote><pre>
4597  **    SELECT eval('DELETE FROM t1') FROM t2;
4598  ** </pre></blockquote>
4599  **
4600  ** But because the [SELECT] statement does not change the database file
4601  ** directly, sqlite3_stmt_readonly() would still return true.)^
4602  **
4603  ** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],
4604  ** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,
4605  ** since the statements themselves do not actually modify the database but
4606  ** rather they control the timing of when other statements modify the
4607  ** database.  ^The [ATTACH] and [DETACH] statements also cause
4608  ** sqlite3_stmt_readonly() to return true since, while those statements
4609  ** change the configuration of a database connection, they do not make
4610  ** changes to the content of the database files on disk.
4611  ** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since
4612  ** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
4613  ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
4614  ** sqlite3_stmt_readonly() returns false for those commands.
4615  **
4616  ** ^This routine returns false if there is any possibility that the
4617  ** statement might change the database file.  ^A false return does
4618  ** not guarantee that the statement will change the database file.
4619  ** ^For example, an UPDATE statement might have a WHERE clause that
4620  ** makes it a no-op, but the sqlite3_stmt_readonly() result would still
4621  ** be false.  ^Similarly, a CREATE TABLE IF NOT EXISTS statement is a
4622  ** read-only no-op if the table already exists, but
4623  ** sqlite3_stmt_readonly() still returns false for such a statement.
4624  **
4625  ** ^If prepared statement X is an [EXPLAIN] or [EXPLAIN QUERY PLAN]
4626  ** statement, then sqlite3_stmt_readonly(X) returns the same value as
4627  ** if the EXPLAIN or EXPLAIN QUERY PLAN prefix were omitted.
4628  */
4629  SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
4630  
4631  /*
4632  ** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement
4633  ** METHOD: sqlite3_stmt
4634  **
4635  ** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the
4636  ** prepared statement S is an EXPLAIN statement, or 2 if the
4637  ** statement S is an EXPLAIN QUERY PLAN.
4638  ** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is
4639  ** an ordinary statement or a NULL pointer.
4640  */
4641  SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt);
4642  
4643  /*
4644  ** CAPI3REF: Change The EXPLAIN Setting For A Prepared Statement
4645  ** METHOD: sqlite3_stmt
4646  **
4647  ** The sqlite3_stmt_explain(S,E) interface changes the EXPLAIN
4648  ** setting for [prepared statement] S.  If E is zero, then S becomes
4649  ** a normal prepared statement.  If E is 1, then S behaves as if
4650  ** its SQL text began with "[EXPLAIN]".  If E is 2, then S behaves as if
4651  ** its SQL text began with "[EXPLAIN QUERY PLAN]".
4652  **
4653  ** Calling sqlite3_stmt_explain(S,E) might cause S to be reprepared.
4654  ** SQLite tries to avoid a reprepare, but a reprepare might be necessary
4655  ** on the first transition into EXPLAIN or EXPLAIN QUERY PLAN mode.
4656  **
4657  ** Because of the potential need to reprepare, a call to
4658  ** sqlite3_stmt_explain(S,E) will fail with SQLITE_ERROR if S cannot be
4659  ** reprepared because it was created using [sqlite3_prepare()] instead of
4660  ** the newer [sqlite3_prepare_v2()] or [sqlite3_prepare_v3()] interfaces and
4661  ** hence has no saved SQL text with which to reprepare.
4662  **
4663  ** Changing the explain setting for a prepared statement does not change
4664  ** the original SQL text for the statement.  Hence, if the SQL text originally
4665  ** began with EXPLAIN or EXPLAIN QUERY PLAN, but sqlite3_stmt_explain(S,0)
4666  ** is called to convert the statement into an ordinary statement, the EXPLAIN
4667  ** or EXPLAIN QUERY PLAN keywords will still appear in the sqlite3_sql(S)
4668  ** output, even though the statement now acts like a normal SQL statement.
4669  **
4670  ** This routine returns SQLITE_OK if the explain mode is successfully
4671  ** changed, or an error code if the explain mode could not be changed.
4672  ** The explain mode cannot be changed while a statement is active.
4673  ** Hence, it is good practice to call [sqlite3_reset(S)]
4674  ** immediately prior to calling sqlite3_stmt_explain(S,E).
4675  */
4676  SQLITE_API int sqlite3_stmt_explain(sqlite3_stmt *pStmt, int eMode);
4677  
4678  /*
4679  ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
4680  ** METHOD: sqlite3_stmt
4681  **
4682  ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
4683  ** [prepared statement] S has been stepped at least once using
4684  ** [sqlite3_step(S)] but has neither run to completion (returned
4685  ** [SQLITE_DONE] from [sqlite3_step(S)]) nor
4686  ** been reset using [sqlite3_reset(S)].  ^The sqlite3_stmt_busy(S)
4687  ** interface returns false if S is a NULL pointer.  If S is not a
4688  ** NULL pointer and is not a pointer to a valid [prepared statement]
4689  ** object, then the behavior is undefined and probably undesirable.
4690  **
4691  ** This interface can be used in combination [sqlite3_next_stmt()]
4692  ** to locate all prepared statements associated with a database
4693  ** connection that are in need of being reset.  This can be used,
4694  ** for example, in diagnostic routines to search for prepared
4695  ** statements that are holding a transaction open.
4696  */
4697  SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*);
4698  
4699  /*
4700  ** CAPI3REF: Dynamically Typed Value Object
4701  ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
4702  **
4703  ** SQLite uses the sqlite3_value object to represent all values
4704  ** that can be stored in a database table. SQLite uses dynamic typing
4705  ** for the values it stores.  ^Values stored in sqlite3_value objects
4706  ** can be integers, floating point values, strings, BLOBs, or NULL.
4707  **
4708  ** An sqlite3_value object may be either "protected" or "unprotected".
4709  ** Some interfaces require a protected sqlite3_value.  Other interfaces
4710  ** will accept either a protected or an unprotected sqlite3_value.
4711  ** Every interface that accepts sqlite3_value arguments specifies
4712  ** whether or not it requires a protected sqlite3_value.  The
4713  ** [sqlite3_value_dup()] interface can be used to construct a new
4714  ** protected sqlite3_value from an unprotected sqlite3_value.
4715  **
4716  ** The terms "protected" and "unprotected" refer to whether or not
4717  ** a mutex is held.  An internal mutex is held for a protected
4718  ** sqlite3_value object but no mutex is held for an unprotected
4719  ** sqlite3_value object.  If SQLite is compiled to be single-threaded
4720  ** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)
4721  ** or if SQLite is run in one of reduced mutex modes
4722  ** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]
4723  ** then there is no distinction between protected and unprotected
4724  ** sqlite3_value objects and they can be used interchangeably.  However,
4725  ** for maximum code portability it is recommended that applications
4726  ** still make the distinction between protected and unprotected
4727  ** sqlite3_value objects even when not strictly required.
4728  **
4729  ** ^The sqlite3_value objects that are passed as parameters into the
4730  ** implementation of [application-defined SQL functions] are protected.
4731  ** ^The sqlite3_value objects returned by [sqlite3_vtab_rhs_value()]
4732  ** are protected.
4733  ** ^The sqlite3_value object returned by
4734  ** [sqlite3_column_value()] is unprotected.
4735  ** Unprotected sqlite3_value objects may only be used as arguments
4736  ** to [sqlite3_result_value()], [sqlite3_bind_value()], and
4737  ** [sqlite3_value_dup()].
4738  ** The [sqlite3_value_blob | sqlite3_value_type()] family of
4739  ** interfaces require protected sqlite3_value objects.
4740  */
4741  typedef struct sqlite3_value sqlite3_value;
4742  
4743  /*
4744  ** CAPI3REF: SQL Function Context Object
4745  **
4746  ** The context in which an SQL function executes is stored in an
4747  ** sqlite3_context object.  ^A pointer to an sqlite3_context object
4748  ** is always first parameter to [application-defined SQL functions].
4749  ** The application-defined SQL function implementation will pass this
4750  ** pointer through into calls to [sqlite3_result_int | sqlite3_result()],
4751  ** [sqlite3_aggregate_context()], [sqlite3_user_data()],
4752  ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],
4753  ** and/or [sqlite3_set_auxdata()].
4754  */
4755  typedef struct sqlite3_context sqlite3_context;
4756  
4757  /*
4758  ** CAPI3REF: Binding Values To Prepared Statements
4759  ** KEYWORDS: {host parameter} {host parameters} {host parameter name}
4760  ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
4761  ** METHOD: sqlite3_stmt
4762  **
4763  ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,
4764  ** literals may be replaced by a [parameter] that matches one of the following
4765  ** templates:
4766  **
4767  ** <ul>
4768  ** <li>  ?
4769  ** <li>  ?NNN
4770  ** <li>  :VVV
4771  ** <li>  @VVV
4772  ** <li>  $VVV
4773  ** </ul>
4774  **
4775  ** In the templates above, NNN represents an integer literal,
4776  ** and VVV represents an alphanumeric identifier.)^  ^The values of these
4777  ** parameters (also called "host parameter names" or "SQL parameters")
4778  ** can be set using the sqlite3_bind_*() routines defined here.
4779  **
4780  ** ^The first argument to the sqlite3_bind_*() routines is always
4781  ** a pointer to the [sqlite3_stmt] object returned from
4782  ** [sqlite3_prepare_v2()] or its variants.
4783  **
4784  ** ^The second argument is the index of the SQL parameter to be set.
4785  ** ^The leftmost SQL parameter has an index of 1.  ^When the same named
4786  ** SQL parameter is used more than once, second and subsequent
4787  ** occurrences have the same index as the first occurrence.
4788  ** ^The index for named parameters can be looked up using the
4789  ** [sqlite3_bind_parameter_index()] API if desired.  ^The index
4790  ** for "?NNN" parameters is the value of NNN.
4791  ** ^The NNN value must be between 1 and the [sqlite3_limit()]
4792  ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 32766).
4793  **
4794  ** ^The third argument is the value to bind to the parameter.
4795  ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16()
4796  ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter
4797  ** is ignored and the end result is the same as sqlite3_bind_null().
4798  ** ^If the third parameter to sqlite3_bind_text() is not NULL, then
4799  ** it should be a pointer to well-formed UTF8 text.
4800  ** ^If the third parameter to sqlite3_bind_text16() is not NULL, then
4801  ** it should be a pointer to well-formed UTF16 text.
4802  ** ^If the third parameter to sqlite3_bind_text64() is not NULL, then
4803  ** it should be a pointer to a well-formed unicode string that is
4804  ** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF16
4805  ** otherwise.
4806  **
4807  ** [[byte-order determination rules]] ^The byte-order of
4808  ** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF)
4809  ** found in the first character, which is removed, or in the absence of a BOM
4810  ** the byte order is the native byte order of the host
4811  ** machine for sqlite3_bind_text16() or the byte order specified in
4812  ** the 6th parameter for sqlite3_bind_text64().)^
4813  ** ^If UTF16 input text contains invalid unicode
4814  ** characters, then SQLite might change those invalid characters
4815  ** into the unicode replacement character: U+FFFD.
4816  **
4817  ** ^(In those routines that have a fourth argument, its value is the
4818  ** number of bytes in the parameter.  To be clear: the value is the
4819  ** number of <u>bytes</u> in the value, not the number of characters.)^
4820  ** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()
4821  ** is negative, then the length of the string is
4822  ** the number of bytes up to the first zero terminator.
4823  ** If the fourth parameter to sqlite3_bind_blob() is negative, then
4824  ** the behavior is undefined.
4825  ** If a non-negative fourth parameter is provided to sqlite3_bind_text()
4826  ** or sqlite3_bind_text16() or sqlite3_bind_text64() then
4827  ** that parameter must be the byte offset
4828  ** where the NUL terminator would occur assuming the string were NUL
4829  ** terminated.  If any NUL characters occur at byte offsets less than
4830  ** the value of the fourth parameter then the resulting string value will
4831  ** contain embedded NULs.  The result of expressions involving strings
4832  ** with embedded NULs is undefined.
4833  **
4834  ** ^The fifth argument to the BLOB and string binding interfaces controls
4835  ** or indicates the lifetime of the object referenced by the third parameter.
4836  ** These three options exist:
4837  ** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished
4838  ** with it may be passed. ^It is called to dispose of the BLOB or string even
4839  ** if the call to the bind API fails, except the destructor is not called if
4840  ** the third parameter is a NULL pointer or the fourth parameter is negative.
4841  ** ^ (2) The special constant, [SQLITE_STATIC], may be passed to indicate that
4842  ** the application remains responsible for disposing of the object. ^In this
4843  ** case, the object and the provided pointer to it must remain valid until
4844  ** either the prepared statement is finalized or the same SQL parameter is
4845  ** bound to something else, whichever occurs sooner.
4846  ** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the
4847  ** object is to be copied prior to the return from sqlite3_bind_*(). ^The
4848  ** object and pointer to it must remain valid until then. ^SQLite will then
4849  ** manage the lifetime of its private copy.
4850  **
4851  ** ^The sixth argument to sqlite3_bind_text64() must be one of
4852  ** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
4853  ** to specify the encoding of the text in the third parameter.  If
4854  ** the sixth argument to sqlite3_bind_text64() is not one of the
4855  ** allowed values shown above, or if the text encoding is different
4856  ** from the encoding specified by the sixth parameter, then the behavior
4857  ** is undefined.
4858  **
4859  ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that
4860  ** is filled with zeroes.  ^A zeroblob uses a fixed amount of memory
4861  ** (just an integer to hold its size) while it is being processed.
4862  ** Zeroblobs are intended to serve as placeholders for BLOBs whose
4863  ** content is later written using
4864  ** [sqlite3_blob_open | incremental BLOB I/O] routines.
4865  ** ^A negative value for the zeroblob results in a zero-length BLOB.
4866  **
4867  ** ^The sqlite3_bind_pointer(S,I,P,T,D) routine causes the I-th parameter in
4868  ** [prepared statement] S to have an SQL value of NULL, but to also be
4869  ** associated with the pointer P of type T.  ^D is either a NULL pointer or
4870  ** a pointer to a destructor function for P. ^SQLite will invoke the
4871  ** destructor D with a single argument of P when it is finished using
4872  ** P.  The T parameter should be a static string, preferably a string
4873  ** literal. The sqlite3_bind_pointer() routine is part of the
4874  ** [pointer passing interface] added for SQLite 3.20.0.
4875  **
4876  ** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer
4877  ** for the [prepared statement] or with a prepared statement for which
4878  ** [sqlite3_step()] has been called more recently than [sqlite3_reset()],
4879  ** then the call will return [SQLITE_MISUSE].  If any sqlite3_bind_()
4880  ** routine is passed a [prepared statement] that has been finalized, the
4881  ** result is undefined and probably harmful.
4882  **
4883  ** ^Bindings are not cleared by the [sqlite3_reset()] routine.
4884  ** ^Unbound parameters are interpreted as NULL.
4885  **
4886  ** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an
4887  ** [error code] if anything goes wrong.
4888  ** ^[SQLITE_TOOBIG] might be returned if the size of a string or BLOB
4889  ** exceeds limits imposed by [sqlite3_limit]([SQLITE_LIMIT_LENGTH]) or
4890  ** [SQLITE_MAX_LENGTH].
4891  ** ^[SQLITE_RANGE] is returned if the parameter
4892  ** index is out of range.  ^[SQLITE_NOMEM] is returned if malloc() fails.
4893  **
4894  ** See also: [sqlite3_bind_parameter_count()],
4895  ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].
4896  */
4897  SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
4898  SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,
4899                          void(*)(void*));
4900  SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);
4901  SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);
4902  SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
4903  SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);
4904  SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
4905  SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));
4906  SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,
4907                           void(*)(void*), unsigned char encoding);
4908  SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);
4909  SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt*, int, void*, const char*,void(*)(void*));
4910  SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);
4911  SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);
4912  
4913  /*
4914  ** CAPI3REF: Number Of SQL Parameters
4915  ** METHOD: sqlite3_stmt
4916  **
4917  ** ^This routine can be used to find the number of [SQL parameters]
4918  ** in a [prepared statement].  SQL parameters are tokens of the
4919  ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as
4920  ** placeholders for values that are [sqlite3_bind_blob | bound]
4921  ** to the parameters at a later time.
4922  **
4923  ** ^(This routine actually returns the index of the largest (rightmost)
4924  ** parameter. For all forms except ?NNN, this will correspond to the
4925  ** number of unique parameters.  If parameters of the ?NNN form are used,
4926  ** there may be gaps in the list.)^
4927  **
4928  ** See also: [sqlite3_bind_blob|sqlite3_bind()],
4929  ** [sqlite3_bind_parameter_name()], and
4930  ** [sqlite3_bind_parameter_index()].
4931  */
4932  SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*);
4933  
4934  /*
4935  ** CAPI3REF: Name Of A Host Parameter
4936  ** METHOD: sqlite3_stmt
4937  **
4938  ** ^The sqlite3_bind_parameter_name(P,N) interface returns
4939  ** the name of the N-th [SQL parameter] in the [prepared statement] P.
4940  ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"
4941  ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"
4942  ** respectively.
4943  ** In other words, the initial ":" or "$" or "@" or "?"
4944  ** is included as part of the name.)^
4945  ** ^Parameters of the form "?" without a following integer have no name
4946  ** and are referred to as "nameless" or "anonymous parameters".
4947  **
4948  ** ^The first host parameter has an index of 1, not 0.
4949  **
4950  ** ^If the value N is out of range or if the N-th parameter is
4951  ** nameless, then NULL is returned.  ^The returned string is
4952  ** always in UTF-8 encoding even if the named parameter was
4953  ** originally specified as UTF-16 in [sqlite3_prepare16()],
4954  ** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()].
4955  **
4956  ** See also: [sqlite3_bind_blob|sqlite3_bind()],
4957  ** [sqlite3_bind_parameter_count()], and
4958  ** [sqlite3_bind_parameter_index()].
4959  */
4960  SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
4961  
4962  /*
4963  ** CAPI3REF: Index Of A Parameter With A Given Name
4964  ** METHOD: sqlite3_stmt
4965  **
4966  ** ^Return the index of an SQL parameter given its name.  ^The
4967  ** index value returned is suitable for use as the second
4968  ** parameter to [sqlite3_bind_blob|sqlite3_bind()].  ^A zero
4969  ** is returned if no matching parameter is found.  ^The parameter
4970  ** name must be given in UTF-8 even if the original statement
4971  ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()] or
4972  ** [sqlite3_prepare16_v3()].
4973  **
4974  ** See also: [sqlite3_bind_blob|sqlite3_bind()],
4975  ** [sqlite3_bind_parameter_count()], and
4976  ** [sqlite3_bind_parameter_name()].
4977  */
4978  SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
4979  
4980  /*
4981  ** CAPI3REF: Reset All Bindings On A Prepared Statement
4982  ** METHOD: sqlite3_stmt
4983  **
4984  ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset
4985  ** the [sqlite3_bind_blob | bindings] on a [prepared statement].
4986  ** ^Use this routine to reset all host parameters to NULL.
4987  */
4988  SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*);
4989  
4990  /*
4991  ** CAPI3REF: Number Of Columns In A Result Set
4992  ** METHOD: sqlite3_stmt
4993  **
4994  ** ^Return the number of columns in the result set returned by the
4995  ** [prepared statement]. ^If this routine returns 0, that means the
4996  ** [prepared statement] returns no data (for example an [UPDATE]).
4997  ** ^However, just because this routine returns a positive number does not
4998  ** mean that one or more rows of data will be returned.  ^A SELECT statement
4999  ** will always have a positive sqlite3_column_count() but depending on the
5000  ** WHERE clause constraints and the table content, it might return no rows.
5001  **
5002  ** See also: [sqlite3_data_count()]
5003  */
5004  SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);
5005  
5006  /*
5007  ** CAPI3REF: Column Names In A Result Set
5008  ** METHOD: sqlite3_stmt
5009  **
5010  ** ^These routines return the name assigned to a particular column
5011  ** in the result set of a [SELECT] statement.  ^The sqlite3_column_name()
5012  ** interface returns a pointer to a zero-terminated UTF-8 string
5013  ** and sqlite3_column_name16() returns a pointer to a zero-terminated
5014  ** UTF-16 string.  ^The first parameter is the [prepared statement]
5015  ** that implements the [SELECT] statement. ^The second parameter is the
5016  ** column number.  ^The leftmost column is number 0.
5017  **
5018  ** ^The returned string pointer is valid until either the [prepared statement]
5019  ** is destroyed by [sqlite3_finalize()] or until the statement is automatically
5020  ** reprepared by the first call to [sqlite3_step()] for a particular run
5021  ** or until the next call to
5022  ** sqlite3_column_name() or sqlite3_column_name16() on the same column.
5023  **
5024  ** ^If sqlite3_malloc() fails during the processing of either routine
5025  ** (for example during a conversion from UTF-8 to UTF-16) then a
5026  ** NULL pointer is returned.
5027  **
5028  ** ^The name of a result column is the value of the "AS" clause for
5029  ** that column, if there is an AS clause.  If there is no AS clause
5030  ** then the name of the column is unspecified and may change from
5031  ** one release of SQLite to the next.
5032  */
5033  SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N);
5034  SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N);
5035  
5036  /*
5037  ** CAPI3REF: Source Of Data In A Query Result
5038  ** METHOD: sqlite3_stmt
5039  **
5040  ** ^These routines provide a means to determine the database, table, and
5041  ** table column that is the origin of a particular result column in a
5042  ** [SELECT] statement.
5043  ** ^The name of the database or table or column can be returned as
5044  ** either a UTF-8 or UTF-16 string.  ^The _database_ routines return
5045  ** the database name, the _table_ routines return the table name, and
5046  ** the origin_ routines return the column name.
5047  ** ^The returned string is valid until the [prepared statement] is destroyed
5048  ** using [sqlite3_finalize()] or until the statement is automatically
5049  ** reprepared by the first call to [sqlite3_step()] for a particular run
5050  ** or until the same information is requested
5051  ** again in a different encoding.
5052  **
5053  ** ^The names returned are the original un-aliased names of the
5054  ** database, table, and column.
5055  **
5056  ** ^The first argument to these interfaces is a [prepared statement].
5057  ** ^These functions return information about the Nth result column returned by
5058  ** the statement, where N is the second function argument.
5059  ** ^The left-most column is column 0 for these routines.
5060  **
5061  ** ^If the Nth column returned by the statement is an expression or
5062  ** subquery and is not a column value, then all of these functions return
5063  ** NULL.  ^These routines might also return NULL if a memory allocation error
5064  ** occurs.  ^Otherwise, they return the name of the attached database, table,
5065  ** or column that query result column was extracted from.
5066  **
5067  ** ^As with all other SQLite APIs, those whose names end with "16" return
5068  ** UTF-16 encoded strings and the other functions return UTF-8.
5069  **
5070  ** ^These APIs are only available if the library was compiled with the
5071  ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.
5072  **
5073  ** If two or more threads call one or more
5074  ** [sqlite3_column_database_name | column metadata interfaces]
5075  ** for the same [prepared statement] and result column
5076  ** at the same time then the results are undefined.
5077  */
5078  SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int);
5079  SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int);
5080  SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int);
5081  SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int);
5082  SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int);
5083  SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);
5084  
5085  /*
5086  ** CAPI3REF: Declared Datatype Of A Query Result
5087  ** METHOD: sqlite3_stmt
5088  **
5089  ** ^(The first parameter is a [prepared statement].
5090  ** If this statement is a [SELECT] statement and the Nth column of the
5091  ** returned result set of that [SELECT] is a table column (not an
5092  ** expression or subquery) then the declared type of the table
5093  ** column is returned.)^  ^If the Nth column of the result set is an
5094  ** expression or subquery, then a NULL pointer is returned.
5095  ** ^The returned string is always UTF-8 encoded.
5096  **
5097  ** ^(For example, given the database schema:
5098  **
5099  ** CREATE TABLE t1(c1 VARIANT);
5100  **
5101  ** and the following statement to be compiled:
5102  **
5103  ** SELECT c1 + 1, c1 FROM t1;
5104  **
5105  ** this routine would return the string "VARIANT" for the second result
5106  ** column (i==1), and a NULL pointer for the first result column (i==0).)^
5107  **
5108  ** ^SQLite uses dynamic run-time typing.  ^So just because a column
5109  ** is declared to contain a particular type does not mean that the
5110  ** data stored in that column is of the declared type.  SQLite is
5111  ** strongly typed, but the typing is dynamic not static.  ^Type
5112  ** is associated with individual values, not with the containers
5113  ** used to hold those values.
5114  */
5115  SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int);
5116  SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int);
5117  
5118  /*
5119  ** CAPI3REF: Evaluate An SQL Statement
5120  ** METHOD: sqlite3_stmt
5121  **
5122  ** After a [prepared statement] has been prepared using any of
5123  ** [sqlite3_prepare_v2()], [sqlite3_prepare_v3()], [sqlite3_prepare16_v2()],
5124  ** or [sqlite3_prepare16_v3()] or one of the legacy
5125  ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function
5126  ** must be called one or more times to evaluate the statement.
5127  **
5128  ** The details of the behavior of the sqlite3_step() interface depend
5129  ** on whether the statement was prepared using the newer "vX" interfaces
5130  ** [sqlite3_prepare_v3()], [sqlite3_prepare_v2()], [sqlite3_prepare16_v3()],
5131  ** [sqlite3_prepare16_v2()] or the older legacy
5132  ** interfaces [sqlite3_prepare()] and [sqlite3_prepare16()].  The use of the
5133  ** new "vX" interface is recommended for new applications but the legacy
5134  ** interface will continue to be supported.
5135  **
5136  ** ^In the legacy interface, the return value will be either [SQLITE_BUSY],
5137  ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
5138  ** ^With the "v2" interface, any of the other [result codes] or
5139  ** [extended result codes] might be returned as well.
5140  **
5141  ** ^[SQLITE_BUSY] means that the database engine was unable to acquire the
5142  ** database locks it needs to do its job.  ^If the statement is a [COMMIT]
5143  ** or occurs outside of an explicit transaction, then you can retry the
5144  ** statement.  If the statement is not a [COMMIT] and occurs within an
5145  ** explicit transaction then you should rollback the transaction before
5146  ** continuing.
5147  **
5148  ** ^[SQLITE_DONE] means that the statement has finished executing
5149  ** successfully.  sqlite3_step() should not be called again on this virtual
5150  ** machine without first calling [sqlite3_reset()] to reset the virtual
5151  ** machine back to its initial state.
5152  **
5153  ** ^If the SQL statement being executed returns any data, then [SQLITE_ROW]
5154  ** is returned each time a new row of data is ready for processing by the
5155  ** caller. The values may be accessed using the [column access functions].
5156  ** sqlite3_step() is called again to retrieve the next row of data.
5157  **
5158  ** ^[SQLITE_ERROR] means that a run-time error (such as a constraint
5159  ** violation) has occurred.  sqlite3_step() should not be called again on
5160  ** the VM. More information may be found by calling [sqlite3_errmsg()].
5161  ** ^With the legacy interface, a more specific error code (for example,
5162  ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
5163  ** can be obtained by calling [sqlite3_reset()] on the
5164  ** [prepared statement].  ^In the "v2" interface,
5165  ** the more specific error code is returned directly by sqlite3_step().
5166  **
5167  ** [SQLITE_MISUSE] means that the this routine was called inappropriately.
5168  ** Perhaps it was called on a [prepared statement] that has
5169  ** already been [sqlite3_finalize | finalized] or on one that had
5170  ** previously returned [SQLITE_ERROR] or [SQLITE_DONE].  Or it could
5171  ** be the case that the same database connection is being used by two or
5172  ** more threads at the same moment in time.
5173  **
5174  ** For all versions of SQLite up to and including 3.6.23.1, a call to
5175  ** [sqlite3_reset()] was required after sqlite3_step() returned anything
5176  ** other than [SQLITE_ROW] before any subsequent invocation of
5177  ** sqlite3_step().  Failure to reset the prepared statement using
5178  ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
5179  ** sqlite3_step().  But after [version 3.6.23.1] ([dateof:3.6.23.1]),
5180  ** sqlite3_step() began
5181  ** calling [sqlite3_reset()] automatically in this circumstance rather
5182  ** than returning [SQLITE_MISUSE].  This is not considered a compatibility
5183  ** break because any application that ever receives an SQLITE_MISUSE error
5184  ** is broken by definition.  The [SQLITE_OMIT_AUTORESET] compile-time option
5185  ** can be used to restore the legacy behavior.
5186  **
5187  ** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step()
5188  ** API always returns a generic error code, [SQLITE_ERROR], following any
5189  ** error other than [SQLITE_BUSY] and [SQLITE_MISUSE].  You must call
5190  ** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the
5191  ** specific [error codes] that better describes the error.
5192  ** We admit that this is a goofy design.  The problem has been fixed
5193  ** with the "v2" interface.  If you prepare all of your SQL statements
5194  ** using [sqlite3_prepare_v3()] or [sqlite3_prepare_v2()]
5195  ** or [sqlite3_prepare16_v2()] or [sqlite3_prepare16_v3()] instead
5196  ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces,
5197  ** then the more specific [error codes] are returned directly
5198  ** by sqlite3_step().  The use of the "vX" interfaces is recommended.
5199  */
5200  SQLITE_API int sqlite3_step(sqlite3_stmt*);
5201  
5202  /*
5203  ** CAPI3REF: Number of columns in a result set
5204  ** METHOD: sqlite3_stmt
5205  **
5206  ** ^The sqlite3_data_count(P) interface returns the number of columns in the
5207  ** current row of the result set of [prepared statement] P.
5208  ** ^If prepared statement P does not have results ready to return
5209  ** (via calls to the [sqlite3_column_int | sqlite3_column()] family of
5210  ** interfaces) then sqlite3_data_count(P) returns 0.
5211  ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.
5212  ** ^The sqlite3_data_count(P) routine returns 0 if the previous call to
5213  ** [sqlite3_step](P) returned [SQLITE_DONE].  ^The sqlite3_data_count(P)
5214  ** will return non-zero if previous call to [sqlite3_step](P) returned
5215  ** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum]
5216  ** where it always returns zero since each step of that multi-step
5217  ** pragma returns 0 columns of data.
5218  **
5219  ** See also: [sqlite3_column_count()]
5220  */
5221  SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);
5222  
5223  /*
5224  ** CAPI3REF: Fundamental Datatypes
5225  ** KEYWORDS: SQLITE_TEXT
5226  **
5227  ** ^(Every value in SQLite has one of five fundamental datatypes:
5228  **
5229  ** <ul>
5230  ** <li> 64-bit signed integer
5231  ** <li> 64-bit IEEE floating point number
5232  ** <li> string
5233  ** <li> BLOB
5234  ** <li> NULL
5235  ** </ul>)^
5236  **
5237  ** These constants are codes for each of those types.
5238  **
5239  ** Note that the SQLITE_TEXT constant was also used in SQLite version 2
5240  ** for a completely different meaning.  Software that links against both
5241  ** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not
5242  ** SQLITE_TEXT.
5243  */
5244  #define SQLITE_INTEGER  1
5245  #define SQLITE_FLOAT    2
5246  #define SQLITE_BLOB     4
5247  #define SQLITE_NULL     5
5248  #ifdef SQLITE_TEXT
5249  # undef SQLITE_TEXT
5250  #else
5251  # define SQLITE_TEXT     3
5252  #endif
5253  #define SQLITE3_TEXT     3
5254  
5255  /*
5256  ** CAPI3REF: Result Values From A Query
5257  ** KEYWORDS: {column access functions}
5258  ** METHOD: sqlite3_stmt
5259  **
5260  ** <b>Summary:</b>
5261  ** <blockquote><table border=0 cellpadding=0 cellspacing=0>
5262  ** <tr><td><b>sqlite3_column_blob</b><td>&rarr;<td>BLOB result
5263  ** <tr><td><b>sqlite3_column_double</b><td>&rarr;<td>REAL result
5264  ** <tr><td><b>sqlite3_column_int</b><td>&rarr;<td>32-bit INTEGER result
5265  ** <tr><td><b>sqlite3_column_int64</b><td>&rarr;<td>64-bit INTEGER result
5266  ** <tr><td><b>sqlite3_column_text</b><td>&rarr;<td>UTF-8 TEXT result
5267  ** <tr><td><b>sqlite3_column_text16</b><td>&rarr;<td>UTF-16 TEXT result
5268  ** <tr><td><b>sqlite3_column_value</b><td>&rarr;<td>The result as an
5269  ** [sqlite3_value|unprotected sqlite3_value] object.
5270  ** <tr><td>&nbsp;<td>&nbsp;<td>&nbsp;
5271  ** <tr><td><b>sqlite3_column_bytes</b><td>&rarr;<td>Size of a BLOB
5272  ** or a UTF-8 TEXT result in bytes
5273  ** <tr><td><b>sqlite3_column_bytes16&nbsp;&nbsp;</b>
5274  ** <td>&rarr;&nbsp;&nbsp;<td>Size of UTF-16
5275  ** TEXT in bytes
5276  ** <tr><td><b>sqlite3_column_type</b><td>&rarr;<td>Default
5277  ** datatype of the result
5278  ** </table></blockquote>
5279  **
5280  ** <b>Details:</b>
5281  **
5282  ** ^These routines return information about a single column of the current
5283  ** result row of a query.  ^In every case the first argument is a pointer
5284  ** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*]
5285  ** that was returned from [sqlite3_prepare_v2()] or one of its variants)
5286  ** and the second argument is the index of the column for which information
5287  ** should be returned. ^The leftmost column of the result set has the index 0.
5288  ** ^The number of columns in the result can be determined using
5289  ** [sqlite3_column_count()].
5290  **
5291  ** If the SQL statement does not currently point to a valid row, or if the
5292  ** column index is out of range, the result is undefined.
5293  ** These routines may only be called when the most recent call to
5294  ** [sqlite3_step()] has returned [SQLITE_ROW] and neither
5295  ** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently.
5296  ** If any of these routines are called after [sqlite3_reset()] or
5297  ** [sqlite3_finalize()] or after [sqlite3_step()] has returned
5298  ** something other than [SQLITE_ROW], the results are undefined.
5299  ** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()]
5300  ** are called from a different thread while any of these routines
5301  ** are pending, then the results are undefined.
5302  **
5303  ** The first six interfaces (_blob, _double, _int, _int64, _text, and _text16)
5304  ** each return the value of a result column in a specific data format.  If
5305  ** the result column is not initially in the requested format (for example,
5306  ** if the query returns an integer but the sqlite3_column_text() interface
5307  ** is used to extract the value) then an automatic type conversion is performed.
5308  **
5309  ** ^The sqlite3_column_type() routine returns the
5310  ** [SQLITE_INTEGER | datatype code] for the initial data type
5311  ** of the result column.  ^The returned value is one of [SQLITE_INTEGER],
5312  ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].
5313  ** The return value of sqlite3_column_type() can be used to decide which
5314  ** of the first six interface should be used to extract the column value.
5315  ** The value returned by sqlite3_column_type() is only meaningful if no
5316  ** automatic type conversions have occurred for the value in question.
5317  ** After a type conversion, the result of calling sqlite3_column_type()
5318  ** is undefined, though harmless.  Future
5319  ** versions of SQLite may change the behavior of sqlite3_column_type()
5320  ** following a type conversion.
5321  **
5322  ** If the result is a BLOB or a TEXT string, then the sqlite3_column_bytes()
5323  ** or sqlite3_column_bytes16() interfaces can be used to determine the size
5324  ** of that BLOB or string.
5325  **
5326  ** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes()
5327  ** routine returns the number of bytes in that BLOB or string.
5328  ** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts
5329  ** the string to UTF-8 and then returns the number of bytes.
5330  ** ^If the result is a numeric value then sqlite3_column_bytes() uses
5331  ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns
5332  ** the number of bytes in that string.
5333  ** ^If the result is NULL, then sqlite3_column_bytes() returns zero.
5334  **
5335  ** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16()
5336  ** routine returns the number of bytes in that BLOB or string.
5337  ** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts
5338  ** the string to UTF-16 and then returns the number of bytes.
5339  ** ^If the result is a numeric value then sqlite3_column_bytes16() uses
5340  ** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns
5341  ** the number of bytes in that string.
5342  ** ^If the result is NULL, then sqlite3_column_bytes16() returns zero.
5343  **
5344  ** ^The values returned by [sqlite3_column_bytes()] and
5345  ** [sqlite3_column_bytes16()] do not include the zero terminators at the end
5346  ** of the string.  ^For clarity: the values returned by
5347  ** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of
5348  ** bytes in the string, not the number of characters.
5349  **
5350  ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),
5351  ** even empty strings, are always zero-terminated.  ^The return
5352  ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.
5353  **
5354  ** ^Strings returned by sqlite3_column_text16() always have the endianness
5355  ** which is native to the platform, regardless of the text encoding set
5356  ** for the database.
5357  **
5358  ** <b>Warning:</b> ^The object returned by [sqlite3_column_value()] is an
5359  ** [unprotected sqlite3_value] object.  In a multithreaded environment,
5360  ** an unprotected sqlite3_value object may only be used safely with
5361  ** [sqlite3_bind_value()] and [sqlite3_result_value()].
5362  ** If the [unprotected sqlite3_value] object returned by
5363  ** [sqlite3_column_value()] is used in any other way, including calls
5364  ** to routines like [sqlite3_value_int()], [sqlite3_value_text()],
5365  ** or [sqlite3_value_bytes()], the behavior is not threadsafe.
5366  ** Hence, the sqlite3_column_value() interface
5367  ** is normally only useful within the implementation of
5368  ** [application-defined SQL functions] or [virtual tables], not within
5369  ** top-level application code.
5370  **
5371  ** These routines may attempt to convert the datatype of the result.
5372  ** ^For example, if the internal representation is FLOAT and a text result
5373  ** is requested, [sqlite3_snprintf()] is used internally to perform the
5374  ** conversion automatically.  ^(The following table details the conversions
5375  ** that are applied:
5376  **
5377  ** <blockquote>
5378  ** <table border="1">
5379  ** <tr><th> Internal<br>Type <th> Requested<br>Type <th>  Conversion
5380  **
5381  ** <tr><td>  NULL    <td> INTEGER   <td> Result is 0
5382  ** <tr><td>  NULL    <td>  FLOAT    <td> Result is 0.0
5383  ** <tr><td>  NULL    <td>   TEXT    <td> Result is a NULL pointer
5384  ** <tr><td>  NULL    <td>   BLOB    <td> Result is a NULL pointer
5385  ** <tr><td> INTEGER  <td>  FLOAT    <td> Convert from integer to float
5386  ** <tr><td> INTEGER  <td>   TEXT    <td> ASCII rendering of the integer
5387  ** <tr><td> INTEGER  <td>   BLOB    <td> Same as INTEGER->TEXT
5388  ** <tr><td>  FLOAT   <td> INTEGER   <td> [CAST] to INTEGER
5389  ** <tr><td>  FLOAT   <td>   TEXT    <td> ASCII rendering of the float
5390  ** <tr><td>  FLOAT   <td>   BLOB    <td> [CAST] to BLOB
5391  ** <tr><td>  TEXT    <td> INTEGER   <td> [CAST] to INTEGER
5392  ** <tr><td>  TEXT    <td>  FLOAT    <td> [CAST] to REAL
5393  ** <tr><td>  TEXT    <td>   BLOB    <td> No change
5394  ** <tr><td>  BLOB    <td> INTEGER   <td> [CAST] to INTEGER
5395  ** <tr><td>  BLOB    <td>  FLOAT    <td> [CAST] to REAL
5396  ** <tr><td>  BLOB    <td>   TEXT    <td> [CAST] to TEXT, ensure zero terminator
5397  ** </table>
5398  ** </blockquote>)^
5399  **
5400  ** Note that when type conversions occur, pointers returned by prior
5401  ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or
5402  ** sqlite3_column_text16() may be invalidated.
5403  ** Type conversions and pointer invalidations might occur
5404  ** in the following cases:
5405  **
5406  ** <ul>
5407  ** <li> The initial content is a BLOB and sqlite3_column_text() or
5408  **      sqlite3_column_text16() is called.  A zero-terminator might
5409  **      need to be added to the string.</li>
5410  ** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or
5411  **      sqlite3_column_text16() is called.  The content must be converted
5412  **      to UTF-16.</li>
5413  ** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or
5414  **      sqlite3_column_text() is called.  The content must be converted
5415  **      to UTF-8.</li>
5416  ** </ul>
5417  **
5418  ** ^Conversions between UTF-16be and UTF-16le are always done in place and do
5419  ** not invalidate a prior pointer, though of course the content of the buffer
5420  ** that the prior pointer references will have been modified.  Other kinds
5421  ** of conversion are done in place when it is possible, but sometimes they
5422  ** are not possible and in those cases prior pointers are invalidated.
5423  **
5424  ** The safest policy is to invoke these routines
5425  ** in one of the following ways:
5426  **
5427  ** <ul>
5428  **  <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>
5429  **  <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>
5430  **  <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>
5431  ** </ul>
5432  **
5433  ** In other words, you should call sqlite3_column_text(),
5434  ** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result
5435  ** into the desired format, then invoke sqlite3_column_bytes() or
5436  ** sqlite3_column_bytes16() to find the size of the result.  Do not mix calls
5437  ** to sqlite3_column_text() or sqlite3_column_blob() with calls to
5438  ** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16()
5439  ** with calls to sqlite3_column_bytes().
5440  **
5441  ** ^The pointers returned are valid until a type conversion occurs as
5442  ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or
5443  ** [sqlite3_finalize()] is called.  ^The memory space used to hold strings
5444  ** and BLOBs is freed automatically.  Do not pass the pointers returned
5445  ** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into
5446  ** [sqlite3_free()].
5447  **
5448  ** As long as the input parameters are correct, these routines will only
5449  ** fail if an out-of-memory error occurs during a format conversion.
5450  ** Only the following subset of interfaces are subject to out-of-memory
5451  ** errors:
5452  **
5453  ** <ul>
5454  ** <li> sqlite3_column_blob()
5455  ** <li> sqlite3_column_text()
5456  ** <li> sqlite3_column_text16()
5457  ** <li> sqlite3_column_bytes()
5458  ** <li> sqlite3_column_bytes16()
5459  ** </ul>
5460  **
5461  ** If an out-of-memory error occurs, then the return value from these
5462  ** routines is the same as if the column had contained an SQL NULL value.
5463  ** Valid SQL NULL returns can be distinguished from out-of-memory errors
5464  ** by invoking the [sqlite3_errcode()] immediately after the suspect
5465  ** return value is obtained and before any
5466  ** other SQLite interface is called on the same [database connection].
5467  */
5468  SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
5469  SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol);
5470  SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol);
5471  SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
5472  SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
5473  SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);
5474  SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
5475  SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
5476  SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);
5477  SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol);
5478  
5479  /*
5480  ** CAPI3REF: Destroy A Prepared Statement Object
5481  ** DESTRUCTOR: sqlite3_stmt
5482  **
5483  ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
5484  ** ^If the most recent evaluation of the statement encountered no errors
5485  ** or if the statement is never been evaluated, then sqlite3_finalize() returns
5486  ** SQLITE_OK.  ^If the most recent evaluation of statement S failed, then
5487  ** sqlite3_finalize(S) returns the appropriate [error code] or
5488  ** [extended error code].
5489  **
5490  ** ^The sqlite3_finalize(S) routine can be called at any point during
5491  ** the life cycle of [prepared statement] S:
5492  ** before statement S is ever evaluated, after
5493  ** one or more calls to [sqlite3_reset()], or after any call
5494  ** to [sqlite3_step()] regardless of whether or not the statement has
5495  ** completed execution.
5496  **
5497  ** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op.
5498  **
5499  ** The application must finalize every [prepared statement] in order to avoid
5500  ** resource leaks.  It is a grievous error for the application to try to use
5501  ** a prepared statement after it has been finalized.  Any use of a prepared
5502  ** statement after it has been finalized can result in undefined and
5503  ** undesirable behavior such as segfaults and heap corruption.
5504  */
5505  SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);
5506  
5507  /*
5508  ** CAPI3REF: Reset A Prepared Statement Object
5509  ** METHOD: sqlite3_stmt
5510  **
5511  ** The sqlite3_reset() function is called to reset a [prepared statement]
5512  ** object back to its initial state, ready to be re-executed.
5513  ** ^Any SQL statement variables that had values bound to them using
5514  ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.
5515  ** Use [sqlite3_clear_bindings()] to reset the bindings.
5516  **
5517  ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S
5518  ** back to the beginning of its program.
5519  **
5520  ** ^The return code from [sqlite3_reset(S)] indicates whether or not
5521  ** the previous evaluation of prepared statement S completed successfully.
5522  ** ^If [sqlite3_step(S)] has never before been called on S or if
5523  ** [sqlite3_step(S)] has not been called since the previous call
5524  ** to [sqlite3_reset(S)], then [sqlite3_reset(S)] will return
5525  ** [SQLITE_OK].
5526  **
5527  ** ^If the most recent call to [sqlite3_step(S)] for the
5528  ** [prepared statement] S indicated an error, then
5529  ** [sqlite3_reset(S)] returns an appropriate [error code].
5530  ** ^The [sqlite3_reset(S)] interface might also return an [error code]
5531  ** if there were no prior errors but the process of resetting
5532  ** the prepared statement caused a new error. ^For example, if an
5533  ** [INSERT] statement with a [RETURNING] clause is only stepped one time,
5534  ** that one call to [sqlite3_step(S)] might return SQLITE_ROW but
5535  ** the overall statement might still fail and the [sqlite3_reset(S)] call
5536  ** might return SQLITE_BUSY if locking constraints prevent the
5537  ** database change from committing.  Therefore, it is important that
5538  ** applications check the return code from [sqlite3_reset(S)] even if
5539  ** no prior call to [sqlite3_step(S)] indicated a problem.
5540  **
5541  ** ^The [sqlite3_reset(S)] interface does not change the values
5542  ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.
5543  */
5544  SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
5545  
5546  
5547  /*
5548  ** CAPI3REF: Create Or Redefine SQL Functions
5549  ** KEYWORDS: {function creation routines}
5550  ** METHOD: sqlite3
5551  **
5552  ** ^These functions (collectively known as "function creation routines")
5553  ** are used to add SQL functions or aggregates or to redefine the behavior
5554  ** of existing SQL functions or aggregates. The only differences between
5555  ** the three "sqlite3_create_function*" routines are the text encoding
5556  ** expected for the second parameter (the name of the function being
5557  ** created) and the presence or absence of a destructor callback for
5558  ** the application data pointer. Function sqlite3_create_window_function()
5559  ** is similar, but allows the user to supply the extra callback functions
5560  ** needed by [aggregate window functions].
5561  **
5562  ** ^The first parameter is the [database connection] to which the SQL
5563  ** function is to be added.  ^If an application uses more than one database
5564  ** connection then application-defined SQL functions must be added
5565  ** to each database connection separately.
5566  **
5567  ** ^The second parameter is the name of the SQL function to be created or
5568  ** redefined.  ^The length of the name is limited to 255 bytes in a UTF-8
5569  ** representation, exclusive of the zero-terminator.  ^Note that the name
5570  ** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes.
5571  ** ^Any attempt to create a function with a longer name
5572  ** will result in [SQLITE_MISUSE] being returned.
5573  **
5574  ** ^The third parameter (nArg)
5575  ** is the number of arguments that the SQL function or
5576  ** aggregate takes. ^If this parameter is -1, then the SQL function or
5577  ** aggregate may take any number of arguments between 0 and the limit
5578  ** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]).  If the third
5579  ** parameter is less than -1 or greater than 127 then the behavior is
5580  ** undefined.
5581  **
5582  ** ^The fourth parameter, eTextRep, specifies what
5583  ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
5584  ** its parameters.  The application should set this parameter to
5585  ** [SQLITE_UTF16LE] if the function implementation invokes
5586  ** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the
5587  ** implementation invokes [sqlite3_value_text16be()] on an input, or
5588  ** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8]
5589  ** otherwise.  ^The same SQL function may be registered multiple times using
5590  ** different preferred text encodings, with different implementations for
5591  ** each encoding.
5592  ** ^When multiple implementations of the same function are available, SQLite
5593  ** will pick the one that involves the least amount of data conversion.
5594  **
5595  ** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC]
5596  ** to signal that the function will always return the same result given
5597  ** the same inputs within a single SQL statement.  Most SQL functions are
5598  ** deterministic.  The built-in [random()] SQL function is an example of a
5599  ** function that is not deterministic.  The SQLite query planner is able to
5600  ** perform additional optimizations on deterministic functions, so use
5601  ** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
5602  **
5603  ** ^The fourth parameter may also optionally include the [SQLITE_DIRECTONLY]
5604  ** flag, which if present prevents the function from being invoked from
5605  ** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions,
5606  ** index expressions, or the WHERE clause of partial indexes.
5607  **
5608  ** For best security, the [SQLITE_DIRECTONLY] flag is recommended for
5609  ** all application-defined SQL functions that do not need to be
5610  ** used inside of triggers, views, CHECK constraints, or other elements of
5611  ** the database schema.  This flag is especially recommended for SQL
5612  ** functions that have side effects or reveal internal application state.
5613  ** Without this flag, an attacker might be able to modify the schema of
5614  ** a database file to include invocations of the function with parameters
5615  ** chosen by the attacker, which the application will then execute when
5616  ** the database file is opened and read.
5617  **
5618  ** ^(The fifth parameter is an arbitrary pointer.  The implementation of the
5619  ** function can gain access to this pointer using [sqlite3_user_data()].)^
5620  **
5621  ** ^The sixth, seventh and eighth parameters passed to the three
5622  ** "sqlite3_create_function*" functions, xFunc, xStep and xFinal, are
5623  ** pointers to C-language functions that implement the SQL function or
5624  ** aggregate. ^A scalar SQL function requires an implementation of the xFunc
5625  ** callback only; NULL pointers must be passed as the xStep and xFinal
5626  ** parameters. ^An aggregate SQL function requires an implementation of xStep
5627  ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
5628  ** SQL function or aggregate, pass NULL pointers for all three function
5629  ** callbacks.
5630  **
5631  ** ^The sixth, seventh, eighth and ninth parameters (xStep, xFinal, xValue
5632  ** and xInverse) passed to sqlite3_create_window_function are pointers to
5633  ** C-language callbacks that implement the new function. xStep and xFinal
5634  ** must both be non-NULL. xValue and xInverse may either both be NULL, in
5635  ** which case a regular aggregate function is created, or must both be
5636  ** non-NULL, in which case the new function may be used as either an aggregate
5637  ** or aggregate window function. More details regarding the implementation
5638  ** of aggregate window functions are
5639  ** [user-defined window functions|available here].
5640  **
5641  ** ^(If the final parameter to sqlite3_create_function_v2() or
5642  ** sqlite3_create_window_function() is not NULL, then it is the destructor for
5643  ** the application data pointer. The destructor is invoked when the function
5644  ** is deleted, either by being overloaded or when the database connection
5645  ** closes.)^ ^The destructor is also invoked if the call to
5646  ** sqlite3_create_function_v2() fails.  ^When the destructor callback is
5647  ** invoked, it is passed a single argument which is a copy of the application
5648  ** data pointer which was the fifth parameter to sqlite3_create_function_v2().
5649  **
5650  ** ^It is permitted to register multiple implementations of the same
5651  ** functions with the same name but with either differing numbers of
5652  ** arguments or differing preferred text encodings.  ^SQLite will use
5653  ** the implementation that most closely matches the way in which the
5654  ** SQL function is used.  ^A function implementation with a non-negative
5655  ** nArg parameter is a better match than a function implementation with
5656  ** a negative nArg.  ^A function where the preferred text encoding
5657  ** matches the database encoding is a better
5658  ** match than a function where the encoding is different.
5659  ** ^A function where the encoding difference is between UTF16le and UTF16be
5660  ** is a closer match than a function where the encoding difference is
5661  ** between UTF8 and UTF16.
5662  **
5663  ** ^Built-in functions may be overloaded by new application-defined functions.
5664  **
5665  ** ^An application-defined function is permitted to call other
5666  ** SQLite interfaces.  However, such calls must not
5667  ** close the database connection nor finalize or reset the prepared
5668  ** statement in which the function is running.
5669  */
5670  SQLITE_API int sqlite3_create_function(
5671    sqlite3 *db,
5672    const char *zFunctionName,
5673    int nArg,
5674    int eTextRep,
5675    void *pApp,
5676    void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
5677    void (*xStep)(sqlite3_context*,int,sqlite3_value**),
5678    void (*xFinal)(sqlite3_context*)
5679  );
5680  SQLITE_API int sqlite3_create_function16(
5681    sqlite3 *db,
5682    const void *zFunctionName,
5683    int nArg,
5684    int eTextRep,
5685    void *pApp,
5686    void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
5687    void (*xStep)(sqlite3_context*,int,sqlite3_value**),
5688    void (*xFinal)(sqlite3_context*)
5689  );
5690  SQLITE_API int sqlite3_create_function_v2(
5691    sqlite3 *db,
5692    const char *zFunctionName,
5693    int nArg,
5694    int eTextRep,
5695    void *pApp,
5696    void (*xFunc)(sqlite3_context*,int,sqlite3_value**),
5697    void (*xStep)(sqlite3_context*,int,sqlite3_value**),
5698    void (*xFinal)(sqlite3_context*),
5699    void(*xDestroy)(void*)
5700  );
5701  SQLITE_API int sqlite3_create_window_function(
5702    sqlite3 *db,
5703    const char *zFunctionName,
5704    int nArg,
5705    int eTextRep,
5706    void *pApp,
5707    void (*xStep)(sqlite3_context*,int,sqlite3_value**),
5708    void (*xFinal)(sqlite3_context*),
5709    void (*xValue)(sqlite3_context*),
5710    void (*xInverse)(sqlite3_context*,int,sqlite3_value**),
5711    void(*xDestroy)(void*)
5712  );
5713  
5714  /*
5715  ** CAPI3REF: Text Encodings
5716  **
5717  ** These constant define integer codes that represent the various
5718  ** text encodings supported by SQLite.
5719  */
5720  #define SQLITE_UTF8           1    /* IMP: R-37514-35566 */
5721  #define SQLITE_UTF16LE        2    /* IMP: R-03371-37637 */
5722  #define SQLITE_UTF16BE        3    /* IMP: R-51971-34154 */
5723  #define SQLITE_UTF16          4    /* Use native byte order */
5724  #define SQLITE_ANY            5    /* Deprecated */
5725  #define SQLITE_UTF16_ALIGNED  8    /* sqlite3_create_collation only */
5726  
5727  /*
5728  ** CAPI3REF: Function Flags
5729  **
5730  ** These constants may be ORed together with the
5731  ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
5732  ** to [sqlite3_create_function()], [sqlite3_create_function16()], or
5733  ** [sqlite3_create_function_v2()].
5734  **
5735  ** <dl>
5736  ** [[SQLITE_DETERMINISTIC]] <dt>SQLITE_DETERMINISTIC</dt><dd>
5737  ** The SQLITE_DETERMINISTIC flag means that the new function always gives
5738  ** the same output when the input parameters are the same.
5739  ** The [abs|abs() function] is deterministic, for example, but
5740  ** [randomblob|randomblob()] is not.  Functions must
5741  ** be deterministic in order to be used in certain contexts such as
5742  ** with the WHERE clause of [partial indexes] or in [generated columns].
5743  ** SQLite might also optimize deterministic functions by factoring them
5744  ** out of inner loops.
5745  ** </dd>
5746  **
5747  ** [[SQLITE_DIRECTONLY]] <dt>SQLITE_DIRECTONLY</dt><dd>
5748  ** The SQLITE_DIRECTONLY flag means that the function may only be invoked
5749  ** from top-level SQL, and cannot be used in VIEWs or TRIGGERs nor in
5750  ** schema structures such as [CHECK constraints], [DEFAULT clauses],
5751  ** [expression indexes], [partial indexes], or [generated columns].
5752  ** <p>
5753  ** The SQLITE_DIRECTONLY flag is recommended for any
5754  ** [application-defined SQL function]
5755  ** that has side-effects or that could potentially leak sensitive information.
5756  ** This will prevent attacks in which an application is tricked
5757  ** into using a database file that has had its schema surreptitiously
5758  ** modified to invoke the application-defined function in ways that are
5759  ** harmful.
5760  ** <p>
5761  ** Some people say it is good practice to set SQLITE_DIRECTONLY on all
5762  ** [application-defined SQL functions], regardless of whether or not they
5763  ** are security sensitive, as doing so prevents those functions from being used
5764  ** inside of the database schema, and thus ensures that the database
5765  ** can be inspected and modified using generic tools (such as the [CLI])
5766  ** that do not have access to the application-defined functions.
5767  ** </dd>
5768  **
5769  ** [[SQLITE_INNOCUOUS]] <dt>SQLITE_INNOCUOUS</dt><dd>
5770  ** The SQLITE_INNOCUOUS flag means that the function is unlikely
5771  ** to cause problems even if misused.  An innocuous function should have
5772  ** no side effects and should not depend on any values other than its
5773  ** input parameters. The [abs|abs() function] is an example of an
5774  ** innocuous function.
5775  ** The [load_extension() SQL function] is not innocuous because of its
5776  ** side effects.
5777  ** <p> SQLITE_INNOCUOUS is similar to SQLITE_DETERMINISTIC, but is not
5778  ** exactly the same.  The [random|random() function] is an example of a
5779  ** function that is innocuous but not deterministic.
5780  ** <p>Some heightened security settings
5781  ** ([SQLITE_DBCONFIG_TRUSTED_SCHEMA] and [PRAGMA trusted_schema=OFF])
5782  ** disable the use of SQL functions inside views and triggers and in
5783  ** schema structures such as [CHECK constraints], [DEFAULT clauses],
5784  ** [expression indexes], [partial indexes], and [generated columns] unless
5785  ** the function is tagged with SQLITE_INNOCUOUS.  Most built-in functions
5786  ** are innocuous.  Developers are advised to avoid using the
5787  ** SQLITE_INNOCUOUS flag for application-defined functions unless the
5788  ** function has been carefully audited and found to be free of potentially
5789  ** security-adverse side-effects and information-leaks.
5790  ** </dd>
5791  **
5792  ** [[SQLITE_SUBTYPE]] <dt>SQLITE_SUBTYPE</dt><dd>
5793  ** The SQLITE_SUBTYPE flag indicates to SQLite that a function might call
5794  ** [sqlite3_value_subtype()] to inspect the sub-types of its arguments.
5795  ** This flag instructs SQLite to omit some corner-case optimizations that
5796  ** might disrupt the operation of the [sqlite3_value_subtype()] function,
5797  ** causing it to return zero rather than the correct subtype().
5798  ** All SQL functions that invoke [sqlite3_value_subtype()] should have this
5799  ** property.  If the SQLITE_SUBTYPE property is omitted, then the return
5800  ** value from [sqlite3_value_subtype()] might sometimes be zero even though
5801  ** a non-zero subtype was specified by the function argument expression.
5802  **
5803  ** [[SQLITE_RESULT_SUBTYPE]] <dt>SQLITE_RESULT_SUBTYPE</dt><dd>
5804  ** The SQLITE_RESULT_SUBTYPE flag indicates to SQLite that a function might call
5805  ** [sqlite3_result_subtype()] to cause a sub-type to be associated with its
5806  ** result.
5807  ** Every function that invokes [sqlite3_result_subtype()] should have this
5808  ** property.  If it does not, then the call to [sqlite3_result_subtype()]
5809  ** might become a no-op if the function is used as term in an
5810  ** [expression index].  On the other hand, SQL functions that never invoke
5811  ** [sqlite3_result_subtype()] should avoid setting this property, as the
5812  ** purpose of this property is to disable certain optimizations that are
5813  ** incompatible with subtypes.
5814  **
5815  ** [[SQLITE_SELFORDER1]] <dt>SQLITE_SELFORDER1</dt><dd>
5816  ** The SQLITE_SELFORDER1 flag indicates that the function is an aggregate
5817  ** that internally orders the values provided to the first argument.  The
5818  ** ordered-set aggregate SQL notation with a single ORDER BY term can be
5819  ** used to invoke this function.  If the ordered-set aggregate notation is
5820  ** used on a function that lacks this flag, then an error is raised. Note
5821  ** that the ordered-set aggregate syntax is only available if SQLite is
5822  ** built using the -DSQLITE_ENABLE_ORDERED_SET_AGGREGATES compile-time option.
5823  ** </dd>
5824  ** </dl>
5825  */
5826  #define SQLITE_DETERMINISTIC    0x000000800
5827  #define SQLITE_DIRECTONLY       0x000080000
5828  #define SQLITE_SUBTYPE          0x000100000
5829  #define SQLITE_INNOCUOUS        0x000200000
5830  #define SQLITE_RESULT_SUBTYPE   0x001000000
5831  #define SQLITE_SELFORDER1       0x002000000
5832  
5833  /*
5834  ** CAPI3REF: Deprecated Functions
5835  ** DEPRECATED
5836  **
5837  ** These functions are [deprecated].  In order to maintain
5838  ** backwards compatibility with older code, these functions continue
5839  ** to be supported.  However, new applications should avoid
5840  ** the use of these functions.  To encourage programmers to avoid
5841  ** these functions, we will not explain what they do.
5842  */
5843  #ifndef SQLITE_OMIT_DEPRECATED
5844  SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
5845  SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
5846  SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
5847  SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void);
5848  SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);
5849  SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),
5850                        void*,sqlite3_int64);
5851  #endif
5852  
5853  /*
5854  ** CAPI3REF: Obtaining SQL Values
5855  ** METHOD: sqlite3_value
5856  **
5857  ** <b>Summary:</b>
5858  ** <blockquote><table border=0 cellpadding=0 cellspacing=0>
5859  ** <tr><td><b>sqlite3_value_blob</b><td>&rarr;<td>BLOB value
5860  ** <tr><td><b>sqlite3_value_double</b><td>&rarr;<td>REAL value
5861  ** <tr><td><b>sqlite3_value_int</b><td>&rarr;<td>32-bit INTEGER value
5862  ** <tr><td><b>sqlite3_value_int64</b><td>&rarr;<td>64-bit INTEGER value
5863  ** <tr><td><b>sqlite3_value_pointer</b><td>&rarr;<td>Pointer value
5864  ** <tr><td><b>sqlite3_value_text</b><td>&rarr;<td>UTF-8 TEXT value
5865  ** <tr><td><b>sqlite3_value_text16</b><td>&rarr;<td>UTF-16 TEXT value in
5866  ** the native byteorder
5867  ** <tr><td><b>sqlite3_value_text16be</b><td>&rarr;<td>UTF-16be TEXT value
5868  ** <tr><td><b>sqlite3_value_text16le</b><td>&rarr;<td>UTF-16le TEXT value
5869  ** <tr><td>&nbsp;<td>&nbsp;<td>&nbsp;
5870  ** <tr><td><b>sqlite3_value_bytes</b><td>&rarr;<td>Size of a BLOB
5871  ** or a UTF-8 TEXT in bytes
5872  ** <tr><td><b>sqlite3_value_bytes16&nbsp;&nbsp;</b>
5873  ** <td>&rarr;&nbsp;&nbsp;<td>Size of UTF-16
5874  ** TEXT in bytes
5875  ** <tr><td><b>sqlite3_value_type</b><td>&rarr;<td>Default
5876  ** datatype of the value
5877  ** <tr><td><b>sqlite3_value_numeric_type&nbsp;&nbsp;</b>
5878  ** <td>&rarr;&nbsp;&nbsp;<td>Best numeric datatype of the value
5879  ** <tr><td><b>sqlite3_value_nochange&nbsp;&nbsp;</b>
5880  ** <td>&rarr;&nbsp;&nbsp;<td>True if the column is unchanged in an UPDATE
5881  ** against a virtual table.
5882  ** <tr><td><b>sqlite3_value_frombind&nbsp;&nbsp;</b>
5883  ** <td>&rarr;&nbsp;&nbsp;<td>True if value originated from a [bound parameter]
5884  ** </table></blockquote>
5885  **
5886  ** <b>Details:</b>
5887  **
5888  ** These routines extract type, size, and content information from
5889  ** [protected sqlite3_value] objects.  Protected sqlite3_value objects
5890  ** are used to pass parameter information into the functions that
5891  ** implement [application-defined SQL functions] and [virtual tables].
5892  **
5893  ** These routines work only with [protected sqlite3_value] objects.
5894  ** Any attempt to use these routines on an [unprotected sqlite3_value]
5895  ** is not threadsafe.
5896  **
5897  ** ^These routines work just like the corresponding [column access functions]
5898  ** except that these routines take a single [protected sqlite3_value] object
5899  ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.
5900  **
5901  ** ^The sqlite3_value_text16() interface extracts a UTF-16 string
5902  ** in the native byte-order of the host machine.  ^The
5903  ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces
5904  ** extract UTF-16 strings as big-endian and little-endian respectively.
5905  **
5906  ** ^If [sqlite3_value] object V was initialized
5907  ** using [sqlite3_bind_pointer(S,I,P,X,D)] or [sqlite3_result_pointer(C,P,X,D)]
5908  ** and if X and Y are strings that compare equal according to strcmp(X,Y),
5909  ** then sqlite3_value_pointer(V,Y) will return the pointer P.  ^Otherwise,
5910  ** sqlite3_value_pointer(V,Y) returns a NULL. The sqlite3_bind_pointer()
5911  ** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
5912  **
5913  ** ^(The sqlite3_value_type(V) interface returns the
5914  ** [SQLITE_INTEGER | datatype code] for the initial datatype of the
5915  ** [sqlite3_value] object V. The returned value is one of [SQLITE_INTEGER],
5916  ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].)^
5917  ** Other interfaces might change the datatype for an sqlite3_value object.
5918  ** For example, if the datatype is initially SQLITE_INTEGER and
5919  ** sqlite3_value_text(V) is called to extract a text value for that
5920  ** integer, then subsequent calls to sqlite3_value_type(V) might return
5921  ** SQLITE_TEXT.  Whether or not a persistent internal datatype conversion
5922  ** occurs is undefined and may change from one release of SQLite to the next.
5923  **
5924  ** ^(The sqlite3_value_numeric_type() interface attempts to apply
5925  ** numeric affinity to the value.  This means that an attempt is
5926  ** made to convert the value to an integer or floating point.  If
5927  ** such a conversion is possible without loss of information (in other
5928  ** words, if the value is a string that looks like a number)
5929  ** then the conversion is performed.  Otherwise no conversion occurs.
5930  ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^
5931  **
5932  ** ^Within the [xUpdate] method of a [virtual table], the
5933  ** sqlite3_value_nochange(X) interface returns true if and only if
5934  ** the column corresponding to X is unchanged by the UPDATE operation
5935  ** that the xUpdate method call was invoked to implement and if
5936  ** and the prior [xColumn] method call that was invoked to extracted
5937  ** the value for that column returned without setting a result (probably
5938  ** because it queried [sqlite3_vtab_nochange()] and found that the column
5939  ** was unchanging).  ^Within an [xUpdate] method, any value for which
5940  ** sqlite3_value_nochange(X) is true will in all other respects appear
5941  ** to be a NULL value.  If sqlite3_value_nochange(X) is invoked anywhere other
5942  ** than within an [xUpdate] method call for an UPDATE statement, then
5943  ** the return value is arbitrary and meaningless.
5944  **
5945  ** ^The sqlite3_value_frombind(X) interface returns non-zero if the
5946  ** value X originated from one of the [sqlite3_bind_int|sqlite3_bind()]
5947  ** interfaces.  ^If X comes from an SQL literal value, or a table column,
5948  ** or an expression, then sqlite3_value_frombind(X) returns zero.
5949  **
5950  ** Please pay particular attention to the fact that the pointer returned
5951  ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
5952  ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
5953  ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
5954  ** or [sqlite3_value_text16()].
5955  **
5956  ** These routines must be called from the same thread as
5957  ** the SQL function that supplied the [sqlite3_value*] parameters.
5958  **
5959  ** As long as the input parameter is correct, these routines can only
5960  ** fail if an out-of-memory error occurs during a format conversion.
5961  ** Only the following subset of interfaces are subject to out-of-memory
5962  ** errors:
5963  **
5964  ** <ul>
5965  ** <li> sqlite3_value_blob()
5966  ** <li> sqlite3_value_text()
5967  ** <li> sqlite3_value_text16()
5968  ** <li> sqlite3_value_text16le()
5969  ** <li> sqlite3_value_text16be()
5970  ** <li> sqlite3_value_bytes()
5971  ** <li> sqlite3_value_bytes16()
5972  ** </ul>
5973  **
5974  ** If an out-of-memory error occurs, then the return value from these
5975  ** routines is the same as if the column had contained an SQL NULL value.
5976  ** Valid SQL NULL returns can be distinguished from out-of-memory errors
5977  ** by invoking the [sqlite3_errcode()] immediately after the suspect
5978  ** return value is obtained and before any
5979  ** other SQLite interface is called on the same [database connection].
5980  */
5981  SQLITE_API const void *sqlite3_value_blob(sqlite3_value*);
5982  SQLITE_API double sqlite3_value_double(sqlite3_value*);
5983  SQLITE_API int sqlite3_value_int(sqlite3_value*);
5984  SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*);
5985  SQLITE_API void *sqlite3_value_pointer(sqlite3_value*, const char*);
5986  SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*);
5987  SQLITE_API const void *sqlite3_value_text16(sqlite3_value*);
5988  SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*);
5989  SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);
5990  SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
5991  SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
5992  SQLITE_API int sqlite3_value_type(sqlite3_value*);
5993  SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
5994  SQLITE_API int sqlite3_value_nochange(sqlite3_value*);
5995  SQLITE_API int sqlite3_value_frombind(sqlite3_value*);
5996  
5997  /*
5998  ** CAPI3REF: Report the internal text encoding state of an sqlite3_value object
5999  ** METHOD: sqlite3_value
6000  **
6001  ** ^(The sqlite3_value_encoding(X) interface returns one of [SQLITE_UTF8],
6002  ** [SQLITE_UTF16BE], or [SQLITE_UTF16LE] according to the current text encoding
6003  ** of the value X, assuming that X has type TEXT.)^  If sqlite3_value_type(X)
6004  ** returns something other than SQLITE_TEXT, then the return value from
6005  ** sqlite3_value_encoding(X) is meaningless.  ^Calls to
6006  ** [sqlite3_value_text(X)], [sqlite3_value_text16(X)], [sqlite3_value_text16be(X)],
6007  ** [sqlite3_value_text16le(X)], [sqlite3_value_bytes(X)], or
6008  ** [sqlite3_value_bytes16(X)] might change the encoding of the value X and
6009  ** thus change the return from subsequent calls to sqlite3_value_encoding(X).
6010  **
6011  ** This routine is intended for used by applications that test and validate
6012  ** the SQLite implementation.  This routine is inquiring about the opaque
6013  ** internal state of an [sqlite3_value] object.  Ordinary applications should
6014  ** not need to know what the internal state of an sqlite3_value object is and
6015  ** hence should not need to use this interface.
6016  */
6017  SQLITE_API int sqlite3_value_encoding(sqlite3_value*);
6018  
6019  /*
6020  ** CAPI3REF: Finding The Subtype Of SQL Values
6021  ** METHOD: sqlite3_value
6022  **
6023  ** The sqlite3_value_subtype(V) function returns the subtype for
6024  ** an [application-defined SQL function] argument V.  The subtype
6025  ** information can be used to pass a limited amount of context from
6026  ** one SQL function to another.  Use the [sqlite3_result_subtype()]
6027  ** routine to set the subtype for the return value of an SQL function.
6028  **
6029  ** Every [application-defined SQL function] that invokes this interface
6030  ** should include the [SQLITE_SUBTYPE] property in the text
6031  ** encoding argument when the function is [sqlite3_create_function|registered].
6032  ** If the [SQLITE_SUBTYPE] property is omitted, then sqlite3_value_subtype()
6033  ** might return zero instead of the upstream subtype in some corner cases.
6034  */
6035  SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value*);
6036  
6037  /*
6038  ** CAPI3REF: Copy And Free SQL Values
6039  ** METHOD: sqlite3_value
6040  **
6041  ** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]
6042  ** object V and returns a pointer to that copy.  ^The [sqlite3_value] returned
6043  ** is a [protected sqlite3_value] object even if the input is not.
6044  ** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a
6045  ** memory allocation fails. ^If V is a [pointer value], then the result
6046  ** of sqlite3_value_dup(V) is a NULL value.
6047  **
6048  ** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object
6049  ** previously obtained from [sqlite3_value_dup()].  ^If V is a NULL pointer
6050  ** then sqlite3_value_free(V) is a harmless no-op.
6051  */
6052  SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value*);
6053  SQLITE_API void sqlite3_value_free(sqlite3_value*);
6054  
6055  /*
6056  ** CAPI3REF: Obtain Aggregate Function Context
6057  ** METHOD: sqlite3_context
6058  **
6059  ** Implementations of aggregate SQL functions use this
6060  ** routine to allocate memory for storing their state.
6061  **
6062  ** ^The first time the sqlite3_aggregate_context(C,N) routine is called
6063  ** for a particular aggregate function, SQLite allocates
6064  ** N bytes of memory, zeroes out that memory, and returns a pointer
6065  ** to the new memory. ^On second and subsequent calls to
6066  ** sqlite3_aggregate_context() for the same aggregate function instance,
6067  ** the same buffer is returned.  Sqlite3_aggregate_context() is normally
6068  ** called once for each invocation of the xStep callback and then one
6069  ** last time when the xFinal callback is invoked.  ^(When no rows match
6070  ** an aggregate query, the xStep() callback of the aggregate function
6071  ** implementation is never called and xFinal() is called exactly once.
6072  ** In those cases, sqlite3_aggregate_context() might be called for the
6073  ** first time from within xFinal().)^
6074  **
6075  ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer
6076  ** when first called if N is less than or equal to zero or if a memory
6077  ** allocation error occurs.
6078  **
6079  ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is
6080  ** determined by the N parameter on the first successful call.  Changing the
6081  ** value of N in any subsequent call to sqlite3_aggregate_context() within
6082  ** the same aggregate function instance will not resize the memory
6083  ** allocation.)^  Within the xFinal callback, it is customary to set
6084  ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no
6085  ** pointless memory allocations occur.
6086  **
6087  ** ^SQLite automatically frees the memory allocated by
6088  ** sqlite3_aggregate_context() when the aggregate query concludes.
6089  **
6090  ** The first parameter must be a copy of the
6091  ** [sqlite3_context | SQL function context] that is the first parameter
6092  ** to the xStep or xFinal callback routine that implements the aggregate
6093  ** function.
6094  **
6095  ** This routine must be called from the same thread in which
6096  ** the aggregate SQL function is running.
6097  */
6098  SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);
6099  
6100  /*
6101  ** CAPI3REF: User Data For Functions
6102  ** METHOD: sqlite3_context
6103  **
6104  ** ^The sqlite3_user_data() interface returns a copy of
6105  ** the pointer that was the pUserData parameter (the 5th parameter)
6106  ** of the [sqlite3_create_function()]
6107  ** and [sqlite3_create_function16()] routines that originally
6108  ** registered the application defined function.
6109  **
6110  ** This routine must be called from the same thread in which
6111  ** the application-defined function is running.
6112  */
6113  SQLITE_API void *sqlite3_user_data(sqlite3_context*);
6114  
6115  /*
6116  ** CAPI3REF: Database Connection For Functions
6117  ** METHOD: sqlite3_context
6118  **
6119  ** ^The sqlite3_context_db_handle() interface returns a copy of
6120  ** the pointer to the [database connection] (the 1st parameter)
6121  ** of the [sqlite3_create_function()]
6122  ** and [sqlite3_create_function16()] routines that originally
6123  ** registered the application defined function.
6124  */
6125  SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);
6126  
6127  /*
6128  ** CAPI3REF: Function Auxiliary Data
6129  ** METHOD: sqlite3_context
6130  **
6131  ** These functions may be used by (non-aggregate) SQL functions to
6132  ** associate auxiliary data with argument values. If the same argument
6133  ** value is passed to multiple invocations of the same SQL function during
6134  ** query execution, under some circumstances the associated auxiliary data
6135  ** might be preserved.  An example of where this might be useful is in a
6136  ** regular-expression matching function. The compiled version of the regular
6137  ** expression can be stored as auxiliary data associated with the pattern string.
6138  ** Then as long as the pattern string remains the same,
6139  ** the compiled regular expression can be reused on multiple
6140  ** invocations of the same function.
6141  **
6142  ** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the auxiliary data
6143  ** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument
6144  ** value to the application-defined function.  ^N is zero for the left-most
6145  ** function argument.  ^If there is no auxiliary data
6146  ** associated with the function argument, the sqlite3_get_auxdata(C,N) interface
6147  ** returns a NULL pointer.
6148  **
6149  ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as auxiliary data for the
6150  ** N-th argument of the application-defined function.  ^Subsequent
6151  ** calls to sqlite3_get_auxdata(C,N) return P from the most recent
6152  ** sqlite3_set_auxdata(C,N,P,X) call if the auxiliary data is still valid or
6153  ** NULL if the auxiliary data has been discarded.
6154  ** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL,
6155  ** SQLite will invoke the destructor function X with parameter P exactly
6156  ** once, when the auxiliary data is discarded.
6157  ** SQLite is free to discard the auxiliary data at any time, including: <ul>
6158  ** <li> ^(when the corresponding function parameter changes)^, or
6159  ** <li> ^(when [sqlite3_reset()] or [sqlite3_finalize()] is called for the
6160  **      SQL statement)^, or
6161  ** <li> ^(when sqlite3_set_auxdata() is invoked again on the same
6162  **       parameter)^, or
6163  ** <li> ^(during the original sqlite3_set_auxdata() call when a memory
6164  **      allocation error occurs.)^
6165  ** <li> ^(during the original sqlite3_set_auxdata() call if the function
6166  **      is evaluated during query planning instead of during query execution,
6167  **      as sometimes happens with [SQLITE_ENABLE_STAT4].)^ </ul>
6168  **
6169  ** Note the last two bullets in particular.  The destructor X in
6170  ** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the
6171  ** sqlite3_set_auxdata() interface even returns.  Hence sqlite3_set_auxdata()
6172  ** should be called near the end of the function implementation and the
6173  ** function implementation should not make any use of P after
6174  ** sqlite3_set_auxdata() has been called.  Furthermore, a call to
6175  ** sqlite3_get_auxdata() that occurs immediately after a corresponding call
6176  ** to sqlite3_set_auxdata() might still return NULL if an out-of-memory
6177  ** condition occurred during the sqlite3_set_auxdata() call or if the
6178  ** function is being evaluated during query planning rather than during
6179  ** query execution.
6180  **
6181  ** ^(In practice, auxiliary data is preserved between function calls for
6182  ** function parameters that are compile-time constants, including literal
6183  ** values and [parameters] and expressions composed from the same.)^
6184  **
6185  ** The value of the N parameter to these interfaces should be non-negative.
6186  ** Future enhancements may make use of negative N values to define new
6187  ** kinds of function caching behavior.
6188  **
6189  ** These routines must be called from the same thread in which
6190  ** the SQL function is running.
6191  **
6192  ** See also: [sqlite3_get_clientdata()] and [sqlite3_set_clientdata()].
6193  */
6194  SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);
6195  SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));
6196  
6197  /*
6198  ** CAPI3REF: Database Connection Client Data
6199  ** METHOD: sqlite3
6200  **
6201  ** These functions are used to associate one or more named pointers
6202  ** with a [database connection].
6203  ** A call to sqlite3_set_clientdata(D,N,P,X) causes the pointer P
6204  ** to be attached to [database connection] D using name N.  Subsequent
6205  ** calls to sqlite3_get_clientdata(D,N) will return a copy of pointer P
6206  ** or a NULL pointer if there were no prior calls to
6207  ** sqlite3_set_clientdata() with the same values of D and N.
6208  ** Names are compared using strcmp() and are thus case sensitive.
6209  **
6210  ** If P and X are both non-NULL, then the destructor X is invoked with
6211  ** argument P on the first of the following occurrences:
6212  ** <ul>
6213  ** <li> An out-of-memory error occurs during the call to
6214  **      sqlite3_set_clientdata() which attempts to register pointer P.
6215  ** <li> A subsequent call to sqlite3_set_clientdata(D,N,P,X) is made
6216  **      with the same D and N parameters.
6217  ** <li> The database connection closes.  SQLite does not make any guarantees
6218  **      about the order in which destructors are called, only that all
6219  **      destructors will be called exactly once at some point during the
6220  **      database connection closing process.
6221  ** </ul>
6222  **
6223  ** SQLite does not do anything with client data other than invoke
6224  ** destructors on the client data at the appropriate time.  The intended
6225  ** use for client data is to provide a mechanism for wrapper libraries
6226  ** to store additional information about an SQLite database connection.
6227  **
6228  ** There is no limit (other than available memory) on the number of different
6229  ** client data pointers (with different names) that can be attached to a
6230  ** single database connection.  However, the implementation is optimized
6231  ** for the case of having only one or two different client data names.
6232  ** Applications and wrapper libraries are discouraged from using more than
6233  ** one client data name each.
6234  **
6235  ** There is no way to enumerate the client data pointers
6236  ** associated with a database connection.  The N parameter can be thought
6237  ** of as a secret key such that only code that knows the secret key is able
6238  ** to access the associated data.
6239  **
6240  ** Security Warning:  These interfaces should not be exposed in scripting
6241  ** languages or in other circumstances where it might be possible for an
6242  ** attacker to invoke them.  Any agent that can invoke these interfaces
6243  ** can probably also take control of the process.
6244  **
6245  ** Database connection client data is only available for SQLite
6246  ** version 3.44.0 ([dateof:3.44.0]) and later.
6247  **
6248  ** See also: [sqlite3_set_auxdata()] and [sqlite3_get_auxdata()].
6249  */
6250  SQLITE_API void *sqlite3_get_clientdata(sqlite3*,const char*);
6251  SQLITE_API int sqlite3_set_clientdata(sqlite3*, const char*, void*, void(*)(void*));
6252  
6253  /*
6254  ** CAPI3REF: Constants Defining Special Destructor Behavior
6255  **
6256  ** These are special values for the destructor that is passed in as the
6257  ** final argument to routines like [sqlite3_result_blob()].  ^If the destructor
6258  ** argument is SQLITE_STATIC, it means that the content pointer is constant
6259  ** and will never change.  It does not need to be destroyed.  ^The
6260  ** SQLITE_TRANSIENT value means that the content will likely change in
6261  ** the near future and that SQLite should make its own private copy of
6262  ** the content before returning.
6263  **
6264  ** The typedef is necessary to work around problems in certain
6265  ** C++ compilers.
6266  */
6267  typedef void (*sqlite3_destructor_type)(void*);
6268  #define SQLITE_STATIC      ((sqlite3_destructor_type)0)
6269  #define SQLITE_TRANSIENT   ((sqlite3_destructor_type)-1)
6270  
6271  /*
6272  ** CAPI3REF: Setting The Result Of An SQL Function
6273  ** METHOD: sqlite3_context
6274  **
6275  ** These routines are used by the xFunc or xFinal callbacks that
6276  ** implement SQL functions and aggregates.  See
6277  ** [sqlite3_create_function()] and [sqlite3_create_function16()]
6278  ** for additional information.
6279  **
6280  ** These functions work very much like the [parameter binding] family of
6281  ** functions used to bind values to host parameters in prepared statements.
6282  ** Refer to the [SQL parameter] documentation for additional information.
6283  **
6284  ** ^The sqlite3_result_blob() interface sets the result from
6285  ** an application-defined function to be the BLOB whose content is pointed
6286  ** to by the second parameter and which is N bytes long where N is the
6287  ** third parameter.
6288  **
6289  ** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N)
6290  ** interfaces set the result of the application-defined function to be
6291  ** a BLOB containing all zero bytes and N bytes in size.
6292  **
6293  ** ^The sqlite3_result_double() interface sets the result from
6294  ** an application-defined function to be a floating point value specified
6295  ** by its 2nd argument.
6296  **
6297  ** ^The sqlite3_result_error() and sqlite3_result_error16() functions
6298  ** cause the implemented SQL function to throw an exception.
6299  ** ^SQLite uses the string pointed to by the
6300  ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()
6301  ** as the text of an error message.  ^SQLite interprets the error
6302  ** message string from sqlite3_result_error() as UTF-8. ^SQLite
6303  ** interprets the string from sqlite3_result_error16() as UTF-16 using
6304  ** the same [byte-order determination rules] as [sqlite3_bind_text16()].
6305  ** ^If the third parameter to sqlite3_result_error()
6306  ** or sqlite3_result_error16() is negative then SQLite takes as the error
6307  ** message all text up through the first zero character.
6308  ** ^If the third parameter to sqlite3_result_error() or
6309  ** sqlite3_result_error16() is non-negative then SQLite takes that many
6310  ** bytes (not characters) from the 2nd parameter as the error message.
6311  ** ^The sqlite3_result_error() and sqlite3_result_error16()
6312  ** routines make a private copy of the error message text before
6313  ** they return.  Hence, the calling function can deallocate or
6314  ** modify the text after they return without harm.
6315  ** ^The sqlite3_result_error_code() function changes the error code
6316  ** returned by SQLite as a result of an error in a function.  ^By default,
6317  ** the error code is SQLITE_ERROR.  ^A subsequent call to sqlite3_result_error()
6318  ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR.
6319  **
6320  ** ^The sqlite3_result_error_toobig() interface causes SQLite to throw an
6321  ** error indicating that a string or BLOB is too long to represent.
6322  **
6323  ** ^The sqlite3_result_error_nomem() interface causes SQLite to throw an
6324  ** error indicating that a memory allocation failed.
6325  **
6326  ** ^The sqlite3_result_int() interface sets the return value
6327  ** of the application-defined function to be the 32-bit signed integer
6328  ** value given in the 2nd argument.
6329  ** ^The sqlite3_result_int64() interface sets the return value
6330  ** of the application-defined function to be the 64-bit signed integer
6331  ** value given in the 2nd argument.
6332  **
6333  ** ^The sqlite3_result_null() interface sets the return value
6334  ** of the application-defined function to be NULL.
6335  **
6336  ** ^The sqlite3_result_text(), sqlite3_result_text16(),
6337  ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces
6338  ** set the return value of the application-defined function to be
6339  ** a text string which is represented as UTF-8, UTF-16 native byte order,
6340  ** UTF-16 little endian, or UTF-16 big endian, respectively.
6341  ** ^The sqlite3_result_text64() interface sets the return value of an
6342  ** application-defined function to be a text string in an encoding
6343  ** specified by the fifth (and last) parameter, which must be one
6344  ** of [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE].
6345  ** ^SQLite takes the text result from the application from
6346  ** the 2nd parameter of the sqlite3_result_text* interfaces.
6347  ** ^If the 3rd parameter to any of the sqlite3_result_text* interfaces
6348  ** other than sqlite3_result_text64() is negative, then SQLite computes
6349  ** the string length itself by searching the 2nd parameter for the first
6350  ** zero character.
6351  ** ^If the 3rd parameter to the sqlite3_result_text* interfaces
6352  ** is non-negative, then as many bytes (not characters) of the text
6353  ** pointed to by the 2nd parameter are taken as the application-defined
6354  ** function result.  If the 3rd parameter is non-negative, then it
6355  ** must be the byte offset into the string where the NUL terminator would
6356  ** appear if the string were NUL terminated.  If any NUL characters occur
6357  ** in the string at a byte offset that is less than the value of the 3rd
6358  ** parameter, then the resulting string will contain embedded NULs and the
6359  ** result of expressions operating on strings with embedded NULs is undefined.
6360  ** ^If the 4th parameter to the sqlite3_result_text* interfaces
6361  ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that
6362  ** function as the destructor on the text or BLOB result when it has
6363  ** finished using that result.
6364  ** ^If the 4th parameter to the sqlite3_result_text* interfaces or to
6365  ** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite
6366  ** assumes that the text or BLOB result is in constant space and does not
6367  ** copy the content of the parameter nor call a destructor on the content
6368  ** when it has finished using that result.
6369  ** ^If the 4th parameter to the sqlite3_result_text* interfaces
6370  ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT
6371  ** then SQLite makes a copy of the result into space obtained
6372  ** from [sqlite3_malloc()] before it returns.
6373  **
6374  ** ^For the sqlite3_result_text16(), sqlite3_result_text16le(), and
6375  ** sqlite3_result_text16be() routines, and for sqlite3_result_text64()
6376  ** when the encoding is not UTF8, if the input UTF16 begins with a
6377  ** byte-order mark (BOM, U+FEFF) then the BOM is removed from the
6378  ** string and the rest of the string is interpreted according to the
6379  ** byte-order specified by the BOM.  ^The byte-order specified by
6380  ** the BOM at the beginning of the text overrides the byte-order
6381  ** specified by the interface procedure.  ^So, for example, if
6382  ** sqlite3_result_text16le() is invoked with text that begins
6383  ** with bytes 0xfe, 0xff (a big-endian byte-order mark) then the
6384  ** first two bytes of input are skipped and the remaining input
6385  ** is interpreted as UTF16BE text.
6386  **
6387  ** ^For UTF16 input text to the sqlite3_result_text16(),
6388  ** sqlite3_result_text16be(), sqlite3_result_text16le(), and
6389  ** sqlite3_result_text64() routines, if the text contains invalid
6390  ** UTF16 characters, the invalid characters might be converted
6391  ** into the unicode replacement character, U+FFFD.
6392  **
6393  ** ^The sqlite3_result_value() interface sets the result of
6394  ** the application-defined function to be a copy of the
6395  ** [unprotected sqlite3_value] object specified by the 2nd parameter.  ^The
6396  ** sqlite3_result_value() interface makes a copy of the [sqlite3_value]
6397  ** so that the [sqlite3_value] specified in the parameter may change or
6398  ** be deallocated after sqlite3_result_value() returns without harm.
6399  ** ^A [protected sqlite3_value] object may always be used where an
6400  ** [unprotected sqlite3_value] object is required, so either
6401  ** kind of [sqlite3_value] object can be used with this interface.
6402  **
6403  ** ^The sqlite3_result_pointer(C,P,T,D) interface sets the result to an
6404  ** SQL NULL value, just like [sqlite3_result_null(C)], except that it
6405  ** also associates the host-language pointer P or type T with that
6406  ** NULL value such that the pointer can be retrieved within an
6407  ** [application-defined SQL function] using [sqlite3_value_pointer()].
6408  ** ^If the D parameter is not NULL, then it is a pointer to a destructor
6409  ** for the P parameter.  ^SQLite invokes D with P as its only argument
6410  ** when SQLite is finished with P.  The T parameter should be a static
6411  ** string and preferably a string literal. The sqlite3_result_pointer()
6412  ** routine is part of the [pointer passing interface] added for SQLite 3.20.0.
6413  **
6414  ** If these routines are called from within a different thread
6415  ** than the one containing the application-defined function that received
6416  ** the [sqlite3_context] pointer, the results are undefined.
6417  */
6418  SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
6419  SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,
6420                             sqlite3_uint64,void(*)(void*));
6421  SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
6422  SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
6423  SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
6424  SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
6425  SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
6426  SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int);
6427  SQLITE_API void sqlite3_result_int(sqlite3_context*, int);
6428  SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);
6429  SQLITE_API void sqlite3_result_null(sqlite3_context*);
6430  SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));
6431  SQLITE_API void sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64,
6432                             void(*)(void*), unsigned char encoding);
6433  SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));
6434  SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
6435  SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
6436  SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
6437  SQLITE_API void sqlite3_result_pointer(sqlite3_context*, void*,const char*,void(*)(void*));
6438  SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);
6439  SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);
6440  
6441  
6442  /*
6443  ** CAPI3REF: Setting The Subtype Of An SQL Function
6444  ** METHOD: sqlite3_context
6445  **
6446  ** The sqlite3_result_subtype(C,T) function causes the subtype of
6447  ** the result from the [application-defined SQL function] with
6448  ** [sqlite3_context] C to be the value T.  Only the lower 8 bits
6449  ** of the subtype T are preserved in current versions of SQLite;
6450  ** higher order bits are discarded.
6451  ** The number of subtype bytes preserved by SQLite might increase
6452  ** in future releases of SQLite.
6453  **
6454  ** Every [application-defined SQL function] that invokes this interface
6455  ** should include the [SQLITE_RESULT_SUBTYPE] property in its
6456  ** text encoding argument when the SQL function is
6457  ** [sqlite3_create_function|registered].  If the [SQLITE_RESULT_SUBTYPE]
6458  ** property is omitted from the function that invokes sqlite3_result_subtype(),
6459  ** then in some cases the sqlite3_result_subtype() might fail to set
6460  ** the result subtype.
6461  **
6462  ** If SQLite is compiled with -DSQLITE_STRICT_SUBTYPE=1, then any
6463  ** SQL function that invokes the sqlite3_result_subtype() interface
6464  ** and that does not have the SQLITE_RESULT_SUBTYPE property will raise
6465  ** an error.  Future versions of SQLite might enable -DSQLITE_STRICT_SUBTYPE=1
6466  ** by default.
6467  */
6468  SQLITE_API void sqlite3_result_subtype(sqlite3_context*,unsigned int);
6469  
6470  /*
6471  ** CAPI3REF: Define New Collating Sequences
6472  ** METHOD: sqlite3
6473  **
6474  ** ^These functions add, remove, or modify a [collation] associated
6475  ** with the [database connection] specified as the first argument.
6476  **
6477  ** ^The name of the collation is a UTF-8 string
6478  ** for sqlite3_create_collation() and sqlite3_create_collation_v2()
6479  ** and a UTF-16 string in native byte order for sqlite3_create_collation16().
6480  ** ^Collation names that compare equal according to [sqlite3_strnicmp()] are
6481  ** considered to be the same name.
6482  **
6483  ** ^(The third argument (eTextRep) must be one of the constants:
6484  ** <ul>
6485  ** <li> [SQLITE_UTF8],
6486  ** <li> [SQLITE_UTF16LE],
6487  ** <li> [SQLITE_UTF16BE],
6488  ** <li> [SQLITE_UTF16], or
6489  ** <li> [SQLITE_UTF16_ALIGNED].
6490  ** </ul>)^
6491  ** ^The eTextRep argument determines the encoding of strings passed
6492  ** to the collating function callback, xCompare.
6493  ** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep
6494  ** force strings to be UTF16 with native byte order.
6495  ** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin
6496  ** on an even byte address.
6497  **
6498  ** ^The fourth argument, pArg, is an application data pointer that is passed
6499  ** through as the first argument to the collating function callback.
6500  **
6501  ** ^The fifth argument, xCompare, is a pointer to the collating function.
6502  ** ^Multiple collating functions can be registered using the same name but
6503  ** with different eTextRep parameters and SQLite will use whichever
6504  ** function requires the least amount of data transformation.
6505  ** ^If the xCompare argument is NULL then the collating function is
6506  ** deleted.  ^When all collating functions having the same name are deleted,
6507  ** that collation is no longer usable.
6508  **
6509  ** ^The collating function callback is invoked with a copy of the pArg
6510  ** application data pointer and with two strings in the encoding specified
6511  ** by the eTextRep argument.  The two integer parameters to the collating
6512  ** function callback are the length of the two strings, in bytes. The collating
6513  ** function must return an integer that is negative, zero, or positive
6514  ** if the first string is less than, equal to, or greater than the second,
6515  ** respectively.  A collating function must always return the same answer
6516  ** given the same inputs.  If two or more collating functions are registered
6517  ** to the same collation name (using different eTextRep values) then all
6518  ** must give an equivalent answer when invoked with equivalent strings.
6519  ** The collating function must obey the following properties for all
6520  ** strings A, B, and C:
6521  **
6522  ** <ol>
6523  ** <li> If A==B then B==A.
6524  ** <li> If A==B and B==C then A==C.
6525  ** <li> If A&lt;B THEN B&gt;A.
6526  ** <li> If A&lt;B and B&lt;C then A&lt;C.
6527  ** </ol>
6528  **
6529  ** If a collating function fails any of the above constraints and that
6530  ** collating function is registered and used, then the behavior of SQLite
6531  ** is undefined.
6532  **
6533  ** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()
6534  ** with the addition that the xDestroy callback is invoked on pArg when
6535  ** the collating function is deleted.
6536  ** ^Collating functions are deleted when they are overridden by later
6537  ** calls to the collation creation functions or when the
6538  ** [database connection] is closed using [sqlite3_close()].
6539  **
6540  ** ^The xDestroy callback is <u>not</u> called if the
6541  ** sqlite3_create_collation_v2() function fails.  Applications that invoke
6542  ** sqlite3_create_collation_v2() with a non-NULL xDestroy argument should
6543  ** check the return code and dispose of the application data pointer
6544  ** themselves rather than expecting SQLite to deal with it for them.
6545  ** This is different from every other SQLite interface.  The inconsistency
6546  ** is unfortunate but cannot be changed without breaking backwards
6547  ** compatibility.
6548  **
6549  ** See also:  [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].
6550  */
6551  SQLITE_API int sqlite3_create_collation(
6552    sqlite3*,
6553    const char *zName,
6554    int eTextRep,
6555    void *pArg,
6556    int(*xCompare)(void*,int,const void*,int,const void*)
6557  );
6558  SQLITE_API int sqlite3_create_collation_v2(
6559    sqlite3*,
6560    const char *zName,
6561    int eTextRep,
6562    void *pArg,
6563    int(*xCompare)(void*,int,const void*,int,const void*),
6564    void(*xDestroy)(void*)
6565  );
6566  SQLITE_API int sqlite3_create_collation16(
6567    sqlite3*,
6568    const void *zName,
6569    int eTextRep,
6570    void *pArg,
6571    int(*xCompare)(void*,int,const void*,int,const void*)
6572  );
6573  
6574  /*
6575  ** CAPI3REF: Collation Needed Callbacks
6576  ** METHOD: sqlite3
6577  **
6578  ** ^To avoid having to register all collation sequences before a database
6579  ** can be used, a single callback function may be registered with the
6580  ** [database connection] to be invoked whenever an undefined collation
6581  ** sequence is required.
6582  **
6583  ** ^If the function is registered using the sqlite3_collation_needed() API,
6584  ** then it is passed the names of undefined collation sequences as strings
6585  ** encoded in UTF-8. ^If sqlite3_collation_needed16() is used,
6586  ** the names are passed as UTF-16 in machine native byte order.
6587  ** ^A call to either function replaces the existing collation-needed callback.
6588  **
6589  ** ^(When the callback is invoked, the first argument passed is a copy
6590  ** of the second argument to sqlite3_collation_needed() or
6591  ** sqlite3_collation_needed16().  The second argument is the database
6592  ** connection.  The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE],
6593  ** or [SQLITE_UTF16LE], indicating the most desirable form of the collation
6594  ** sequence function required.  The fourth parameter is the name of the
6595  ** required collation sequence.)^
6596  **
6597  ** The callback function should register the desired collation using
6598  ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or
6599  ** [sqlite3_create_collation_v2()].
6600  */
6601  SQLITE_API int sqlite3_collation_needed(
6602    sqlite3*,
6603    void*,
6604    void(*)(void*,sqlite3*,int eTextRep,const char*)
6605  );
6606  SQLITE_API int sqlite3_collation_needed16(
6607    sqlite3*,
6608    void*,
6609    void(*)(void*,sqlite3*,int eTextRep,const void*)
6610  );
6611  
6612  #ifdef SQLITE_ENABLE_CEROD
6613  /*
6614  ** Specify the activation key for a CEROD database.  Unless
6615  ** activated, none of the CEROD routines will work.
6616  */
6617  SQLITE_API void sqlite3_activate_cerod(
6618    const char *zPassPhrase        /* Activation phrase */
6619  );
6620  #endif
6621  
6622  /*
6623  ** CAPI3REF: Suspend Execution For A Short Time
6624  **
6625  ** The sqlite3_sleep() function causes the current thread to suspend execution
6626  ** for at least a number of milliseconds specified in its parameter.
6627  **
6628  ** If the operating system does not support sleep requests with
6629  ** millisecond time resolution, then the time will be rounded up to
6630  ** the nearest second. The number of milliseconds of sleep actually
6631  ** requested from the operating system is returned.
6632  **
6633  ** ^SQLite implements this interface by calling the xSleep()
6634  ** method of the default [sqlite3_vfs] object.  If the xSleep() method
6635  ** of the default VFS is not implemented correctly, or not implemented at
6636  ** all, then the behavior of sqlite3_sleep() may deviate from the description
6637  ** in the previous paragraphs.
6638  **
6639  ** If a negative argument is passed to sqlite3_sleep() the results vary by
6640  ** VFS and operating system.  Some system treat a negative argument as an
6641  ** instruction to sleep forever.  Others understand it to mean do not sleep
6642  ** at all. ^In SQLite version 3.42.0 and later, a negative
6643  ** argument passed into sqlite3_sleep() is changed to zero before it is relayed
6644  ** down into the xSleep method of the VFS.
6645  */
6646  SQLITE_API int sqlite3_sleep(int);
6647  
6648  /*
6649  ** CAPI3REF: Name Of The Folder Holding Temporary Files
6650  **
6651  ** ^(If this global variable is made to point to a string which is
6652  ** the name of a folder (a.k.a. directory), then all temporary files
6653  ** created by SQLite when using a built-in [sqlite3_vfs | VFS]
6654  ** will be placed in that directory.)^  ^If this variable
6655  ** is a NULL pointer, then SQLite performs a search for an appropriate
6656  ** temporary file directory.
6657  **
6658  ** Applications are strongly discouraged from using this global variable.
6659  ** It is required to set a temporary folder on Windows Runtime (WinRT).
6660  ** But for all other platforms, it is highly recommended that applications
6661  ** neither read nor write this variable.  This global variable is a relic
6662  ** that exists for backwards compatibility of legacy applications and should
6663  ** be avoided in new projects.
6664  **
6665  ** It is not safe to read or modify this variable in more than one
6666  ** thread at a time.  It is not safe to read or modify this variable
6667  ** if a [database connection] is being used at the same time in a separate
6668  ** thread.
6669  ** It is intended that this variable be set once
6670  ** as part of process initialization and before any SQLite interface
6671  ** routines have been called and that this variable remain unchanged
6672  ** thereafter.
6673  **
6674  ** ^The [temp_store_directory pragma] may modify this variable and cause
6675  ** it to point to memory obtained from [sqlite3_malloc].  ^Furthermore,
6676  ** the [temp_store_directory pragma] always assumes that any string
6677  ** that this variable points to is held in memory obtained from
6678  ** [sqlite3_malloc] and the pragma may attempt to free that memory
6679  ** using [sqlite3_free].
6680  ** Hence, if this variable is modified directly, either it should be
6681  ** made NULL or made to point to memory obtained from [sqlite3_malloc]
6682  ** or else the use of the [temp_store_directory pragma] should be avoided.
6683  ** Except when requested by the [temp_store_directory pragma], SQLite
6684  ** does not free the memory that sqlite3_temp_directory points to.  If
6685  ** the application wants that memory to be freed, it must do
6686  ** so itself, taking care to only do so after all [database connection]
6687  ** objects have been destroyed.
6688  **
6689  ** <b>Note to Windows Runtime users:</b>  The temporary directory must be set
6690  ** prior to calling [sqlite3_open] or [sqlite3_open_v2].  Otherwise, various
6691  ** features that require the use of temporary files may fail.  Here is an
6692  ** example of how to do this using C++ with the Windows Runtime:
6693  **
6694  ** <blockquote><pre>
6695  ** LPCWSTR zPath = Windows::Storage::ApplicationData::Current->
6696  ** &nbsp;     TemporaryFolder->Path->Data();
6697  ** char zPathBuf&#91;MAX_PATH + 1&#93;;
6698  ** memset(zPathBuf, 0, sizeof(zPathBuf));
6699  ** WideCharToMultiByte(CP_UTF8, 0, zPath, -1, zPathBuf, sizeof(zPathBuf),
6700  ** &nbsp;     NULL, NULL);
6701  ** sqlite3_temp_directory = sqlite3_mprintf("%s", zPathBuf);
6702  ** </pre></blockquote>
6703  */
6704  SQLITE_API SQLITE_EXTERN char *sqlite3_temp_directory;
6705  
6706  /*
6707  ** CAPI3REF: Name Of The Folder Holding Database Files
6708  **
6709  ** ^(If this global variable is made to point to a string which is
6710  ** the name of a folder (a.k.a. directory), then all database files
6711  ** specified with a relative pathname and created or accessed by
6712  ** SQLite when using a built-in windows [sqlite3_vfs | VFS] will be assumed
6713  ** to be relative to that directory.)^ ^If this variable is a NULL
6714  ** pointer, then SQLite assumes that all database files specified
6715  ** with a relative pathname are relative to the current directory
6716  ** for the process.  Only the windows VFS makes use of this global
6717  ** variable; it is ignored by the unix VFS.
6718  **
6719  ** Changing the value of this variable while a database connection is
6720  ** open can result in a corrupt database.
6721  **
6722  ** It is not safe to read or modify this variable in more than one
6723  ** thread at a time.  It is not safe to read or modify this variable
6724  ** if a [database connection] is being used at the same time in a separate
6725  ** thread.
6726  ** It is intended that this variable be set once
6727  ** as part of process initialization and before any SQLite interface
6728  ** routines have been called and that this variable remain unchanged
6729  ** thereafter.
6730  **
6731  ** ^The [data_store_directory pragma] may modify this variable and cause
6732  ** it to point to memory obtained from [sqlite3_malloc].  ^Furthermore,
6733  ** the [data_store_directory pragma] always assumes that any string
6734  ** that this variable points to is held in memory obtained from
6735  ** [sqlite3_malloc] and the pragma may attempt to free that memory
6736  ** using [sqlite3_free].
6737  ** Hence, if this variable is modified directly, either it should be
6738  ** made NULL or made to point to memory obtained from [sqlite3_malloc]
6739  ** or else the use of the [data_store_directory pragma] should be avoided.
6740  */
6741  SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory;
6742  
6743  /*
6744  ** CAPI3REF: Win32 Specific Interface
6745  **
6746  ** These interfaces are available only on Windows.  The
6747  ** [sqlite3_win32_set_directory] interface is used to set the value associated
6748  ** with the [sqlite3_temp_directory] or [sqlite3_data_directory] variable, to
6749  ** zValue, depending on the value of the type parameter.  The zValue parameter
6750  ** should be NULL to cause the previous value to be freed via [sqlite3_free];
6751  ** a non-NULL value will be copied into memory obtained from [sqlite3_malloc]
6752  ** prior to being used.  The [sqlite3_win32_set_directory] interface returns
6753  ** [SQLITE_OK] to indicate success, [SQLITE_ERROR] if the type is unsupported,
6754  ** or [SQLITE_NOMEM] if memory could not be allocated.  The value of the
6755  ** [sqlite3_data_directory] variable is intended to act as a replacement for
6756  ** the current directory on the sub-platforms of Win32 where that concept is
6757  ** not present, e.g. WinRT and UWP.  The [sqlite3_win32_set_directory8] and
6758  ** [sqlite3_win32_set_directory16] interfaces behave exactly the same as the
6759  ** sqlite3_win32_set_directory interface except the string parameter must be
6760  ** UTF-8 or UTF-16, respectively.
6761  */
6762  SQLITE_API int sqlite3_win32_set_directory(
6763    unsigned long type, /* Identifier for directory being set or reset */
6764    void *zValue        /* New value for directory being set or reset */
6765  );
6766  SQLITE_API int sqlite3_win32_set_directory8(unsigned long type, const char *zValue);
6767  SQLITE_API int sqlite3_win32_set_directory16(unsigned long type, const void *zValue);
6768  
6769  /*
6770  ** CAPI3REF: Win32 Directory Types
6771  **
6772  ** These macros are only available on Windows.  They define the allowed values
6773  ** for the type argument to the [sqlite3_win32_set_directory] interface.
6774  */
6775  #define SQLITE_WIN32_DATA_DIRECTORY_TYPE  1
6776  #define SQLITE_WIN32_TEMP_DIRECTORY_TYPE  2
6777  
6778  /*
6779  ** CAPI3REF: Test For Auto-Commit Mode
6780  ** KEYWORDS: {autocommit mode}
6781  ** METHOD: sqlite3
6782  **
6783  ** ^The sqlite3_get_autocommit() interface returns non-zero or
6784  ** zero if the given database connection is or is not in autocommit mode,
6785  ** respectively.  ^Autocommit mode is on by default.
6786  ** ^Autocommit mode is disabled by a [BEGIN] statement.
6787  ** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK].
6788  **
6789  ** If certain kinds of errors occur on a statement within a multi-statement
6790  ** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR],
6791  ** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the
6792  ** transaction might be rolled back automatically.  The only way to
6793  ** find out whether SQLite automatically rolled back the transaction after
6794  ** an error is to use this function.
6795  **
6796  ** If another thread changes the autocommit status of the database
6797  ** connection while this routine is running, then the return value
6798  ** is undefined.
6799  */
6800  SQLITE_API int sqlite3_get_autocommit(sqlite3*);
6801  
6802  /*
6803  ** CAPI3REF: Find The Database Handle Of A Prepared Statement
6804  ** METHOD: sqlite3_stmt
6805  **
6806  ** ^The sqlite3_db_handle interface returns the [database connection] handle
6807  ** to which a [prepared statement] belongs.  ^The [database connection]
6808  ** returned by sqlite3_db_handle is the same [database connection]
6809  ** that was the first argument
6810  ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
6811  ** create the statement in the first place.
6812  */
6813  SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
6814  
6815  /*
6816  ** CAPI3REF: Return The Schema Name For A Database Connection
6817  ** METHOD: sqlite3
6818  **
6819  ** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name
6820  ** for the N-th database on database connection D, or a NULL pointer if N is
6821  ** out of range.  An N value of 0 means the main database file.  An N of 1 is
6822  ** the "temp" schema.  Larger values of N correspond to various ATTACH-ed
6823  ** databases.
6824  **
6825  ** Space to hold the string that is returned by sqlite3_db_name() is managed
6826  ** by SQLite itself.  The string might be deallocated by any operation that
6827  ** changes the schema, including [ATTACH] or [DETACH] or calls to
6828  ** [sqlite3_serialize()] or [sqlite3_deserialize()], even operations that
6829  ** occur on a different thread.  Applications that need to
6830  ** remember the string long-term should make their own copy.  Applications that
6831  ** are accessing the same database connection simultaneously on multiple
6832  ** threads should mutex-protect calls to this API and should make their own
6833  ** private copy of the result prior to releasing the mutex.
6834  */
6835  SQLITE_API const char *sqlite3_db_name(sqlite3 *db, int N);
6836  
6837  /*
6838  ** CAPI3REF: Return The Filename For A Database Connection
6839  ** METHOD: sqlite3
6840  **
6841  ** ^The sqlite3_db_filename(D,N) interface returns a pointer to the filename
6842  ** associated with database N of connection D.
6843  ** ^If there is no attached database N on the database
6844  ** connection D, or if database N is a temporary or in-memory database, then
6845  ** this function will return either a NULL pointer or an empty string.
6846  **
6847  ** ^The string value returned by this routine is owned and managed by
6848  ** the database connection.  ^The value will be valid until the database N
6849  ** is [DETACH]-ed or until the database connection closes.
6850  **
6851  ** ^The filename returned by this function is the output of the
6852  ** xFullPathname method of the [VFS].  ^In other words, the filename
6853  ** will be an absolute pathname, even if the filename used
6854  ** to open the database originally was a URI or relative pathname.
6855  **
6856  ** If the filename pointer returned by this routine is not NULL, then it
6857  ** can be used as the filename input parameter to these routines:
6858  ** <ul>
6859  ** <li> [sqlite3_uri_parameter()]
6860  ** <li> [sqlite3_uri_boolean()]
6861  ** <li> [sqlite3_uri_int64()]
6862  ** <li> [sqlite3_filename_database()]
6863  ** <li> [sqlite3_filename_journal()]
6864  ** <li> [sqlite3_filename_wal()]
6865  ** </ul>
6866  */
6867  SQLITE_API sqlite3_filename sqlite3_db_filename(sqlite3 *db, const char *zDbName);
6868  
6869  /*
6870  ** CAPI3REF: Determine if a database is read-only
6871  ** METHOD: sqlite3
6872  **
6873  ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N
6874  ** of connection D is read-only, 0 if it is read/write, or -1 if N is not
6875  ** the name of a database on connection D.
6876  */
6877  SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
6878  
6879  /*
6880  ** CAPI3REF: Determine the transaction state of a database
6881  ** METHOD: sqlite3
6882  **
6883  ** ^The sqlite3_txn_state(D,S) interface returns the current
6884  ** [transaction state] of schema S in database connection D.  ^If S is NULL,
6885  ** then the highest transaction state of any schema on database connection D
6886  ** is returned.  Transaction states are (in order of lowest to highest):
6887  ** <ol>
6888  ** <li value="0"> SQLITE_TXN_NONE
6889  ** <li value="1"> SQLITE_TXN_READ
6890  ** <li value="2"> SQLITE_TXN_WRITE
6891  ** </ol>
6892  ** ^If the S argument to sqlite3_txn_state(D,S) is not the name of
6893  ** a valid schema, then -1 is returned.
6894  */
6895  SQLITE_API int sqlite3_txn_state(sqlite3*,const char *zSchema);
6896  
6897  /*
6898  ** CAPI3REF: Allowed return values from sqlite3_txn_state()
6899  ** KEYWORDS: {transaction state}
6900  **
6901  ** These constants define the current transaction state of a database file.
6902  ** ^The [sqlite3_txn_state(D,S)] interface returns one of these
6903  ** constants in order to describe the transaction state of schema S
6904  ** in [database connection] D.
6905  **
6906  ** <dl>
6907  ** [[SQLITE_TXN_NONE]] <dt>SQLITE_TXN_NONE</dt>
6908  ** <dd>The SQLITE_TXN_NONE state means that no transaction is currently
6909  ** pending.</dd>
6910  **
6911  ** [[SQLITE_TXN_READ]] <dt>SQLITE_TXN_READ</dt>
6912  ** <dd>The SQLITE_TXN_READ state means that the database is currently
6913  ** in a read transaction.  Content has been read from the database file
6914  ** but nothing in the database file has changed.  The transaction state
6915  ** will be advanced to SQLITE_TXN_WRITE if any changes occur and there are
6916  ** no other conflicting concurrent write transactions.  The transaction
6917  ** state will revert to SQLITE_TXN_NONE following a [ROLLBACK] or
6918  ** [COMMIT].</dd>
6919  **
6920  ** [[SQLITE_TXN_WRITE]] <dt>SQLITE_TXN_WRITE</dt>
6921  ** <dd>The SQLITE_TXN_WRITE state means that the database is currently
6922  ** in a write transaction.  Content has been written to the database file
6923  ** but has not yet committed.  The transaction state will change to
6924  ** SQLITE_TXN_NONE at the next [ROLLBACK] or [COMMIT].</dd>
6925  */
6926  #define SQLITE_TXN_NONE  0
6927  #define SQLITE_TXN_READ  1
6928  #define SQLITE_TXN_WRITE 2
6929  
6930  /*
6931  ** CAPI3REF: Find the next prepared statement
6932  ** METHOD: sqlite3
6933  **
6934  ** ^This interface returns a pointer to the next [prepared statement] after
6935  ** pStmt associated with the [database connection] pDb.  ^If pStmt is NULL
6936  ** then this interface returns a pointer to the first prepared statement
6937  ** associated with the database connection pDb.  ^If no prepared statement
6938  ** satisfies the conditions of this routine, it returns NULL.
6939  **
6940  ** The [database connection] pointer D in a call to
6941  ** [sqlite3_next_stmt(D,S)] must refer to an open database
6942  ** connection and in particular must not be a NULL pointer.
6943  */
6944  SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);
6945  
6946  /*
6947  ** CAPI3REF: Commit And Rollback Notification Callbacks
6948  ** METHOD: sqlite3
6949  **
6950  ** ^The sqlite3_commit_hook() interface registers a callback
6951  ** function to be invoked whenever a transaction is [COMMIT | committed].
6952  ** ^Any callback set by a previous call to sqlite3_commit_hook()
6953  ** for the same database connection is overridden.
6954  ** ^The sqlite3_rollback_hook() interface registers a callback
6955  ** function to be invoked whenever a transaction is [ROLLBACK | rolled back].
6956  ** ^Any callback set by a previous call to sqlite3_rollback_hook()
6957  ** for the same database connection is overridden.
6958  ** ^The pArg argument is passed through to the callback.
6959  ** ^If the callback on a commit hook function returns non-zero,
6960  ** then the commit is converted into a rollback.
6961  **
6962  ** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions
6963  ** return the P argument from the previous call of the same function
6964  ** on the same [database connection] D, or NULL for
6965  ** the first call for each function on D.
6966  **
6967  ** The commit and rollback hook callbacks are not reentrant.
6968  ** The callback implementation must not do anything that will modify
6969  ** the database connection that invoked the callback.  Any actions
6970  ** to modify the database connection must be deferred until after the
6971  ** completion of the [sqlite3_step()] call that triggered the commit
6972  ** or rollback hook in the first place.
6973  ** Note that running any other SQL statements, including SELECT statements,
6974  ** or merely calling [sqlite3_prepare_v2()] and [sqlite3_step()] will modify
6975  ** the database connections for the meaning of "modify" in this paragraph.
6976  **
6977  ** ^Registering a NULL function disables the callback.
6978  **
6979  ** ^When the commit hook callback routine returns zero, the [COMMIT]
6980  ** operation is allowed to continue normally.  ^If the commit hook
6981  ** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK].
6982  ** ^The rollback hook is invoked on a rollback that results from a commit
6983  ** hook returning non-zero, just as it would be with any other rollback.
6984  **
6985  ** ^For the purposes of this API, a transaction is said to have been
6986  ** rolled back if an explicit "ROLLBACK" statement is executed, or
6987  ** an error or constraint causes an implicit rollback to occur.
6988  ** ^The rollback callback is not invoked if a transaction is
6989  ** automatically rolled back because the database connection is closed.
6990  **
6991  ** See also the [sqlite3_update_hook()] interface.
6992  */
6993  SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);
6994  SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);
6995  
6996  /*
6997  ** CAPI3REF: Autovacuum Compaction Amount Callback
6998  ** METHOD: sqlite3
6999  **
7000  ** ^The sqlite3_autovacuum_pages(D,C,P,X) interface registers a callback
7001  ** function C that is invoked prior to each autovacuum of the database
7002  ** file.  ^The callback is passed a copy of the generic data pointer (P),
7003  ** the schema-name of the attached database that is being autovacuumed,
7004  ** the size of the database file in pages, the number of free pages,
7005  ** and the number of bytes per page, respectively.  The callback should
7006  ** return the number of free pages that should be removed by the
7007  ** autovacuum.  ^If the callback returns zero, then no autovacuum happens.
7008  ** ^If the value returned is greater than or equal to the number of
7009  ** free pages, then a complete autovacuum happens.
7010  **
7011  ** <p>^If there are multiple ATTACH-ed database files that are being
7012  ** modified as part of a transaction commit, then the autovacuum pages
7013  ** callback is invoked separately for each file.
7014  **
7015  ** <p><b>The callback is not reentrant.</b> The callback function should
7016  ** not attempt to invoke any other SQLite interface.  If it does, bad
7017  ** things may happen, including segmentation faults and corrupt database
7018  ** files.  The callback function should be a simple function that
7019  ** does some arithmetic on its input parameters and returns a result.
7020  **
7021  ** ^The X parameter to sqlite3_autovacuum_pages(D,C,P,X) is an optional
7022  ** destructor for the P parameter.  ^If X is not NULL, then X(P) is
7023  ** invoked whenever the database connection closes or when the callback
7024  ** is overwritten by another invocation of sqlite3_autovacuum_pages().
7025  **
7026  ** <p>^There is only one autovacuum pages callback per database connection.
7027  ** ^Each call to the sqlite3_autovacuum_pages() interface overrides all
7028  ** previous invocations for that database connection.  ^If the callback
7029  ** argument (C) to sqlite3_autovacuum_pages(D,C,P,X) is a NULL pointer,
7030  ** then the autovacuum steps callback is canceled.  The return value
7031  ** from sqlite3_autovacuum_pages() is normally SQLITE_OK, but might
7032  ** be some other error code if something goes wrong.  The current
7033  ** implementation will only return SQLITE_OK or SQLITE_MISUSE, but other
7034  ** return codes might be added in future releases.
7035  **
7036  ** <p>If no autovacuum pages callback is specified (the usual case) or
7037  ** a NULL pointer is provided for the callback,
7038  ** then the default behavior is to vacuum all free pages.  So, in other
7039  ** words, the default behavior is the same as if the callback function
7040  ** were something like this:
7041  **
7042  ** <blockquote><pre>
7043  ** &nbsp;   unsigned int demonstration_autovac_pages_callback(
7044  ** &nbsp;     void *pClientData,
7045  ** &nbsp;     const char *zSchema,
7046  ** &nbsp;     unsigned int nDbPage,
7047  ** &nbsp;     unsigned int nFreePage,
7048  ** &nbsp;     unsigned int nBytePerPage
7049  ** &nbsp;   ){
7050  ** &nbsp;     return nFreePage;
7051  ** &nbsp;   }
7052  ** </pre></blockquote>
7053  */
7054  SQLITE_API int sqlite3_autovacuum_pages(
7055    sqlite3 *db,
7056    unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int),
7057    void*,
7058    void(*)(void*)
7059  );
7060  
7061  
7062  /*
7063  ** CAPI3REF: Data Change Notification Callbacks
7064  ** METHOD: sqlite3
7065  **
7066  ** ^The sqlite3_update_hook() interface registers a callback function
7067  ** with the [database connection] identified by the first argument
7068  ** to be invoked whenever a row is updated, inserted or deleted in
7069  ** a [rowid table].
7070  ** ^Any callback set by a previous call to this function
7071  ** for the same database connection is overridden.
7072  **
7073  ** ^The second argument is a pointer to the function to invoke when a
7074  ** row is updated, inserted or deleted in a rowid table.
7075  ** ^The update hook is disabled by invoking sqlite3_update_hook()
7076  ** with a NULL pointer as the second parameter.
7077  ** ^The first argument to the callback is a copy of the third argument
7078  ** to sqlite3_update_hook().
7079  ** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],
7080  ** or [SQLITE_UPDATE], depending on the operation that caused the callback
7081  ** to be invoked.
7082  ** ^The third and fourth arguments to the callback contain pointers to the
7083  ** database and table name containing the affected row.
7084  ** ^The final callback parameter is the [rowid] of the row.
7085  ** ^In the case of an update, this is the [rowid] after the update takes place.
7086  **
7087  ** ^(The update hook is not invoked when internal system tables are
7088  ** modified (i.e. sqlite_sequence).)^
7089  ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
7090  **
7091  ** ^In the current implementation, the update hook
7092  ** is not invoked when conflicting rows are deleted because of an
7093  ** [ON CONFLICT | ON CONFLICT REPLACE] clause.  ^Nor is the update hook
7094  ** invoked when rows are deleted using the [truncate optimization].
7095  ** The exceptions defined in this paragraph might change in a future
7096  ** release of SQLite.
7097  **
7098  ** Whether the update hook is invoked before or after the
7099  ** corresponding change is currently unspecified and may differ
7100  ** depending on the type of change. Do not rely on the order of the
7101  ** hook call with regards to the final result of the operation which
7102  ** triggers the hook.
7103  **
7104  ** The update hook implementation must not do anything that will modify
7105  ** the database connection that invoked the update hook.  Any actions
7106  ** to modify the database connection must be deferred until after the
7107  ** completion of the [sqlite3_step()] call that triggered the update hook.
7108  ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
7109  ** database connections for the meaning of "modify" in this paragraph.
7110  **
7111  ** ^The sqlite3_update_hook(D,C,P) function
7112  ** returns the P argument from the previous call
7113  ** on the same [database connection] D, or NULL for
7114  ** the first call on D.
7115  **
7116  ** See also the [sqlite3_commit_hook()], [sqlite3_rollback_hook()],
7117  ** and [sqlite3_preupdate_hook()] interfaces.
7118  */
7119  SQLITE_API void *sqlite3_update_hook(
7120    sqlite3*,
7121    void(*)(void *,int ,char const *,char const *,sqlite3_int64),
7122    void*
7123  );
7124  
7125  /*
7126  ** CAPI3REF: Enable Or Disable Shared Pager Cache
7127  **
7128  ** ^(This routine enables or disables the sharing of the database cache
7129  ** and schema data structures between [database connection | connections]
7130  ** to the same database. Sharing is enabled if the argument is true
7131  ** and disabled if the argument is false.)^
7132  **
7133  ** This interface is omitted if SQLite is compiled with
7134  ** [-DSQLITE_OMIT_SHARED_CACHE].  The [-DSQLITE_OMIT_SHARED_CACHE]
7135  ** compile-time option is recommended because the
7136  ** [use of shared cache mode is discouraged].
7137  **
7138  ** ^Cache sharing is enabled and disabled for an entire process.
7139  ** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]).
7140  ** In prior versions of SQLite,
7141  ** sharing was enabled or disabled for each thread separately.
7142  **
7143  ** ^(The cache sharing mode set by this interface effects all subsequent
7144  ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].
7145  ** Existing database connections continue to use the sharing mode
7146  ** that was in effect at the time they were opened.)^
7147  **
7148  ** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled
7149  ** successfully.  An [error code] is returned otherwise.)^
7150  **
7151  ** ^Shared cache is disabled by default. It is recommended that it stay
7152  ** that way.  In other words, do not use this routine.  This interface
7153  ** continues to be provided for historical compatibility, but its use is
7154  ** discouraged.  Any use of shared cache is discouraged.  If shared cache
7155  ** must be used, it is recommended that shared cache only be enabled for
7156  ** individual database connections using the [sqlite3_open_v2()] interface
7157  ** with the [SQLITE_OPEN_SHAREDCACHE] flag.
7158  **
7159  ** Note: This method is disabled on MacOS X 10.7 and iOS version 5.0
7160  ** and will always return SQLITE_MISUSE. On those systems,
7161  ** shared cache mode should be enabled per-database connection via
7162  ** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE].
7163  **
7164  ** This interface is threadsafe on processors where writing a
7165  ** 32-bit integer is atomic.
7166  **
7167  ** See Also:  [SQLite Shared-Cache Mode]
7168  */
7169  SQLITE_API int sqlite3_enable_shared_cache(int);
7170  
7171  /*
7172  ** CAPI3REF: Attempt To Free Heap Memory
7173  **
7174  ** ^The sqlite3_release_memory() interface attempts to free N bytes
7175  ** of heap memory by deallocating non-essential memory allocations
7176  ** held by the database library.   Memory used to cache database
7177  ** pages to improve performance is an example of non-essential memory.
7178  ** ^sqlite3_release_memory() returns the number of bytes actually freed,
7179  ** which might be more or less than the amount requested.
7180  ** ^The sqlite3_release_memory() routine is a no-op returning zero
7181  ** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT].
7182  **
7183  ** See also: [sqlite3_db_release_memory()]
7184  */
7185  SQLITE_API int sqlite3_release_memory(int);
7186  
7187  /*
7188  ** CAPI3REF: Free Memory Used By A Database Connection
7189  ** METHOD: sqlite3
7190  **
7191  ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap
7192  ** memory as possible from database connection D. Unlike the
7193  ** [sqlite3_release_memory()] interface, this interface is in effect even
7194  ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
7195  ** omitted.
7196  **
7197  ** See also: [sqlite3_release_memory()]
7198  */
7199  SQLITE_API int sqlite3_db_release_memory(sqlite3*);
7200  
7201  /*
7202  ** CAPI3REF: Impose A Limit On Heap Size
7203  **
7204  ** These interfaces impose limits on the amount of heap memory that will be
7205  ** used by all database connections within a single process.
7206  **
7207  ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
7208  ** soft limit on the amount of heap memory that may be allocated by SQLite.
7209  ** ^SQLite strives to keep heap memory utilization below the soft heap
7210  ** limit by reducing the number of pages held in the page cache
7211  ** as heap memory usages approaches the limit.
7212  ** ^The soft heap limit is "soft" because even though SQLite strives to stay
7213  ** below the limit, it will exceed the limit rather than generate
7214  ** an [SQLITE_NOMEM] error.  In other words, the soft heap limit
7215  ** is advisory only.
7216  **
7217  ** ^The sqlite3_hard_heap_limit64(N) interface sets a hard upper bound of
7218  ** N bytes on the amount of memory that will be allocated.  ^The
7219  ** sqlite3_hard_heap_limit64(N) interface is similar to
7220  ** sqlite3_soft_heap_limit64(N) except that memory allocations will fail
7221  ** when the hard heap limit is reached.
7222  **
7223  ** ^The return value from both sqlite3_soft_heap_limit64() and
7224  ** sqlite3_hard_heap_limit64() is the size of
7225  ** the heap limit prior to the call, or negative in the case of an
7226  ** error.  ^If the argument N is negative
7227  ** then no change is made to the heap limit.  Hence, the current
7228  ** size of heap limits can be determined by invoking
7229  ** sqlite3_soft_heap_limit64(-1) or sqlite3_hard_heap_limit(-1).
7230  **
7231  ** ^Setting the heap limits to zero disables the heap limiter mechanism.
7232  **
7233  ** ^The soft heap limit may not be greater than the hard heap limit.
7234  ** ^If the hard heap limit is enabled and if sqlite3_soft_heap_limit(N)
7235  ** is invoked with a value of N that is greater than the hard heap limit,
7236  ** the soft heap limit is set to the value of the hard heap limit.
7237  ** ^The soft heap limit is automatically enabled whenever the hard heap
7238  ** limit is enabled. ^When sqlite3_hard_heap_limit64(N) is invoked and
7239  ** the soft heap limit is outside the range of 1..N, then the soft heap
7240  ** limit is set to N.  ^Invoking sqlite3_soft_heap_limit64(0) when the
7241  ** hard heap limit is enabled makes the soft heap limit equal to the
7242  ** hard heap limit.
7243  **
7244  ** The memory allocation limits can also be adjusted using
7245  ** [PRAGMA soft_heap_limit] and [PRAGMA hard_heap_limit].
7246  **
7247  ** ^(The heap limits are not enforced in the current implementation
7248  ** if one or more of following conditions are true:
7249  **
7250  ** <ul>
7251  ** <li> The limit value is set to zero.
7252  ** <li> Memory accounting is disabled using a combination of the
7253  **      [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and
7254  **      the [SQLITE_DEFAULT_MEMSTATUS] compile-time option.
7255  ** <li> An alternative page cache implementation is specified using
7256  **      [sqlite3_config]([SQLITE_CONFIG_PCACHE2],...).
7257  ** <li> The page cache allocates from its own memory pool supplied
7258  **      by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
7259  **      from the heap.
7260  ** </ul>)^
7261  **
7262  ** The circumstances under which SQLite will enforce the heap limits may
7263  ** change in future releases of SQLite.
7264  */
7265  SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);
7266  SQLITE_API sqlite3_int64 sqlite3_hard_heap_limit64(sqlite3_int64 N);
7267  
7268  /*
7269  ** CAPI3REF: Deprecated Soft Heap Limit Interface
7270  ** DEPRECATED
7271  **
7272  ** This is a deprecated version of the [sqlite3_soft_heap_limit64()]
7273  ** interface.  This routine is provided for historical compatibility
7274  ** only.  All new applications should use the
7275  ** [sqlite3_soft_heap_limit64()] interface rather than this one.
7276  */
7277  SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N);
7278  
7279  
7280  /*
7281  ** CAPI3REF: Extract Metadata About A Column Of A Table
7282  ** METHOD: sqlite3
7283  **
7284  ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
7285  ** information about column C of table T in database D
7286  ** on [database connection] X.)^  ^The sqlite3_table_column_metadata()
7287  ** interface returns SQLITE_OK and fills in the non-NULL pointers in
7288  ** the final five arguments with appropriate values if the specified
7289  ** column exists.  ^The sqlite3_table_column_metadata() interface returns
7290  ** SQLITE_ERROR if the specified column does not exist.
7291  ** ^If the column-name parameter to sqlite3_table_column_metadata() is a
7292  ** NULL pointer, then this routine simply checks for the existence of the
7293  ** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
7294  ** does not.  If the table name parameter T in a call to
7295  ** sqlite3_table_column_metadata(X,D,T,C,...) is NULL then the result is
7296  ** undefined behavior.
7297  **
7298  ** ^The column is identified by the second, third and fourth parameters to
7299  ** this function. ^(The second parameter is either the name of the database
7300  ** (i.e. "main", "temp", or an attached database) containing the specified
7301  ** table or NULL.)^ ^If it is NULL, then all attached databases are searched
7302  ** for the table using the same algorithm used by the database engine to
7303  ** resolve unqualified table references.
7304  **
7305  ** ^The third and fourth parameters to this function are the table and column
7306  ** name of the desired column, respectively.
7307  **
7308  ** ^Metadata is returned by writing to the memory locations passed as the 5th
7309  ** and subsequent parameters to this function. ^Any of these arguments may be
7310  ** NULL, in which case the corresponding element of metadata is omitted.
7311  **
7312  ** ^(<blockquote>
7313  ** <table border="1">
7314  ** <tr><th> Parameter <th> Output<br>Type <th>  Description
7315  **
7316  ** <tr><td> 5th <td> const char* <td> Data type
7317  ** <tr><td> 6th <td> const char* <td> Name of default collation sequence
7318  ** <tr><td> 7th <td> int         <td> True if column has a NOT NULL constraint
7319  ** <tr><td> 8th <td> int         <td> True if column is part of the PRIMARY KEY
7320  ** <tr><td> 9th <td> int         <td> True if column is [AUTOINCREMENT]
7321  ** </table>
7322  ** </blockquote>)^
7323  **
7324  ** ^The memory pointed to by the character pointers returned for the
7325  ** declaration type and collation sequence is valid until the next
7326  ** call to any SQLite API function.
7327  **
7328  ** ^If the specified table is actually a view, an [error code] is returned.
7329  **
7330  ** ^If the specified column is "rowid", "oid" or "_rowid_" and the table
7331  ** is not a [WITHOUT ROWID] table and an
7332  ** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
7333  ** parameters are set for the explicitly declared column. ^(If there is no
7334  ** [INTEGER PRIMARY KEY] column, then the outputs
7335  ** for the [rowid] are set as follows:
7336  **
7337  ** <pre>
7338  **     data type: "INTEGER"
7339  **     collation sequence: "BINARY"
7340  **     not null: 0
7341  **     primary key: 1
7342  **     auto increment: 0
7343  ** </pre>)^
7344  **
7345  ** ^This function causes all database schemas to be read from disk and
7346  ** parsed, if that has not already been done, and returns an error if
7347  ** any errors are encountered while loading the schema.
7348  */
7349  SQLITE_API int sqlite3_table_column_metadata(
7350    sqlite3 *db,                /* Connection handle */
7351    const char *zDbName,        /* Database name or NULL */
7352    const char *zTableName,     /* Table name */
7353    const char *zColumnName,    /* Column name */
7354    char const **pzDataType,    /* OUTPUT: Declared data type */
7355    char const **pzCollSeq,     /* OUTPUT: Collation sequence name */
7356    int *pNotNull,              /* OUTPUT: True if NOT NULL constraint exists */
7357    int *pPrimaryKey,           /* OUTPUT: True if column part of PK */
7358    int *pAutoinc               /* OUTPUT: True if column is auto-increment */
7359  );
7360  
7361  /*
7362  ** CAPI3REF: Load An Extension
7363  ** METHOD: sqlite3
7364  **
7365  ** ^This interface loads an SQLite extension library from the named file.
7366  **
7367  ** ^The sqlite3_load_extension() interface attempts to load an
7368  ** [SQLite extension] library contained in the file zFile.  If
7369  ** the file cannot be loaded directly, attempts are made to load
7370  ** with various operating-system specific extensions added.
7371  ** So for example, if "samplelib" cannot be loaded, then names like
7372  ** "samplelib.so" or "samplelib.dylib" or "samplelib.dll" might
7373  ** be tried also.
7374  **
7375  ** ^The entry point is zProc.
7376  ** ^(zProc may be 0, in which case SQLite will try to come up with an
7377  ** entry point name on its own.  It first tries "sqlite3_extension_init".
7378  ** If that does not work, it constructs a name "sqlite3_X_init" where
7379  ** X consists of the lower-case equivalent of all ASCII alphabetic
7380  ** characters in the filename from the last "/" to the first following
7381  ** "." and omitting any initial "lib".)^
7382  ** ^The sqlite3_load_extension() interface returns
7383  ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.
7384  ** ^If an error occurs and pzErrMsg is not 0, then the
7385  ** [sqlite3_load_extension()] interface shall attempt to
7386  ** fill *pzErrMsg with error message text stored in memory
7387  ** obtained from [sqlite3_malloc()]. The calling function
7388  ** should free this memory by calling [sqlite3_free()].
7389  **
7390  ** ^Extension loading must be enabled using
7391  ** [sqlite3_enable_load_extension()] or
7392  ** [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],1,NULL)
7393  ** prior to calling this API,
7394  ** otherwise an error will be returned.
7395  **
7396  ** <b>Security warning:</b> It is recommended that the
7397  ** [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method be used to enable only this
7398  ** interface.  The use of the [sqlite3_enable_load_extension()] interface
7399  ** should be avoided.  This will keep the SQL function [load_extension()]
7400  ** disabled and prevent SQL injections from giving attackers
7401  ** access to extension loading capabilities.
7402  **
7403  ** See also the [load_extension() SQL function].
7404  */
7405  SQLITE_API int sqlite3_load_extension(
7406    sqlite3 *db,          /* Load the extension into this database connection */
7407    const char *zFile,    /* Name of the shared library containing extension */
7408    const char *zProc,    /* Entry point.  Derived from zFile if 0 */
7409    char **pzErrMsg       /* Put error message here if not 0 */
7410  );
7411  
7412  /*
7413  ** CAPI3REF: Enable Or Disable Extension Loading
7414  ** METHOD: sqlite3
7415  **
7416  ** ^So as not to open security holes in older applications that are
7417  ** unprepared to deal with [extension loading], and as a means of disabling
7418  ** [extension loading] while evaluating user-entered SQL, the following API
7419  ** is provided to turn the [sqlite3_load_extension()] mechanism on and off.
7420  **
7421  ** ^Extension loading is off by default.
7422  ** ^Call the sqlite3_enable_load_extension() routine with onoff==1
7423  ** to turn extension loading on and call it with onoff==0 to turn
7424  ** it back off again.
7425  **
7426  ** ^This interface enables or disables both the C-API
7427  ** [sqlite3_load_extension()] and the SQL function [load_extension()].
7428  ** ^(Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
7429  ** to enable or disable only the C-API.)^
7430  **
7431  ** <b>Security warning:</b> It is recommended that extension loading
7432  ** be enabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
7433  ** rather than this interface, so the [load_extension()] SQL function
7434  ** remains disabled. This will prevent SQL injections from giving attackers
7435  ** access to extension loading capabilities.
7436  */
7437  SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);
7438  
7439  /*
7440  ** CAPI3REF: Automatically Load Statically Linked Extensions
7441  **
7442  ** ^This interface causes the xEntryPoint() function to be invoked for
7443  ** each new [database connection] that is created.  The idea here is that
7444  ** xEntryPoint() is the entry point for a statically linked [SQLite extension]
7445  ** that is to be automatically loaded into all new database connections.
7446  **
7447  ** ^(Even though the function prototype shows that xEntryPoint() takes
7448  ** no arguments and returns void, SQLite invokes xEntryPoint() with three
7449  ** arguments and expects an integer result as if the signature of the
7450  ** entry point were as follows:
7451  **
7452  ** <blockquote><pre>
7453  ** &nbsp;  int xEntryPoint(
7454  ** &nbsp;    sqlite3 *db,
7455  ** &nbsp;    const char **pzErrMsg,
7456  ** &nbsp;    const struct sqlite3_api_routines *pThunk
7457  ** &nbsp;  );
7458  ** </pre></blockquote>)^
7459  **
7460  ** If the xEntryPoint routine encounters an error, it should make *pzErrMsg
7461  ** point to an appropriate error message (obtained from [sqlite3_mprintf()])
7462  ** and return an appropriate [error code].  ^SQLite ensures that *pzErrMsg
7463  ** is NULL before calling the xEntryPoint().  ^SQLite will invoke
7464  ** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns.  ^If any
7465  ** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()],
7466  ** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail.
7467  **
7468  ** ^Calling sqlite3_auto_extension(X) with an entry point X that is already
7469  ** on the list of automatic extensions is a harmless no-op. ^No entry point
7470  ** will be called more than once for each database connection that is opened.
7471  **
7472  ** See also: [sqlite3_reset_auto_extension()]
7473  ** and [sqlite3_cancel_auto_extension()]
7474  */
7475  SQLITE_API int sqlite3_auto_extension(void(*xEntryPoint)(void));
7476  
7477  /*
7478  ** CAPI3REF: Cancel Automatic Extension Loading
7479  **
7480  ** ^The [sqlite3_cancel_auto_extension(X)] interface unregisters the
7481  ** initialization routine X that was registered using a prior call to
7482  ** [sqlite3_auto_extension(X)].  ^The [sqlite3_cancel_auto_extension(X)]
7483  ** routine returns 1 if initialization routine X was successfully
7484  ** unregistered and it returns 0 if X was not on the list of initialization
7485  ** routines.
7486  */
7487  SQLITE_API int sqlite3_cancel_auto_extension(void(*xEntryPoint)(void));
7488  
7489  /*
7490  ** CAPI3REF: Reset Automatic Extension Loading
7491  **
7492  ** ^This interface disables all automatic extensions previously
7493  ** registered using [sqlite3_auto_extension()].
7494  */
7495  SQLITE_API void sqlite3_reset_auto_extension(void);
7496  
7497  /*
7498  ** Structures used by the virtual table interface
7499  */
7500  typedef struct sqlite3_vtab sqlite3_vtab;
7501  typedef struct sqlite3_index_info sqlite3_index_info;
7502  typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor;
7503  typedef struct sqlite3_module sqlite3_module;
7504  
7505  /*
7506  ** CAPI3REF: Virtual Table Object
7507  ** KEYWORDS: sqlite3_module {virtual table module}
7508  **
7509  ** This structure, sometimes called a "virtual table module",
7510  ** defines the implementation of a [virtual table].
7511  ** This structure consists mostly of methods for the module.
7512  **
7513  ** ^A virtual table module is created by filling in a persistent
7514  ** instance of this structure and passing a pointer to that instance
7515  ** to [sqlite3_create_module()] or [sqlite3_create_module_v2()].
7516  ** ^The registration remains valid until it is replaced by a different
7517  ** module or until the [database connection] closes.  The content
7518  ** of this structure must not change while it is registered with
7519  ** any database connection.
7520  */
7521  struct sqlite3_module {
7522    int iVersion;
7523    int (*xCreate)(sqlite3*, void *pAux,
7524                 int argc, const char *const*argv,
7525                 sqlite3_vtab **ppVTab, char**);
7526    int (*xConnect)(sqlite3*, void *pAux,
7527                 int argc, const char *const*argv,
7528                 sqlite3_vtab **ppVTab, char**);
7529    int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
7530    int (*xDisconnect)(sqlite3_vtab *pVTab);
7531    int (*xDestroy)(sqlite3_vtab *pVTab);
7532    int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor);
7533    int (*xClose)(sqlite3_vtab_cursor*);
7534    int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr,
7535                  int argc, sqlite3_value **argv);
7536    int (*xNext)(sqlite3_vtab_cursor*);
7537    int (*xEof)(sqlite3_vtab_cursor*);
7538    int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int);
7539    int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid);
7540    int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *);
7541    int (*xBegin)(sqlite3_vtab *pVTab);
7542    int (*xSync)(sqlite3_vtab *pVTab);
7543    int (*xCommit)(sqlite3_vtab *pVTab);
7544    int (*xRollback)(sqlite3_vtab *pVTab);
7545    int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,
7546                         void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
7547                         void **ppArg);
7548    int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
7549    /* The methods above are in version 1 of the sqlite_module object. Those
7550    ** below are for version 2 and greater. */
7551    int (*xSavepoint)(sqlite3_vtab *pVTab, int);
7552    int (*xRelease)(sqlite3_vtab *pVTab, int);
7553    int (*xRollbackTo)(sqlite3_vtab *pVTab, int);
7554    /* The methods above are in versions 1 and 2 of the sqlite_module object.
7555    ** Those below are for version 3 and greater. */
7556    int (*xShadowName)(const char*);
7557    /* The methods above are in versions 1 through 3 of the sqlite_module object.
7558    ** Those below are for version 4 and greater. */
7559    int (*xIntegrity)(sqlite3_vtab *pVTab, const char *zSchema,
7560                      const char *zTabName, int mFlags, char **pzErr);
7561  };
7562  
7563  /*
7564  ** CAPI3REF: Virtual Table Indexing Information
7565  ** KEYWORDS: sqlite3_index_info
7566  **
7567  ** The sqlite3_index_info structure and its substructures is used as part
7568  ** of the [virtual table] interface to
7569  ** pass information into and receive the reply from the [xBestIndex]
7570  ** method of a [virtual table module].  The fields under **Inputs** are the
7571  ** inputs to xBestIndex and are read-only.  xBestIndex inserts its
7572  ** results into the **Outputs** fields.
7573  **
7574  ** ^(The aConstraint[] array records WHERE clause constraints of the form:
7575  **
7576  ** <blockquote>column OP expr</blockquote>
7577  **
7578  ** where OP is =, &lt;, &lt;=, &gt;, or &gt;=.)^  ^(The particular operator is
7579  ** stored in aConstraint[].op using one of the
7580  ** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^
7581  ** ^(The index of the column is stored in
7582  ** aConstraint[].iColumn.)^  ^(aConstraint[].usable is TRUE if the
7583  ** expr on the right-hand side can be evaluated (and thus the constraint
7584  ** is usable) and false if it cannot.)^
7585  **
7586  ** ^The optimizer automatically inverts terms of the form "expr OP column"
7587  ** and makes other simplifications to the WHERE clause in an attempt to
7588  ** get as many WHERE clause terms into the form shown above as possible.
7589  ** ^The aConstraint[] array only reports WHERE clause terms that are
7590  ** relevant to the particular virtual table being queried.
7591  **
7592  ** ^Information about the ORDER BY clause is stored in aOrderBy[].
7593  ** ^Each term of aOrderBy records a column of the ORDER BY clause.
7594  **
7595  ** The colUsed field indicates which columns of the virtual table may be
7596  ** required by the current scan. Virtual table columns are numbered from
7597  ** zero in the order in which they appear within the CREATE TABLE statement
7598  ** passed to sqlite3_declare_vtab(). For the first 63 columns (columns 0-62),
7599  ** the corresponding bit is set within the colUsed mask if the column may be
7600  ** required by SQLite. If the table has at least 64 columns and any column
7601  ** to the right of the first 63 is required, then bit 63 of colUsed is also
7602  ** set. In other words, column iCol may be required if the expression
7603  ** (colUsed & ((sqlite3_uint64)1 << (iCol>=63 ? 63 : iCol))) evaluates to
7604  ** non-zero.
7605  **
7606  ** The [xBestIndex] method must fill aConstraintUsage[] with information
7607  ** about what parameters to pass to xFilter.  ^If argvIndex>0 then
7608  ** the right-hand side of the corresponding aConstraint[] is evaluated
7609  ** and becomes the argvIndex-th entry in argv.  ^(If aConstraintUsage[].omit
7610  ** is true, then the constraint is assumed to be fully handled by the
7611  ** virtual table and might not be checked again by the byte code.)^ ^(The
7612  ** aConstraintUsage[].omit flag is an optimization hint. When the omit flag
7613  ** is left in its default setting of false, the constraint will always be
7614  ** checked separately in byte code.  If the omit flag is changed to true, then
7615  ** the constraint may or may not be checked in byte code.  In other words,
7616  ** when the omit flag is true there is no guarantee that the constraint will
7617  ** not be checked again using byte code.)^
7618  **
7619  ** ^The idxNum and idxStr values are recorded and passed into the
7620  ** [xFilter] method.
7621  ** ^[sqlite3_free()] is used to free idxStr if and only if
7622  ** needToFreeIdxStr is true.
7623  **
7624  ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
7625  ** the correct order to satisfy the ORDER BY clause so that no separate
7626  ** sorting step is required.
7627  **
7628  ** ^The estimatedCost value is an estimate of the cost of a particular
7629  ** strategy. A cost of N indicates that the cost of the strategy is similar
7630  ** to a linear scan of an SQLite table with N rows. A cost of log(N)
7631  ** indicates that the expense of the operation is similar to that of a
7632  ** binary search on a unique indexed field of an SQLite table with N rows.
7633  **
7634  ** ^The estimatedRows value is an estimate of the number of rows that
7635  ** will be returned by the strategy.
7636  **
7637  ** The xBestIndex method may optionally populate the idxFlags field with a
7638  ** mask of SQLITE_INDEX_SCAN_* flags. One such flag is
7639  ** [SQLITE_INDEX_SCAN_HEX], which if set causes the [EXPLAIN QUERY PLAN]
7640  ** output to show the idxNum as hex instead of as decimal.  Another flag is
7641  ** SQLITE_INDEX_SCAN_UNIQUE, which if set indicates that the query plan will
7642  ** return at most one row.
7643  **
7644  ** Additionally, if xBestIndex sets the SQLITE_INDEX_SCAN_UNIQUE flag, then
7645  ** SQLite also assumes that if a call to the xUpdate() method is made as
7646  ** part of the same statement to delete or update a virtual table row and the
7647  ** implementation returns SQLITE_CONSTRAINT, then there is no need to rollback
7648  ** any database changes. In other words, if the xUpdate() returns
7649  ** SQLITE_CONSTRAINT, the database contents must be exactly as they were
7650  ** before xUpdate was called. By contrast, if SQLITE_INDEX_SCAN_UNIQUE is not
7651  ** set and xUpdate returns SQLITE_CONSTRAINT, any database changes made by
7652  ** the xUpdate method are automatically rolled back by SQLite.
7653  **
7654  ** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
7655  ** structure for SQLite [version 3.8.2] ([dateof:3.8.2]).
7656  ** If a virtual table extension is
7657  ** used with an SQLite version earlier than 3.8.2, the results of attempting
7658  ** to read or write the estimatedRows field are undefined (but are likely
7659  ** to include crashing the application). The estimatedRows field should
7660  ** therefore only be used if [sqlite3_libversion_number()] returns a
7661  ** value greater than or equal to 3008002. Similarly, the idxFlags field
7662  ** was added for [version 3.9.0] ([dateof:3.9.0]).
7663  ** It may therefore only be used if
7664  ** sqlite3_libversion_number() returns a value greater than or equal to
7665  ** 3009000.
7666  */
7667  struct sqlite3_index_info {
7668    /* Inputs */
7669    int nConstraint;           /* Number of entries in aConstraint */
7670    struct sqlite3_index_constraint {
7671       int iColumn;              /* Column constrained.  -1 for ROWID */
7672       unsigned char op;         /* Constraint operator */
7673       unsigned char usable;     /* True if this constraint is usable */
7674       int iTermOffset;          /* Used internally - xBestIndex should ignore */
7675    } *aConstraint;            /* Table of WHERE clause constraints */
7676    int nOrderBy;              /* Number of terms in the ORDER BY clause */
7677    struct sqlite3_index_orderby {
7678       int iColumn;              /* Column number */
7679       unsigned char desc;       /* True for DESC.  False for ASC. */
7680    } *aOrderBy;               /* The ORDER BY clause */
7681    /* Outputs */
7682    struct sqlite3_index_constraint_usage {
7683      int argvIndex;           /* if >0, constraint is part of argv to xFilter */
7684      unsigned char omit;      /* Do not code a test for this constraint */
7685    } *aConstraintUsage;
7686    int idxNum;                /* Number used to identify the index */
7687    char *idxStr;              /* String, possibly obtained from sqlite3_malloc */
7688    int needToFreeIdxStr;      /* Free idxStr using sqlite3_free() if true */
7689    int orderByConsumed;       /* True if output is already ordered */
7690    double estimatedCost;           /* Estimated cost of using this index */
7691    /* Fields below are only available in SQLite 3.8.2 and later */
7692    sqlite3_int64 estimatedRows;    /* Estimated number of rows returned */
7693    /* Fields below are only available in SQLite 3.9.0 and later */
7694    int idxFlags;              /* Mask of SQLITE_INDEX_SCAN_* flags */
7695    /* Fields below are only available in SQLite 3.10.0 and later */
7696    sqlite3_uint64 colUsed;    /* Input: Mask of columns used by statement */
7697  };
7698  
7699  /*
7700  ** CAPI3REF: Virtual Table Scan Flags
7701  **
7702  ** Virtual table implementations are allowed to set the
7703  ** [sqlite3_index_info].idxFlags field to some combination of
7704  ** these bits.
7705  */
7706  #define SQLITE_INDEX_SCAN_UNIQUE 0x00000001 /* Scan visits at most 1 row */
7707  #define SQLITE_INDEX_SCAN_HEX    0x00000002 /* Display idxNum as hex */
7708                                              /* in EXPLAIN QUERY PLAN */
7709  
7710  /*
7711  ** CAPI3REF: Virtual Table Constraint Operator Codes
7712  **
7713  ** These macros define the allowed values for the
7714  ** [sqlite3_index_info].aConstraint[].op field.  Each value represents
7715  ** an operator that is part of a constraint term in the WHERE clause of
7716  ** a query that uses a [virtual table].
7717  **
7718  ** ^The left-hand operand of the operator is given by the corresponding
7719  ** aConstraint[].iColumn field.  ^An iColumn of -1 indicates the left-hand
7720  ** operand is the rowid.
7721  ** The SQLITE_INDEX_CONSTRAINT_LIMIT and SQLITE_INDEX_CONSTRAINT_OFFSET
7722  ** operators have no left-hand operand, and so for those operators the
7723  ** corresponding aConstraint[].iColumn is meaningless and should not be
7724  ** used.
7725  **
7726  ** All operator values from SQLITE_INDEX_CONSTRAINT_FUNCTION through
7727  ** value 255 are reserved to represent functions that are overloaded
7728  ** by the [xFindFunction|xFindFunction method] of the virtual table
7729  ** implementation.
7730  **
7731  ** The right-hand operands for each constraint might be accessible using
7732  ** the [sqlite3_vtab_rhs_value()] interface.  Usually the right-hand
7733  ** operand is only available if it appears as a single constant literal
7734  ** in the input SQL.  If the right-hand operand is another column or an
7735  ** expression (even a constant expression) or a parameter, then the
7736  ** sqlite3_vtab_rhs_value() probably will not be able to extract it.
7737  ** ^The SQLITE_INDEX_CONSTRAINT_ISNULL and
7738  ** SQLITE_INDEX_CONSTRAINT_ISNOTNULL operators have no right-hand operand
7739  ** and hence calls to sqlite3_vtab_rhs_value() for those operators will
7740  ** always return SQLITE_NOTFOUND.
7741  **
7742  ** The collating sequence to be used for comparison can be found using
7743  ** the [sqlite3_vtab_collation()] interface.  For most real-world virtual
7744  ** tables, the collating sequence of constraints does not matter (for example
7745  ** because the constraints are numeric) and so the sqlite3_vtab_collation()
7746  ** interface is not commonly needed.
7747  */
7748  #define SQLITE_INDEX_CONSTRAINT_EQ          2
7749  #define SQLITE_INDEX_CONSTRAINT_GT          4
7750  #define SQLITE_INDEX_CONSTRAINT_LE          8
7751  #define SQLITE_INDEX_CONSTRAINT_LT         16
7752  #define SQLITE_INDEX_CONSTRAINT_GE         32
7753  #define SQLITE_INDEX_CONSTRAINT_MATCH      64
7754  #define SQLITE_INDEX_CONSTRAINT_LIKE       65
7755  #define SQLITE_INDEX_CONSTRAINT_GLOB       66
7756  #define SQLITE_INDEX_CONSTRAINT_REGEXP     67
7757  #define SQLITE_INDEX_CONSTRAINT_NE         68
7758  #define SQLITE_INDEX_CONSTRAINT_ISNOT      69
7759  #define SQLITE_INDEX_CONSTRAINT_ISNOTNULL  70
7760  #define SQLITE_INDEX_CONSTRAINT_ISNULL     71
7761  #define SQLITE_INDEX_CONSTRAINT_IS         72
7762  #define SQLITE_INDEX_CONSTRAINT_LIMIT      73
7763  #define SQLITE_INDEX_CONSTRAINT_OFFSET     74
7764  #define SQLITE_INDEX_CONSTRAINT_FUNCTION  150
7765  
7766  /*
7767  ** CAPI3REF: Register A Virtual Table Implementation
7768  ** METHOD: sqlite3
7769  **
7770  ** ^These routines are used to register a new [virtual table module] name.
7771  ** ^Module names must be registered before
7772  ** creating a new [virtual table] using the module and before using a
7773  ** preexisting [virtual table] for the module.
7774  **
7775  ** ^The module name is registered on the [database connection] specified
7776  ** by the first parameter.  ^The name of the module is given by the
7777  ** second parameter.  ^The third parameter is a pointer to
7778  ** the implementation of the [virtual table module].   ^The fourth
7779  ** parameter is an arbitrary client data pointer that is passed through
7780  ** into the [xCreate] and [xConnect] methods of the virtual table module
7781  ** when a new virtual table is being created or reinitialized.
7782  **
7783  ** ^The sqlite3_create_module_v2() interface has a fifth parameter which
7784  ** is a pointer to a destructor for the pClientData.  ^SQLite will
7785  ** invoke the destructor function (if it is not NULL) when SQLite
7786  ** no longer needs the pClientData pointer.  ^The destructor will also
7787  ** be invoked if the call to sqlite3_create_module_v2() fails.
7788  ** ^The sqlite3_create_module()
7789  ** interface is equivalent to sqlite3_create_module_v2() with a NULL
7790  ** destructor.
7791  **
7792  ** ^If the third parameter (the pointer to the sqlite3_module object) is
7793  ** NULL then no new module is created and any existing modules with the
7794  ** same name are dropped.
7795  **
7796  ** See also: [sqlite3_drop_modules()]
7797  */
7798  SQLITE_API int sqlite3_create_module(
7799    sqlite3 *db,               /* SQLite connection to register module with */
7800    const char *zName,         /* Name of the module */
7801    const sqlite3_module *p,   /* Methods for the module */
7802    void *pClientData          /* Client data for xCreate/xConnect */
7803  );
7804  SQLITE_API int sqlite3_create_module_v2(
7805    sqlite3 *db,               /* SQLite connection to register module with */
7806    const char *zName,         /* Name of the module */
7807    const sqlite3_module *p,   /* Methods for the module */
7808    void *pClientData,         /* Client data for xCreate/xConnect */
7809    void(*xDestroy)(void*)     /* Module destructor function */
7810  );
7811  
7812  /*
7813  ** CAPI3REF: Remove Unnecessary Virtual Table Implementations
7814  ** METHOD: sqlite3
7815  **
7816  ** ^The sqlite3_drop_modules(D,L) interface removes all virtual
7817  ** table modules from database connection D except those named on list L.
7818  ** The L parameter must be either NULL or a pointer to an array of pointers
7819  ** to strings where the array is terminated by a single NULL pointer.
7820  ** ^If the L parameter is NULL, then all virtual table modules are removed.
7821  **
7822  ** See also: [sqlite3_create_module()]
7823  */
7824  SQLITE_API int sqlite3_drop_modules(
7825    sqlite3 *db,                /* Remove modules from this connection */
7826    const char **azKeep         /* Except, do not remove the ones named here */
7827  );
7828  
7829  /*
7830  ** CAPI3REF: Virtual Table Instance Object
7831  ** KEYWORDS: sqlite3_vtab
7832  **
7833  ** Every [virtual table module] implementation uses a subclass
7834  ** of this object to describe a particular instance
7835  ** of the [virtual table].  Each subclass will
7836  ** be tailored to the specific needs of the module implementation.
7837  ** The purpose of this superclass is to define certain fields that are
7838  ** common to all module implementations.
7839  **
7840  ** ^Virtual tables methods can set an error message by assigning a
7841  ** string obtained from [sqlite3_mprintf()] to zErrMsg.  The method should
7842  ** take care that any prior string is freed by a call to [sqlite3_free()]
7843  ** prior to assigning a new string to zErrMsg.  ^After the error message
7844  ** is delivered up to the client application, the string will be automatically
7845  ** freed by sqlite3_free() and the zErrMsg field will be zeroed.
7846  */
7847  struct sqlite3_vtab {
7848    const sqlite3_module *pModule;  /* The module for this virtual table */
7849    int nRef;                       /* Number of open cursors */
7850    char *zErrMsg;                  /* Error message from sqlite3_mprintf() */
7851    /* Virtual table implementations will typically add additional fields */
7852  };
7853  
7854  /*
7855  ** CAPI3REF: Virtual Table Cursor Object
7856  ** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}
7857  **
7858  ** Every [virtual table module] implementation uses a subclass of the
7859  ** following structure to describe cursors that point into the
7860  ** [virtual table] and are used
7861  ** to loop through the virtual table.  Cursors are created using the
7862  ** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed
7863  ** by the [sqlite3_module.xClose | xClose] method.  Cursors are used
7864  ** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods
7865  ** of the module.  Each module implementation will define
7866  ** the content of a cursor structure to suit its own needs.
7867  **
7868  ** This superclass exists in order to define fields of the cursor that
7869  ** are common to all implementations.
7870  */
7871  struct sqlite3_vtab_cursor {
7872    sqlite3_vtab *pVtab;      /* Virtual table of this cursor */
7873    /* Virtual table implementations will typically add additional fields */
7874  };
7875  
7876  /*
7877  ** CAPI3REF: Declare The Schema Of A Virtual Table
7878  **
7879  ** ^The [xCreate] and [xConnect] methods of a
7880  ** [virtual table module] call this interface
7881  ** to declare the format (the names and datatypes of the columns) of
7882  ** the virtual tables they implement.
7883  */
7884  SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
7885  
7886  /*
7887  ** CAPI3REF: Overload A Function For A Virtual Table
7888  ** METHOD: sqlite3
7889  **
7890  ** ^(Virtual tables can provide alternative implementations of functions
7891  ** using the [xFindFunction] method of the [virtual table module].
7892  ** But global versions of those functions
7893  ** must exist in order to be overloaded.)^
7894  **
7895  ** ^(This API makes sure a global version of a function with a particular
7896  ** name and number of parameters exists.  If no such function exists
7897  ** before this API is called, a new function is created.)^  ^The implementation
7898  ** of the new function always causes an exception to be thrown.  So
7899  ** the new function is not good for anything by itself.  Its only
7900  ** purpose is to be a placeholder function that can be overloaded
7901  ** by a [virtual table].
7902  */
7903  SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
7904  
7905  /*
7906  ** CAPI3REF: A Handle To An Open BLOB
7907  ** KEYWORDS: {BLOB handle} {BLOB handles}
7908  **
7909  ** An instance of this object represents an open BLOB on which
7910  ** [sqlite3_blob_open | incremental BLOB I/O] can be performed.
7911  ** ^Objects of this type are created by [sqlite3_blob_open()]
7912  ** and destroyed by [sqlite3_blob_close()].
7913  ** ^The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces
7914  ** can be used to read or write small subsections of the BLOB.
7915  ** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes.
7916  */
7917  typedef struct sqlite3_blob sqlite3_blob;
7918  
7919  /*
7920  ** CAPI3REF: Open A BLOB For Incremental I/O
7921  ** METHOD: sqlite3
7922  ** CONSTRUCTOR: sqlite3_blob
7923  **
7924  ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located
7925  ** in row iRow, column zColumn, table zTable in database zDb;
7926  ** in other words, the same BLOB that would be selected by:
7927  **
7928  ** <pre>
7929  **     SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
7930  ** </pre>)^
7931  **
7932  ** ^(Parameter zDb is not the filename that contains the database, but
7933  ** rather the symbolic name of the database. For attached databases, this is
7934  ** the name that appears after the AS keyword in the [ATTACH] statement.
7935  ** For the main database file, the database name is "main". For TEMP
7936  ** tables, the database name is "temp".)^
7937  **
7938  ** ^If the flags parameter is non-zero, then the BLOB is opened for read
7939  ** and write access. ^If the flags parameter is zero, the BLOB is opened for
7940  ** read-only access.
7941  **
7942  ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
7943  ** in *ppBlob. Otherwise an [error code] is returned and, unless the error
7944  ** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
7945  ** the API is not misused, it is always safe to call [sqlite3_blob_close()]
7946  ** on *ppBlob after this function returns.
7947  **
7948  ** This function fails with SQLITE_ERROR if any of the following are true:
7949  ** <ul>
7950  **   <li> ^(Database zDb does not exist)^,
7951  **   <li> ^(Table zTable does not exist within database zDb)^,
7952  **   <li> ^(Table zTable is a WITHOUT ROWID table)^,
7953  **   <li> ^(Column zColumn does not exist)^,
7954  **   <li> ^(Row iRow is not present in the table)^,
7955  **   <li> ^(The specified column of row iRow contains a value that is not
7956  **         a TEXT or BLOB value)^,
7957  **   <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE
7958  **         constraint and the blob is being opened for read/write access)^,
7959  **   <li> ^([foreign key constraints | Foreign key constraints] are enabled,
7960  **         column zColumn is part of a [child key] definition and the blob is
7961  **         being opened for read/write access)^.
7962  ** </ul>
7963  **
7964  ** ^Unless it returns SQLITE_MISUSE, this function sets the
7965  ** [database connection] error code and message accessible via
7966  ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
7967  **
7968  ** A BLOB referenced by sqlite3_blob_open() may be read using the
7969  ** [sqlite3_blob_read()] interface and modified by using
7970  ** [sqlite3_blob_write()].  The [BLOB handle] can be moved to a
7971  ** different row of the same table using the [sqlite3_blob_reopen()]
7972  ** interface.  However, the column, table, or database of a [BLOB handle]
7973  ** cannot be changed after the [BLOB handle] is opened.
7974  **
7975  ** ^(If the row that a BLOB handle points to is modified by an
7976  ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
7977  ** then the BLOB handle is marked as "expired".
7978  ** This is true if any column of the row is changed, even a column
7979  ** other than the one the BLOB handle is open on.)^
7980  ** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for
7981  ** an expired BLOB handle fail with a return code of [SQLITE_ABORT].
7982  ** ^(Changes written into a BLOB prior to the BLOB expiring are not
7983  ** rolled back by the expiration of the BLOB.  Such changes will eventually
7984  ** commit if the transaction continues to completion.)^
7985  **
7986  ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
7987  ** the opened blob.  ^The size of a blob may not be changed by this
7988  ** interface.  Use the [UPDATE] SQL command to change the size of a
7989  ** blob.
7990  **
7991  ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
7992  ** and the built-in [zeroblob] SQL function may be used to create a
7993  ** zero-filled blob to read or write using the incremental-blob interface.
7994  **
7995  ** To avoid a resource leak, every open [BLOB handle] should eventually
7996  ** be released by a call to [sqlite3_blob_close()].
7997  **
7998  ** See also: [sqlite3_blob_close()],
7999  ** [sqlite3_blob_reopen()], [sqlite3_blob_read()],
8000  ** [sqlite3_blob_bytes()], [sqlite3_blob_write()].
8001  */
8002  SQLITE_API int sqlite3_blob_open(
8003    sqlite3*,
8004    const char *zDb,
8005    const char *zTable,
8006    const char *zColumn,
8007    sqlite3_int64 iRow,
8008    int flags,
8009    sqlite3_blob **ppBlob
8010  );
8011  
8012  /*
8013  ** CAPI3REF: Move a BLOB Handle to a New Row
8014  ** METHOD: sqlite3_blob
8015  **
8016  ** ^This function is used to move an existing [BLOB handle] so that it points
8017  ** to a different row of the same database table. ^The new row is identified
8018  ** by the rowid value passed as the second argument. Only the row can be
8019  ** changed. ^The database, table and column on which the blob handle is open
8020  ** remain the same. Moving an existing [BLOB handle] to a new row is
8021  ** faster than closing the existing handle and opening a new one.
8022  **
8023  ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] -
8024  ** it must exist and there must be either a blob or text value stored in
8025  ** the nominated column.)^ ^If the new row is not present in the table, or if
8026  ** it does not contain a blob or text value, or if another error occurs, an
8027  ** SQLite error code is returned and the blob handle is considered aborted.
8028  ** ^All subsequent calls to [sqlite3_blob_read()], [sqlite3_blob_write()] or
8029  ** [sqlite3_blob_reopen()] on an aborted blob handle immediately return
8030  ** SQLITE_ABORT. ^Calling [sqlite3_blob_bytes()] on an aborted blob handle
8031  ** always returns zero.
8032  **
8033  ** ^This function sets the database handle error code and message.
8034  */
8035  SQLITE_API int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
8036  
8037  /*
8038  ** CAPI3REF: Close A BLOB Handle
8039  ** DESTRUCTOR: sqlite3_blob
8040  **
8041  ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
8042  ** unconditionally.  Even if this routine returns an error code, the
8043  ** handle is still closed.)^
8044  **
8045  ** ^If the blob handle being closed was opened for read-write access, and if
8046  ** the database is in auto-commit mode and there are no other open read-write
8047  ** blob handles or active write statements, the current transaction is
8048  ** committed. ^If an error occurs while committing the transaction, an error
8049  ** code is returned and the transaction rolled back.
8050  **
8051  ** Calling this function with an argument that is not a NULL pointer or an
8052  ** open blob handle results in undefined behavior. ^Calling this routine
8053  ** with a null pointer (such as would be returned by a failed call to
8054  ** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function
8055  ** is passed a valid open blob handle, the values returned by the
8056  ** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
8057  */
8058  SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
8059  
8060  /*
8061  ** CAPI3REF: Return The Size Of An Open BLOB
8062  ** METHOD: sqlite3_blob
8063  **
8064  ** ^Returns the size in bytes of the BLOB accessible via the
8065  ** successfully opened [BLOB handle] in its only argument.  ^The
8066  ** incremental blob I/O routines can only read or overwrite existing
8067  ** blob content; they cannot change the size of a blob.
8068  **
8069  ** This routine only works on a [BLOB handle] which has been created
8070  ** by a prior successful call to [sqlite3_blob_open()] and which has not
8071  ** been closed by [sqlite3_blob_close()].  Passing any other pointer in
8072  ** to this routine results in undefined and probably undesirable behavior.
8073  */
8074  SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *);
8075  
8076  /*
8077  ** CAPI3REF: Read Data From A BLOB Incrementally
8078  ** METHOD: sqlite3_blob
8079  **
8080  ** ^(This function is used to read data from an open [BLOB handle] into a
8081  ** caller-supplied buffer. N bytes of data are copied into buffer Z
8082  ** from the open BLOB, starting at offset iOffset.)^
8083  **
8084  ** ^If offset iOffset is less than N bytes from the end of the BLOB,
8085  ** [SQLITE_ERROR] is returned and no data is read.  ^If N or iOffset is
8086  ** less than zero, [SQLITE_ERROR] is returned and no data is read.
8087  ** ^The size of the blob (and hence the maximum value of N+iOffset)
8088  ** can be determined using the [sqlite3_blob_bytes()] interface.
8089  **
8090  ** ^An attempt to read from an expired [BLOB handle] fails with an
8091  ** error code of [SQLITE_ABORT].
8092  **
8093  ** ^(On success, sqlite3_blob_read() returns SQLITE_OK.
8094  ** Otherwise, an [error code] or an [extended error code] is returned.)^
8095  **
8096  ** This routine only works on a [BLOB handle] which has been created
8097  ** by a prior successful call to [sqlite3_blob_open()] and which has not
8098  ** been closed by [sqlite3_blob_close()].  Passing any other pointer in
8099  ** to this routine results in undefined and probably undesirable behavior.
8100  **
8101  ** See also: [sqlite3_blob_write()].
8102  */
8103  SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
8104  
8105  /*
8106  ** CAPI3REF: Write Data Into A BLOB Incrementally
8107  ** METHOD: sqlite3_blob
8108  **
8109  ** ^(This function is used to write data into an open [BLOB handle] from a
8110  ** caller-supplied buffer. N bytes of data are copied from the buffer Z
8111  ** into the open BLOB, starting at offset iOffset.)^
8112  **
8113  ** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
8114  ** Otherwise, an  [error code] or an [extended error code] is returned.)^
8115  ** ^Unless SQLITE_MISUSE is returned, this function sets the
8116  ** [database connection] error code and message accessible via
8117  ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
8118  **
8119  ** ^If the [BLOB handle] passed as the first argument was not opened for
8120  ** writing (the flags parameter to [sqlite3_blob_open()] was zero),
8121  ** this function returns [SQLITE_READONLY].
8122  **
8123  ** This function may only modify the contents of the BLOB; it is
8124  ** not possible to increase the size of a BLOB using this API.
8125  ** ^If offset iOffset is less than N bytes from the end of the BLOB,
8126  ** [SQLITE_ERROR] is returned and no data is written. The size of the
8127  ** BLOB (and hence the maximum value of N+iOffset) can be determined
8128  ** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less
8129  ** than zero [SQLITE_ERROR] is returned and no data is written.
8130  **
8131  ** ^An attempt to write to an expired [BLOB handle] fails with an
8132  ** error code of [SQLITE_ABORT].  ^Writes to the BLOB that occurred
8133  ** before the [BLOB handle] expired are not rolled back by the
8134  ** expiration of the handle, though of course those changes might
8135  ** have been overwritten by the statement that expired the BLOB handle
8136  ** or by other independent statements.
8137  **
8138  ** This routine only works on a [BLOB handle] which has been created
8139  ** by a prior successful call to [sqlite3_blob_open()] and which has not
8140  ** been closed by [sqlite3_blob_close()].  Passing any other pointer in
8141  ** to this routine results in undefined and probably undesirable behavior.
8142  **
8143  ** See also: [sqlite3_blob_read()].
8144  */
8145  SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);
8146  
8147  /*
8148  ** CAPI3REF: Virtual File System Objects
8149  **
8150  ** A virtual filesystem (VFS) is an [sqlite3_vfs] object
8151  ** that SQLite uses to interact
8152  ** with the underlying operating system.  Most SQLite builds come with a
8153  ** single default VFS that is appropriate for the host computer.
8154  ** New VFSes can be registered and existing VFSes can be unregistered.
8155  ** The following interfaces are provided.
8156  **
8157  ** ^The sqlite3_vfs_find() interface returns a pointer to a VFS given its name.
8158  ** ^Names are case sensitive.
8159  ** ^Names are zero-terminated UTF-8 strings.
8160  ** ^If there is no match, a NULL pointer is returned.
8161  ** ^If zVfsName is NULL then the default VFS is returned.
8162  **
8163  ** ^New VFSes are registered with sqlite3_vfs_register().
8164  ** ^Each new VFS becomes the default VFS if the makeDflt flag is set.
8165  ** ^The same VFS can be registered multiple times without injury.
8166  ** ^To make an existing VFS into the default VFS, register it again
8167  ** with the makeDflt flag set.  If two different VFSes with the
8168  ** same name are registered, the behavior is undefined.  If a
8169  ** VFS is registered with a name that is NULL or an empty string,
8170  ** then the behavior is undefined.
8171  **
8172  ** ^Unregister a VFS with the sqlite3_vfs_unregister() interface.
8173  ** ^(If the default VFS is unregistered, another VFS is chosen as
8174  ** the default.  The choice for the new VFS is arbitrary.)^
8175  */
8176  SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName);
8177  SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);
8178  SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*);
8179  
8180  /*
8181  ** CAPI3REF: Mutexes
8182  **
8183  ** The SQLite core uses these routines for thread
8184  ** synchronization. Though they are intended for internal
8185  ** use by SQLite, code that links against SQLite is
8186  ** permitted to use any of these routines.
8187  **
8188  ** The SQLite source code contains multiple implementations
8189  ** of these mutex routines.  An appropriate implementation
8190  ** is selected automatically at compile-time.  The following
8191  ** implementations are available in the SQLite core:
8192  **
8193  ** <ul>
8194  ** <li>   SQLITE_MUTEX_PTHREADS
8195  ** <li>   SQLITE_MUTEX_W32
8196  ** <li>   SQLITE_MUTEX_NOOP
8197  ** </ul>
8198  **
8199  ** The SQLITE_MUTEX_NOOP implementation is a set of routines
8200  ** that does no real locking and is appropriate for use in
8201  ** a single-threaded application.  The SQLITE_MUTEX_PTHREADS and
8202  ** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix
8203  ** and Windows.
8204  **
8205  ** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
8206  ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
8207  ** implementation is included with the library. In this case the
8208  ** application must supply a custom mutex implementation using the
8209  ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
8210  ** before calling sqlite3_initialize() or any other public sqlite3_
8211  ** function that calls sqlite3_initialize().
8212  **
8213  ** ^The sqlite3_mutex_alloc() routine allocates a new
8214  ** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()
8215  ** routine returns NULL if it is unable to allocate the requested
8216  ** mutex.  The argument to sqlite3_mutex_alloc() must be one of these
8217  ** integer constants:
8218  **
8219  ** <ul>
8220  ** <li>  SQLITE_MUTEX_FAST
8221  ** <li>  SQLITE_MUTEX_RECURSIVE
8222  ** <li>  SQLITE_MUTEX_STATIC_MAIN
8223  ** <li>  SQLITE_MUTEX_STATIC_MEM
8224  ** <li>  SQLITE_MUTEX_STATIC_OPEN
8225  ** <li>  SQLITE_MUTEX_STATIC_PRNG
8226  ** <li>  SQLITE_MUTEX_STATIC_LRU
8227  ** <li>  SQLITE_MUTEX_STATIC_PMEM
8228  ** <li>  SQLITE_MUTEX_STATIC_APP1
8229  ** <li>  SQLITE_MUTEX_STATIC_APP2
8230  ** <li>  SQLITE_MUTEX_STATIC_APP3
8231  ** <li>  SQLITE_MUTEX_STATIC_VFS1
8232  ** <li>  SQLITE_MUTEX_STATIC_VFS2
8233  ** <li>  SQLITE_MUTEX_STATIC_VFS3
8234  ** </ul>
8235  **
8236  ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
8237  ** cause sqlite3_mutex_alloc() to create
8238  ** a new mutex.  ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
8239  ** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
8240  ** The mutex implementation does not need to make a distinction
8241  ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
8242  ** not want to.  SQLite will only request a recursive mutex in
8243  ** cases where it really needs one.  If a faster non-recursive mutex
8244  ** implementation is available on the host platform, the mutex subsystem
8245  ** might return such a mutex in response to SQLITE_MUTEX_FAST.
8246  **
8247  ** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other
8248  ** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return
8249  ** a pointer to a static preexisting mutex.  ^Nine static mutexes are
8250  ** used by the current version of SQLite.  Future versions of SQLite
8251  ** may add additional static mutexes.  Static mutexes are for internal
8252  ** use by SQLite only.  Applications that use SQLite mutexes should
8253  ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
8254  ** SQLITE_MUTEX_RECURSIVE.
8255  **
8256  ** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
8257  ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
8258  ** returns a different mutex on every call.  ^For the static
8259  ** mutex types, the same mutex is returned on every call that has
8260  ** the same type number.
8261  **
8262  ** ^The sqlite3_mutex_free() routine deallocates a previously
8263  ** allocated dynamic mutex.  Attempting to deallocate a static
8264  ** mutex results in undefined behavior.
8265  **
8266  ** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
8267  ** to enter a mutex.  ^If another thread is already within the mutex,
8268  ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
8269  ** SQLITE_BUSY.  ^The sqlite3_mutex_try() interface returns [SQLITE_OK]
8270  ** upon successful entry.  ^(Mutexes created using
8271  ** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.
8272  ** In such cases, the
8273  ** mutex must be exited an equal number of times before another thread
8274  ** can enter.)^  If the same thread tries to enter any mutex other
8275  ** than an SQLITE_MUTEX_RECURSIVE more than once, the behavior is undefined.
8276  **
8277  ** ^(Some systems (for example, Windows 95) do not support the operation
8278  ** implemented by sqlite3_mutex_try().  On those systems, sqlite3_mutex_try()
8279  ** will always return SQLITE_BUSY. In most cases the SQLite core only uses
8280  ** sqlite3_mutex_try() as an optimization, so this is acceptable
8281  ** behavior. The exceptions are unix builds that set the
8282  ** SQLITE_ENABLE_SETLK_TIMEOUT build option. In that case a working
8283  ** sqlite3_mutex_try() is required.)^
8284  **
8285  ** ^The sqlite3_mutex_leave() routine exits a mutex that was
8286  ** previously entered by the same thread.   The behavior
8287  ** is undefined if the mutex is not currently entered by the
8288  ** calling thread or is not currently allocated.
8289  **
8290  ** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(),
8291  ** sqlite3_mutex_leave(), or sqlite3_mutex_free() is a NULL pointer,
8292  ** then any of the four routines behaves as a no-op.
8293  **
8294  ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()].
8295  */
8296  SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int);
8297  SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*);
8298  SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*);
8299  SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);
8300  SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);
8301  
8302  /*
8303  ** CAPI3REF: Mutex Methods Object
8304  **
8305  ** An instance of this structure defines the low-level routines
8306  ** used to allocate and use mutexes.
8307  **
8308  ** Usually, the default mutex implementations provided by SQLite are
8309  ** sufficient, however the application has the option of substituting a custom
8310  ** implementation for specialized deployments or systems for which SQLite
8311  ** does not provide a suitable implementation. In this case, the application
8312  ** creates and populates an instance of this structure to pass
8313  ** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option.
8314  ** Additionally, an instance of this structure can be used as an
8315  ** output variable when querying the system for the current mutex
8316  ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
8317  **
8318  ** ^The xMutexInit method defined by this structure is invoked as
8319  ** part of system initialization by the sqlite3_initialize() function.
8320  ** ^The xMutexInit routine is called by SQLite exactly once for each
8321  ** effective call to [sqlite3_initialize()].
8322  **
8323  ** ^The xMutexEnd method defined by this structure is invoked as
8324  ** part of system shutdown by the sqlite3_shutdown() function. The
8325  ** implementation of this method is expected to release all outstanding
8326  ** resources obtained by the mutex methods implementation, especially
8327  ** those obtained by the xMutexInit method.  ^The xMutexEnd()
8328  ** interface is invoked exactly once for each call to [sqlite3_shutdown()].
8329  **
8330  ** ^(The remaining seven methods defined by this structure (xMutexAlloc,
8331  ** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and
8332  ** xMutexNotheld) implement the following interfaces (respectively):
8333  **
8334  ** <ul>
8335  **   <li>  [sqlite3_mutex_alloc()] </li>
8336  **   <li>  [sqlite3_mutex_free()] </li>
8337  **   <li>  [sqlite3_mutex_enter()] </li>
8338  **   <li>  [sqlite3_mutex_try()] </li>
8339  **   <li>  [sqlite3_mutex_leave()] </li>
8340  **   <li>  [sqlite3_mutex_held()] </li>
8341  **   <li>  [sqlite3_mutex_notheld()] </li>
8342  ** </ul>)^
8343  **
8344  ** The only difference is that the public sqlite3_XXX functions enumerated
8345  ** above silently ignore any invocations that pass a NULL pointer instead
8346  ** of a valid mutex handle. The implementations of the methods defined
8347  ** by this structure are not required to handle this case. The results
8348  ** of passing a NULL pointer instead of a valid mutex handle are undefined
8349  ** (i.e. it is acceptable to provide an implementation that segfaults if
8350  ** it is passed a NULL pointer).
8351  **
8352  ** The xMutexInit() method must be threadsafe.  It must be harmless to
8353  ** invoke xMutexInit() multiple times within the same process and without
8354  ** intervening calls to xMutexEnd().  Second and subsequent calls to
8355  ** xMutexInit() must be no-ops.
8356  **
8357  ** xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()]
8358  ** and its associates).  Similarly, xMutexAlloc() must not use SQLite memory
8359  ** allocation for a static mutex.  ^However xMutexAlloc() may use SQLite
8360  ** memory allocation for a fast or recursive mutex.
8361  **
8362  ** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is
8363  ** called, but only if the prior call to xMutexInit returned SQLITE_OK.
8364  ** If xMutexInit fails in any way, it is expected to clean up after itself
8365  ** prior to returning.
8366  */
8367  typedef struct sqlite3_mutex_methods sqlite3_mutex_methods;
8368  struct sqlite3_mutex_methods {
8369    int (*xMutexInit)(void);
8370    int (*xMutexEnd)(void);
8371    sqlite3_mutex *(*xMutexAlloc)(int);
8372    void (*xMutexFree)(sqlite3_mutex *);
8373    void (*xMutexEnter)(sqlite3_mutex *);
8374    int (*xMutexTry)(sqlite3_mutex *);
8375    void (*xMutexLeave)(sqlite3_mutex *);
8376    int (*xMutexHeld)(sqlite3_mutex *);
8377    int (*xMutexNotheld)(sqlite3_mutex *);
8378  };
8379  
8380  /*
8381  ** CAPI3REF: Mutex Verification Routines
8382  **
8383  ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
8384  ** are intended for use inside assert() statements.  The SQLite core
8385  ** never uses these routines except inside an assert() and applications
8386  ** are advised to follow the lead of the core.  The SQLite core only
8387  ** provides implementations for these routines when it is compiled
8388  ** with the SQLITE_DEBUG flag.  External mutex implementations
8389  ** are only required to provide these routines if SQLITE_DEBUG is
8390  ** defined and if NDEBUG is not defined.
8391  **
8392  ** These routines should return true if the mutex in their argument
8393  ** is held or not held, respectively, by the calling thread.
8394  **
8395  ** The implementation is not required to provide versions of these
8396  ** routines that actually work. If the implementation does not provide working
8397  ** versions of these routines, it should at least provide stubs that always
8398  ** return true so that one does not get spurious assertion failures.
8399  **
8400  ** If the argument to sqlite3_mutex_held() is a NULL pointer then
8401  ** the routine should return 1.   This seems counter-intuitive since
8402  ** clearly the mutex cannot be held if it does not exist.  But
8403  ** the reason the mutex does not exist is because the build is not
8404  ** using mutexes.  And we do not want the assert() containing the
8405  ** call to sqlite3_mutex_held() to fail, so a non-zero return is
8406  ** the appropriate thing to do.  The sqlite3_mutex_notheld()
8407  ** interface should also return 1 when given a NULL pointer.
8408  */
8409  #ifndef NDEBUG
8410  SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*);
8411  SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*);
8412  #endif
8413  
8414  /*
8415  ** CAPI3REF: Mutex Types
8416  **
8417  ** The [sqlite3_mutex_alloc()] interface takes a single argument
8418  ** which is one of these integer constants.
8419  **
8420  ** The set of static mutexes may change from one SQLite release to the
8421  ** next.  Applications that override the built-in mutex logic must be
8422  ** prepared to accommodate additional static mutexes.
8423  */
8424  #define SQLITE_MUTEX_FAST             0
8425  #define SQLITE_MUTEX_RECURSIVE        1
8426  #define SQLITE_MUTEX_STATIC_MAIN      2
8427  #define SQLITE_MUTEX_STATIC_MEM       3  /* sqlite3_malloc() */
8428  #define SQLITE_MUTEX_STATIC_MEM2      4  /* NOT USED */
8429  #define SQLITE_MUTEX_STATIC_OPEN      4  /* sqlite3BtreeOpen() */
8430  #define SQLITE_MUTEX_STATIC_PRNG      5  /* sqlite3_randomness() */
8431  #define SQLITE_MUTEX_STATIC_LRU       6  /* lru page list */
8432  #define SQLITE_MUTEX_STATIC_LRU2      7  /* NOT USED */
8433  #define SQLITE_MUTEX_STATIC_PMEM      7  /* sqlite3PageMalloc() */
8434  #define SQLITE_MUTEX_STATIC_APP1      8  /* For use by application */
8435  #define SQLITE_MUTEX_STATIC_APP2      9  /* For use by application */
8436  #define SQLITE_MUTEX_STATIC_APP3     10  /* For use by application */
8437  #define SQLITE_MUTEX_STATIC_VFS1     11  /* For use by built-in VFS */
8438  #define SQLITE_MUTEX_STATIC_VFS2     12  /* For use by extension VFS */
8439  #define SQLITE_MUTEX_STATIC_VFS3     13  /* For use by application VFS */
8440  
8441  /* Legacy compatibility: */
8442  #define SQLITE_MUTEX_STATIC_MASTER    2
8443  
8444  
8445  /*
8446  ** CAPI3REF: Retrieve the mutex for a database connection
8447  ** METHOD: sqlite3
8448  **
8449  ** ^This interface returns a pointer to the [sqlite3_mutex] object that
8450  ** serializes access to the [database connection] given in the argument
8451  ** when the [threading mode] is Serialized.
8452  ** ^If the [threading mode] is Single-thread or Multi-thread then this
8453  ** routine returns a NULL pointer.
8454  */
8455  SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*);
8456  
8457  /*
8458  ** CAPI3REF: Low-Level Control Of Database Files
8459  ** METHOD: sqlite3
8460  ** KEYWORDS: {file control}
8461  **
8462  ** ^The [sqlite3_file_control()] interface makes a direct call to the
8463  ** xFileControl method for the [sqlite3_io_methods] object associated
8464  ** with a particular database identified by the second argument. ^The
8465  ** name of the database is "main" for the main database or "temp" for the
8466  ** TEMP database, or the name that appears after the AS keyword for
8467  ** databases that are added using the [ATTACH] SQL command.
8468  ** ^A NULL pointer can be used in place of "main" to refer to the
8469  ** main database file.
8470  ** ^The third and fourth parameters to this routine
8471  ** are passed directly through to the second and third parameters of
8472  ** the xFileControl method.  ^The return value of the xFileControl
8473  ** method becomes the return value of this routine.
8474  **
8475  ** A few opcodes for [sqlite3_file_control()] are handled directly
8476  ** by the SQLite core and never invoke the
8477  ** sqlite3_io_methods.xFileControl method.
8478  ** ^The [SQLITE_FCNTL_FILE_POINTER] value for the op parameter causes
8479  ** a pointer to the underlying [sqlite3_file] object to be written into
8480  ** the space pointed to by the 4th parameter.  The
8481  ** [SQLITE_FCNTL_JOURNAL_POINTER] works similarly except that it returns
8482  ** the [sqlite3_file] object associated with the journal file instead of
8483  ** the main database.  The [SQLITE_FCNTL_VFS_POINTER] opcode returns
8484  ** a pointer to the underlying [sqlite3_vfs] object for the file.
8485  ** The [SQLITE_FCNTL_DATA_VERSION] returns the data version counter
8486  ** from the pager.
8487  **
8488  ** ^If the second parameter (zDbName) does not match the name of any
8489  ** open database file, then SQLITE_ERROR is returned.  ^This error
8490  ** code is not remembered and will not be recalled by [sqlite3_errcode()]
8491  ** or [sqlite3_errmsg()].  The underlying xFileControl method might
8492  ** also return SQLITE_ERROR.  There is no way to distinguish between
8493  ** an incorrect zDbName and an SQLITE_ERROR return from the underlying
8494  ** xFileControl method.
8495  **
8496  ** See also: [file control opcodes]
8497  */
8498  SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);
8499  
8500  /*
8501  ** CAPI3REF: Testing Interface
8502  **
8503  ** ^The sqlite3_test_control() interface is used to read out internal
8504  ** state of SQLite and to inject faults into SQLite for testing
8505  ** purposes.  ^The first parameter is an operation code that determines
8506  ** the number, meaning, and operation of all subsequent parameters.
8507  **
8508  ** This interface is not for use by applications.  It exists solely
8509  ** for verifying the correct operation of the SQLite library.  Depending
8510  ** on how the SQLite library is compiled, this interface might not exist.
8511  **
8512  ** The details of the operation codes, their meanings, the parameters
8513  ** they take, and what they do are all subject to change without notice.
8514  ** Unlike most of the SQLite API, this function is not guaranteed to
8515  ** operate consistently from one release to the next.
8516  */
8517  SQLITE_API int sqlite3_test_control(int op, ...);
8518  
8519  /*
8520  ** CAPI3REF: Testing Interface Operation Codes
8521  **
8522  ** These constants are the valid operation code parameters used
8523  ** as the first argument to [sqlite3_test_control()].
8524  **
8525  ** These parameters and their meanings are subject to change
8526  ** without notice.  These values are for testing purposes only.
8527  ** Applications should not use any of these parameters or the
8528  ** [sqlite3_test_control()] interface.
8529  */
8530  #define SQLITE_TESTCTRL_FIRST                    5
8531  #define SQLITE_TESTCTRL_PRNG_SAVE                5
8532  #define SQLITE_TESTCTRL_PRNG_RESTORE             6
8533  #define SQLITE_TESTCTRL_PRNG_RESET               7  /* NOT USED */
8534  #define SQLITE_TESTCTRL_FK_NO_ACTION             7
8535  #define SQLITE_TESTCTRL_BITVEC_TEST              8
8536  #define SQLITE_TESTCTRL_FAULT_INSTALL            9
8537  #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS     10
8538  #define SQLITE_TESTCTRL_PENDING_BYTE            11
8539  #define SQLITE_TESTCTRL_ASSERT                  12
8540  #define SQLITE_TESTCTRL_ALWAYS                  13
8541  #define SQLITE_TESTCTRL_RESERVE                 14  /* NOT USED */
8542  #define SQLITE_TESTCTRL_JSON_SELFCHECK          14
8543  #define SQLITE_TESTCTRL_OPTIMIZATIONS           15
8544  #define SQLITE_TESTCTRL_ISKEYWORD               16  /* NOT USED */
8545  #define SQLITE_TESTCTRL_GETOPT                  16
8546  #define SQLITE_TESTCTRL_SCRATCHMALLOC           17  /* NOT USED */
8547  #define SQLITE_TESTCTRL_INTERNAL_FUNCTIONS      17
8548  #define SQLITE_TESTCTRL_LOCALTIME_FAULT         18
8549  #define SQLITE_TESTCTRL_EXPLAIN_STMT            19  /* NOT USED */
8550  #define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD    19
8551  #define SQLITE_TESTCTRL_NEVER_CORRUPT           20
8552  #define SQLITE_TESTCTRL_VDBE_COVERAGE           21
8553  #define SQLITE_TESTCTRL_BYTEORDER               22
8554  #define SQLITE_TESTCTRL_ISINIT                  23
8555  #define SQLITE_TESTCTRL_SORTER_MMAP             24
8556  #define SQLITE_TESTCTRL_IMPOSTER                25
8557  #define SQLITE_TESTCTRL_PARSER_COVERAGE         26
8558  #define SQLITE_TESTCTRL_RESULT_INTREAL          27
8559  #define SQLITE_TESTCTRL_PRNG_SEED               28
8560  #define SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS     29
8561  #define SQLITE_TESTCTRL_SEEK_COUNT              30
8562  #define SQLITE_TESTCTRL_TRACEFLAGS              31
8563  #define SQLITE_TESTCTRL_TUNE                    32
8564  #define SQLITE_TESTCTRL_LOGEST                  33
8565  #define SQLITE_TESTCTRL_USELONGDOUBLE           34  /* NOT USED */
8566  #define SQLITE_TESTCTRL_LAST                    34  /* Largest TESTCTRL */
8567  
8568  /*
8569  ** CAPI3REF: SQL Keyword Checking
8570  **
8571  ** These routines provide access to the set of SQL language keywords
8572  ** recognized by SQLite.  Applications can use these routines to determine
8573  ** whether or not a specific identifier needs to be escaped (for example,
8574  ** by enclosing in double-quotes) so as not to confuse the parser.
8575  **
8576  ** The sqlite3_keyword_count() interface returns the number of distinct
8577  ** keywords understood by SQLite.
8578  **
8579  ** The sqlite3_keyword_name(N,Z,L) interface finds the 0-based N-th keyword and
8580  ** makes *Z point to that keyword expressed as UTF8 and writes the number
8581  ** of bytes in the keyword into *L.  The string that *Z points to is not
8582  ** zero-terminated.  The sqlite3_keyword_name(N,Z,L) routine returns
8583  ** SQLITE_OK if N is within bounds and SQLITE_ERROR if not. If either Z
8584  ** or L are NULL or invalid pointers then calls to
8585  ** sqlite3_keyword_name(N,Z,L) result in undefined behavior.
8586  **
8587  ** The sqlite3_keyword_check(Z,L) interface checks to see whether or not
8588  ** the L-byte UTF8 identifier that Z points to is a keyword, returning non-zero
8589  ** if it is and zero if not.
8590  **
8591  ** The parser used by SQLite is forgiving.  It is often possible to use
8592  ** a keyword as an identifier as long as such use does not result in a
8593  ** parsing ambiguity.  For example, the statement
8594  ** "CREATE TABLE BEGIN(REPLACE,PRAGMA,END);" is accepted by SQLite, and
8595  ** creates a new table named "BEGIN" with three columns named
8596  ** "REPLACE", "PRAGMA", and "END".  Nevertheless, best practice is to avoid
8597  ** using keywords as identifiers.  Common techniques used to avoid keyword
8598  ** name collisions include:
8599  ** <ul>
8600  ** <li> Put all identifier names inside double-quotes.  This is the official
8601  **      SQL way to escape identifier names.
8602  ** <li> Put identifier names inside &#91;...&#93;.  This is not standard SQL,
8603  **      but it is what SQL Server does and so lots of programmers use this
8604  **      technique.
8605  ** <li> Begin every identifier with the letter "Z" as no SQL keywords start
8606  **      with "Z".
8607  ** <li> Include a digit somewhere in every identifier name.
8608  ** </ul>
8609  **
8610  ** Note that the number of keywords understood by SQLite can depend on
8611  ** compile-time options.  For example, "VACUUM" is not a keyword if
8612  ** SQLite is compiled with the [-DSQLITE_OMIT_VACUUM] option.  Also,
8613  ** new keywords may be added to future releases of SQLite.
8614  */
8615  SQLITE_API int sqlite3_keyword_count(void);
8616  SQLITE_API int sqlite3_keyword_name(int,const char**,int*);
8617  SQLITE_API int sqlite3_keyword_check(const char*,int);
8618  
8619  /*
8620  ** CAPI3REF: Dynamic String Object
8621  ** KEYWORDS: {dynamic string}
8622  **
8623  ** An instance of the sqlite3_str object contains a dynamically-sized
8624  ** string under construction.
8625  **
8626  ** The lifecycle of an sqlite3_str object is as follows:
8627  ** <ol>
8628  ** <li> ^The sqlite3_str object is created using [sqlite3_str_new()].
8629  ** <li> ^Text is appended to the sqlite3_str object using various
8630  ** methods, such as [sqlite3_str_appendf()].
8631  ** <li> ^The sqlite3_str object is destroyed and the string it created
8632  ** is returned using the [sqlite3_str_finish()] interface.
8633  ** </ol>
8634  */
8635  typedef struct sqlite3_str sqlite3_str;
8636  
8637  /*
8638  ** CAPI3REF: Create A New Dynamic String Object
8639  ** CONSTRUCTOR: sqlite3_str
8640  **
8641  ** ^The [sqlite3_str_new(D)] interface allocates and initializes
8642  ** a new [sqlite3_str] object.  To avoid memory leaks, the object returned by
8643  ** [sqlite3_str_new()] must be freed by a subsequent call to
8644  ** [sqlite3_str_finish(X)].
8645  **
8646  ** ^The [sqlite3_str_new(D)] interface always returns a pointer to a
8647  ** valid [sqlite3_str] object, though in the event of an out-of-memory
8648  ** error the returned object might be a special singleton that will
8649  ** silently reject new text, always return SQLITE_NOMEM from
8650  ** [sqlite3_str_errcode()], always return 0 for
8651  ** [sqlite3_str_length()], and always return NULL from
8652  ** [sqlite3_str_finish(X)].  It is always safe to use the value
8653  ** returned by [sqlite3_str_new(D)] as the sqlite3_str parameter
8654  ** to any of the other [sqlite3_str] methods.
8655  **
8656  ** The D parameter to [sqlite3_str_new(D)] may be NULL.  If the
8657  ** D parameter in [sqlite3_str_new(D)] is not NULL, then the maximum
8658  ** length of the string contained in the [sqlite3_str] object will be
8659  ** the value set for [sqlite3_limit](D,[SQLITE_LIMIT_LENGTH]) instead
8660  ** of [SQLITE_MAX_LENGTH].
8661  */
8662  SQLITE_API sqlite3_str *sqlite3_str_new(sqlite3*);
8663  
8664  /*
8665  ** CAPI3REF: Finalize A Dynamic String
8666  ** DESTRUCTOR: sqlite3_str
8667  **
8668  ** ^The [sqlite3_str_finish(X)] interface destroys the sqlite3_str object X
8669  ** and returns a pointer to a memory buffer obtained from [sqlite3_malloc64()]
8670  ** that contains the constructed string.  The calling application should
8671  ** pass the returned value to [sqlite3_free()] to avoid a memory leak.
8672  ** ^The [sqlite3_str_finish(X)] interface may return a NULL pointer if any
8673  ** errors were encountered during construction of the string.  ^The
8674  ** [sqlite3_str_finish(X)] interface will also return a NULL pointer if the
8675  ** string in [sqlite3_str] object X is zero bytes long.
8676  */
8677  SQLITE_API char *sqlite3_str_finish(sqlite3_str*);
8678  
8679  /*
8680  ** CAPI3REF: Add Content To A Dynamic String
8681  ** METHOD: sqlite3_str
8682  **
8683  ** These interfaces add content to an sqlite3_str object previously obtained
8684  ** from [sqlite3_str_new()].
8685  **
8686  ** ^The [sqlite3_str_appendf(X,F,...)] and
8687  ** [sqlite3_str_vappendf(X,F,V)] interfaces uses the [built-in printf]
8688  ** functionality of SQLite to append formatted text onto the end of
8689  ** [sqlite3_str] object X.
8690  **
8691  ** ^The [sqlite3_str_append(X,S,N)] method appends exactly N bytes from string S
8692  ** onto the end of the [sqlite3_str] object X.  N must be non-negative.
8693  ** S must contain at least N non-zero bytes of content.  To append a
8694  ** zero-terminated string in its entirety, use the [sqlite3_str_appendall()]
8695  ** method instead.
8696  **
8697  ** ^The [sqlite3_str_appendall(X,S)] method appends the complete content of
8698  ** zero-terminated string S onto the end of [sqlite3_str] object X.
8699  **
8700  ** ^The [sqlite3_str_appendchar(X,N,C)] method appends N copies of the
8701  ** single-byte character C onto the end of [sqlite3_str] object X.
8702  ** ^This method can be used, for example, to add whitespace indentation.
8703  **
8704  ** ^The [sqlite3_str_reset(X)] method resets the string under construction
8705  ** inside [sqlite3_str] object X back to zero bytes in length.
8706  **
8707  ** These methods do not return a result code.  ^If an error occurs, that fact
8708  ** is recorded in the [sqlite3_str] object and can be recovered by a
8709  ** subsequent call to [sqlite3_str_errcode(X)].
8710  */
8711  SQLITE_API void sqlite3_str_appendf(sqlite3_str*, const char *zFormat, ...);
8712  SQLITE_API void sqlite3_str_vappendf(sqlite3_str*, const char *zFormat, va_list);
8713  SQLITE_API void sqlite3_str_append(sqlite3_str*, const char *zIn, int N);
8714  SQLITE_API void sqlite3_str_appendall(sqlite3_str*, const char *zIn);
8715  SQLITE_API void sqlite3_str_appendchar(sqlite3_str*, int N, char C);
8716  SQLITE_API void sqlite3_str_reset(sqlite3_str*);
8717  
8718  /*
8719  ** CAPI3REF: Status Of A Dynamic String
8720  ** METHOD: sqlite3_str
8721  **
8722  ** These interfaces return the current status of an [sqlite3_str] object.
8723  **
8724  ** ^If any prior errors have occurred while constructing the dynamic string
8725  ** in sqlite3_str X, then the [sqlite3_str_errcode(X)] method will return
8726  ** an appropriate error code.  ^The [sqlite3_str_errcode(X)] method returns
8727  ** [SQLITE_NOMEM] following any out-of-memory error, or
8728  ** [SQLITE_TOOBIG] if the size of the dynamic string exceeds
8729  ** [SQLITE_MAX_LENGTH], or [SQLITE_OK] if there have been no errors.
8730  **
8731  ** ^The [sqlite3_str_length(X)] method returns the current length, in bytes,
8732  ** of the dynamic string under construction in [sqlite3_str] object X.
8733  ** ^The length returned by [sqlite3_str_length(X)] does not include the
8734  ** zero-termination byte.
8735  **
8736  ** ^The [sqlite3_str_value(X)] method returns a pointer to the current
8737  ** content of the dynamic string under construction in X.  The value
8738  ** returned by [sqlite3_str_value(X)] is managed by the sqlite3_str object X
8739  ** and might be freed or altered by any subsequent method on the same
8740  ** [sqlite3_str] object.  Applications must not use the pointer returned by
8741  ** [sqlite3_str_value(X)] after any subsequent method call on the same
8742  ** object.  ^Applications may change the content of the string returned
8743  ** by [sqlite3_str_value(X)] as long as they do not write into any bytes
8744  ** outside the range of 0 to [sqlite3_str_length(X)] and do not read or
8745  ** write any byte after any subsequent sqlite3_str method call.
8746  */
8747  SQLITE_API int sqlite3_str_errcode(sqlite3_str*);
8748  SQLITE_API int sqlite3_str_length(sqlite3_str*);
8749  SQLITE_API char *sqlite3_str_value(sqlite3_str*);
8750  
8751  /*
8752  ** CAPI3REF: SQLite Runtime Status
8753  **
8754  ** ^These interfaces are used to retrieve runtime status information
8755  ** about the performance of SQLite, and optionally to reset various
8756  ** highwater marks.  ^The first argument is an integer code for
8757  ** the specific parameter to measure.  ^(Recognized integer codes
8758  ** are of the form [status parameters | SQLITE_STATUS_...].)^
8759  ** ^The current value of the parameter is returned into *pCurrent.
8760  ** ^The highest recorded value is returned in *pHighwater.  ^If the
8761  ** resetFlag is true, then the highest record value is reset after
8762  ** *pHighwater is written.  ^(Some parameters do not record the highest
8763  ** value.  For those parameters
8764  ** nothing is written into *pHighwater and the resetFlag is ignored.)^
8765  ** ^(Other parameters record only the highwater mark and not the current
8766  ** value.  For these latter parameters nothing is written into *pCurrent.)^
8767  **
8768  ** ^The sqlite3_status() and sqlite3_status64() routines return
8769  ** SQLITE_OK on success and a non-zero [error code] on failure.
8770  **
8771  ** If either the current value or the highwater mark is too large to
8772  ** be represented by a 32-bit integer, then the values returned by
8773  ** sqlite3_status() are undefined.
8774  **
8775  ** See also: [sqlite3_db_status()]
8776  */
8777  SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
8778  SQLITE_API int sqlite3_status64(
8779    int op,
8780    sqlite3_int64 *pCurrent,
8781    sqlite3_int64 *pHighwater,
8782    int resetFlag
8783  );
8784  
8785  
8786  /*
8787  ** CAPI3REF: Status Parameters
8788  ** KEYWORDS: {status parameters}
8789  **
8790  ** These integer constants designate various run-time status parameters
8791  ** that can be returned by [sqlite3_status()].
8792  **
8793  ** <dl>
8794  ** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
8795  ** <dd>This parameter is the current amount of memory checked out
8796  ** using [sqlite3_malloc()], either directly or indirectly.  The
8797  ** figure includes calls made to [sqlite3_malloc()] by the application
8798  ** and internal memory usage by the SQLite library.  Auxiliary page-cache
8799  ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
8800  ** this parameter.  The amount returned is the sum of the allocation
8801  ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
8802  **
8803  ** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
8804  ** <dd>This parameter records the largest memory allocation request
8805  ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their
8806  ** internal equivalents).  Only the value returned in the
8807  ** *pHighwater parameter to [sqlite3_status()] is of interest.
8808  ** The value written into the *pCurrent parameter is undefined.</dd>)^
8809  **
8810  ** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>
8811  ** <dd>This parameter records the number of separate memory allocations
8812  ** currently checked out.</dd>)^
8813  **
8814  ** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>
8815  ** <dd>This parameter returns the number of pages used out of the
8816  ** [pagecache memory allocator] that was configured using
8817  ** [SQLITE_CONFIG_PAGECACHE].  The
8818  ** value returned is in pages, not in bytes.</dd>)^
8819  **
8820  ** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]]
8821  ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>
8822  ** <dd>This parameter returns the number of bytes of page cache
8823  ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]
8824  ** buffer and where forced to overflow to [sqlite3_malloc()].  The
8825  ** returned value includes allocations that overflowed because they
8826  ** were too large (they were larger than the "sz" parameter to
8827  ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because
8828  ** no space was left in the page cache.</dd>)^
8829  **
8830  ** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>
8831  ** <dd>This parameter records the largest memory allocation request
8832  ** handed to the [pagecache memory allocator].  Only the value returned in the
8833  ** *pHighwater parameter to [sqlite3_status()] is of interest.
8834  ** The value written into the *pCurrent parameter is undefined.</dd>)^
8835  **
8836  ** [[SQLITE_STATUS_SCRATCH_USED]] <dt>SQLITE_STATUS_SCRATCH_USED</dt>
8837  ** <dd>No longer used.</dd>
8838  **
8839  ** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
8840  ** <dd>No longer used.</dd>
8841  **
8842  ** [[SQLITE_STATUS_SCRATCH_SIZE]] <dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
8843  ** <dd>No longer used.</dd>
8844  **
8845  ** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
8846  ** <dd>The *pHighwater parameter records the deepest parser stack.
8847  ** The *pCurrent value is undefined.  The *pHighwater value is only
8848  ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
8849  ** </dl>
8850  **
8851  ** New status parameters may be added from time to time.
8852  */
8853  #define SQLITE_STATUS_MEMORY_USED          0
8854  #define SQLITE_STATUS_PAGECACHE_USED       1
8855  #define SQLITE_STATUS_PAGECACHE_OVERFLOW   2
8856  #define SQLITE_STATUS_SCRATCH_USED         3  /* NOT USED */
8857  #define SQLITE_STATUS_SCRATCH_OVERFLOW     4  /* NOT USED */
8858  #define SQLITE_STATUS_MALLOC_SIZE          5
8859  #define SQLITE_STATUS_PARSER_STACK         6
8860  #define SQLITE_STATUS_PAGECACHE_SIZE       7
8861  #define SQLITE_STATUS_SCRATCH_SIZE         8  /* NOT USED */
8862  #define SQLITE_STATUS_MALLOC_COUNT         9
8863  
8864  /*
8865  ** CAPI3REF: Database Connection Status
8866  ** METHOD: sqlite3
8867  **
8868  ** ^This interface is used to retrieve runtime status information
8869  ** about a single [database connection].  ^The first argument is the
8870  ** database connection object to be interrogated.  ^The second argument
8871  ** is an integer constant, taken from the set of
8872  ** [SQLITE_DBSTATUS options], that
8873  ** determines the parameter to interrogate.  The set of
8874  ** [SQLITE_DBSTATUS options] is likely
8875  ** to grow in future releases of SQLite.
8876  **
8877  ** ^The current value of the requested parameter is written into *pCur
8878  ** and the highest instantaneous value is written into *pHiwtr.  ^If
8879  ** the resetFlg is true, then the highest instantaneous value is
8880  ** reset back down to the current value.
8881  **
8882  ** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a
8883  ** non-zero [error code] on failure.
8884  **
8885  ** See also: [sqlite3_status()] and [sqlite3_stmt_status()].
8886  */
8887  SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);
8888  
8889  /*
8890  ** CAPI3REF: Status Parameters for database connections
8891  ** KEYWORDS: {SQLITE_DBSTATUS options}
8892  **
8893  ** These constants are the available integer "verbs" that can be passed as
8894  ** the second argument to the [sqlite3_db_status()] interface.
8895  **
8896  ** New verbs may be added in future releases of SQLite. Existing verbs
8897  ** might be discontinued. Applications should check the return code from
8898  ** [sqlite3_db_status()] to make sure that the call worked.
8899  ** The [sqlite3_db_status()] interface will return a non-zero error code
8900  ** if a discontinued or unsupported verb is invoked.
8901  **
8902  ** <dl>
8903  ** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>
8904  ** <dd>This parameter returns the number of lookaside memory slots currently
8905  ** checked out.</dd>)^
8906  **
8907  ** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>
8908  ** <dd>This parameter returns the number of malloc attempts that were
8909  ** satisfied using lookaside memory. Only the high-water value is meaningful;
8910  ** the current value is always zero.</dd>)^
8911  **
8912  ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]
8913  ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>
8914  ** <dd>This parameter returns the number of malloc attempts that might have
8915  ** been satisfied using lookaside memory but failed due to the amount of
8916  ** memory requested being larger than the lookaside slot size.
8917  ** Only the high-water value is meaningful;
8918  ** the current value is always zero.</dd>)^
8919  **
8920  ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]]
8921  ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>
8922  ** <dd>This parameter returns the number of malloc attempts that might have
8923  ** been satisfied using lookaside memory but failed due to all lookaside
8924  ** memory already being in use.
8925  ** Only the high-water value is meaningful;
8926  ** the current value is always zero.</dd>)^
8927  **
8928  ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>
8929  ** <dd>This parameter returns the approximate number of bytes of heap
8930  ** memory used by all pager caches associated with the database connection.)^
8931  ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.
8932  ** </dd>
8933  **
8934  ** [[SQLITE_DBSTATUS_CACHE_USED_SHARED]]
8935  ** ^(<dt>SQLITE_DBSTATUS_CACHE_USED_SHARED</dt>
8936  ** <dd>This parameter is similar to DBSTATUS_CACHE_USED, except that if a
8937  ** pager cache is shared between two or more connections the bytes of heap
8938  ** memory used by that pager cache is divided evenly between the attached
8939  ** connections.)^  In other words, if none of the pager caches associated
8940  ** with the database connection are shared, this request returns the same
8941  ** value as DBSTATUS_CACHE_USED. Or, if one or more of the pager caches are
8942  ** shared, the value returned by this call will be smaller than that returned
8943  ** by DBSTATUS_CACHE_USED. ^The highwater mark associated with
8944  ** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0.</dd>
8945  **
8946  ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>
8947  ** <dd>This parameter returns the approximate number of bytes of heap
8948  ** memory used to store the schema for all databases associated
8949  ** with the connection - main, temp, and any [ATTACH]-ed databases.)^
8950  ** ^The full amount of memory used by the schemas is reported, even if the
8951  ** schema memory is shared with other database connections due to
8952  ** [shared cache mode] being enabled.
8953  ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.
8954  ** </dd>
8955  **
8956  ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>
8957  ** <dd>This parameter returns the approximate number of bytes of heap
8958  ** and lookaside memory used by all prepared statements associated with
8959  ** the database connection.)^
8960  ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.
8961  ** </dd>
8962  **
8963  ** [[SQLITE_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE_DBSTATUS_CACHE_HIT</dt>
8964  ** <dd>This parameter returns the number of pager cache hits that have
8965  ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_HIT
8966  ** is always 0.
8967  ** </dd>
8968  **
8969  ** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt>
8970  ** <dd>This parameter returns the number of pager cache misses that have
8971  ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS
8972  ** is always 0.
8973  ** </dd>
8974  **
8975  ** [[SQLITE_DBSTATUS_CACHE_WRITE]] ^(<dt>SQLITE_DBSTATUS_CACHE_WRITE</dt>
8976  ** <dd>This parameter returns the number of dirty cache entries that have
8977  ** been written to disk. Specifically, the number of pages written to the
8978  ** wal file in wal mode databases, or the number of pages written to the
8979  ** database file in rollback mode databases. Any pages written as part of
8980  ** transaction rollback or database recovery operations are not included.
8981  ** If an IO or other error occurs while writing a page to disk, the effect
8982  ** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The
8983  ** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0.
8984  ** </dd>
8985  **
8986  ** [[SQLITE_DBSTATUS_CACHE_SPILL]] ^(<dt>SQLITE_DBSTATUS_CACHE_SPILL</dt>
8987  ** <dd>This parameter returns the number of dirty cache entries that have
8988  ** been written to disk in the middle of a transaction due to the page
8989  ** cache overflowing. Transactions are more efficient if they are written
8990  ** to disk all at once. When pages spill mid-transaction, that introduces
8991  ** additional overhead. This parameter can be used to help identify
8992  ** inefficiencies that can be resolved by increasing the cache size.
8993  ** </dd>
8994  **
8995  ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>
8996  ** <dd>This parameter returns zero for the current value if and only if
8997  ** all foreign key constraints (deferred or immediate) have been
8998  ** resolved.)^  ^The highwater mark is always 0.
8999  ** </dd>
9000  ** </dl>
9001  */
9002  #define SQLITE_DBSTATUS_LOOKASIDE_USED       0
9003  #define SQLITE_DBSTATUS_CACHE_USED           1
9004  #define SQLITE_DBSTATUS_SCHEMA_USED          2
9005  #define SQLITE_DBSTATUS_STMT_USED            3
9006  #define SQLITE_DBSTATUS_LOOKASIDE_HIT        4
9007  #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE  5
9008  #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL  6
9009  #define SQLITE_DBSTATUS_CACHE_HIT            7
9010  #define SQLITE_DBSTATUS_CACHE_MISS           8
9011  #define SQLITE_DBSTATUS_CACHE_WRITE          9
9012  #define SQLITE_DBSTATUS_DEFERRED_FKS        10
9013  #define SQLITE_DBSTATUS_CACHE_USED_SHARED   11
9014  #define SQLITE_DBSTATUS_CACHE_SPILL         12
9015  #define SQLITE_DBSTATUS_MAX                 12   /* Largest defined DBSTATUS */
9016  
9017  
9018  /*
9019  ** CAPI3REF: Prepared Statement Status
9020  ** METHOD: sqlite3_stmt
9021  **
9022  ** ^(Each prepared statement maintains various
9023  ** [SQLITE_STMTSTATUS counters] that measure the number
9024  ** of times it has performed specific operations.)^  These counters can
9025  ** be used to monitor the performance characteristics of the prepared
9026  ** statements.  For example, if the number of table steps greatly exceeds
9027  ** the number of table searches or result rows, that would tend to indicate
9028  ** that the prepared statement is using a full table scan rather than
9029  ** an index.
9030  **
9031  ** ^(This interface is used to retrieve and reset counter values from
9032  ** a [prepared statement].  The first argument is the prepared statement
9033  ** object to be interrogated.  The second argument
9034  ** is an integer code for a specific [SQLITE_STMTSTATUS counter]
9035  ** to be interrogated.)^
9036  ** ^The current value of the requested counter is returned.
9037  ** ^If the resetFlg is true, then the counter is reset to zero after this
9038  ** interface call returns.
9039  **
9040  ** See also: [sqlite3_status()] and [sqlite3_db_status()].
9041  */
9042  SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);
9043  
9044  /*
9045  ** CAPI3REF: Status Parameters for prepared statements
9046  ** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters}
9047  **
9048  ** These preprocessor macros define integer codes that name counter
9049  ** values associated with the [sqlite3_stmt_status()] interface.
9050  ** The meanings of the various counters are as follows:
9051  **
9052  ** <dl>
9053  ** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>
9054  ** <dd>^This is the number of times that SQLite has stepped forward in
9055  ** a table as part of a full table scan.  Large numbers for this counter
9056  ** may indicate opportunities for performance improvement through
9057  ** careful use of indices.</dd>
9058  **
9059  ** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt>
9060  ** <dd>^This is the number of sort operations that have occurred.
9061  ** A non-zero value in this counter may indicate an opportunity to
9062  ** improve performance through careful use of indices.</dd>
9063  **
9064  ** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>
9065  ** <dd>^This is the number of rows inserted into transient indices that
9066  ** were created automatically in order to help joins run faster.
9067  ** A non-zero value in this counter may indicate an opportunity to
9068  ** improve performance by adding permanent indices that do not
9069  ** need to be reinitialized each time the statement is run.</dd>
9070  **
9071  ** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>
9072  ** <dd>^This is the number of virtual machine operations executed
9073  ** by the prepared statement if that number is less than or equal
9074  ** to 2147483647.  The number of virtual machine operations can be
9075  ** used as a proxy for the total work done by the prepared statement.
9076  ** If the number of virtual machine operations exceeds 2147483647
9077  ** then the value returned by this statement status code is undefined.</dd>
9078  **
9079  ** [[SQLITE_STMTSTATUS_REPREPARE]] <dt>SQLITE_STMTSTATUS_REPREPARE</dt>
9080  ** <dd>^This is the number of times that the prepare statement has been
9081  ** automatically regenerated due to schema changes or changes to
9082  ** [bound parameters] that might affect the query plan.</dd>
9083  **
9084  ** [[SQLITE_STMTSTATUS_RUN]] <dt>SQLITE_STMTSTATUS_RUN</dt>
9085  ** <dd>^This is the number of times that the prepared statement has
9086  ** been run.  A single "run" for the purposes of this counter is one
9087  ** or more calls to [sqlite3_step()] followed by a call to [sqlite3_reset()].
9088  ** The counter is incremented on the first [sqlite3_step()] call of each
9089  ** cycle.</dd>
9090  **
9091  ** [[SQLITE_STMTSTATUS_FILTER_MISS]]
9092  ** [[SQLITE_STMTSTATUS_FILTER HIT]]
9093  ** <dt>SQLITE_STMTSTATUS_FILTER_HIT<br>
9094  ** SQLITE_STMTSTATUS_FILTER_MISS</dt>
9095  ** <dd>^SQLITE_STMTSTATUS_FILTER_HIT is the number of times that a join
9096  ** step was bypassed because a Bloom filter returned not-found.  The
9097  ** corresponding SQLITE_STMTSTATUS_FILTER_MISS value is the number of
9098  ** times that the Bloom filter returned a find, and thus the join step
9099  ** had to be processed as normal.</dd>
9100  **
9101  ** [[SQLITE_STMTSTATUS_MEMUSED]] <dt>SQLITE_STMTSTATUS_MEMUSED</dt>
9102  ** <dd>^This is the approximate number of bytes of heap memory
9103  ** used to store the prepared statement.  ^This value is not actually
9104  ** a counter, and so the resetFlg parameter to sqlite3_stmt_status()
9105  ** is ignored when the opcode is SQLITE_STMTSTATUS_MEMUSED.
9106  ** </dd>
9107  ** </dl>
9108  */
9109  #define SQLITE_STMTSTATUS_FULLSCAN_STEP     1
9110  #define SQLITE_STMTSTATUS_SORT              2
9111  #define SQLITE_STMTSTATUS_AUTOINDEX         3
9112  #define SQLITE_STMTSTATUS_VM_STEP           4
9113  #define SQLITE_STMTSTATUS_REPREPARE         5
9114  #define SQLITE_STMTSTATUS_RUN               6
9115  #define SQLITE_STMTSTATUS_FILTER_MISS       7
9116  #define SQLITE_STMTSTATUS_FILTER_HIT        8
9117  #define SQLITE_STMTSTATUS_MEMUSED           99
9118  
9119  /*
9120  ** CAPI3REF: Custom Page Cache Object
9121  **
9122  ** The sqlite3_pcache type is opaque.  It is implemented by
9123  ** the pluggable module.  The SQLite core has no knowledge of
9124  ** its size or internal structure and never deals with the
9125  ** sqlite3_pcache object except by holding and passing pointers
9126  ** to the object.
9127  **
9128  ** See [sqlite3_pcache_methods2] for additional information.
9129  */
9130  typedef struct sqlite3_pcache sqlite3_pcache;
9131  
9132  /*
9133  ** CAPI3REF: Custom Page Cache Object
9134  **
9135  ** The sqlite3_pcache_page object represents a single page in the
9136  ** page cache.  The page cache will allocate instances of this
9137  ** object.  Various methods of the page cache use pointers to instances
9138  ** of this object as parameters or as their return value.
9139  **
9140  ** See [sqlite3_pcache_methods2] for additional information.
9141  */
9142  typedef struct sqlite3_pcache_page sqlite3_pcache_page;
9143  struct sqlite3_pcache_page {
9144    void *pBuf;        /* The content of the page */
9145    void *pExtra;      /* Extra information associated with the page */
9146  };
9147  
9148  /*
9149  ** CAPI3REF: Application Defined Page Cache.
9150  ** KEYWORDS: {page cache}
9151  **
9152  ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE2], ...) interface can
9153  ** register an alternative page cache implementation by passing in an
9154  ** instance of the sqlite3_pcache_methods2 structure.)^
9155  ** In many applications, most of the heap memory allocated by
9156  ** SQLite is used for the page cache.
9157  ** By implementing a
9158  ** custom page cache using this API, an application can better control
9159  ** the amount of memory consumed by SQLite, the way in which
9160  ** that memory is allocated and released, and the policies used to
9161  ** determine exactly which parts of a database file are cached and for
9162  ** how long.
9163  **
9164  ** The alternative page cache mechanism is an
9165  ** extreme measure that is only needed by the most demanding applications.
9166  ** The built-in page cache is recommended for most uses.
9167  **
9168  ** ^(The contents of the sqlite3_pcache_methods2 structure are copied to an
9169  ** internal buffer by SQLite within the call to [sqlite3_config].  Hence
9170  ** the application may discard the parameter after the call to
9171  ** [sqlite3_config()] returns.)^
9172  **
9173  ** [[the xInit() page cache method]]
9174  ** ^(The xInit() method is called once for each effective
9175  ** call to [sqlite3_initialize()])^
9176  ** (usually only once during the lifetime of the process). ^(The xInit()
9177  ** method is passed a copy of the sqlite3_pcache_methods2.pArg value.)^
9178  ** The intent of the xInit() method is to set up global data structures
9179  ** required by the custom page cache implementation.
9180  ** ^(If the xInit() method is NULL, then the
9181  ** built-in default page cache is used instead of the application defined
9182  ** page cache.)^
9183  **
9184  ** [[the xShutdown() page cache method]]
9185  ** ^The xShutdown() method is called by [sqlite3_shutdown()].
9186  ** It can be used to clean up
9187  ** any outstanding resources before process shutdown, if required.
9188  ** ^The xShutdown() method may be NULL.
9189  **
9190  ** ^SQLite automatically serializes calls to the xInit method,
9191  ** so the xInit method need not be threadsafe.  ^The
9192  ** xShutdown method is only called from [sqlite3_shutdown()] so it does
9193  ** not need to be threadsafe either.  All other methods must be threadsafe
9194  ** in multithreaded applications.
9195  **
9196  ** ^SQLite will never invoke xInit() more than once without an intervening
9197  ** call to xShutdown().
9198  **
9199  ** [[the xCreate() page cache methods]]
9200  ** ^SQLite invokes the xCreate() method to construct a new cache instance.
9201  ** SQLite will typically create one cache instance for each open database file,
9202  ** though this is not guaranteed. ^The
9203  ** first parameter, szPage, is the size in bytes of the pages that must
9204  ** be allocated by the cache.  ^szPage will always be a power of two.  ^The
9205  ** second parameter szExtra is a number of bytes of extra storage
9206  ** associated with each page cache entry.  ^The szExtra parameter will be
9207  ** a number less than 250.  SQLite will use the
9208  ** extra szExtra bytes on each page to store metadata about the underlying
9209  ** database page on disk.  The value passed into szExtra depends
9210  ** on the SQLite version, the target platform, and how SQLite was compiled.
9211  ** ^The third argument to xCreate(), bPurgeable, is true if the cache being
9212  ** created will be used to cache database pages of a file stored on disk, or
9213  ** false if it is used for an in-memory database. The cache implementation
9214  ** does not have to do anything special based upon the value of bPurgeable;
9215  ** it is purely advisory.  ^On a cache where bPurgeable is false, SQLite will
9216  ** never invoke xUnpin() except to deliberately delete a page.
9217  ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
9218  ** false will always have the "discard" flag set to true.
9219  ** ^Hence, a cache created with bPurgeable set to false will
9220  ** never contain any unpinned pages.
9221  **
9222  ** [[the xCachesize() page cache method]]
9223  ** ^(The xCachesize() method may be called at any time by SQLite to set the
9224  ** suggested maximum cache-size (number of pages stored) for the cache
9225  ** instance passed as the first argument. This is the value configured using
9226  ** the SQLite "[PRAGMA cache_size]" command.)^  As with the bPurgeable
9227  ** parameter, the implementation is not required to do anything with this
9228  ** value; it is advisory only.
9229  **
9230  ** [[the xPagecount() page cache methods]]
9231  ** The xPagecount() method must return the number of pages currently
9232  ** stored in the cache, both pinned and unpinned.
9233  **
9234  ** [[the xFetch() page cache methods]]
9235  ** The xFetch() method locates a page in the cache and returns a pointer to
9236  ** an sqlite3_pcache_page object associated with that page, or a NULL pointer.
9237  ** The pBuf element of the returned sqlite3_pcache_page object will be a
9238  ** pointer to a buffer of szPage bytes used to store the content of a
9239  ** single database page.  The pExtra element of sqlite3_pcache_page will be
9240  ** a pointer to the szExtra bytes of extra storage that SQLite has requested
9241  ** for each entry in the page cache.
9242  **
9243  ** The page to be fetched is determined by the key. ^The minimum key value
9244  ** is 1.  After it has been retrieved using xFetch, the page is considered
9245  ** to be "pinned".
9246  **
9247  ** If the requested page is already in the page cache, then the page cache
9248  ** implementation must return a pointer to the page buffer with its content
9249  ** intact.  If the requested page is not already in the cache, then the
9250  ** cache implementation should use the value of the createFlag
9251  ** parameter to help it determine what action to take:
9252  **
9253  ** <table border=1 width=85% align=center>
9254  ** <tr><th> createFlag <th> Behavior when page is not already in cache
9255  ** <tr><td> 0 <td> Do not allocate a new page.  Return NULL.
9256  ** <tr><td> 1 <td> Allocate a new page if it is easy and convenient to do so.
9257  **                 Otherwise return NULL.
9258  ** <tr><td> 2 <td> Make every effort to allocate a new page.  Only return
9259  **                 NULL if allocating a new page is effectively impossible.
9260  ** </table>
9261  **
9262  ** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1.  SQLite
9263  ** will only use a createFlag of 2 after a prior call with a createFlag of 1
9264  ** failed.)^  In between the xFetch() calls, SQLite may
9265  ** attempt to unpin one or more cache pages by spilling the content of
9266  ** pinned pages to disk and synching the operating system disk cache.
9267  **
9268  ** [[the xUnpin() page cache method]]
9269  ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page
9270  ** as its second argument.  If the third parameter, discard, is non-zero,
9271  ** then the page must be evicted from the cache.
9272  ** ^If the discard parameter is
9273  ** zero, then the page may be discarded or retained at the discretion of the
9274  ** page cache implementation. ^The page cache implementation
9275  ** may choose to evict unpinned pages at any time.
9276  **
9277  ** The cache must not perform any reference counting. A single
9278  ** call to xUnpin() unpins the page regardless of the number of prior calls
9279  ** to xFetch().
9280  **
9281  ** [[the xRekey() page cache methods]]
9282  ** The xRekey() method is used to change the key value associated with the
9283  ** page passed as the second argument. If the cache
9284  ** previously contains an entry associated with newKey, it must be
9285  ** discarded. ^Any prior cache entry associated with newKey is guaranteed not
9286  ** to be pinned.
9287  **
9288  ** When SQLite calls the xTruncate() method, the cache must discard all
9289  ** existing cache entries with page numbers (keys) greater than or equal
9290  ** to the value of the iLimit parameter passed to xTruncate(). If any
9291  ** of these pages are pinned, they become implicitly unpinned, meaning that
9292  ** they can be safely discarded.
9293  **
9294  ** [[the xDestroy() page cache method]]
9295  ** ^The xDestroy() method is used to delete a cache allocated by xCreate().
9296  ** All resources associated with the specified cache should be freed. ^After
9297  ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
9298  ** handle invalid, and will not use it with any other sqlite3_pcache_methods2
9299  ** functions.
9300  **
9301  ** [[the xShrink() page cache method]]
9302  ** ^SQLite invokes the xShrink() method when it wants the page cache to
9303  ** free up as much of heap memory as possible.  The page cache implementation
9304  ** is not obligated to free any memory, but well-behaved implementations should
9305  ** do their best.
9306  */
9307  typedef struct sqlite3_pcache_methods2 sqlite3_pcache_methods2;
9308  struct sqlite3_pcache_methods2 {
9309    int iVersion;
9310    void *pArg;
9311    int (*xInit)(void*);
9312    void (*xShutdown)(void*);
9313    sqlite3_pcache *(*xCreate)(int szPage, int szExtra, int bPurgeable);
9314    void (*xCachesize)(sqlite3_pcache*, int nCachesize);
9315    int (*xPagecount)(sqlite3_pcache*);
9316    sqlite3_pcache_page *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
9317    void (*xUnpin)(sqlite3_pcache*, sqlite3_pcache_page*, int discard);
9318    void (*xRekey)(sqlite3_pcache*, sqlite3_pcache_page*,
9319        unsigned oldKey, unsigned newKey);
9320    void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
9321    void (*xDestroy)(sqlite3_pcache*);
9322    void (*xShrink)(sqlite3_pcache*);
9323  };
9324  
9325  /*
9326  ** This is the obsolete pcache_methods object that has now been replaced
9327  ** by sqlite3_pcache_methods2.  This object is not used by SQLite.  It is
9328  ** retained in the header file for backwards compatibility only.
9329  */
9330  typedef struct sqlite3_pcache_methods sqlite3_pcache_methods;
9331  struct sqlite3_pcache_methods {
9332    void *pArg;
9333    int (*xInit)(void*);
9334    void (*xShutdown)(void*);
9335    sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable);
9336    void (*xCachesize)(sqlite3_pcache*, int nCachesize);
9337    int (*xPagecount)(sqlite3_pcache*);
9338    void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
9339    void (*xUnpin)(sqlite3_pcache*, void*, int discard);
9340    void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey);
9341    void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
9342    void (*xDestroy)(sqlite3_pcache*);
9343  };
9344  
9345  
9346  /*
9347  ** CAPI3REF: Online Backup Object
9348  **
9349  ** The sqlite3_backup object records state information about an ongoing
9350  ** online backup operation.  ^The sqlite3_backup object is created by
9351  ** a call to [sqlite3_backup_init()] and is destroyed by a call to
9352  ** [sqlite3_backup_finish()].
9353  **
9354  ** See Also: [Using the SQLite Online Backup API]
9355  */
9356  typedef struct sqlite3_backup sqlite3_backup;
9357  
9358  /*
9359  ** CAPI3REF: Online Backup API.
9360  **
9361  ** The backup API copies the content of one database into another.
9362  ** It is useful either for creating backups of databases or
9363  ** for copying in-memory databases to or from persistent files.
9364  **
9365  ** See Also: [Using the SQLite Online Backup API]
9366  **
9367  ** ^SQLite holds a write transaction open on the destination database file
9368  ** for the duration of the backup operation.
9369  ** ^The source database is read-locked only while it is being read;
9370  ** it is not locked continuously for the entire backup operation.
9371  ** ^Thus, the backup may be performed on a live source database without
9372  ** preventing other database connections from
9373  ** reading or writing to the source database while the backup is underway.
9374  **
9375  ** ^(To perform a backup operation:
9376  **   <ol>
9377  **     <li><b>sqlite3_backup_init()</b> is called once to initialize the
9378  **         backup,
9379  **     <li><b>sqlite3_backup_step()</b> is called one or more times to transfer
9380  **         the data between the two databases, and finally
9381  **     <li><b>sqlite3_backup_finish()</b> is called to release all resources
9382  **         associated with the backup operation.
9383  **   </ol>)^
9384  ** There should be exactly one call to sqlite3_backup_finish() for each
9385  ** successful call to sqlite3_backup_init().
9386  **
9387  ** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b>
9388  **
9389  ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the
9390  ** [database connection] associated with the destination database
9391  ** and the database name, respectively.
9392  ** ^The database name is "main" for the main database, "temp" for the
9393  ** temporary database, or the name specified after the AS keyword in
9394  ** an [ATTACH] statement for an attached database.
9395  ** ^The S and M arguments passed to
9396  ** sqlite3_backup_init(D,N,S,M) identify the [database connection]
9397  ** and database name of the source database, respectively.
9398  ** ^The source and destination [database connections] (parameters S and D)
9399  ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
9400  ** an error.
9401  **
9402  ** ^A call to sqlite3_backup_init() will fail, returning NULL, if
9403  ** there is already a read or read-write transaction open on the
9404  ** destination database.
9405  **
9406  ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
9407  ** returned and an error code and error message are stored in the
9408  ** destination [database connection] D.
9409  ** ^The error code and message for the failed call to sqlite3_backup_init()
9410  ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or
9411  ** [sqlite3_errmsg16()] functions.
9412  ** ^A successful call to sqlite3_backup_init() returns a pointer to an
9413  ** [sqlite3_backup] object.
9414  ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and
9415  ** sqlite3_backup_finish() functions to perform the specified backup
9416  ** operation.
9417  **
9418  ** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b>
9419  **
9420  ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between
9421  ** the source and destination databases specified by [sqlite3_backup] object B.
9422  ** ^If N is negative, all remaining source pages are copied.
9423  ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there
9424  ** are still more pages to be copied, then the function returns [SQLITE_OK].
9425  ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages
9426  ** from source to destination, then it returns [SQLITE_DONE].
9427  ** ^If an error occurs while running sqlite3_backup_step(B,N),
9428  ** then an [error code] is returned. ^As well as [SQLITE_OK] and
9429  ** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
9430  ** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an
9431  ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code.
9432  **
9433  ** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if
9434  ** <ol>
9435  ** <li> the destination database was opened read-only, or
9436  ** <li> the destination database is using write-ahead-log journaling
9437  ** and the destination and source page sizes differ, or
9438  ** <li> the destination database is an in-memory database and the
9439  ** destination and source page sizes differ.
9440  ** </ol>)^
9441  **
9442  ** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then
9443  ** the [sqlite3_busy_handler | busy-handler function]
9444  ** is invoked (if one is specified). ^If the
9445  ** busy-handler returns non-zero before the lock is available, then
9446  ** [SQLITE_BUSY] is returned to the caller. ^In this case the call to
9447  ** sqlite3_backup_step() can be retried later. ^If the source
9448  ** [database connection]
9449  ** is being used to write to the source database when sqlite3_backup_step()
9450  ** is called, then [SQLITE_LOCKED] is returned immediately. ^Again, in this
9451  ** case the call to sqlite3_backup_step() can be retried later on. ^(If
9452  ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or
9453  ** [SQLITE_READONLY] is returned, then
9454  ** there is no point in retrying the call to sqlite3_backup_step(). These
9455  ** errors are considered fatal.)^  The application must accept
9456  ** that the backup operation has failed and pass the backup operation handle
9457  ** to the sqlite3_backup_finish() to release associated resources.
9458  **
9459  ** ^The first call to sqlite3_backup_step() obtains an exclusive lock
9460  ** on the destination file. ^The exclusive lock is not released until either
9461  ** sqlite3_backup_finish() is called or the backup operation is complete
9462  ** and sqlite3_backup_step() returns [SQLITE_DONE].  ^Every call to
9463  ** sqlite3_backup_step() obtains a [shared lock] on the source database that
9464  ** lasts for the duration of the sqlite3_backup_step() call.
9465  ** ^Because the source database is not locked between calls to
9466  ** sqlite3_backup_step(), the source database may be modified mid-way
9467  ** through the backup process.  ^If the source database is modified by an
9468  ** external process or via a database connection other than the one being
9469  ** used by the backup operation, then the backup will be automatically
9470  ** restarted by the next call to sqlite3_backup_step(). ^If the source
9471  ** database is modified by using the same database connection as is used
9472  ** by the backup operation, then the backup database is automatically
9473  ** updated at the same time.
9474  **
9475  ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>
9476  **
9477  ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the
9478  ** application wishes to abandon the backup operation, the application
9479  ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish().
9480  ** ^The sqlite3_backup_finish() interfaces releases all
9481  ** resources associated with the [sqlite3_backup] object.
9482  ** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any
9483  ** active write-transaction on the destination database is rolled back.
9484  ** The [sqlite3_backup] object is invalid
9485  ** and may not be used following a call to sqlite3_backup_finish().
9486  **
9487  ** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no
9488  ** sqlite3_backup_step() errors occurred, regardless of whether or not
9489  ** sqlite3_backup_step() completed.
9490  ** ^If an out-of-memory condition or IO error occurred during any prior
9491  ** sqlite3_backup_step() call on the same [sqlite3_backup] object, then
9492  ** sqlite3_backup_finish() returns the corresponding [error code].
9493  **
9494  ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
9495  ** is not a permanent error and does not affect the return value of
9496  ** sqlite3_backup_finish().
9497  **
9498  ** [[sqlite3_backup_remaining()]] [[sqlite3_backup_pagecount()]]
9499  ** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b>
9500  **
9501  ** ^The sqlite3_backup_remaining() routine returns the number of pages still
9502  ** to be backed up at the conclusion of the most recent sqlite3_backup_step().
9503  ** ^The sqlite3_backup_pagecount() routine returns the total number of pages
9504  ** in the source database at the conclusion of the most recent
9505  ** sqlite3_backup_step().
9506  ** ^(The values returned by these functions are only updated by
9507  ** sqlite3_backup_step(). If the source database is modified in a way that
9508  ** changes the size of the source database or the number of pages remaining,
9509  ** those changes are not reflected in the output of sqlite3_backup_pagecount()
9510  ** and sqlite3_backup_remaining() until after the next
9511  ** sqlite3_backup_step().)^
9512  **
9513  ** <b>Concurrent Usage of Database Handles</b>
9514  **
9515  ** ^The source [database connection] may be used by the application for other
9516  ** purposes while a backup operation is underway or being initialized.
9517  ** ^If SQLite is compiled and configured to support threadsafe database
9518  ** connections, then the source database connection may be used concurrently
9519  ** from within other threads.
9520  **
9521  ** However, the application must guarantee that the destination
9522  ** [database connection] is not passed to any other API (by any thread) after
9523  ** sqlite3_backup_init() is called and before the corresponding call to
9524  ** sqlite3_backup_finish().  SQLite does not currently check to see
9525  ** if the application incorrectly accesses the destination [database connection]
9526  ** and so no error code is reported, but the operations may malfunction
9527  ** nevertheless.  Use of the destination database connection while a
9528  ** backup is in progress might also cause a mutex deadlock.
9529  **
9530  ** If running in [shared cache mode], the application must
9531  ** guarantee that the shared cache used by the destination database
9532  ** is not accessed while the backup is running. In practice this means
9533  ** that the application must guarantee that the disk file being
9534  ** backed up to is not accessed by any connection within the process,
9535  ** not just the specific connection that was passed to sqlite3_backup_init().
9536  **
9537  ** The [sqlite3_backup] object itself is partially threadsafe. Multiple
9538  ** threads may safely make multiple concurrent calls to sqlite3_backup_step().
9539  ** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount()
9540  ** APIs are not strictly speaking threadsafe. If they are invoked at the
9541  ** same time as another thread is invoking sqlite3_backup_step() it is
9542  ** possible that they return invalid values.
9543  **
9544  ** <b>Alternatives To Using The Backup API</b>
9545  **
9546  ** Other techniques for safely creating a consistent backup of an SQLite
9547  ** database include:
9548  **
9549  ** <ul>
9550  ** <li> The [VACUUM INTO] command.
9551  ** <li> The [sqlite3_rsync] utility program.
9552  ** </ul>
9553  */
9554  SQLITE_API sqlite3_backup *sqlite3_backup_init(
9555    sqlite3 *pDest,                        /* Destination database handle */
9556    const char *zDestName,                 /* Destination database name */
9557    sqlite3 *pSource,                      /* Source database handle */
9558    const char *zSourceName                /* Source database name */
9559  );
9560  SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage);
9561  SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p);
9562  SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);
9563  SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);
9564  
9565  /*
9566  ** CAPI3REF: Unlock Notification
9567  ** METHOD: sqlite3
9568  **
9569  ** ^When running in shared-cache mode, a database operation may fail with
9570  ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or
9571  ** individual tables within the shared-cache cannot be obtained. See
9572  ** [SQLite Shared-Cache Mode] for a description of shared-cache locking.
9573  ** ^This API may be used to register a callback that SQLite will invoke
9574  ** when the connection currently holding the required lock relinquishes it.
9575  ** ^This API is only available if the library was compiled with the
9576  ** [SQLITE_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined.
9577  **
9578  ** See Also: [Using the SQLite Unlock Notification Feature].
9579  **
9580  ** ^Shared-cache locks are released when a database connection concludes
9581  ** its current transaction, either by committing it or rolling it back.
9582  **
9583  ** ^When a connection (known as the blocked connection) fails to obtain a
9584  ** shared-cache lock and SQLITE_LOCKED is returned to the caller, the
9585  ** identity of the database connection (the blocking connection) that
9586  ** has locked the required resource is stored internally. ^After an
9587  ** application receives an SQLITE_LOCKED error, it may call the
9588  ** sqlite3_unlock_notify() method with the blocked connection handle as
9589  ** the first argument to register for a callback that will be invoked
9590  ** when the blocking connection's current transaction is concluded. ^The
9591  ** callback is invoked from within the [sqlite3_step] or [sqlite3_close]
9592  ** call that concludes the blocking connection's transaction.
9593  **
9594  ** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,
9595  ** there is a chance that the blocking connection will have already
9596  ** concluded its transaction by the time sqlite3_unlock_notify() is invoked.
9597  ** If this happens, then the specified callback is invoked immediately,
9598  ** from within the call to sqlite3_unlock_notify().)^
9599  **
9600  ** ^If the blocked connection is attempting to obtain a write-lock on a
9601  ** shared-cache table, and more than one other connection currently holds
9602  ** a read-lock on the same table, then SQLite arbitrarily selects one of
9603  ** the other connections to use as the blocking connection.
9604  **
9605  ** ^(There may be at most one unlock-notify callback registered by a
9606  ** blocked connection. If sqlite3_unlock_notify() is called when the
9607  ** blocked connection already has a registered unlock-notify callback,
9608  ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is
9609  ** called with a NULL pointer as its second argument, then any existing
9610  ** unlock-notify callback is canceled. ^The blocked connection's
9611  ** unlock-notify callback may also be canceled by closing the blocked
9612  ** connection using [sqlite3_close()].
9613  **
9614  ** The unlock-notify callback is not reentrant. If an application invokes
9615  ** any sqlite3_xxx API functions from within an unlock-notify callback, a
9616  ** crash or deadlock may be the result.
9617  **
9618  ** ^Unless deadlock is detected (see below), sqlite3_unlock_notify() always
9619  ** returns SQLITE_OK.
9620  **
9621  ** <b>Callback Invocation Details</b>
9622  **
9623  ** When an unlock-notify callback is registered, the application provides a
9624  ** single void* pointer that is passed to the callback when it is invoked.
9625  ** However, the signature of the callback function allows SQLite to pass
9626  ** it an array of void* context pointers. The first argument passed to
9627  ** an unlock-notify callback is a pointer to an array of void* pointers,
9628  ** and the second is the number of entries in the array.
9629  **
9630  ** When a blocking connection's transaction is concluded, there may be
9631  ** more than one blocked connection that has registered for an unlock-notify
9632  ** callback. ^If two or more such blocked connections have specified the
9633  ** same callback function, then instead of invoking the callback function
9634  ** multiple times, it is invoked once with the set of void* context pointers
9635  ** specified by the blocked connections bundled together into an array.
9636  ** This gives the application an opportunity to prioritize any actions
9637  ** related to the set of unblocked database connections.
9638  **
9639  ** <b>Deadlock Detection</b>
9640  **
9641  ** Assuming that after registering for an unlock-notify callback a
9642  ** database waits for the callback to be issued before taking any further
9643  ** action (a reasonable assumption), then using this API may cause the
9644  ** application to deadlock. For example, if connection X is waiting for
9645  ** connection Y's transaction to be concluded, and similarly connection
9646  ** Y is waiting on connection X's transaction, then neither connection
9647  ** will proceed and the system may remain deadlocked indefinitely.
9648  **
9649  ** To avoid this scenario, the sqlite3_unlock_notify() performs deadlock
9650  ** detection. ^If a given call to sqlite3_unlock_notify() would put the
9651  ** system in a deadlocked state, then SQLITE_LOCKED is returned and no
9652  ** unlock-notify callback is registered. The system is said to be in
9653  ** a deadlocked state if connection A has registered for an unlock-notify
9654  ** callback on the conclusion of connection B's transaction, and connection
9655  ** B has itself registered for an unlock-notify callback when connection
9656  ** A's transaction is concluded. ^Indirect deadlock is also detected, so
9657  ** the system is also considered to be deadlocked if connection B has
9658  ** registered for an unlock-notify callback on the conclusion of connection
9659  ** C's transaction, where connection C is waiting on connection A. ^Any
9660  ** number of levels of indirection are allowed.
9661  **
9662  ** <b>The "DROP TABLE" Exception</b>
9663  **
9664  ** When a call to [sqlite3_step()] returns SQLITE_LOCKED, it is almost
9665  ** always appropriate to call sqlite3_unlock_notify(). There is however,
9666  ** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement,
9667  ** SQLite checks if there are any currently executing SELECT statements
9668  ** that belong to the same connection. If there are, SQLITE_LOCKED is
9669  ** returned. In this case there is no "blocking connection", so invoking
9670  ** sqlite3_unlock_notify() results in the unlock-notify callback being
9671  ** invoked immediately. If the application then re-attempts the "DROP TABLE"
9672  ** or "DROP INDEX" query, an infinite loop might be the result.
9673  **
9674  ** One way around this problem is to check the extended error code returned
9675  ** by an sqlite3_step() call. ^(If there is a blocking connection, then the
9676  ** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in
9677  ** the special "DROP TABLE/INDEX" case, the extended error code is just
9678  ** SQLITE_LOCKED.)^
9679  */
9680  SQLITE_API int sqlite3_unlock_notify(
9681    sqlite3 *pBlocked,                          /* Waiting connection */
9682    void (*xNotify)(void **apArg, int nArg),    /* Callback function to invoke */
9683    void *pNotifyArg                            /* Argument to pass to xNotify */
9684  );
9685  
9686  
9687  /*
9688  ** CAPI3REF: String Comparison
9689  **
9690  ** ^The [sqlite3_stricmp()] and [sqlite3_strnicmp()] APIs allow applications
9691  ** and extensions to compare the contents of two buffers containing UTF-8
9692  ** strings in a case-independent fashion, using the same definition of "case
9693  ** independence" that SQLite uses internally when comparing identifiers.
9694  */
9695  SQLITE_API int sqlite3_stricmp(const char *, const char *);
9696  SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);
9697  
9698  /*
9699  ** CAPI3REF: String Globbing
9700  *
9701  ** ^The [sqlite3_strglob(P,X)] interface returns zero if and only if
9702  ** string X matches the [GLOB] pattern P.
9703  ** ^The definition of [GLOB] pattern matching used in
9704  ** [sqlite3_strglob(P,X)] is the same as for the "X GLOB P" operator in the
9705  ** SQL dialect understood by SQLite.  ^The [sqlite3_strglob(P,X)] function
9706  ** is case sensitive.
9707  **
9708  ** Note that this routine returns zero on a match and non-zero if the strings
9709  ** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()].
9710  **
9711  ** See also: [sqlite3_strlike()].
9712  */
9713  SQLITE_API int sqlite3_strglob(const char *zGlob, const char *zStr);
9714  
9715  /*
9716  ** CAPI3REF: String LIKE Matching
9717  *
9718  ** ^The [sqlite3_strlike(P,X,E)] interface returns zero if and only if
9719  ** string X matches the [LIKE] pattern P with escape character E.
9720  ** ^The definition of [LIKE] pattern matching used in
9721  ** [sqlite3_strlike(P,X,E)] is the same as for the "X LIKE P ESCAPE E"
9722  ** operator in the SQL dialect understood by SQLite.  ^For "X LIKE P" without
9723  ** the ESCAPE clause, set the E parameter of [sqlite3_strlike(P,X,E)] to 0.
9724  ** ^As with the LIKE operator, the [sqlite3_strlike(P,X,E)] function is case
9725  ** insensitive - equivalent upper and lower case ASCII characters match
9726  ** one another.
9727  **
9728  ** ^The [sqlite3_strlike(P,X,E)] function matches Unicode characters, though
9729  ** only ASCII characters are case folded.
9730  **
9731  ** Note that this routine returns zero on a match and non-zero if the strings
9732  ** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()].
9733  **
9734  ** See also: [sqlite3_strglob()].
9735  */
9736  SQLITE_API int sqlite3_strlike(const char *zGlob, const char *zStr, unsigned int cEsc);
9737  
9738  /*
9739  ** CAPI3REF: Error Logging Interface
9740  **
9741  ** ^The [sqlite3_log()] interface writes a message into the [error log]
9742  ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].
9743  ** ^If logging is enabled, the zFormat string and subsequent arguments are
9744  ** used with [sqlite3_snprintf()] to generate the final output string.
9745  **
9746  ** The sqlite3_log() interface is intended for use by extensions such as
9747  ** virtual tables, collating functions, and SQL functions.  While there is
9748  ** nothing to prevent an application from calling sqlite3_log(), doing so
9749  ** is considered bad form.
9750  **
9751  ** The zFormat string must not be NULL.
9752  **
9753  ** To avoid deadlocks and other threading problems, the sqlite3_log() routine
9754  ** will not use dynamically allocated memory.  The log message is stored in
9755  ** a fixed-length buffer on the stack.  If the log message is longer than
9756  ** a few hundred characters, it will be truncated to the length of the
9757  ** buffer.
9758  */
9759  SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...);
9760  
9761  /*
9762  ** CAPI3REF: Write-Ahead Log Commit Hook
9763  ** METHOD: sqlite3
9764  **
9765  ** ^The [sqlite3_wal_hook()] function is used to register a callback that
9766  ** is invoked each time data is committed to a database in wal mode.
9767  **
9768  ** ^(The callback is invoked by SQLite after the commit has taken place and
9769  ** the associated write-lock on the database released)^, so the implementation
9770  ** may read, write or [checkpoint] the database as required.
9771  **
9772  ** ^The first parameter passed to the callback function when it is invoked
9773  ** is a copy of the third parameter passed to sqlite3_wal_hook() when
9774  ** registering the callback. ^The second is a copy of the database handle.
9775  ** ^The third parameter is the name of the database that was written to -
9776  ** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter
9777  ** is the number of pages currently in the write-ahead log file,
9778  ** including those that were just committed.
9779  **
9780  ** The callback function should normally return [SQLITE_OK].  ^If an error
9781  ** code is returned, that error will propagate back up through the
9782  ** SQLite code base to cause the statement that provoked the callback
9783  ** to report an error, though the commit will have still occurred. If the
9784  ** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value
9785  ** that does not correspond to any valid SQLite error code, the results
9786  ** are undefined.
9787  **
9788  ** A single database handle may have at most a single write-ahead log callback
9789  ** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any
9790  ** previously registered write-ahead log callback. ^The return value is
9791  ** a copy of the third parameter from the previous call, if any, or 0.
9792  ** ^Note that the [sqlite3_wal_autocheckpoint()] interface and the
9793  ** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will
9794  ** overwrite any prior [sqlite3_wal_hook()] settings.
9795  */
9796  SQLITE_API void *sqlite3_wal_hook(
9797    sqlite3*,
9798    int(*)(void *,sqlite3*,const char*,int),
9799    void*
9800  );
9801  
9802  /*
9803  ** CAPI3REF: Configure an auto-checkpoint
9804  ** METHOD: sqlite3
9805  **
9806  ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around
9807  ** [sqlite3_wal_hook()] that causes any database on [database connection] D
9808  ** to automatically [checkpoint]
9809  ** after committing a transaction if there are N or
9810  ** more frames in the [write-ahead log] file.  ^Passing zero or
9811  ** a negative value as the nFrame parameter disables automatic
9812  ** checkpoints entirely.
9813  **
9814  ** ^The callback registered by this function replaces any existing callback
9815  ** registered using [sqlite3_wal_hook()].  ^Likewise, registering a callback
9816  ** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism
9817  ** configured by this function.
9818  **
9819  ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface
9820  ** from SQL.
9821  **
9822  ** ^Checkpoints initiated by this mechanism are
9823  ** [sqlite3_wal_checkpoint_v2|PASSIVE].
9824  **
9825  ** ^Every new [database connection] defaults to having the auto-checkpoint
9826  ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]
9827  ** pages.  The use of this interface
9828  ** is only necessary if the default setting is found to be suboptimal
9829  ** for a particular application.
9830  */
9831  SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
9832  
9833  /*
9834  ** CAPI3REF: Checkpoint a database
9835  ** METHOD: sqlite3
9836  **
9837  ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
9838  ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
9839  **
9840  ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
9841  ** [write-ahead log] for database X on [database connection] D to be
9842  ** transferred into the database file and for the write-ahead log to
9843  ** be reset.  See the [checkpointing] documentation for addition
9844  ** information.
9845  **
9846  ** This interface used to be the only way to cause a checkpoint to
9847  ** occur.  But then the newer and more powerful [sqlite3_wal_checkpoint_v2()]
9848  ** interface was added.  This interface is retained for backwards
9849  ** compatibility and as a convenience for applications that need to manually
9850  ** start a callback but which do not need the full power (and corresponding
9851  ** complication) of [sqlite3_wal_checkpoint_v2()].
9852  */
9853  SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
9854  
9855  /*
9856  ** CAPI3REF: Checkpoint a database
9857  ** METHOD: sqlite3
9858  **
9859  ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
9860  ** operation on database X of [database connection] D in mode M.  Status
9861  ** information is written back into integers pointed to by L and C.)^
9862  ** ^(The M parameter must be a valid [checkpoint mode]:)^
9863  **
9864  ** <dl>
9865  ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>
9866  **   ^Checkpoint as many frames as possible without waiting for any database
9867  **   readers or writers to finish, then sync the database file if all frames
9868  **   in the log were checkpointed. ^The [busy-handler callback]
9869  **   is never invoked in the SQLITE_CHECKPOINT_PASSIVE mode.
9870  **   ^On the other hand, passive mode might leave the checkpoint unfinished
9871  **   if there are concurrent readers or writers.
9872  **
9873  ** <dt>SQLITE_CHECKPOINT_FULL<dd>
9874  **   ^This mode blocks (it invokes the
9875  **   [sqlite3_busy_handler|busy-handler callback]) until there is no
9876  **   database writer and all readers are reading from the most recent database
9877  **   snapshot. ^It then checkpoints all frames in the log file and syncs the
9878  **   database file. ^This mode blocks new database writers while it is pending,
9879  **   but new database readers are allowed to continue unimpeded.
9880  **
9881  ** <dt>SQLITE_CHECKPOINT_RESTART<dd>
9882  **   ^This mode works the same way as SQLITE_CHECKPOINT_FULL with the addition
9883  **   that after checkpointing the log file it blocks (calls the
9884  **   [busy-handler callback])
9885  **   until all readers are reading from the database file only. ^This ensures
9886  **   that the next writer will restart the log file from the beginning.
9887  **   ^Like SQLITE_CHECKPOINT_FULL, this mode blocks new
9888  **   database writer attempts while it is pending, but does not impede readers.
9889  **
9890  ** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd>
9891  **   ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the
9892  **   addition that it also truncates the log file to zero bytes just prior
9893  **   to a successful return.
9894  ** </dl>
9895  **
9896  ** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in
9897  ** the log file or to -1 if the checkpoint could not run because
9898  ** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not
9899  ** NULL,then *pnCkpt is set to the total number of checkpointed frames in the
9900  ** log file (including any that were already checkpointed before the function
9901  ** was called) or to -1 if the checkpoint could not run due to an error or
9902  ** because the database is not in WAL mode. ^Note that upon successful
9903  ** completion of an SQLITE_CHECKPOINT_TRUNCATE, the log file will have been
9904  ** truncated to zero bytes and so both *pnLog and *pnCkpt will be set to zero.
9905  **
9906  ** ^All calls obtain an exclusive "checkpoint" lock on the database file. ^If
9907  ** any other process is running a checkpoint operation at the same time, the
9908  ** lock cannot be obtained and SQLITE_BUSY is returned. ^Even if there is a
9909  ** busy-handler configured, it will not be invoked in this case.
9910  **
9911  ** ^The SQLITE_CHECKPOINT_FULL, RESTART and TRUNCATE modes also obtain the
9912  ** exclusive "writer" lock on the database file. ^If the writer lock cannot be
9913  ** obtained immediately, and a busy-handler is configured, it is invoked and
9914  ** the writer lock retried until either the busy-handler returns 0 or the lock
9915  ** is successfully obtained. ^The busy-handler is also invoked while waiting for
9916  ** database readers as described above. ^If the busy-handler returns 0 before
9917  ** the writer lock is obtained or while waiting for database readers, the
9918  ** checkpoint operation proceeds from that point in the same way as
9919  ** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible
9920  ** without blocking any further. ^SQLITE_BUSY is returned in this case.
9921  **
9922  ** ^If parameter zDb is NULL or points to a zero length string, then the
9923  ** specified operation is attempted on all WAL databases [attached] to
9924  ** [database connection] db.  In this case the
9925  ** values written to output parameters *pnLog and *pnCkpt are undefined. ^If
9926  ** an SQLITE_BUSY error is encountered when processing one or more of the
9927  ** attached WAL databases, the operation is still attempted on any remaining
9928  ** attached databases and SQLITE_BUSY is returned at the end. ^If any other
9929  ** error occurs while processing an attached database, processing is abandoned
9930  ** and the error code is returned to the caller immediately. ^If no error
9931  ** (SQLITE_BUSY or otherwise) is encountered while processing the attached
9932  ** databases, SQLITE_OK is returned.
9933  **
9934  ** ^If database zDb is the name of an attached database that is not in WAL
9935  ** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. ^If
9936  ** zDb is not NULL (or a zero length string) and is not the name of any
9937  ** attached database, SQLITE_ERROR is returned to the caller.
9938  **
9939  ** ^Unless it returns SQLITE_MISUSE,
9940  ** the sqlite3_wal_checkpoint_v2() interface
9941  ** sets the error information that is queried by
9942  ** [sqlite3_errcode()] and [sqlite3_errmsg()].
9943  **
9944  ** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface
9945  ** from SQL.
9946  */
9947  SQLITE_API int sqlite3_wal_checkpoint_v2(
9948    sqlite3 *db,                    /* Database handle */
9949    const char *zDb,                /* Name of attached database (or NULL) */
9950    int eMode,                      /* SQLITE_CHECKPOINT_* value */
9951    int *pnLog,                     /* OUT: Size of WAL log in frames */
9952    int *pnCkpt                     /* OUT: Total number of frames checkpointed */
9953  );
9954  
9955  /*
9956  ** CAPI3REF: Checkpoint Mode Values
9957  ** KEYWORDS: {checkpoint mode}
9958  **
9959  ** These constants define all valid values for the "checkpoint mode" passed
9960  ** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface.
9961  ** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the
9962  ** meaning of each of these checkpoint modes.
9963  */
9964  #define SQLITE_CHECKPOINT_PASSIVE  0  /* Do as much as possible w/o blocking */
9965  #define SQLITE_CHECKPOINT_FULL     1  /* Wait for writers, then checkpoint */
9966  #define SQLITE_CHECKPOINT_RESTART  2  /* Like FULL but wait for readers */
9967  #define SQLITE_CHECKPOINT_TRUNCATE 3  /* Like RESTART but also truncate WAL */
9968  
9969  /*
9970  ** CAPI3REF: Virtual Table Interface Configuration
9971  **
9972  ** This function may be called by either the [xConnect] or [xCreate] method
9973  ** of a [virtual table] implementation to configure
9974  ** various facets of the virtual table interface.
9975  **
9976  ** If this interface is invoked outside the context of an xConnect or
9977  ** xCreate virtual table method then the behavior is undefined.
9978  **
9979  ** In the call sqlite3_vtab_config(D,C,...) the D parameter is the
9980  ** [database connection] in which the virtual table is being created and
9981  ** which is passed in as the first argument to the [xConnect] or [xCreate]
9982  ** method that is invoking sqlite3_vtab_config().  The C parameter is one
9983  ** of the [virtual table configuration options].  The presence and meaning
9984  ** of parameters after C depend on which [virtual table configuration option]
9985  ** is used.
9986  */
9987  SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...);
9988  
9989  /*
9990  ** CAPI3REF: Virtual Table Configuration Options
9991  ** KEYWORDS: {virtual table configuration options}
9992  ** KEYWORDS: {virtual table configuration option}
9993  **
9994  ** These macros define the various options to the
9995  ** [sqlite3_vtab_config()] interface that [virtual table] implementations
9996  ** can use to customize and optimize their behavior.
9997  **
9998  ** <dl>
9999  ** [[SQLITE_VTAB_CONSTRAINT_SUPPORT]]
10000  ** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT</dt>
10001  ** <dd>Calls of the form
10002  ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
10003  ** where X is an integer.  If X is zero, then the [virtual table] whose
10004  ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
10005  ** support constraints.  In this configuration (which is the default) if
10006  ** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire
10007  ** statement is rolled back as if [ON CONFLICT | OR ABORT] had been
10008  ** specified as part of the user's SQL statement, regardless of the actual
10009  ** ON CONFLICT mode specified.
10010  **
10011  ** If X is non-zero, then the virtual table implementation guarantees
10012  ** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before
10013  ** any modifications to internal or persistent data structures have been made.
10014  ** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite
10015  ** is able to roll back a statement or database transaction, and abandon
10016  ** or continue processing the current SQL statement as appropriate.
10017  ** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns
10018  ** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode
10019  ** had been ABORT.
10020  **
10021  ** Virtual table implementations that are required to handle OR REPLACE
10022  ** must do so within the [xUpdate] method. If a call to the
10023  ** [sqlite3_vtab_on_conflict()] function indicates that the current ON
10024  ** CONFLICT policy is REPLACE, the virtual table implementation should
10025  ** silently replace the appropriate rows within the xUpdate callback and
10026  ** return SQLITE_OK. Or, if this is not possible, it may return
10027  ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
10028  ** constraint handling.
10029  ** </dd>
10030  **
10031  ** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt>
10032  ** <dd>Calls of the form
10033  ** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the
10034  ** the [xConnect] or [xCreate] methods of a [virtual table] implementation
10035  ** prohibits that virtual table from being used from within triggers and
10036  ** views.
10037  ** </dd>
10038  **
10039  ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
10040  ** <dd>Calls of the form
10041  ** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the
10042  ** [xConnect] or [xCreate] methods of a [virtual table] implementation
10043  ** identify that virtual table as being safe to use from within triggers
10044  ** and views.  Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the
10045  ** virtual table can do no serious harm even if it is controlled by a
10046  ** malicious hacker.  Developers should avoid setting the SQLITE_VTAB_INNOCUOUS
10047  ** flag unless absolutely necessary.
10048  ** </dd>
10049  **
10050  ** [[SQLITE_VTAB_USES_ALL_SCHEMAS]]<dt>SQLITE_VTAB_USES_ALL_SCHEMAS</dt>
10051  ** <dd>Calls of the form
10052  ** [sqlite3_vtab_config](db,SQLITE_VTAB_USES_ALL_SCHEMA) from within the
10053  ** the [xConnect] or [xCreate] methods of a [virtual table] implementation
10054  ** instruct the query planner to begin at least a read transaction on
10055  ** all schemas ("main", "temp", and any ATTACH-ed databases) whenever the
10056  ** virtual table is used.
10057  ** </dd>
10058  ** </dl>
10059  */
10060  #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
10061  #define SQLITE_VTAB_INNOCUOUS          2
10062  #define SQLITE_VTAB_DIRECTONLY         3
10063  #define SQLITE_VTAB_USES_ALL_SCHEMAS   4
10064  
10065  /*
10066  ** CAPI3REF: Determine The Virtual Table Conflict Policy
10067  **
10068  ** This function may only be called from within a call to the [xUpdate] method
10069  ** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The
10070  ** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL],
10071  ** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode
10072  ** of the SQL statement that triggered the call to the [xUpdate] method of the
10073  ** [virtual table].
10074  */
10075  SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
10076  
10077  /*
10078  ** CAPI3REF: Determine If Virtual Table Column Access Is For UPDATE
10079  **
10080  ** If the sqlite3_vtab_nochange(X) routine is called within the [xColumn]
10081  ** method of a [virtual table], then it might return true if the
10082  ** column is being fetched as part of an UPDATE operation during which the
10083  ** column value will not change.  The virtual table implementation can use
10084  ** this hint as permission to substitute a return value that is less
10085  ** expensive to compute and that the corresponding
10086  ** [xUpdate] method understands as a "no-change" value.
10087  **
10088  ** If the [xColumn] method calls sqlite3_vtab_nochange() and finds that
10089  ** the column is not changed by the UPDATE statement, then the xColumn
10090  ** method can optionally return without setting a result, without calling
10091  ** any of the [sqlite3_result_int|sqlite3_result_xxxxx() interfaces].
10092  ** In that case, [sqlite3_value_nochange(X)] will return true for the
10093  ** same column in the [xUpdate] method.
10094  **
10095  ** The sqlite3_vtab_nochange() routine is an optimization.  Virtual table
10096  ** implementations should continue to give a correct answer even if the
10097  ** sqlite3_vtab_nochange() interface were to always return false.  In the
10098  ** current implementation, the sqlite3_vtab_nochange() interface does always
10099  ** returns false for the enhanced [UPDATE FROM] statement.
10100  */
10101  SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
10102  
10103  /*
10104  ** CAPI3REF: Determine The Collation For a Virtual Table Constraint
10105  ** METHOD: sqlite3_index_info
10106  **
10107  ** This function may only be called from within a call to the [xBestIndex]
10108  ** method of a [virtual table].  This function returns a pointer to a string
10109  ** that is the name of the appropriate collation sequence to use for text
10110  ** comparisons on the constraint identified by its arguments.
10111  **
10112  ** The first argument must be the pointer to the [sqlite3_index_info] object
10113  ** that is the first parameter to the xBestIndex() method. The second argument
10114  ** must be an index into the aConstraint[] array belonging to the
10115  ** sqlite3_index_info structure passed to xBestIndex.
10116  **
10117  ** Important:
10118  ** The first parameter must be the same pointer that is passed into the
10119  ** xBestMethod() method.  The first parameter may not be a pointer to a
10120  ** different [sqlite3_index_info] object, even an exact copy.
10121  **
10122  ** The return value is computed as follows:
10123  **
10124  ** <ol>
10125  ** <li><p> If the constraint comes from a WHERE clause expression that contains
10126  **         a [COLLATE operator], then the name of the collation specified by
10127  **         that COLLATE operator is returned.
10128  ** <li><p> If there is no COLLATE operator, but the column that is the subject
10129  **         of the constraint specifies an alternative collating sequence via
10130  **         a [COLLATE clause] on the column definition within the CREATE TABLE
10131  **         statement that was passed into [sqlite3_declare_vtab()], then the
10132  **         name of that alternative collating sequence is returned.
10133  ** <li><p> Otherwise, "BINARY" is returned.
10134  ** </ol>
10135  */
10136  SQLITE_API const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
10137  
10138  /*
10139  ** CAPI3REF: Determine if a virtual table query is DISTINCT
10140  ** METHOD: sqlite3_index_info
10141  **
10142  ** This API may only be used from within an [xBestIndex|xBestIndex method]
10143  ** of a [virtual table] implementation. The result of calling this
10144  ** interface from outside of xBestIndex() is undefined and probably harmful.
10145  **
10146  ** ^The sqlite3_vtab_distinct() interface returns an integer between 0 and
10147  ** 3.  The integer returned by sqlite3_vtab_distinct()
10148  ** gives the virtual table additional information about how the query
10149  ** planner wants the output to be ordered. As long as the virtual table
10150  ** can meet the ordering requirements of the query planner, it may set
10151  ** the "orderByConsumed" flag.
10152  **
10153  ** <ol><li value="0"><p>
10154  ** ^If the sqlite3_vtab_distinct() interface returns 0, that means
10155  ** that the query planner needs the virtual table to return all rows in the
10156  ** sort order defined by the "nOrderBy" and "aOrderBy" fields of the
10157  ** [sqlite3_index_info] object.  This is the default expectation.  If the
10158  ** virtual table outputs all rows in sorted order, then it is always safe for
10159  ** the xBestIndex method to set the "orderByConsumed" flag, regardless of
10160  ** the return value from sqlite3_vtab_distinct().
10161  ** <li value="1"><p>
10162  ** ^(If the sqlite3_vtab_distinct() interface returns 1, that means
10163  ** that the query planner does not need the rows to be returned in sorted order
10164  ** as long as all rows with the same values in all columns identified by the
10165  ** "aOrderBy" field are adjacent.)^  This mode is used when the query planner
10166  ** is doing a GROUP BY.
10167  ** <li value="2"><p>
10168  ** ^(If the sqlite3_vtab_distinct() interface returns 2, that means
10169  ** that the query planner does not need the rows returned in any particular
10170  ** order, as long as rows with the same values in all columns identified
10171  ** by "aOrderBy" are adjacent.)^  ^(Furthermore, when two or more rows
10172  ** contain the same values for all columns identified by "colUsed", all but
10173  ** one such row may optionally be omitted from the result.)^
10174  ** The virtual table is not required to omit rows that are duplicates
10175  ** over the "colUsed" columns, but if the virtual table can do that without
10176  ** too much extra effort, it could potentially help the query to run faster.
10177  ** This mode is used for a DISTINCT query.
10178  ** <li value="3"><p>
10179  ** ^(If the sqlite3_vtab_distinct() interface returns 3, that means the
10180  ** virtual table must return rows in the order defined by "aOrderBy" as
10181  ** if the sqlite3_vtab_distinct() interface had returned 0.  However if
10182  ** two or more rows in the result have the same values for all columns
10183  ** identified by "colUsed", then all but one such row may optionally be
10184  ** omitted.)^  Like when the return value is 2, the virtual table
10185  ** is not required to omit rows that are duplicates over the "colUsed"
10186  ** columns, but if the virtual table can do that without
10187  ** too much extra effort, it could potentially help the query to run faster.
10188  ** This mode is used for queries
10189  ** that have both DISTINCT and ORDER BY clauses.
10190  ** </ol>
10191  **
10192  ** <p>The following table summarizes the conditions under which the
10193  ** virtual table is allowed to set the "orderByConsumed" flag based on
10194  ** the value returned by sqlite3_vtab_distinct().  This table is a
10195  ** restatement of the previous four paragraphs:
10196  **
10197  ** <table border=1 cellspacing=0 cellpadding=10 width="90%">
10198  ** <tr>
10199  ** <td valign="top">sqlite3_vtab_distinct() return value
10200  ** <td valign="top">Rows are returned in aOrderBy order
10201  ** <td valign="top">Rows with the same value in all aOrderBy columns are adjacent
10202  ** <td valign="top">Duplicates over all colUsed columns may be omitted
10203  ** <tr><td>0<td>yes<td>yes<td>no
10204  ** <tr><td>1<td>no<td>yes<td>no
10205  ** <tr><td>2<td>no<td>yes<td>yes
10206  ** <tr><td>3<td>yes<td>yes<td>yes
10207  ** </table>
10208  **
10209  ** ^For the purposes of comparing virtual table output values to see if the
10210  ** values are the same value for sorting purposes, two NULL values are considered
10211  ** to be the same.  In other words, the comparison operator is "IS"
10212  ** (or "IS NOT DISTINCT FROM") and not "==".
10213  **
10214  ** If a virtual table implementation is unable to meet the requirements
10215  ** specified above, then it must not set the "orderByConsumed" flag in the
10216  ** [sqlite3_index_info] object or an incorrect answer may result.
10217  **
10218  ** ^A virtual table implementation is always free to return rows in any order
10219  ** it wants, as long as the "orderByConsumed" flag is not set.  ^When the
10220  ** "orderByConsumed" flag is unset, the query planner will add extra
10221  ** [bytecode] to ensure that the final results returned by the SQL query are
10222  ** ordered correctly.  The use of the "orderByConsumed" flag and the
10223  ** sqlite3_vtab_distinct() interface is merely an optimization.  ^Careful
10224  ** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed"
10225  ** flag might help queries against a virtual table to run faster.  Being
10226  ** overly aggressive and setting the "orderByConsumed" flag when it is not
10227  ** valid to do so, on the other hand, might cause SQLite to return incorrect
10228  ** results.
10229  */
10230  SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*);
10231  
10232  /*
10233  ** CAPI3REF: Identify and handle IN constraints in xBestIndex
10234  **
10235  ** This interface may only be used from within an
10236  ** [xBestIndex|xBestIndex() method] of a [virtual table] implementation.
10237  ** The result of invoking this interface from any other context is
10238  ** undefined and probably harmful.
10239  **
10240  ** ^(A constraint on a virtual table of the form
10241  ** "[IN operator|column IN (...)]" is
10242  ** communicated to the xBestIndex method as a
10243  ** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^  If xBestIndex wants to use
10244  ** this constraint, it must set the corresponding
10245  ** aConstraintUsage[].argvIndex to a positive integer.  ^(Then, under
10246  ** the usual mode of handling IN operators, SQLite generates [bytecode]
10247  ** that invokes the [xFilter|xFilter() method] once for each value
10248  ** on the right-hand side of the IN operator.)^  Thus the virtual table
10249  ** only sees a single value from the right-hand side of the IN operator
10250  ** at a time.
10251  **
10252  ** In some cases, however, it would be advantageous for the virtual
10253  ** table to see all values on the right-hand of the IN operator all at
10254  ** once.  The sqlite3_vtab_in() interfaces facilitates this in two ways:
10255  **
10256  ** <ol>
10257  ** <li><p>
10258  **   ^A call to sqlite3_vtab_in(P,N,-1) will return true (non-zero)
10259  **   if and only if the [sqlite3_index_info|P->aConstraint][N] constraint
10260  **   is an [IN operator] that can be processed all at once.  ^In other words,
10261  **   sqlite3_vtab_in() with -1 in the third argument is a mechanism
10262  **   by which the virtual table can ask SQLite if all-at-once processing
10263  **   of the IN operator is even possible.
10264  **
10265  ** <li><p>
10266  **   ^A call to sqlite3_vtab_in(P,N,F) with F==1 or F==0 indicates
10267  **   to SQLite that the virtual table does or does not want to process
10268  **   the IN operator all-at-once, respectively.  ^Thus when the third
10269  **   parameter (F) is non-negative, this interface is the mechanism by
10270  **   which the virtual table tells SQLite how it wants to process the
10271  **   IN operator.
10272  ** </ol>
10273  **
10274  ** ^The sqlite3_vtab_in(P,N,F) interface can be invoked multiple times
10275  ** within the same xBestIndex method call.  ^For any given P,N pair,
10276  ** the return value from sqlite3_vtab_in(P,N,F) will always be the same
10277  ** within the same xBestIndex call.  ^If the interface returns true
10278  ** (non-zero), that means that the constraint is an IN operator
10279  ** that can be processed all-at-once.  ^If the constraint is not an IN
10280  ** operator or cannot be processed all-at-once, then the interface returns
10281  ** false.
10282  **
10283  ** ^(All-at-once processing of the IN operator is selected if both of the
10284  ** following conditions are met:
10285  **
10286  ** <ol>
10287  ** <li><p> The P->aConstraintUsage[N].argvIndex value is set to a positive
10288  ** integer.  This is how the virtual table tells SQLite that it wants to
10289  ** use the N-th constraint.
10290  **
10291  ** <li><p> The last call to sqlite3_vtab_in(P,N,F) for which F was
10292  ** non-negative had F>=1.
10293  ** </ol>)^
10294  **
10295  ** ^If either or both of the conditions above are false, then SQLite uses
10296  ** the traditional one-at-a-time processing strategy for the IN constraint.
10297  ** ^If both conditions are true, then the argvIndex-th parameter to the
10298  ** xFilter method will be an [sqlite3_value] that appears to be NULL,
10299  ** but which can be passed to [sqlite3_vtab_in_first()] and
10300  ** [sqlite3_vtab_in_next()] to find all values on the right-hand side
10301  ** of the IN constraint.
10302  */
10303  SQLITE_API int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle);
10304  
10305  /*
10306  ** CAPI3REF: Find all elements on the right-hand side of an IN constraint.
10307  **
10308  ** These interfaces are only useful from within the
10309  ** [xFilter|xFilter() method] of a [virtual table] implementation.
10310  ** The result of invoking these interfaces from any other context
10311  ** is undefined and probably harmful.
10312  **
10313  ** The X parameter in a call to sqlite3_vtab_in_first(X,P) or
10314  ** sqlite3_vtab_in_next(X,P) should be one of the parameters to the
10315  ** xFilter method which invokes these routines, and specifically
10316  ** a parameter that was previously selected for all-at-once IN constraint
10317  ** processing using the [sqlite3_vtab_in()] interface in the
10318  ** [xBestIndex|xBestIndex method].  ^(If the X parameter is not
10319  ** an xFilter argument that was selected for all-at-once IN constraint
10320  ** processing, then these routines return [SQLITE_ERROR].)^
10321  **
10322  ** ^(Use these routines to access all values on the right-hand side
10323  ** of the IN constraint using code like the following:
10324  **
10325  ** <blockquote><pre>
10326  ** &nbsp;  for(rc=sqlite3_vtab_in_first(pList, &pVal);
10327  ** &nbsp;      rc==SQLITE_OK && pVal;
10328  ** &nbsp;      rc=sqlite3_vtab_in_next(pList, &pVal)
10329  ** &nbsp;  ){
10330  ** &nbsp;    // do something with pVal
10331  ** &nbsp;  }
10332  ** &nbsp;  if( rc!=SQLITE_OK ){
10333  ** &nbsp;    // an error has occurred
10334  ** &nbsp;  }
10335  ** </pre></blockquote>)^
10336  **
10337  ** ^On success, the sqlite3_vtab_in_first(X,P) and sqlite3_vtab_in_next(X,P)
10338  ** routines return SQLITE_OK and set *P to point to the first or next value
10339  ** on the RHS of the IN constraint.  ^If there are no more values on the
10340  ** right hand side of the IN constraint, then *P is set to NULL and these
10341  ** routines return [SQLITE_DONE].  ^The return value might be
10342  ** some other value, such as SQLITE_NOMEM, in the event of a malfunction.
10343  **
10344  ** The *ppOut values returned by these routines are only valid until the
10345  ** next call to either of these routines or until the end of the xFilter
10346  ** method from which these routines were called.  If the virtual table
10347  ** implementation needs to retain the *ppOut values for longer, it must make
10348  ** copies.  The *ppOut values are [protected sqlite3_value|protected].
10349  */
10350  SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut);
10351  SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut);
10352  
10353  /*
10354  ** CAPI3REF: Constraint values in xBestIndex()
10355  ** METHOD: sqlite3_index_info
10356  **
10357  ** This API may only be used from within the [xBestIndex|xBestIndex method]
10358  ** of a [virtual table] implementation. The result of calling this interface
10359  ** from outside of an xBestIndex method are undefined and probably harmful.
10360  **
10361  ** ^When the sqlite3_vtab_rhs_value(P,J,V) interface is invoked from within
10362  ** the [xBestIndex] method of a [virtual table] implementation, with P being
10363  ** a copy of the [sqlite3_index_info] object pointer passed into xBestIndex and
10364  ** J being a 0-based index into P->aConstraint[], then this routine
10365  ** attempts to set *V to the value of the right-hand operand of
10366  ** that constraint if the right-hand operand is known.  ^If the
10367  ** right-hand operand is not known, then *V is set to a NULL pointer.
10368  ** ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if
10369  ** and only if *V is set to a value.  ^The sqlite3_vtab_rhs_value(P,J,V)
10370  ** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th
10371  ** constraint is not available.  ^The sqlite3_vtab_rhs_value() interface
10372  ** can return a result code other than SQLITE_OK or SQLITE_NOTFOUND if
10373  ** something goes wrong.
10374  **
10375  ** The sqlite3_vtab_rhs_value() interface is usually only successful if
10376  ** the right-hand operand of a constraint is a literal value in the original
10377  ** SQL statement.  If the right-hand operand is an expression or a reference
10378  ** to some other column or a [host parameter], then sqlite3_vtab_rhs_value()
10379  ** will probably return [SQLITE_NOTFOUND].
10380  **
10381  ** ^(Some constraints, such as [SQLITE_INDEX_CONSTRAINT_ISNULL] and
10382  ** [SQLITE_INDEX_CONSTRAINT_ISNOTNULL], have no right-hand operand.  For such
10383  ** constraints, sqlite3_vtab_rhs_value() always returns SQLITE_NOTFOUND.)^
10384  **
10385  ** ^The [sqlite3_value] object returned in *V is a protected sqlite3_value
10386  ** and remains valid for the duration of the xBestIndex method call.
10387  ** ^When xBestIndex returns, the sqlite3_value object returned by
10388  ** sqlite3_vtab_rhs_value() is automatically deallocated.
10389  **
10390  ** The "_rhs_" in the name of this routine is an abbreviation for
10391  ** "Right-Hand Side".
10392  */
10393  SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal);
10394  
10395  /*
10396  ** CAPI3REF: Conflict resolution modes
10397  ** KEYWORDS: {conflict resolution mode}
10398  **
10399  ** These constants are returned by [sqlite3_vtab_on_conflict()] to
10400  ** inform a [virtual table] implementation of the [ON CONFLICT] mode
10401  ** for the SQL statement being evaluated.
10402  **
10403  ** Note that the [SQLITE_IGNORE] constant is also used as a potential
10404  ** return value from the [sqlite3_set_authorizer()] callback and that
10405  ** [SQLITE_ABORT] is also a [result code].
10406  */
10407  #define SQLITE_ROLLBACK 1
10408  /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */
10409  #define SQLITE_FAIL     3
10410  /* #define SQLITE_ABORT 4  // Also an error code */
10411  #define SQLITE_REPLACE  5
10412  
10413  /*
10414  ** CAPI3REF: Prepared Statement Scan Status Opcodes
10415  ** KEYWORDS: {scanstatus options}
10416  **
10417  ** The following constants can be used for the T parameter to the
10418  ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface.  Each constant designates a
10419  ** different metric for sqlite3_stmt_scanstatus() to return.
10420  **
10421  ** When the value returned to V is a string, space to hold that string is
10422  ** managed by the prepared statement S and will be automatically freed when
10423  ** S is finalized.
10424  **
10425  ** Not all values are available for all query elements. When a value is
10426  ** not available, the output variable is set to -1 if the value is numeric,
10427  ** or to NULL if it is a string (SQLITE_SCANSTAT_NAME).
10428  **
10429  ** <dl>
10430  ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
10431  ** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be
10432  ** set to the total number of times that the X-th loop has run.</dd>
10433  **
10434  ** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>
10435  ** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be set
10436  ** to the total number of rows examined by all iterations of the X-th loop.</dd>
10437  **
10438  ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
10439  ** <dd>^The "double" variable pointed to by the V parameter will be set to the
10440  ** query planner's estimate for the average number of rows output from each
10441  ** iteration of the X-th loop.  If the query planner's estimate was accurate,
10442  ** then this value will approximate the quotient NVISIT/NLOOP and the
10443  ** product of this value for all prior loops with the same SELECTID will
10444  ** be the NLOOP value for the current loop.</dd>
10445  **
10446  ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
10447  ** <dd>^The "const char *" variable pointed to by the V parameter will be set
10448  ** to a zero-terminated UTF-8 string containing the name of the index or table
10449  ** used for the X-th loop.</dd>
10450  **
10451  ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
10452  ** <dd>^The "const char *" variable pointed to by the V parameter will be set
10453  ** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
10454  ** description for the X-th loop.</dd>
10455  **
10456  ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECTID</dt>
10457  ** <dd>^The "int" variable pointed to by the V parameter will be set to the
10458  ** id for the X-th query plan element. The id value is unique within the
10459  ** statement. The select-id is the same value as is output in the first
10460  ** column of an [EXPLAIN QUERY PLAN] query.</dd>
10461  **
10462  ** [[SQLITE_SCANSTAT_PARENTID]] <dt>SQLITE_SCANSTAT_PARENTID</dt>
10463  ** <dd>The "int" variable pointed to by the V parameter will be set to the
10464  ** id of the parent of the current query element, if applicable, or
10465  ** to zero if the query element has no parent. This is the same value as
10466  ** returned in the second column of an [EXPLAIN QUERY PLAN] query.</dd>
10467  **
10468  ** [[SQLITE_SCANSTAT_NCYCLE]] <dt>SQLITE_SCANSTAT_NCYCLE</dt>
10469  ** <dd>The sqlite3_int64 output value is set to the number of cycles,
10470  ** according to the processor time-stamp counter, that elapsed while the
10471  ** query element was being processed. This value is not available for
10472  ** all query elements - if it is unavailable the output variable is
10473  ** set to -1.</dd>
10474  ** </dl>
10475  */
10476  #define SQLITE_SCANSTAT_NLOOP    0
10477  #define SQLITE_SCANSTAT_NVISIT   1
10478  #define SQLITE_SCANSTAT_EST      2
10479  #define SQLITE_SCANSTAT_NAME     3
10480  #define SQLITE_SCANSTAT_EXPLAIN  4
10481  #define SQLITE_SCANSTAT_SELECTID 5
10482  #define SQLITE_SCANSTAT_PARENTID 6
10483  #define SQLITE_SCANSTAT_NCYCLE   7
10484  
10485  /*
10486  ** CAPI3REF: Prepared Statement Scan Status
10487  ** METHOD: sqlite3_stmt
10488  **
10489  ** These interfaces return information about the predicted and measured
10490  ** performance for pStmt.  Advanced applications can use this
10491  ** interface to compare the predicted and the measured performance and
10492  ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
10493  **
10494  ** Since this interface is expected to be rarely used, it is only
10495  ** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS]
10496  ** compile-time option.
10497  **
10498  ** The "iScanStatusOp" parameter determines which status information to return.
10499  ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
10500  ** of this interface is undefined. ^The requested measurement is written into
10501  ** a variable pointed to by the "pOut" parameter.
10502  **
10503  ** The "flags" parameter must be passed a mask of flags. At present only
10504  ** one flag is defined - SQLITE_SCANSTAT_COMPLEX. If SQLITE_SCANSTAT_COMPLEX
10505  ** is specified, then status information is available for all elements
10506  ** of a query plan that are reported by "EXPLAIN QUERY PLAN" output. If
10507  ** SQLITE_SCANSTAT_COMPLEX is not specified, then only query plan elements
10508  ** that correspond to query loops (the "SCAN..." and "SEARCH..." elements of
10509  ** the EXPLAIN QUERY PLAN output) are available. Invoking API
10510  ** sqlite3_stmt_scanstatus() is equivalent to calling
10511  ** sqlite3_stmt_scanstatus_v2() with a zeroed flags parameter.
10512  **
10513  ** Parameter "idx" identifies the specific query element to retrieve statistics
10514  ** for. Query elements are numbered starting from zero. A value of -1 may
10515  ** retrieve statistics for the entire query. ^If idx is out of range
10516  ** - less than -1 or greater than or equal to the total number of query
10517  ** elements used to implement the statement - a non-zero value is returned and
10518  ** the variable that pOut points to is unchanged.
10519  **
10520  ** See also: [sqlite3_stmt_scanstatus_reset()]
10521  */
10522  SQLITE_API int sqlite3_stmt_scanstatus(
10523    sqlite3_stmt *pStmt,      /* Prepared statement for which info desired */
10524    int idx,                  /* Index of loop to report on */
10525    int iScanStatusOp,        /* Information desired.  SQLITE_SCANSTAT_* */
10526    void *pOut                /* Result written here */
10527  );
10528  SQLITE_API int sqlite3_stmt_scanstatus_v2(
10529    sqlite3_stmt *pStmt,      /* Prepared statement for which info desired */
10530    int idx,                  /* Index of loop to report on */
10531    int iScanStatusOp,        /* Information desired.  SQLITE_SCANSTAT_* */
10532    int flags,                /* Mask of flags defined below */
10533    void *pOut                /* Result written here */
10534  );
10535  
10536  /*
10537  ** CAPI3REF: Prepared Statement Scan Status
10538  ** KEYWORDS: {scan status flags}
10539  */
10540  #define SQLITE_SCANSTAT_COMPLEX 0x0001
10541  
10542  /*
10543  ** CAPI3REF: Zero Scan-Status Counters
10544  ** METHOD: sqlite3_stmt
10545  **
10546  ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
10547  **
10548  ** This API is only available if the library is built with pre-processor
10549  ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
10550  */
10551  SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
10552  
10553  /*
10554  ** CAPI3REF: Flush caches to disk mid-transaction
10555  ** METHOD: sqlite3
10556  **
10557  ** ^If a write-transaction is open on [database connection] D when the
10558  ** [sqlite3_db_cacheflush(D)] interface is invoked, any dirty
10559  ** pages in the pager-cache that are not currently in use are written out
10560  ** to disk. A dirty page may be in use if a database cursor created by an
10561  ** active SQL statement is reading from it, or if it is page 1 of a database
10562  ** file (page 1 is always "in use").  ^The [sqlite3_db_cacheflush(D)]
10563  ** interface flushes caches for all schemas - "main", "temp", and
10564  ** any [attached] databases.
10565  **
10566  ** ^If this function needs to obtain extra database locks before dirty pages
10567  ** can be flushed to disk, it does so. ^If those locks cannot be obtained
10568  ** immediately and there is a busy-handler callback configured, it is invoked
10569  ** in the usual manner. ^If the required lock still cannot be obtained, then
10570  ** the database is skipped and an attempt made to flush any dirty pages
10571  ** belonging to the next (if any) database. ^If any databases are skipped
10572  ** because locks cannot be obtained, but no other error occurs, this
10573  ** function returns SQLITE_BUSY.
10574  **
10575  ** ^If any other error occurs while flushing dirty pages to disk (for
10576  ** example an IO error or out-of-memory condition), then processing is
10577  ** abandoned and an SQLite [error code] is returned to the caller immediately.
10578  **
10579  ** ^Otherwise, if no error occurs, [sqlite3_db_cacheflush()] returns SQLITE_OK.
10580  **
10581  ** ^This function does not set the database handle error code or message
10582  ** returned by the [sqlite3_errcode()] and [sqlite3_errmsg()] functions.
10583  */
10584  SQLITE_API int sqlite3_db_cacheflush(sqlite3*);
10585  
10586  /*
10587  ** CAPI3REF: The pre-update hook.
10588  ** METHOD: sqlite3
10589  **
10590  ** ^These interfaces are only available if SQLite is compiled using the
10591  ** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option.
10592  **
10593  ** ^The [sqlite3_preupdate_hook()] interface registers a callback function
10594  ** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation
10595  ** on a database table.
10596  ** ^At most one preupdate hook may be registered at a time on a single
10597  ** [database connection]; each call to [sqlite3_preupdate_hook()] overrides
10598  ** the previous setting.
10599  ** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()]
10600  ** with a NULL pointer as the second parameter.
10601  ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as
10602  ** the first parameter to callbacks.
10603  **
10604  ** ^The preupdate hook only fires for changes to real database tables; the
10605  ** preupdate hook is not invoked for changes to [virtual tables] or to
10606  ** system tables like sqlite_sequence or sqlite_stat1.
10607  **
10608  ** ^The second parameter to the preupdate callback is a pointer to
10609  ** the [database connection] that registered the preupdate hook.
10610  ** ^The third parameter to the preupdate callback is one of the constants
10611  ** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the
10612  ** kind of update operation that is about to occur.
10613  ** ^(The fourth parameter to the preupdate callback is the name of the
10614  ** database within the database connection that is being modified.  This
10615  ** will be "main" for the main database or "temp" for TEMP tables or
10616  ** the name given after the AS keyword in the [ATTACH] statement for attached
10617  ** databases.)^
10618  ** ^The fifth parameter to the preupdate callback is the name of the
10619  ** table that is being modified.
10620  **
10621  ** For an UPDATE or DELETE operation on a [rowid table], the sixth
10622  ** parameter passed to the preupdate callback is the initial [rowid] of the
10623  ** row being modified or deleted. For an INSERT operation on a rowid table,
10624  ** or any operation on a WITHOUT ROWID table, the value of the sixth
10625  ** parameter is undefined. For an INSERT or UPDATE on a rowid table the
10626  ** seventh parameter is the final rowid value of the row being inserted
10627  ** or updated. The value of the seventh parameter passed to the callback
10628  ** function is not defined for operations on WITHOUT ROWID tables, or for
10629  ** DELETE operations on rowid tables.
10630  **
10631  ** ^The sqlite3_preupdate_hook(D,C,P) function returns the P argument from
10632  ** the previous call on the same [database connection] D, or NULL for
10633  ** the first call on D.
10634  **
10635  ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
10636  ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
10637  ** provide additional information about a preupdate event. These routines
10638  ** may only be called from within a preupdate callback.  Invoking any of
10639  ** these routines from outside of a preupdate callback or with a
10640  ** [database connection] pointer that is different from the one supplied
10641  ** to the preupdate callback results in undefined and probably undesirable
10642  ** behavior.
10643  **
10644  ** ^The [sqlite3_preupdate_count(D)] interface returns the number of columns
10645  ** in the row that is being inserted, updated, or deleted.
10646  **
10647  ** ^The [sqlite3_preupdate_old(D,N,P)] interface writes into P a pointer to
10648  ** a [protected sqlite3_value] that contains the value of the Nth column of
10649  ** the table row before it is updated.  The N parameter must be between 0
10650  ** and one less than the number of columns or the behavior will be
10651  ** undefined. This must only be used within SQLITE_UPDATE and SQLITE_DELETE
10652  ** preupdate callbacks; if it is used by an SQLITE_INSERT callback then the
10653  ** behavior is undefined.  The [sqlite3_value] that P points to
10654  ** will be destroyed when the preupdate callback returns.
10655  **
10656  ** ^The [sqlite3_preupdate_new(D,N,P)] interface writes into P a pointer to
10657  ** a [protected sqlite3_value] that contains the value of the Nth column of
10658  ** the table row after it is updated.  The N parameter must be between 0
10659  ** and one less than the number of columns or the behavior will be
10660  ** undefined. This must only be used within SQLITE_INSERT and SQLITE_UPDATE
10661  ** preupdate callbacks; if it is used by an SQLITE_DELETE callback then the
10662  ** behavior is undefined.  The [sqlite3_value] that P points to
10663  ** will be destroyed when the preupdate callback returns.
10664  **
10665  ** ^The [sqlite3_preupdate_depth(D)] interface returns 0 if the preupdate
10666  ** callback was invoked as a result of a direct insert, update, or delete
10667  ** operation; or 1 for inserts, updates, or deletes invoked by top-level
10668  ** triggers; or 2 for changes resulting from triggers called by top-level
10669  ** triggers; and so forth.
10670  **
10671  ** When the [sqlite3_blob_write()] API is used to update a blob column,
10672  ** the pre-update hook is invoked with SQLITE_DELETE, because
10673  ** the new values are not yet available. In this case, when a
10674  ** callback made with op==SQLITE_DELETE is actually a write using the
10675  ** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns
10676  ** the index of the column being written. In other cases, where the
10677  ** pre-update hook is being invoked for some other reason, including a
10678  ** regular DELETE, sqlite3_preupdate_blobwrite() returns -1.
10679  **
10680  ** See also:  [sqlite3_update_hook()]
10681  */
10682  #if defined(SQLITE_ENABLE_PREUPDATE_HOOK)
10683  SQLITE_API void *sqlite3_preupdate_hook(
10684    sqlite3 *db,
10685    void(*xPreUpdate)(
10686      void *pCtx,                   /* Copy of third arg to preupdate_hook() */
10687      sqlite3 *db,                  /* Database handle */
10688      int op,                       /* SQLITE_UPDATE, DELETE or INSERT */
10689      char const *zDb,              /* Database name */
10690      char const *zName,            /* Table name */
10691      sqlite3_int64 iKey1,          /* Rowid of row about to be deleted/updated */
10692      sqlite3_int64 iKey2           /* New rowid value (for a rowid UPDATE) */
10693    ),
10694    void*
10695  );
10696  SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
10697  SQLITE_API int sqlite3_preupdate_count(sqlite3 *);
10698  SQLITE_API int sqlite3_preupdate_depth(sqlite3 *);
10699  SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
10700  SQLITE_API int sqlite3_preupdate_blobwrite(sqlite3 *);
10701  #endif
10702  
10703  /*
10704  ** CAPI3REF: Low-level system error code
10705  ** METHOD: sqlite3
10706  **
10707  ** ^Attempt to return the underlying operating system error code or error
10708  ** number that caused the most recent I/O error or failure to open a file.
10709  ** The return value is OS-dependent.  For example, on unix systems, after
10710  ** [sqlite3_open_v2()] returns [SQLITE_CANTOPEN], this interface could be
10711  ** called to get back the underlying "errno" that caused the problem, such
10712  ** as ENOSPC, EAUTH, EISDIR, and so forth.
10713  */
10714  SQLITE_API int sqlite3_system_errno(sqlite3*);
10715  
10716  /*
10717  ** CAPI3REF: Database Snapshot
10718  ** KEYWORDS: {snapshot} {sqlite3_snapshot}
10719  **
10720  ** An instance of the snapshot object records the state of a [WAL mode]
10721  ** database for some specific point in history.
10722  **
10723  ** In [WAL mode], multiple [database connections] that are open on the
10724  ** same database file can each be reading a different historical version
10725  ** of the database file.  When a [database connection] begins a read
10726  ** transaction, that connection sees an unchanging copy of the database
10727  ** as it existed for the point in time when the transaction first started.
10728  ** Subsequent changes to the database from other connections are not seen
10729  ** by the reader until a new read transaction is started.
10730  **
10731  ** The sqlite3_snapshot object records state information about an historical
10732  ** version of the database file so that it is possible to later open a new read
10733  ** transaction that sees that historical version of the database rather than
10734  ** the most recent version.
10735  */
10736  typedef struct sqlite3_snapshot {
10737    unsigned char hidden[48];
10738  } sqlite3_snapshot;
10739  
10740  /*
10741  ** CAPI3REF: Record A Database Snapshot
10742  ** CONSTRUCTOR: sqlite3_snapshot
10743  **
10744  ** ^The [sqlite3_snapshot_get(D,S,P)] interface attempts to make a
10745  ** new [sqlite3_snapshot] object that records the current state of
10746  ** schema S in database connection D.  ^On success, the
10747  ** [sqlite3_snapshot_get(D,S,P)] interface writes a pointer to the newly
10748  ** created [sqlite3_snapshot] object into *P and returns SQLITE_OK.
10749  ** If there is not already a read-transaction open on schema S when
10750  ** this function is called, one is opened automatically.
10751  **
10752  ** If a read-transaction is opened by this function, then it is guaranteed
10753  ** that the returned snapshot object may not be invalidated by a database
10754  ** writer or checkpointer until after the read-transaction is closed. This
10755  ** is not guaranteed if a read-transaction is already open when this
10756  ** function is called. In that case, any subsequent write or checkpoint
10757  ** operation on the database may invalidate the returned snapshot handle,
10758  ** even while the read-transaction remains open.
10759  **
10760  ** The following must be true for this function to succeed. If any of
10761  ** the following statements are false when sqlite3_snapshot_get() is
10762  ** called, SQLITE_ERROR is returned. The final value of *P is undefined
10763  ** in this case.
10764  **
10765  ** <ul>
10766  **   <li> The database handle must not be in [autocommit mode].
10767  **
10768  **   <li> Schema S of [database connection] D must be a [WAL mode] database.
10769  **
10770  **   <li> There must not be a write transaction open on schema S of database
10771  **        connection D.
10772  **
10773  **   <li> One or more transactions must have been written to the current wal
10774  **        file since it was created on disk (by any connection). This means
10775  **        that a snapshot cannot be taken on a wal mode database with no wal
10776  **        file immediately after it is first opened. At least one transaction
10777  **        must be written to it first.
10778  ** </ul>
10779  **
10780  ** This function may also return SQLITE_NOMEM.  If it is called with the
10781  ** database handle in autocommit mode but fails for some other reason,
10782  ** whether or not a read transaction is opened on schema S is undefined.
10783  **
10784  ** The [sqlite3_snapshot] object returned from a successful call to
10785  ** [sqlite3_snapshot_get()] must be freed using [sqlite3_snapshot_free()]
10786  ** to avoid a memory leak.
10787  **
10788  ** The [sqlite3_snapshot_get()] interface is only available when the
10789  ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
10790  */
10791  SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_get(
10792    sqlite3 *db,
10793    const char *zSchema,
10794    sqlite3_snapshot **ppSnapshot
10795  );
10796  
10797  /*
10798  ** CAPI3REF: Start a read transaction on an historical snapshot
10799  ** METHOD: sqlite3_snapshot
10800  **
10801  ** ^The [sqlite3_snapshot_open(D,S,P)] interface either starts a new read
10802  ** transaction or upgrades an existing one for schema S of
10803  ** [database connection] D such that the read transaction refers to
10804  ** historical [snapshot] P, rather than the most recent change to the
10805  ** database. ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK
10806  ** on success or an appropriate [error code] if it fails.
10807  **
10808  ** ^In order to succeed, the database connection must not be in
10809  ** [autocommit mode] when [sqlite3_snapshot_open(D,S,P)] is called. If there
10810  ** is already a read transaction open on schema S, then the database handle
10811  ** must have no active statements (SELECT statements that have been passed
10812  ** to sqlite3_step() but not sqlite3_reset() or sqlite3_finalize()).
10813  ** SQLITE_ERROR is returned if either of these conditions is violated, or
10814  ** if schema S does not exist, or if the snapshot object is invalid.
10815  **
10816  ** ^A call to sqlite3_snapshot_open() will fail to open if the specified
10817  ** snapshot has been overwritten by a [checkpoint]. In this case
10818  ** SQLITE_ERROR_SNAPSHOT is returned.
10819  **
10820  ** If there is already a read transaction open when this function is
10821  ** invoked, then the same read transaction remains open (on the same
10822  ** database snapshot) if SQLITE_ERROR, SQLITE_BUSY or SQLITE_ERROR_SNAPSHOT
10823  ** is returned. If another error code - for example SQLITE_PROTOCOL or an
10824  ** SQLITE_IOERR error code - is returned, then the final state of the
10825  ** read transaction is undefined. If SQLITE_OK is returned, then the
10826  ** read transaction is now open on database snapshot P.
10827  **
10828  ** ^(A call to [sqlite3_snapshot_open(D,S,P)] will fail if the
10829  ** database connection D does not know that the database file for
10830  ** schema S is in [WAL mode].  A database connection might not know
10831  ** that the database file is in [WAL mode] if there has been no prior
10832  ** I/O on that database connection, or if the database entered [WAL mode]
10833  ** after the most recent I/O on the database connection.)^
10834  ** (Hint: Run "[PRAGMA application_id]" against a newly opened
10835  ** database connection in order to make it ready to use snapshots.)
10836  **
10837  ** The [sqlite3_snapshot_open()] interface is only available when the
10838  ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
10839  */
10840  SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_open(
10841    sqlite3 *db,
10842    const char *zSchema,
10843    sqlite3_snapshot *pSnapshot
10844  );
10845  
10846  /*
10847  ** CAPI3REF: Destroy a snapshot
10848  ** DESTRUCTOR: sqlite3_snapshot
10849  **
10850  ** ^The [sqlite3_snapshot_free(P)] interface destroys [sqlite3_snapshot] P.
10851  ** The application must eventually free every [sqlite3_snapshot] object
10852  ** using this routine to avoid a memory leak.
10853  **
10854  ** The [sqlite3_snapshot_free()] interface is only available when the
10855  ** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.
10856  */
10857  SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_snapshot_free(sqlite3_snapshot*);
10858  
10859  /*
10860  ** CAPI3REF: Compare the ages of two snapshot handles.
10861  ** METHOD: sqlite3_snapshot
10862  **
10863  ** The sqlite3_snapshot_cmp(P1, P2) interface is used to compare the ages
10864  ** of two valid snapshot handles.
10865  **
10866  ** If the two snapshot handles are not associated with the same database
10867  ** file, the result of the comparison is undefined.
10868  **
10869  ** Additionally, the result of the comparison is only valid if both of the
10870  ** snapshot handles were obtained by calling sqlite3_snapshot_get() since the
10871  ** last time the wal file was deleted. The wal file is deleted when the
10872  ** database is changed back to rollback mode or when the number of database
10873  ** clients drops to zero. If either snapshot handle was obtained before the
10874  ** wal file was last deleted, the value returned by this function
10875  ** is undefined.
10876  **
10877  ** Otherwise, this API returns a negative value if P1 refers to an older
10878  ** snapshot than P2, zero if the two handles refer to the same database
10879  ** snapshot, and a positive value if P1 is a newer snapshot than P2.
10880  **
10881  ** This interface is only available if SQLite is compiled with the
10882  ** [SQLITE_ENABLE_SNAPSHOT] option.
10883  */
10884  SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp(
10885    sqlite3_snapshot *p1,
10886    sqlite3_snapshot *p2
10887  );
10888  
10889  /*
10890  ** CAPI3REF: Recover snapshots from a wal file
10891  ** METHOD: sqlite3_snapshot
10892  **
10893  ** If a [WAL file] remains on disk after all database connections close
10894  ** (either through the use of the [SQLITE_FCNTL_PERSIST_WAL] [file control]
10895  ** or because the last process to have the database opened exited without
10896  ** calling [sqlite3_close()]) and a new connection is subsequently opened
10897  ** on that database and [WAL file], the [sqlite3_snapshot_open()] interface
10898  ** will only be able to open the last transaction added to the WAL file
10899  ** even though the WAL file contains other valid transactions.
10900  **
10901  ** This function attempts to scan the WAL file associated with database zDb
10902  ** of database handle db and make all valid snapshots available to
10903  ** sqlite3_snapshot_open(). It is an error if there is already a read
10904  ** transaction open on the database, or if the database is not a WAL mode
10905  ** database.
10906  **
10907  ** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
10908  **
10909  ** This interface is only available if SQLite is compiled with the
10910  ** [SQLITE_ENABLE_SNAPSHOT] option.
10911  */
10912  SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);
10913  
10914  /*
10915  ** CAPI3REF: Serialize a database
10916  **
10917  ** The sqlite3_serialize(D,S,P,F) interface returns a pointer to
10918  ** memory that is a serialization of the S database on
10919  ** [database connection] D.  If S is a NULL pointer, the main database is used.
10920  ** If P is not a NULL pointer, then the size of the database in bytes
10921  ** is written into *P.
10922  **
10923  ** For an ordinary on-disk database file, the serialization is just a
10924  ** copy of the disk file.  For an in-memory database or a "TEMP" database,
10925  ** the serialization is the same sequence of bytes which would be written
10926  ** to disk if that database were backed up to disk.
10927  **
10928  ** The usual case is that sqlite3_serialize() copies the serialization of
10929  ** the database into memory obtained from [sqlite3_malloc64()] and returns
10930  ** a pointer to that memory.  The caller is responsible for freeing the
10931  ** returned value to avoid a memory leak.  However, if the F argument
10932  ** contains the SQLITE_SERIALIZE_NOCOPY bit, then no memory allocations
10933  ** are made, and the sqlite3_serialize() function will return a pointer
10934  ** to the contiguous memory representation of the database that SQLite
10935  ** is currently using for that database, or NULL if no such contiguous
10936  ** memory representation of the database exists.  A contiguous memory
10937  ** representation of the database will usually only exist if there has
10938  ** been a prior call to [sqlite3_deserialize(D,S,...)] with the same
10939  ** values of D and S.
10940  ** The size of the database is written into *P even if the
10941  ** SQLITE_SERIALIZE_NOCOPY bit is set but no contiguous copy
10942  ** of the database exists.
10943  **
10944  ** After the call, if the SQLITE_SERIALIZE_NOCOPY bit had been set,
10945  ** the returned buffer content will remain accessible and unchanged
10946  ** until either the next write operation on the connection or when
10947  ** the connection is closed, and applications must not modify the
10948  ** buffer. If the bit had been clear, the returned buffer will not
10949  ** be accessed by SQLite after the call.
10950  **
10951  ** A call to sqlite3_serialize(D,S,P,F) might return NULL even if the
10952  ** SQLITE_SERIALIZE_NOCOPY bit is omitted from argument F if a memory
10953  ** allocation error occurs.
10954  **
10955  ** This interface is omitted if SQLite is compiled with the
10956  ** [SQLITE_OMIT_DESERIALIZE] option.
10957  */
10958  SQLITE_API unsigned char *sqlite3_serialize(
10959    sqlite3 *db,           /* The database connection */
10960    const char *zSchema,   /* Which DB to serialize. ex: "main", "temp", ... */
10961    sqlite3_int64 *piSize, /* Write size of the DB here, if not NULL */
10962    unsigned int mFlags    /* Zero or more SQLITE_SERIALIZE_* flags */
10963  );
10964  
10965  /*
10966  ** CAPI3REF: Flags for sqlite3_serialize
10967  **
10968  ** Zero or more of the following constants can be OR-ed together for
10969  ** the F argument to [sqlite3_serialize(D,S,P,F)].
10970  **
10971  ** SQLITE_SERIALIZE_NOCOPY means that [sqlite3_serialize()] will return
10972  ** a pointer to contiguous in-memory database that it is currently using,
10973  ** without making a copy of the database.  If SQLite is not currently using
10974  ** a contiguous in-memory database, then this option causes
10975  ** [sqlite3_serialize()] to return a NULL pointer.  SQLite will only be
10976  ** using a contiguous in-memory database if it has been initialized by a
10977  ** prior call to [sqlite3_deserialize()].
10978  */
10979  #define SQLITE_SERIALIZE_NOCOPY 0x001   /* Do no memory allocations */
10980  
10981  /*
10982  ** CAPI3REF: Deserialize a database
10983  **
10984  ** The sqlite3_deserialize(D,S,P,N,M,F) interface causes the
10985  ** [database connection] D to disconnect from database S and then
10986  ** reopen S as an in-memory database based on the serialization contained
10987  ** in P.  The serialized database P is N bytes in size.  M is the size of
10988  ** the buffer P, which might be larger than N.  If M is larger than N, and
10989  ** the SQLITE_DESERIALIZE_READONLY bit is not set in F, then SQLite is
10990  ** permitted to add content to the in-memory database as long as the total
10991  ** size does not exceed M bytes.
10992  **
10993  ** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will
10994  ** invoke sqlite3_free() on the serialization buffer when the database
10995  ** connection closes.  If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then
10996  ** SQLite will try to increase the buffer size using sqlite3_realloc64()
10997  ** if writes on the database cause it to grow larger than M bytes.
10998  **
10999  ** Applications must not modify the buffer P or invalidate it before
11000  ** the database connection D is closed.
11001  **
11002  ** The sqlite3_deserialize() interface will fail with SQLITE_BUSY if the
11003  ** database is currently in a read transaction or is involved in a backup
11004  ** operation.
11005  **
11006  ** It is not possible to deserialize into the TEMP database.  If the
11007  ** S argument to sqlite3_deserialize(D,S,P,N,M,F) is "temp" then the
11008  ** function returns SQLITE_ERROR.
11009  **
11010  ** The deserialized database should not be in [WAL mode].  If the database
11011  ** is in WAL mode, then any attempt to use the database file will result
11012  ** in an [SQLITE_CANTOPEN] error.  The application can set the
11013  ** [file format version numbers] (bytes 18 and 19) of the input database P
11014  ** to 0x01 prior to invoking sqlite3_deserialize(D,S,P,N,M,F) to force the
11015  ** database file into rollback mode and work around this limitation.
11016  **
11017  ** If sqlite3_deserialize(D,S,P,N,M,F) fails for any reason and if the
11018  ** SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then
11019  ** [sqlite3_free()] is invoked on argument P prior to returning.
11020  **
11021  ** This interface is omitted if SQLite is compiled with the
11022  ** [SQLITE_OMIT_DESERIALIZE] option.
11023  */
11024  SQLITE_API int sqlite3_deserialize(
11025    sqlite3 *db,            /* The database connection */
11026    const char *zSchema,    /* Which DB to reopen with the deserialization */
11027    unsigned char *pData,   /* The serialized database content */
11028    sqlite3_int64 szDb,     /* Number of bytes in the deserialization */
11029    sqlite3_int64 szBuf,    /* Total size of buffer pData[] */
11030    unsigned mFlags         /* Zero or more SQLITE_DESERIALIZE_* flags */
11031  );
11032  
11033  /*
11034  ** CAPI3REF: Flags for sqlite3_deserialize()
11035  **
11036  ** The following are allowed values for the 6th argument (the F argument) to
11037  ** the [sqlite3_deserialize(D,S,P,N,M,F)] interface.
11038  **
11039  ** The SQLITE_DESERIALIZE_FREEONCLOSE means that the database serialization
11040  ** in the P argument is held in memory obtained from [sqlite3_malloc64()]
11041  ** and that SQLite should take ownership of this memory and automatically
11042  ** free it when it has finished using it.  Without this flag, the caller
11043  ** is responsible for freeing any dynamically allocated memory.
11044  **
11045  ** The SQLITE_DESERIALIZE_RESIZEABLE flag means that SQLite is allowed to
11046  ** grow the size of the database using calls to [sqlite3_realloc64()].  This
11047  ** flag should only be used if SQLITE_DESERIALIZE_FREEONCLOSE is also used.
11048  ** Without this flag, the deserialized database cannot increase in size beyond
11049  ** the number of bytes specified by the M parameter.
11050  **
11051  ** The SQLITE_DESERIALIZE_READONLY flag means that the deserialized database
11052  ** should be treated as read-only.
11053  */
11054  #define SQLITE_DESERIALIZE_FREEONCLOSE 1 /* Call sqlite3_free() on close */
11055  #define SQLITE_DESERIALIZE_RESIZEABLE  2 /* Resize using sqlite3_realloc64() */
11056  #define SQLITE_DESERIALIZE_READONLY    4 /* Database is read-only */
11057  
11058  /*
11059  ** Undo the hack that converts floating point types to integer for
11060  ** builds on processors without floating point support.
11061  */
11062  #ifdef SQLITE_OMIT_FLOATING_POINT
11063  # undef double
11064  #endif
11065  
11066  #if defined(__wasi__)
11067  # undef SQLITE_WASI
11068  # define SQLITE_WASI 1
11069  # ifndef SQLITE_OMIT_LOAD_EXTENSION
11070  #  define SQLITE_OMIT_LOAD_EXTENSION
11071  # endif
11072  # ifndef SQLITE_THREADSAFE
11073  #  define SQLITE_THREADSAFE 0
11074  # endif
11075  #endif
11076  
11077  #ifdef __cplusplus
11078  }  /* End of the 'extern "C"' block */
11079  #endif
11080  /* #endif for SQLITE3_H will be added by mksqlite3.tcl */
11081  
11082  /******** Begin file sqlite3rtree.h *********/
11083  /*
11084  ** 2010 August 30
11085  **
11086  ** The author disclaims copyright to this source code.  In place of
11087  ** a legal notice, here is a blessing:
11088  **
11089  **    May you do good and not evil.
11090  **    May you find forgiveness for yourself and forgive others.
11091  **    May you share freely, never taking more than you give.
11092  **
11093  *************************************************************************
11094  */
11095  
11096  #ifndef _SQLITE3RTREE_H_
11097  #define _SQLITE3RTREE_H_
11098  
11099  
11100  #ifdef __cplusplus
11101  extern "C" {
11102  #endif
11103  
11104  typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry;
11105  typedef struct sqlite3_rtree_query_info sqlite3_rtree_query_info;
11106  
11107  /* The double-precision datatype used by RTree depends on the
11108  ** SQLITE_RTREE_INT_ONLY compile-time option.
11109  */
11110  #ifdef SQLITE_RTREE_INT_ONLY
11111    typedef sqlite3_int64 sqlite3_rtree_dbl;
11112  #else
11113    typedef double sqlite3_rtree_dbl;
11114  #endif
11115  
11116  /*
11117  ** Register a geometry callback named zGeom that can be used as part of an
11118  ** R-Tree geometry query as follows:
11119  **
11120  **   SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...)
11121  */
11122  SQLITE_API int sqlite3_rtree_geometry_callback(
11123    sqlite3 *db,
11124    const char *zGeom,
11125    int (*xGeom)(sqlite3_rtree_geometry*, int, sqlite3_rtree_dbl*,int*),
11126    void *pContext
11127  );
11128  
11129  
11130  /*
11131  ** A pointer to a structure of the following type is passed as the first
11132  ** argument to callbacks registered using rtree_geometry_callback().
11133  */
11134  struct sqlite3_rtree_geometry {
11135    void *pContext;                 /* Copy of pContext passed to s_r_g_c() */
11136    int nParam;                     /* Size of array aParam[] */
11137    sqlite3_rtree_dbl *aParam;      /* Parameters passed to SQL geom function */
11138    void *pUser;                    /* Callback implementation user data */
11139    void (*xDelUser)(void *);       /* Called by SQLite to clean up pUser */
11140  };
11141  
11142  /*
11143  ** Register a 2nd-generation geometry callback named zScore that can be
11144  ** used as part of an R-Tree geometry query as follows:
11145  **
11146  **   SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zQueryFunc(... params ...)
11147  */
11148  SQLITE_API int sqlite3_rtree_query_callback(
11149    sqlite3 *db,
11150    const char *zQueryFunc,
11151    int (*xQueryFunc)(sqlite3_rtree_query_info*),
11152    void *pContext,
11153    void (*xDestructor)(void*)
11154  );
11155  
11156  
11157  /*
11158  ** A pointer to a structure of the following type is passed as the
11159  ** argument to scored geometry callback registered using
11160  ** sqlite3_rtree_query_callback().
11161  **
11162  ** Note that the first 5 fields of this structure are identical to
11163  ** sqlite3_rtree_geometry.  This structure is a subclass of
11164  ** sqlite3_rtree_geometry.
11165  */
11166  struct sqlite3_rtree_query_info {
11167    void *pContext;                   /* pContext from when function registered */
11168    int nParam;                       /* Number of function parameters */
11169    sqlite3_rtree_dbl *aParam;        /* value of function parameters */
11170    void *pUser;                      /* callback can use this, if desired */
11171    void (*xDelUser)(void*);          /* function to free pUser */
11172    sqlite3_rtree_dbl *aCoord;        /* Coordinates of node or entry to check */
11173    unsigned int *anQueue;            /* Number of pending entries in the queue */
11174    int nCoord;                       /* Number of coordinates */
11175    int iLevel;                       /* Level of current node or entry */
11176    int mxLevel;                      /* The largest iLevel value in the tree */
11177    sqlite3_int64 iRowid;             /* Rowid for current entry */
11178    sqlite3_rtree_dbl rParentScore;   /* Score of parent node */
11179    int eParentWithin;                /* Visibility of parent node */
11180    int eWithin;                      /* OUT: Visibility */
11181    sqlite3_rtree_dbl rScore;         /* OUT: Write the score here */
11182    /* The following fields are only available in 3.8.11 and later */
11183    sqlite3_value **apSqlParam;       /* Original SQL values of parameters */
11184  };
11185  
11186  /*
11187  ** Allowed values for sqlite3_rtree_query.eWithin and .eParentWithin.
11188  */
11189  #define NOT_WITHIN       0   /* Object completely outside of query region */
11190  #define PARTLY_WITHIN    1   /* Object partially overlaps query region */
11191  #define FULLY_WITHIN     2   /* Object fully contained within query region */
11192  
11193  
11194  #ifdef __cplusplus
11195  }  /* end of the 'extern "C"' block */
11196  #endif
11197  
11198  #endif  /* ifndef _SQLITE3RTREE_H_ */
11199  
11200  /******** End of sqlite3rtree.h *********/
11201  /******** Begin file sqlite3session.h *********/
11202  
11203  #if !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION)
11204  #define __SQLITESESSION_H_ 1
11205  
11206  /*
11207  ** Make sure we can call this stuff from C++.
11208  */
11209  #ifdef __cplusplus
11210  extern "C" {
11211  #endif
11212  
11213  
11214  /*
11215  ** CAPI3REF: Session Object Handle
11216  **
11217  ** An instance of this object is a [session] that can be used to
11218  ** record changes to a database.
11219  */
11220  typedef struct sqlite3_session sqlite3_session;
11221  
11222  /*
11223  ** CAPI3REF: Changeset Iterator Handle
11224  **
11225  ** An instance of this object acts as a cursor for iterating
11226  ** over the elements of a [changeset] or [patchset].
11227  */
11228  typedef struct sqlite3_changeset_iter sqlite3_changeset_iter;
11229  
11230  /*
11231  ** CAPI3REF: Create A New Session Object
11232  ** CONSTRUCTOR: sqlite3_session
11233  **
11234  ** Create a new session object attached to database handle db. If successful,
11235  ** a pointer to the new object is written to *ppSession and SQLITE_OK is
11236  ** returned. If an error occurs, *ppSession is set to NULL and an SQLite
11237  ** error code (e.g. SQLITE_NOMEM) is returned.
11238  **
11239  ** It is possible to create multiple session objects attached to a single
11240  ** database handle.
11241  **
11242  ** Session objects created using this function should be deleted using the
11243  ** [sqlite3session_delete()] function before the database handle that they
11244  ** are attached to is itself closed. If the database handle is closed before
11245  ** the session object is deleted, then the results of calling any session
11246  ** module function, including [sqlite3session_delete()] on the session object
11247  ** are undefined.
11248  **
11249  ** Because the session module uses the [sqlite3_preupdate_hook()] API, it
11250  ** is not possible for an application to register a pre-update hook on a
11251  ** database handle that has one or more session objects attached. Nor is
11252  ** it possible to create a session object attached to a database handle for
11253  ** which a pre-update hook is already defined. The results of attempting
11254  ** either of these things are undefined.
11255  **
11256  ** The session object will be used to create changesets for tables in
11257  ** database zDb, where zDb is either "main", or "temp", or the name of an
11258  ** attached database. It is not an error if database zDb is not attached
11259  ** to the database when the session object is created.
11260  */
11261  SQLITE_API int sqlite3session_create(
11262    sqlite3 *db,                    /* Database handle */
11263    const char *zDb,                /* Name of db (e.g. "main") */
11264    sqlite3_session **ppSession     /* OUT: New session object */
11265  );
11266  
11267  /*
11268  ** CAPI3REF: Delete A Session Object
11269  ** DESTRUCTOR: sqlite3_session
11270  **
11271  ** Delete a session object previously allocated using
11272  ** [sqlite3session_create()]. Once a session object has been deleted, the
11273  ** results of attempting to use pSession with any other session module
11274  ** function are undefined.
11275  **
11276  ** Session objects must be deleted before the database handle to which they
11277  ** are attached is closed. Refer to the documentation for
11278  ** [sqlite3session_create()] for details.
11279  */
11280  SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);
11281  
11282  /*
11283  ** CAPI3REF: Configure a Session Object
11284  ** METHOD: sqlite3_session
11285  **
11286  ** This method is used to configure a session object after it has been
11287  ** created. At present the only valid values for the second parameter are
11288  ** [SQLITE_SESSION_OBJCONFIG_SIZE] and [SQLITE_SESSION_OBJCONFIG_ROWID].
11289  **
11290  */
11291  SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
11292  
11293  /*
11294  ** CAPI3REF: Options for sqlite3session_object_config
11295  **
11296  ** The following values may passed as the the 2nd parameter to
11297  ** sqlite3session_object_config().
11298  **
11299  ** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>
11300  **   This option is used to set, clear or query the flag that enables
11301  **   the [sqlite3session_changeset_size()] API. Because it imposes some
11302  **   computational overhead, this API is disabled by default. Argument
11303  **   pArg must point to a value of type (int). If the value is initially
11304  **   0, then the sqlite3session_changeset_size() API is disabled. If it
11305  **   is greater than 0, then the same API is enabled. Or, if the initial
11306  **   value is less than zero, no change is made. In all cases the (int)
11307  **   variable is set to 1 if the sqlite3session_changeset_size() API is
11308  **   enabled following the current call, or 0 otherwise.
11309  **
11310  **   It is an error (SQLITE_MISUSE) to attempt to modify this setting after
11311  **   the first table has been attached to the session object.
11312  **
11313  ** <dt>SQLITE_SESSION_OBJCONFIG_ROWID <dd>
11314  **   This option is used to set, clear or query the flag that enables
11315  **   collection of data for tables with no explicit PRIMARY KEY.
11316  **
11317  **   Normally, tables with no explicit PRIMARY KEY are simply ignored
11318  **   by the sessions module. However, if this flag is set, it behaves
11319  **   as if such tables have a column "_rowid_ INTEGER PRIMARY KEY" inserted
11320  **   as their leftmost columns.
11321  **
11322  **   It is an error (SQLITE_MISUSE) to attempt to modify this setting after
11323  **   the first table has been attached to the session object.
11324  */
11325  #define SQLITE_SESSION_OBJCONFIG_SIZE  1
11326  #define SQLITE_SESSION_OBJCONFIG_ROWID 2
11327  
11328  /*
11329  ** CAPI3REF: Enable Or Disable A Session Object
11330  ** METHOD: sqlite3_session
11331  **
11332  ** Enable or disable the recording of changes by a session object. When
11333  ** enabled, a session object records changes made to the database. When
11334  ** disabled - it does not. A newly created session object is enabled.
11335  ** Refer to the documentation for [sqlite3session_changeset()] for further
11336  ** details regarding how enabling and disabling a session object affects
11337  ** the eventual changesets.
11338  **
11339  ** Passing zero to this function disables the session. Passing a value
11340  ** greater than zero enables it. Passing a value less than zero is a
11341  ** no-op, and may be used to query the current state of the session.
11342  **
11343  ** The return value indicates the final state of the session object: 0 if
11344  ** the session is disabled, or 1 if it is enabled.
11345  */
11346  SQLITE_API int sqlite3session_enable(sqlite3_session *pSession, int bEnable);
11347  
11348  /*
11349  ** CAPI3REF: Set Or Clear the Indirect Change Flag
11350  ** METHOD: sqlite3_session
11351  **
11352  ** Each change recorded by a session object is marked as either direct or
11353  ** indirect. A change is marked as indirect if either:
11354  **
11355  ** <ul>
11356  **   <li> The session object "indirect" flag is set when the change is
11357  **        made, or
11358  **   <li> The change is made by an SQL trigger or foreign key action
11359  **        instead of directly as a result of a users SQL statement.
11360  ** </ul>
11361  **
11362  ** If a single row is affected by more than one operation within a session,
11363  ** then the change is considered indirect if all operations meet the criteria
11364  ** for an indirect change above, or direct otherwise.
11365  **
11366  ** This function is used to set, clear or query the session object indirect
11367  ** flag.  If the second argument passed to this function is zero, then the
11368  ** indirect flag is cleared. If it is greater than zero, the indirect flag
11369  ** is set. Passing a value less than zero does not modify the current value
11370  ** of the indirect flag, and may be used to query the current state of the
11371  ** indirect flag for the specified session object.
11372  **
11373  ** The return value indicates the final state of the indirect flag: 0 if
11374  ** it is clear, or 1 if it is set.
11375  */
11376  SQLITE_API int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);
11377  
11378  /*
11379  ** CAPI3REF: Attach A Table To A Session Object
11380  ** METHOD: sqlite3_session
11381  **
11382  ** If argument zTab is not NULL, then it is the name of a table to attach
11383  ** to the session object passed as the first argument. All subsequent changes
11384  ** made to the table while the session object is enabled will be recorded. See
11385  ** documentation for [sqlite3session_changeset()] for further details.
11386  **
11387  ** Or, if argument zTab is NULL, then changes are recorded for all tables
11388  ** in the database. If additional tables are added to the database (by
11389  ** executing "CREATE TABLE" statements) after this call is made, changes for
11390  ** the new tables are also recorded.
11391  **
11392  ** Changes can only be recorded for tables that have a PRIMARY KEY explicitly
11393  ** defined as part of their CREATE TABLE statement. It does not matter if the
11394  ** PRIMARY KEY is an "INTEGER PRIMARY KEY" (rowid alias) or not. The PRIMARY
11395  ** KEY may consist of a single column, or may be a composite key.
11396  **
11397  ** It is not an error if the named table does not exist in the database. Nor
11398  ** is it an error if the named table does not have a PRIMARY KEY. However,
11399  ** no changes will be recorded in either of these scenarios.
11400  **
11401  ** Changes are not recorded for individual rows that have NULL values stored
11402  ** in one or more of their PRIMARY KEY columns.
11403  **
11404  ** SQLITE_OK is returned if the call completes without error. Or, if an error
11405  ** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
11406  **
11407  ** <h3>Special sqlite_stat1 Handling</h3>
11408  **
11409  ** As of SQLite version 3.22.0, the "sqlite_stat1" table is an exception to
11410  ** some of the rules above. In SQLite, the schema of sqlite_stat1 is:
11411  **  <pre>
11412  **  &nbsp;     CREATE TABLE sqlite_stat1(tbl,idx,stat)
11413  **  </pre>
11414  **
11415  ** Even though sqlite_stat1 does not have a PRIMARY KEY, changes are
11416  ** recorded for it as if the PRIMARY KEY is (tbl,idx). Additionally, changes
11417  ** are recorded for rows for which (idx IS NULL) is true. However, for such
11418  ** rows a zero-length blob (SQL value X'') is stored in the changeset or
11419  ** patchset instead of a NULL value. This allows such changesets to be
11420  ** manipulated by legacy implementations of sqlite3changeset_invert(),
11421  ** concat() and similar.
11422  **
11423  ** The sqlite3changeset_apply() function automatically converts the
11424  ** zero-length blob back to a NULL value when updating the sqlite_stat1
11425  ** table. However, if the application calls sqlite3changeset_new(),
11426  ** sqlite3changeset_old() or sqlite3changeset_conflict on a changeset
11427  ** iterator directly (including on a changeset iterator passed to a
11428  ** conflict-handler callback) then the X'' value is returned. The application
11429  ** must translate X'' to NULL itself if required.
11430  **
11431  ** Legacy (older than 3.22.0) versions of the sessions module cannot capture
11432  ** changes made to the sqlite_stat1 table. Legacy versions of the
11433  ** sqlite3changeset_apply() function silently ignore any modifications to the
11434  ** sqlite_stat1 table that are part of a changeset or patchset.
11435  */
11436  SQLITE_API int sqlite3session_attach(
11437    sqlite3_session *pSession,      /* Session object */
11438    const char *zTab                /* Table name */
11439  );
11440  
11441  /*
11442  ** CAPI3REF: Set a table filter on a Session Object.
11443  ** METHOD: sqlite3_session
11444  **
11445  ** The second argument (xFilter) is the "filter callback". For changes to rows
11446  ** in tables that are not attached to the Session object, the filter is called
11447  ** to determine whether changes to the table's rows should be tracked or not.
11448  ** If xFilter returns 0, changes are not tracked. Note that once a table is
11449  ** attached, xFilter will not be called again.
11450  */
11451  SQLITE_API void sqlite3session_table_filter(
11452    sqlite3_session *pSession,      /* Session object */
11453    int(*xFilter)(
11454      void *pCtx,                   /* Copy of third arg to _filter_table() */
11455      const char *zTab              /* Table name */
11456    ),
11457    void *pCtx                      /* First argument passed to xFilter */
11458  );
11459  
11460  /*
11461  ** CAPI3REF: Generate A Changeset From A Session Object
11462  ** METHOD: sqlite3_session
11463  **
11464  ** Obtain a changeset containing changes to the tables attached to the
11465  ** session object passed as the first argument. If successful,
11466  ** set *ppChangeset to point to a buffer containing the changeset
11467  ** and *pnChangeset to the size of the changeset in bytes before returning
11468  ** SQLITE_OK. If an error occurs, set both *ppChangeset and *pnChangeset to
11469  ** zero and return an SQLite error code.
11470  **
11471  ** A changeset consists of zero or more INSERT, UPDATE and/or DELETE changes,
11472  ** each representing a change to a single row of an attached table. An INSERT
11473  ** change contains the values of each field of a new database row. A DELETE
11474  ** contains the original values of each field of a deleted database row. An
11475  ** UPDATE change contains the original values of each field of an updated
11476  ** database row along with the updated values for each updated non-primary-key
11477  ** column. It is not possible for an UPDATE change to represent a change that
11478  ** modifies the values of primary key columns. If such a change is made, it
11479  ** is represented in a changeset as a DELETE followed by an INSERT.
11480  **
11481  ** Changes are not recorded for rows that have NULL values stored in one or
11482  ** more of their PRIMARY KEY columns. If such a row is inserted or deleted,
11483  ** no corresponding change is present in the changesets returned by this
11484  ** function. If an existing row with one or more NULL values stored in
11485  ** PRIMARY KEY columns is updated so that all PRIMARY KEY columns are non-NULL,
11486  ** only an INSERT is appears in the changeset. Similarly, if an existing row
11487  ** with non-NULL PRIMARY KEY values is updated so that one or more of its
11488  ** PRIMARY KEY columns are set to NULL, the resulting changeset contains a
11489  ** DELETE change only.
11490  **
11491  ** The contents of a changeset may be traversed using an iterator created
11492  ** using the [sqlite3changeset_start()] API. A changeset may be applied to
11493  ** a database with a compatible schema using the [sqlite3changeset_apply()]
11494  ** API.
11495  **
11496  ** Within a changeset generated by this function, all changes related to a
11497  ** single table are grouped together. In other words, when iterating through
11498  ** a changeset or when applying a changeset to a database, all changes related
11499  ** to a single table are processed before moving on to the next table. Tables
11500  ** are sorted in the same order in which they were attached (or auto-attached)
11501  ** to the sqlite3_session object. The order in which the changes related to
11502  ** a single table are stored is undefined.
11503  **
11504  ** Following a successful call to this function, it is the responsibility of
11505  ** the caller to eventually free the buffer that *ppChangeset points to using
11506  ** [sqlite3_free()].
11507  **
11508  ** <h3>Changeset Generation</h3>
11509  **
11510  ** Once a table has been attached to a session object, the session object
11511  ** records the primary key values of all new rows inserted into the table.
11512  ** It also records the original primary key and other column values of any
11513  ** deleted or updated rows. For each unique primary key value, data is only
11514  ** recorded once - the first time a row with said primary key is inserted,
11515  ** updated or deleted in the lifetime of the session.
11516  **
11517  ** There is one exception to the previous paragraph: when a row is inserted,
11518  ** updated or deleted, if one or more of its primary key columns contain a
11519  ** NULL value, no record of the change is made.
11520  **
11521  ** The session object therefore accumulates two types of records - those
11522  ** that consist of primary key values only (created when the user inserts
11523  ** a new record) and those that consist of the primary key values and the
11524  ** original values of other table columns (created when the users deletes
11525  ** or updates a record).
11526  **
11527  ** When this function is called, the requested changeset is created using
11528  ** both the accumulated records and the current contents of the database
11529  ** file. Specifically:
11530  **
11531  ** <ul>
11532  **   <li> For each record generated by an insert, the database is queried
11533  **        for a row with a matching primary key. If one is found, an INSERT
11534  **        change is added to the changeset. If no such row is found, no change
11535  **        is added to the changeset.
11536  **
11537  **   <li> For each record generated by an update or delete, the database is
11538  **        queried for a row with a matching primary key. If such a row is
11539  **        found and one or more of the non-primary key fields have been
11540  **        modified from their original values, an UPDATE change is added to
11541  **        the changeset. Or, if no such row is found in the table, a DELETE
11542  **        change is added to the changeset. If there is a row with a matching
11543  **        primary key in the database, but all fields contain their original
11544  **        values, no change is added to the changeset.
11545  ** </ul>
11546  **
11547  ** This means, amongst other things, that if a row is inserted and then later
11548  ** deleted while a session object is active, neither the insert nor the delete
11549  ** will be present in the changeset. Or if a row is deleted and then later a
11550  ** row with the same primary key values inserted while a session object is
11551  ** active, the resulting changeset will contain an UPDATE change instead of
11552  ** a DELETE and an INSERT.
11553  **
11554  ** When a session object is disabled (see the [sqlite3session_enable()] API),
11555  ** it does not accumulate records when rows are inserted, updated or deleted.
11556  ** This may appear to have some counter-intuitive effects if a single row
11557  ** is written to more than once during a session. For example, if a row
11558  ** is inserted while a session object is enabled, then later deleted while
11559  ** the same session object is disabled, no INSERT record will appear in the
11560  ** changeset, even though the delete took place while the session was disabled.
11561  ** Or, if one field of a row is updated while a session is enabled, and
11562  ** then another field of the same row is updated while the session is disabled,
11563  ** the resulting changeset will contain an UPDATE change that updates both
11564  ** fields.
11565  */
11566  SQLITE_API int sqlite3session_changeset(
11567    sqlite3_session *pSession,      /* Session object */
11568    int *pnChangeset,               /* OUT: Size of buffer at *ppChangeset */
11569    void **ppChangeset              /* OUT: Buffer containing changeset */
11570  );
11571  
11572  /*
11573  ** CAPI3REF: Return An Upper-limit For The Size Of The Changeset
11574  ** METHOD: sqlite3_session
11575  **
11576  ** By default, this function always returns 0. For it to return
11577  ** a useful result, the sqlite3_session object must have been configured
11578  ** to enable this API using sqlite3session_object_config() with the
11579  ** SQLITE_SESSION_OBJCONFIG_SIZE verb.
11580  **
11581  ** When enabled, this function returns an upper limit, in bytes, for the size
11582  ** of the changeset that might be produced if sqlite3session_changeset() were
11583  ** called. The final changeset size might be equal to or smaller than the
11584  ** size in bytes returned by this function.
11585  */
11586  SQLITE_API sqlite3_int64 sqlite3session_changeset_size(sqlite3_session *pSession);
11587  
11588  /*
11589  ** CAPI3REF: Load The Difference Between Tables Into A Session
11590  ** METHOD: sqlite3_session
11591  **
11592  ** If it is not already attached to the session object passed as the first
11593  ** argument, this function attaches table zTbl in the same manner as the
11594  ** [sqlite3session_attach()] function. If zTbl does not exist, or if it
11595  ** does not have a primary key, this function is a no-op (but does not return
11596  ** an error).
11597  **
11598  ** Argument zFromDb must be the name of a database ("main", "temp" etc.)
11599  ** attached to the same database handle as the session object that contains
11600  ** a table compatible with the table attached to the session by this function.
11601  ** A table is considered compatible if it:
11602  **
11603  ** <ul>
11604  **   <li> Has the same name,
11605  **   <li> Has the same set of columns declared in the same order, and
11606  **   <li> Has the same PRIMARY KEY definition.
11607  ** </ul>
11608  **
11609  ** If the tables are not compatible, SQLITE_SCHEMA is returned. If the tables
11610  ** are compatible but do not have any PRIMARY KEY columns, it is not an error
11611  ** but no changes are added to the session object. As with other session
11612  ** APIs, tables without PRIMARY KEYs are simply ignored.
11613  **
11614  ** This function adds a set of changes to the session object that could be
11615  ** used to update the table in database zFrom (call this the "from-table")
11616  ** so that its content is the same as the table attached to the session
11617  ** object (call this the "to-table"). Specifically:
11618  **
11619  ** <ul>
11620  **   <li> For each row (primary key) that exists in the to-table but not in
11621  **     the from-table, an INSERT record is added to the session object.
11622  **
11623  **   <li> For each row (primary key) that exists in the to-table but not in
11624  **     the from-table, a DELETE record is added to the session object.
11625  **
11626  **   <li> For each row (primary key) that exists in both tables, but features
11627  **     different non-PK values in each, an UPDATE record is added to the
11628  **     session.
11629  ** </ul>
11630  **
11631  ** To clarify, if this function is called and then a changeset constructed
11632  ** using [sqlite3session_changeset()], then after applying that changeset to
11633  ** database zFrom the contents of the two compatible tables would be
11634  ** identical.
11635  **
11636  ** Unless the call to this function is a no-op as described above, it is an
11637  ** error if database zFrom does not exist or does not contain the required
11638  ** compatible table.
11639  **
11640  ** If the operation is successful, SQLITE_OK is returned. Otherwise, an SQLite
11641  ** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
11642  ** may be set to point to a buffer containing an English language error
11643  ** message. It is the responsibility of the caller to free this buffer using
11644  ** sqlite3_free().
11645  */
11646  SQLITE_API int sqlite3session_diff(
11647    sqlite3_session *pSession,
11648    const char *zFromDb,
11649    const char *zTbl,
11650    char **pzErrMsg
11651  );
11652  
11653  
11654  /*
11655  ** CAPI3REF: Generate A Patchset From A Session Object
11656  ** METHOD: sqlite3_session
11657  **
11658  ** The differences between a patchset and a changeset are that:
11659  **
11660  ** <ul>
11661  **   <li> DELETE records consist of the primary key fields only. The
11662  **        original values of other fields are omitted.
11663  **   <li> The original values of any modified fields are omitted from
11664  **        UPDATE records.
11665  ** </ul>
11666  **
11667  ** A patchset blob may be used with up to date versions of all
11668  ** sqlite3changeset_xxx API functions except for sqlite3changeset_invert(),
11669  ** which returns SQLITE_CORRUPT if it is passed a patchset. Similarly,
11670  ** attempting to use a patchset blob with old versions of the
11671  ** sqlite3changeset_xxx APIs also provokes an SQLITE_CORRUPT error.
11672  **
11673  ** Because the non-primary key "old.*" fields are omitted, no
11674  ** SQLITE_CHANGESET_DATA conflicts can be detected or reported if a patchset
11675  ** is passed to the sqlite3changeset_apply() API. Other conflict types work
11676  ** in the same way as for changesets.
11677  **
11678  ** Changes within a patchset are ordered in the same way as for changesets
11679  ** generated by the sqlite3session_changeset() function (i.e. all changes for
11680  ** a single table are grouped together, tables appear in the order in which
11681  ** they were attached to the session object).
11682  */
11683  SQLITE_API int sqlite3session_patchset(
11684    sqlite3_session *pSession,      /* Session object */
11685    int *pnPatchset,                /* OUT: Size of buffer at *ppPatchset */
11686    void **ppPatchset               /* OUT: Buffer containing patchset */
11687  );
11688  
11689  /*
11690  ** CAPI3REF: Test if a changeset has recorded any changes.
11691  **
11692  ** Return non-zero if no changes to attached tables have been recorded by
11693  ** the session object passed as the first argument. Otherwise, if one or
11694  ** more changes have been recorded, return zero.
11695  **
11696  ** Even if this function returns zero, it is possible that calling
11697  ** [sqlite3session_changeset()] on the session handle may still return a
11698  ** changeset that contains no changes. This can happen when a row in
11699  ** an attached table is modified and then later on the original values
11700  ** are restored. However, if this function returns non-zero, then it is
11701  ** guaranteed that a call to sqlite3session_changeset() will return a
11702  ** changeset containing zero changes.
11703  */
11704  SQLITE_API int sqlite3session_isempty(sqlite3_session *pSession);
11705  
11706  /*
11707  ** CAPI3REF: Query for the amount of heap memory used by a session object.
11708  **
11709  ** This API returns the total amount of heap memory in bytes currently
11710  ** used by the session object passed as the only argument.
11711  */
11712  SQLITE_API sqlite3_int64 sqlite3session_memory_used(sqlite3_session *pSession);
11713  
11714  /*
11715  ** CAPI3REF: Create An Iterator To Traverse A Changeset
11716  ** CONSTRUCTOR: sqlite3_changeset_iter
11717  **
11718  ** Create an iterator used to iterate through the contents of a changeset.
11719  ** If successful, *pp is set to point to the iterator handle and SQLITE_OK
11720  ** is returned. Otherwise, if an error occurs, *pp is set to zero and an
11721  ** SQLite error code is returned.
11722  **
11723  ** The following functions can be used to advance and query a changeset
11724  ** iterator created by this function:
11725  **
11726  ** <ul>
11727  **   <li> [sqlite3changeset_next()]
11728  **   <li> [sqlite3changeset_op()]
11729  **   <li> [sqlite3changeset_new()]
11730  **   <li> [sqlite3changeset_old()]
11731  ** </ul>
11732  **
11733  ** It is the responsibility of the caller to eventually destroy the iterator
11734  ** by passing it to [sqlite3changeset_finalize()]. The buffer containing the
11735  ** changeset (pChangeset) must remain valid until after the iterator is
11736  ** destroyed.
11737  **
11738  ** Assuming the changeset blob was created by one of the
11739  ** [sqlite3session_changeset()], [sqlite3changeset_concat()] or
11740  ** [sqlite3changeset_invert()] functions, all changes within the changeset
11741  ** that apply to a single table are grouped together. This means that when
11742  ** an application iterates through a changeset using an iterator created by
11743  ** this function, all changes that relate to a single table are visited
11744  ** consecutively. There is no chance that the iterator will visit a change
11745  ** the applies to table X, then one for table Y, and then later on visit
11746  ** another change for table X.
11747  **
11748  ** The behavior of sqlite3changeset_start_v2() and its streaming equivalent
11749  ** may be modified by passing a combination of
11750  ** [SQLITE_CHANGESETSTART_INVERT | supported flags] as the 4th parameter.
11751  **
11752  ** Note that the sqlite3changeset_start_v2() API is still <b>experimental</b>
11753  ** and therefore subject to change.
11754  */
11755  SQLITE_API int sqlite3changeset_start(
11756    sqlite3_changeset_iter **pp,    /* OUT: New changeset iterator handle */
11757    int nChangeset,                 /* Size of changeset blob in bytes */
11758    void *pChangeset                /* Pointer to blob containing changeset */
11759  );
11760  SQLITE_API int sqlite3changeset_start_v2(
11761    sqlite3_changeset_iter **pp,    /* OUT: New changeset iterator handle */
11762    int nChangeset,                 /* Size of changeset blob in bytes */
11763    void *pChangeset,               /* Pointer to blob containing changeset */
11764    int flags                       /* SESSION_CHANGESETSTART_* flags */
11765  );
11766  
11767  /*
11768  ** CAPI3REF: Flags for sqlite3changeset_start_v2
11769  **
11770  ** The following flags may passed via the 4th parameter to
11771  ** [sqlite3changeset_start_v2] and [sqlite3changeset_start_v2_strm]:
11772  **
11773  ** <dt>SQLITE_CHANGESETSTART_INVERT <dd>
11774  **   Invert the changeset while iterating through it. This is equivalent to
11775  **   inverting a changeset using sqlite3changeset_invert() before applying it.
11776  **   It is an error to specify this flag with a patchset.
11777  */
11778  #define SQLITE_CHANGESETSTART_INVERT        0x0002
11779  
11780  
11781  /*
11782  ** CAPI3REF: Advance A Changeset Iterator
11783  ** METHOD: sqlite3_changeset_iter
11784  **
11785  ** This function may only be used with iterators created by the function
11786  ** [sqlite3changeset_start()]. If it is called on an iterator passed to
11787  ** a conflict-handler callback by [sqlite3changeset_apply()], SQLITE_MISUSE
11788  ** is returned and the call has no effect.
11789  **
11790  ** Immediately after an iterator is created by sqlite3changeset_start(), it
11791  ** does not point to any change in the changeset. Assuming the changeset
11792  ** is not empty, the first call to this function advances the iterator to
11793  ** point to the first change in the changeset. Each subsequent call advances
11794  ** the iterator to point to the next change in the changeset (if any). If
11795  ** no error occurs and the iterator points to a valid change after a call
11796  ** to sqlite3changeset_next() has advanced it, SQLITE_ROW is returned.
11797  ** Otherwise, if all changes in the changeset have already been visited,
11798  ** SQLITE_DONE is returned.
11799  **
11800  ** If an error occurs, an SQLite error code is returned. Possible error
11801  ** codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or
11802  ** SQLITE_NOMEM.
11803  */
11804  SQLITE_API int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
11805  
11806  /*
11807  ** CAPI3REF: Obtain The Current Operation From A Changeset Iterator
11808  ** METHOD: sqlite3_changeset_iter
11809  **
11810  ** The pIter argument passed to this function may either be an iterator
11811  ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
11812  ** created by [sqlite3changeset_start()]. In the latter case, the most recent
11813  ** call to [sqlite3changeset_next()] must have returned [SQLITE_ROW]. If this
11814  ** is not the case, this function returns [SQLITE_MISUSE].
11815  **
11816  ** Arguments pOp, pnCol and pzTab may not be NULL. Upon return, three
11817  ** outputs are set through these pointers:
11818  **
11819  ** *pOp is set to one of [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE],
11820  ** depending on the type of change that the iterator currently points to;
11821  **
11822  ** *pnCol is set to the number of columns in the table affected by the change; and
11823  **
11824  ** *pzTab is set to point to a nul-terminated utf-8 encoded string containing
11825  ** the name of the table affected by the current change. The buffer remains
11826  ** valid until either sqlite3changeset_next() is called on the iterator
11827  ** or until the conflict-handler function returns.
11828  **
11829  ** If pbIndirect is not NULL, then *pbIndirect is set to true (1) if the change
11830  ** is an indirect change, or false (0) otherwise. See the documentation for
11831  ** [sqlite3session_indirect()] for a description of direct and indirect
11832  ** changes.
11833  **
11834  ** If no error occurs, SQLITE_OK is returned. If an error does occur, an
11835  ** SQLite error code is returned. The values of the output variables may not
11836  ** be trusted in this case.
11837  */
11838  SQLITE_API int sqlite3changeset_op(
11839    sqlite3_changeset_iter *pIter,  /* Iterator object */
11840    const char **pzTab,             /* OUT: Pointer to table name */
11841    int *pnCol,                     /* OUT: Number of columns in table */
11842    int *pOp,                       /* OUT: SQLITE_INSERT, DELETE or UPDATE */
11843    int *pbIndirect                 /* OUT: True for an 'indirect' change */
11844  );
11845  
11846  /*
11847  ** CAPI3REF: Obtain The Primary Key Definition Of A Table
11848  ** METHOD: sqlite3_changeset_iter
11849  **
11850  ** For each modified table, a changeset includes the following:
11851  **
11852  ** <ul>
11853  **   <li> The number of columns in the table, and
11854  **   <li> Which of those columns make up the tables PRIMARY KEY.
11855  ** </ul>
11856  **
11857  ** This function is used to find which columns comprise the PRIMARY KEY of
11858  ** the table modified by the change that iterator pIter currently points to.
11859  ** If successful, *pabPK is set to point to an array of nCol entries, where
11860  ** nCol is the number of columns in the table. Elements of *pabPK are set to
11861  ** 0x01 if the corresponding column is part of the tables primary key, or
11862  ** 0x00 if it is not.
11863  **
11864  ** If argument pnCol is not NULL, then *pnCol is set to the number of columns
11865  ** in the table.
11866  **
11867  ** If this function is called when the iterator does not point to a valid
11868  ** entry, SQLITE_MISUSE is returned and the output variables zeroed. Otherwise,
11869  ** SQLITE_OK is returned and the output variables populated as described
11870  ** above.
11871  */
11872  SQLITE_API int sqlite3changeset_pk(
11873    sqlite3_changeset_iter *pIter,  /* Iterator object */
11874    unsigned char **pabPK,          /* OUT: Array of boolean - true for PK cols */
11875    int *pnCol                      /* OUT: Number of entries in output array */
11876  );
11877  
11878  /*
11879  ** CAPI3REF: Obtain old.* Values From A Changeset Iterator
11880  ** METHOD: sqlite3_changeset_iter
11881  **
11882  ** The pIter argument passed to this function may either be an iterator
11883  ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
11884  ** created by [sqlite3changeset_start()]. In the latter case, the most recent
11885  ** call to [sqlite3changeset_next()] must have returned SQLITE_ROW.
11886  ** Furthermore, it may only be called if the type of change that the iterator
11887  ** currently points to is either [SQLITE_DELETE] or [SQLITE_UPDATE]. Otherwise,
11888  ** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL.
11889  **
11890  ** Argument iVal must be greater than or equal to 0, and less than the number
11891  ** of columns in the table affected by the current change. Otherwise,
11892  ** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
11893  **
11894  ** If successful, this function sets *ppValue to point to a protected
11895  ** sqlite3_value object containing the iVal'th value from the vector of
11896  ** original row values stored as part of the UPDATE or DELETE change and
11897  ** returns SQLITE_OK. The name of the function comes from the fact that this
11898  ** is similar to the "old.*" columns available to update or delete triggers.
11899  **
11900  ** If some other error occurs (e.g. an OOM condition), an SQLite error code
11901  ** is returned and *ppValue is set to NULL.
11902  */
11903  SQLITE_API int sqlite3changeset_old(
11904    sqlite3_changeset_iter *pIter,  /* Changeset iterator */
11905    int iVal,                       /* Column number */
11906    sqlite3_value **ppValue         /* OUT: Old value (or NULL pointer) */
11907  );
11908  
11909  /*
11910  ** CAPI3REF: Obtain new.* Values From A Changeset Iterator
11911  ** METHOD: sqlite3_changeset_iter
11912  **
11913  ** The pIter argument passed to this function may either be an iterator
11914  ** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator
11915  ** created by [sqlite3changeset_start()]. In the latter case, the most recent
11916  ** call to [sqlite3changeset_next()] must have returned SQLITE_ROW.
11917  ** Furthermore, it may only be called if the type of change that the iterator
11918  ** currently points to is either [SQLITE_UPDATE] or [SQLITE_INSERT]. Otherwise,
11919  ** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL.
11920  **
11921  ** Argument iVal must be greater than or equal to 0, and less than the number
11922  ** of columns in the table affected by the current change. Otherwise,
11923  ** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
11924  **
11925  ** If successful, this function sets *ppValue to point to a protected
11926  ** sqlite3_value object containing the iVal'th value from the vector of
11927  ** new row values stored as part of the UPDATE or INSERT change and
11928  ** returns SQLITE_OK. If the change is an UPDATE and does not include
11929  ** a new value for the requested column, *ppValue is set to NULL and
11930  ** SQLITE_OK returned. The name of the function comes from the fact that
11931  ** this is similar to the "new.*" columns available to update or delete
11932  ** triggers.
11933  **
11934  ** If some other error occurs (e.g. an OOM condition), an SQLite error code
11935  ** is returned and *ppValue is set to NULL.
11936  */
11937  SQLITE_API int sqlite3changeset_new(
11938    sqlite3_changeset_iter *pIter,  /* Changeset iterator */
11939    int iVal,                       /* Column number */
11940    sqlite3_value **ppValue         /* OUT: New value (or NULL pointer) */
11941  );
11942  
11943  /*
11944  ** CAPI3REF: Obtain Conflicting Row Values From A Changeset Iterator
11945  ** METHOD: sqlite3_changeset_iter
11946  **
11947  ** This function should only be used with iterator objects passed to a
11948  ** conflict-handler callback by [sqlite3changeset_apply()] with either
11949  ** [SQLITE_CHANGESET_DATA] or [SQLITE_CHANGESET_CONFLICT]. If this function
11950  ** is called on any other iterator, [SQLITE_MISUSE] is returned and *ppValue
11951  ** is set to NULL.
11952  **
11953  ** Argument iVal must be greater than or equal to 0, and less than the number
11954  ** of columns in the table affected by the current change. Otherwise,
11955  ** [SQLITE_RANGE] is returned and *ppValue is set to NULL.
11956  **
11957  ** If successful, this function sets *ppValue to point to a protected
11958  ** sqlite3_value object containing the iVal'th value from the
11959  ** "conflicting row" associated with the current conflict-handler callback
11960  ** and returns SQLITE_OK.
11961  **
11962  ** If some other error occurs (e.g. an OOM condition), an SQLite error code
11963  ** is returned and *ppValue is set to NULL.
11964  */
11965  SQLITE_API int sqlite3changeset_conflict(
11966    sqlite3_changeset_iter *pIter,  /* Changeset iterator */
11967    int iVal,                       /* Column number */
11968    sqlite3_value **ppValue         /* OUT: Value from conflicting row */
11969  );
11970  
11971  /*
11972  ** CAPI3REF: Determine The Number Of Foreign Key Constraint Violations
11973  ** METHOD: sqlite3_changeset_iter
11974  **
11975  ** This function may only be called with an iterator passed to an
11976  ** SQLITE_CHANGESET_FOREIGN_KEY conflict handler callback. In this case
11977  ** it sets the output variable to the total number of known foreign key
11978  ** violations in the destination database and returns SQLITE_OK.
11979  **
11980  ** In all other cases this function returns SQLITE_MISUSE.
11981  */
11982  SQLITE_API int sqlite3changeset_fk_conflicts(
11983    sqlite3_changeset_iter *pIter,  /* Changeset iterator */
11984    int *pnOut                      /* OUT: Number of FK violations */
11985  );
11986  
11987  
11988  /*
11989  ** CAPI3REF: Finalize A Changeset Iterator
11990  ** METHOD: sqlite3_changeset_iter
11991  **
11992  ** This function is used to finalize an iterator allocated with
11993  ** [sqlite3changeset_start()].
11994  **
11995  ** This function should only be called on iterators created using the
11996  ** [sqlite3changeset_start()] function. If an application calls this
11997  ** function with an iterator passed to a conflict-handler by
11998  ** [sqlite3changeset_apply()], [SQLITE_MISUSE] is immediately returned and the
11999  ** call has no effect.
12000  **
12001  ** If an error was encountered within a call to an sqlite3changeset_xxx()
12002  ** function (for example an [SQLITE_CORRUPT] in [sqlite3changeset_next()] or an
12003  ** [SQLITE_NOMEM] in [sqlite3changeset_new()]) then an error code corresponding
12004  ** to that error is returned by this function. Otherwise, SQLITE_OK is
12005  ** returned. This is to allow the following pattern (pseudo-code):
12006  **
12007  ** <pre>
12008  **   sqlite3changeset_start();
12009  **   while( SQLITE_ROW==sqlite3changeset_next() ){
12010  **     // Do something with change.
12011  **   }
12012  **   rc = sqlite3changeset_finalize();
12013  **   if( rc!=SQLITE_OK ){
12014  **     // An error has occurred
12015  **   }
12016  ** </pre>
12017  */
12018  SQLITE_API int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);
12019  
12020  /*
12021  ** CAPI3REF: Invert A Changeset
12022  **
12023  ** This function is used to "invert" a changeset object. Applying an inverted
12024  ** changeset to a database reverses the effects of applying the uninverted
12025  ** changeset. Specifically:
12026  **
12027  ** <ul>
12028  **   <li> Each DELETE change is changed to an INSERT, and
12029  **   <li> Each INSERT change is changed to a DELETE, and
12030  **   <li> For each UPDATE change, the old.* and new.* values are exchanged.
12031  ** </ul>
12032  **
12033  ** This function does not change the order in which changes appear within
12034  ** the changeset. It merely reverses the sense of each individual change.
12035  **
12036  ** If successful, a pointer to a buffer containing the inverted changeset
12037  ** is stored in *ppOut, the size of the same buffer is stored in *pnOut, and
12038  ** SQLITE_OK is returned. If an error occurs, both *pnOut and *ppOut are
12039  ** zeroed and an SQLite error code returned.
12040  **
12041  ** It is the responsibility of the caller to eventually call sqlite3_free()
12042  ** on the *ppOut pointer to free the buffer allocation following a successful
12043  ** call to this function.
12044  **
12045  ** WARNING/TODO: This function currently assumes that the input is a valid
12046  ** changeset. If it is not, the results are undefined.
12047  */
12048  SQLITE_API int sqlite3changeset_invert(
12049    int nIn, const void *pIn,       /* Input changeset */
12050    int *pnOut, void **ppOut        /* OUT: Inverse of input */
12051  );
12052  
12053  /*
12054  ** CAPI3REF: Concatenate Two Changeset Objects
12055  **
12056  ** This function is used to concatenate two changesets, A and B, into a
12057  ** single changeset. The result is a changeset equivalent to applying
12058  ** changeset A followed by changeset B.
12059  **
12060  ** This function combines the two input changesets using an
12061  ** sqlite3_changegroup object. Calling it produces similar results as the
12062  ** following code fragment:
12063  **
12064  ** <pre>
12065  **   sqlite3_changegroup *pGrp;
12066  **   rc = sqlite3_changegroup_new(&pGrp);
12067  **   if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nA, pA);
12068  **   if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nB, pB);
12069  **   if( rc==SQLITE_OK ){
12070  **     rc = sqlite3changegroup_output(pGrp, pnOut, ppOut);
12071  **   }else{
12072  **     *ppOut = 0;
12073  **     *pnOut = 0;
12074  **   }
12075  ** </pre>
12076  **
12077  ** Refer to the sqlite3_changegroup documentation below for details.
12078  */
12079  SQLITE_API int sqlite3changeset_concat(
12080    int nA,                         /* Number of bytes in buffer pA */
12081    void *pA,                       /* Pointer to buffer containing changeset A */
12082    int nB,                         /* Number of bytes in buffer pB */
12083    void *pB,                       /* Pointer to buffer containing changeset B */
12084    int *pnOut,                     /* OUT: Number of bytes in output changeset */
12085    void **ppOut                    /* OUT: Buffer containing output changeset */
12086  );
12087  
12088  /*
12089  ** CAPI3REF: Changegroup Handle
12090  **
12091  ** A changegroup is an object used to combine two or more
12092  ** [changesets] or [patchsets]
12093  */
12094  typedef struct sqlite3_changegroup sqlite3_changegroup;
12095  
12096  /*
12097  ** CAPI3REF: Create A New Changegroup Object
12098  ** CONSTRUCTOR: sqlite3_changegroup
12099  **
12100  ** An sqlite3_changegroup object is used to combine two or more changesets
12101  ** (or patchsets) into a single changeset (or patchset). A single changegroup
12102  ** object may combine changesets or patchsets, but not both. The output is
12103  ** always in the same format as the input.
12104  **
12105  ** If successful, this function returns SQLITE_OK and populates (*pp) with
12106  ** a pointer to a new sqlite3_changegroup object before returning. The caller
12107  ** should eventually free the returned object using a call to
12108  ** sqlite3changegroup_delete(). If an error occurs, an SQLite error code
12109  ** (i.e. SQLITE_NOMEM) is returned and *pp is set to NULL.
12110  **
12111  ** The usual usage pattern for an sqlite3_changegroup object is as follows:
12112  **
12113  ** <ul>
12114  **   <li> It is created using a call to sqlite3changegroup_new().
12115  **
12116  **   <li> Zero or more changesets (or patchsets) are added to the object
12117  **        by calling sqlite3changegroup_add().
12118  **
12119  **   <li> The result of combining all input changesets together is obtained
12120  **        by the application via a call to sqlite3changegroup_output().
12121  **
12122  **   <li> The object is deleted using a call to sqlite3changegroup_delete().
12123  ** </ul>
12124  **
12125  ** Any number of calls to add() and output() may be made between the calls to
12126  ** new() and delete(), and in any order.
12127  **
12128  ** As well as the regular sqlite3changegroup_add() and
12129  ** sqlite3changegroup_output() functions, also available are the streaming
12130  ** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm().
12131  */
12132  SQLITE_API int sqlite3changegroup_new(sqlite3_changegroup **pp);
12133  
12134  /*
12135  ** CAPI3REF: Add a Schema to a Changegroup
12136  ** METHOD: sqlite3_changegroup_schema
12137  **
12138  ** This method may be used to optionally enforce the rule that the changesets
12139  ** added to the changegroup handle must match the schema of database zDb
12140  ** ("main", "temp", or the name of an attached database). If
12141  ** sqlite3changegroup_add() is called to add a changeset that is not compatible
12142  ** with the configured schema, SQLITE_SCHEMA is returned and the changegroup
12143  ** object is left in an undefined state.
12144  **
12145  ** A changeset schema is considered compatible with the database schema in
12146  ** the same way as for sqlite3changeset_apply(). Specifically, for each
12147  ** table in the changeset, there exists a database table with:
12148  **
12149  ** <ul>
12150  **   <li> The name identified by the changeset, and
12151  **   <li> at least as many columns as recorded in the changeset, and
12152  **   <li> the primary key columns in the same position as recorded in
12153  **        the changeset.
12154  ** </ul>
12155  **
12156  ** The output of the changegroup object always has the same schema as the
12157  ** database nominated using this function. In cases where changesets passed
12158  ** to sqlite3changegroup_add() have fewer columns than the corresponding table
12159  ** in the database schema, these are filled in using the default column
12160  ** values from the database schema. This makes it possible to combined
12161  ** changesets that have different numbers of columns for a single table
12162  ** within a changegroup, provided that they are otherwise compatible.
12163  */
12164  SQLITE_API int sqlite3changegroup_schema(sqlite3_changegroup*, sqlite3*, const char *zDb);
12165  
12166  /*
12167  ** CAPI3REF: Add A Changeset To A Changegroup
12168  ** METHOD: sqlite3_changegroup
12169  **
12170  ** Add all changes within the changeset (or patchset) in buffer pData (size
12171  ** nData bytes) to the changegroup.
12172  **
12173  ** If the buffer contains a patchset, then all prior calls to this function
12174  ** on the same changegroup object must also have specified patchsets. Or, if
12175  ** the buffer contains a changeset, so must have the earlier calls to this
12176  ** function. Otherwise, SQLITE_ERROR is returned and no changes are added
12177  ** to the changegroup.
12178  **
12179  ** Rows within the changeset and changegroup are identified by the values in
12180  ** their PRIMARY KEY columns. A change in the changeset is considered to
12181  ** apply to the same row as a change already present in the changegroup if
12182  ** the two rows have the same primary key.
12183  **
12184  ** Changes to rows that do not already appear in the changegroup are
12185  ** simply copied into it. Or, if both the new changeset and the changegroup
12186  ** contain changes that apply to a single row, the final contents of the
12187  ** changegroup depends on the type of each change, as follows:
12188  **
12189  ** <table border=1 style="margin-left:8ex;margin-right:8ex">
12190  **   <tr><th style="white-space:pre">Existing Change  </th>
12191  **       <th style="white-space:pre">New Change       </th>
12192  **       <th>Output Change
12193  **   <tr><td>INSERT <td>INSERT <td>
12194  **       The new change is ignored. This case does not occur if the new
12195  **       changeset was recorded immediately after the changesets already
12196  **       added to the changegroup.
12197  **   <tr><td>INSERT <td>UPDATE <td>
12198  **       The INSERT change remains in the changegroup. The values in the
12199  **       INSERT change are modified as if the row was inserted by the
12200  **       existing change and then updated according to the new change.
12201  **   <tr><td>INSERT <td>DELETE <td>
12202  **       The existing INSERT is removed from the changegroup. The DELETE is
12203  **       not added.
12204  **   <tr><td>UPDATE <td>INSERT <td>
12205  **       The new change is ignored. This case does not occur if the new
12206  **       changeset was recorded immediately after the changesets already
12207  **       added to the changegroup.
12208  **   <tr><td>UPDATE <td>UPDATE <td>
12209  **       The existing UPDATE remains within the changegroup. It is amended
12210  **       so that the accompanying values are as if the row was updated once
12211  **       by the existing change and then again by the new change.
12212  **   <tr><td>UPDATE <td>DELETE <td>
12213  **       The existing UPDATE is replaced by the new DELETE within the
12214  **       changegroup.
12215  **   <tr><td>DELETE <td>INSERT <td>
12216  **       If one or more of the column values in the row inserted by the
12217  **       new change differ from those in the row deleted by the existing
12218  **       change, the existing DELETE is replaced by an UPDATE within the
12219  **       changegroup. Otherwise, if the inserted row is exactly the same
12220  **       as the deleted row, the existing DELETE is simply discarded.
12221  **   <tr><td>DELETE <td>UPDATE <td>
12222  **       The new change is ignored. This case does not occur if the new
12223  **       changeset was recorded immediately after the changesets already
12224  **       added to the changegroup.
12225  **   <tr><td>DELETE <td>DELETE <td>
12226  **       The new change is ignored. This case does not occur if the new
12227  **       changeset was recorded immediately after the changesets already
12228  **       added to the changegroup.
12229  ** </table>
12230  **
12231  ** If the new changeset contains changes to a table that is already present
12232  ** in the changegroup, then the number of columns and the position of the
12233  ** primary key columns for the table must be consistent. If this is not the
12234  ** case, this function fails with SQLITE_SCHEMA. Except, if the changegroup
12235  ** object has been configured with a database schema using the
12236  ** sqlite3changegroup_schema() API, then it is possible to combine changesets
12237  ** with different numbers of columns for a single table, provided that
12238  ** they are otherwise compatible.
12239  **
12240  ** If the input changeset appears to be corrupt and the corruption is
12241  ** detected, SQLITE_CORRUPT is returned. Or, if an out-of-memory condition
12242  ** occurs during processing, this function returns SQLITE_NOMEM.
12243  **
12244  ** In all cases, if an error occurs the state of the final contents of the
12245  ** changegroup is undefined. If no error occurs, SQLITE_OK is returned.
12246  */
12247  SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
12248  
12249  /*
12250  ** CAPI3REF: Add A Single Change To A Changegroup
12251  ** METHOD: sqlite3_changegroup
12252  **
12253  ** This function adds the single change currently indicated by the iterator
12254  ** passed as the second argument to the changegroup object. The rules for
12255  ** adding the change are just as described for [sqlite3changegroup_add()].
12256  **
12257  ** If the change is successfully added to the changegroup, SQLITE_OK is
12258  ** returned. Otherwise, an SQLite error code is returned.
12259  **
12260  ** The iterator must point to a valid entry when this function is called.
12261  ** If it does not, SQLITE_ERROR is returned and no change is added to the
12262  ** changegroup. Additionally, the iterator must not have been opened with
12263  ** the SQLITE_CHANGESETAPPLY_INVERT flag. In this case SQLITE_ERROR is also
12264  ** returned.
12265  */
12266  SQLITE_API int sqlite3changegroup_add_change(
12267    sqlite3_changegroup*,
12268    sqlite3_changeset_iter*
12269  );
12270  
12271  
12272  
12273  /*
12274  ** CAPI3REF: Obtain A Composite Changeset From A Changegroup
12275  ** METHOD: sqlite3_changegroup
12276  **
12277  ** Obtain a buffer containing a changeset (or patchset) representing the
12278  ** current contents of the changegroup. If the inputs to the changegroup
12279  ** were themselves changesets, the output is a changeset. Or, if the
12280  ** inputs were patchsets, the output is also a patchset.
12281  **
12282  ** As with the output of the sqlite3session_changeset() and
12283  ** sqlite3session_patchset() functions, all changes related to a single
12284  ** table are grouped together in the output of this function. Tables appear
12285  ** in the same order as for the very first changeset added to the changegroup.
12286  ** If the second or subsequent changesets added to the changegroup contain
12287  ** changes for tables that do not appear in the first changeset, they are
12288  ** appended onto the end of the output changeset, again in the order in
12289  ** which they are first encountered.
12290  **
12291  ** If an error occurs, an SQLite error code is returned and the output
12292  ** variables (*pnData) and (*ppData) are set to 0. Otherwise, SQLITE_OK
12293  ** is returned and the output variables are set to the size of and a
12294  ** pointer to the output buffer, respectively. In this case it is the
12295  ** responsibility of the caller to eventually free the buffer using a
12296  ** call to sqlite3_free().
12297  */
12298  SQLITE_API int sqlite3changegroup_output(
12299    sqlite3_changegroup*,
12300    int *pnData,                    /* OUT: Size of output buffer in bytes */
12301    void **ppData                   /* OUT: Pointer to output buffer */
12302  );
12303  
12304  /*
12305  ** CAPI3REF: Delete A Changegroup Object
12306  ** DESTRUCTOR: sqlite3_changegroup
12307  */
12308  SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*);
12309  
12310  /*
12311  ** CAPI3REF: Apply A Changeset To A Database
12312  **
12313  ** Apply a changeset or patchset to a database. These functions attempt to
12314  ** update the "main" database attached to handle db with the changes found in
12315  ** the changeset passed via the second and third arguments.
12316  **
12317  ** The fourth argument (xFilter) passed to these functions is the "filter
12318  ** callback". If it is not NULL, then for each table affected by at least one
12319  ** change in the changeset, the filter callback is invoked with
12320  ** the table name as the second argument, and a copy of the context pointer
12321  ** passed as the sixth argument as the first. If the "filter callback"
12322  ** returns zero, then no attempt is made to apply any changes to the table.
12323  ** Otherwise, if the return value is non-zero or the xFilter argument to
12324  ** is NULL, all changes related to the table are attempted.
12325  **
12326  ** For each table that is not excluded by the filter callback, this function
12327  ** tests that the target database contains a compatible table. A table is
12328  ** considered compatible if all of the following are true:
12329  **
12330  ** <ul>
12331  **   <li> The table has the same name as the name recorded in the
12332  **        changeset, and
12333  **   <li> The table has at least as many columns as recorded in the
12334  **        changeset, and
12335  **   <li> The table has primary key columns in the same position as
12336  **        recorded in the changeset.
12337  ** </ul>
12338  **
12339  ** If there is no compatible table, it is not an error, but none of the
12340  ** changes associated with the table are applied. A warning message is issued
12341  ** via the sqlite3_log() mechanism with the error code SQLITE_SCHEMA. At most
12342  ** one such warning is issued for each table in the changeset.
12343  **
12344  ** For each change for which there is a compatible table, an attempt is made
12345  ** to modify the table contents according to the UPDATE, INSERT or DELETE
12346  ** change. If a change cannot be applied cleanly, the conflict handler
12347  ** function passed as the fifth argument to sqlite3changeset_apply() may be
12348  ** invoked. A description of exactly when the conflict handler is invoked for
12349  ** each type of change is below.
12350  **
12351  ** Unlike the xFilter argument, xConflict may not be passed NULL. The results
12352  ** of passing anything other than a valid function pointer as the xConflict
12353  ** argument are undefined.
12354  **
12355  ** Each time the conflict handler function is invoked, it must return one
12356  ** of [SQLITE_CHANGESET_OMIT], [SQLITE_CHANGESET_ABORT] or
12357  ** [SQLITE_CHANGESET_REPLACE]. SQLITE_CHANGESET_REPLACE may only be returned
12358  ** if the second argument passed to the conflict handler is either
12359  ** SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If the conflict-handler
12360  ** returns an illegal value, any changes already made are rolled back and
12361  ** the call to sqlite3changeset_apply() returns SQLITE_MISUSE. Different
12362  ** actions are taken by sqlite3changeset_apply() depending on the value
12363  ** returned by each invocation of the conflict-handler function. Refer to
12364  ** the documentation for the three
12365  ** [SQLITE_CHANGESET_OMIT|available return values] for details.
12366  **
12367  ** <dl>
12368  ** <dt>DELETE Changes<dd>
12369  **   For each DELETE change, the function checks if the target database
12370  **   contains a row with the same primary key value (or values) as the
12371  **   original row values stored in the changeset. If it does, and the values
12372  **   stored in all non-primary key columns also match the values stored in
12373  **   the changeset the row is deleted from the target database.
12374  **
12375  **   If a row with matching primary key values is found, but one or more of
12376  **   the non-primary key fields contains a value different from the original
12377  **   row value stored in the changeset, the conflict-handler function is
12378  **   invoked with [SQLITE_CHANGESET_DATA] as the second argument. If the
12379  **   database table has more columns than are recorded in the changeset,
12380  **   only the values of those non-primary key fields are compared against
12381  **   the current database contents - any trailing database table columns
12382  **   are ignored.
12383  **
12384  **   If no row with matching primary key values is found in the database,
12385  **   the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
12386  **   passed as the second argument.
12387  **
12388  **   If the DELETE operation is attempted, but SQLite returns SQLITE_CONSTRAINT
12389  **   (which can only happen if a foreign key constraint is violated), the
12390  **   conflict-handler function is invoked with [SQLITE_CHANGESET_CONSTRAINT]
12391  **   passed as the second argument. This includes the case where the DELETE
12392  **   operation is attempted because an earlier call to the conflict handler
12393  **   function returned [SQLITE_CHANGESET_REPLACE].
12394  **
12395  ** <dt>INSERT Changes<dd>
12396  **   For each INSERT change, an attempt is made to insert the new row into
12397  **   the database. If the changeset row contains fewer fields than the
12398  **   database table, the trailing fields are populated with their default
12399  **   values.
12400  **
12401  **   If the attempt to insert the row fails because the database already
12402  **   contains a row with the same primary key values, the conflict handler
12403  **   function is invoked with the second argument set to
12404  **   [SQLITE_CHANGESET_CONFLICT].
12405  **
12406  **   If the attempt to insert the row fails because of some other constraint
12407  **   violation (e.g. NOT NULL or UNIQUE), the conflict handler function is
12408  **   invoked with the second argument set to [SQLITE_CHANGESET_CONSTRAINT].
12409  **   This includes the case where the INSERT operation is re-attempted because
12410  **   an earlier call to the conflict handler function returned
12411  **   [SQLITE_CHANGESET_REPLACE].
12412  **
12413  ** <dt>UPDATE Changes<dd>
12414  **   For each UPDATE change, the function checks if the target database
12415  **   contains a row with the same primary key value (or values) as the
12416  **   original row values stored in the changeset. If it does, and the values
12417  **   stored in all modified non-primary key columns also match the values
12418  **   stored in the changeset the row is updated within the target database.
12419  **
12420  **   If a row with matching primary key values is found, but one or more of
12421  **   the modified non-primary key fields contains a value different from an
12422  **   original row value stored in the changeset, the conflict-handler function
12423  **   is invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since
12424  **   UPDATE changes only contain values for non-primary key fields that are
12425  **   to be modified, only those fields need to match the original values to
12426  **   avoid the SQLITE_CHANGESET_DATA conflict-handler callback.
12427  **
12428  **   If no row with matching primary key values is found in the database,
12429  **   the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
12430  **   passed as the second argument.
12431  **
12432  **   If the UPDATE operation is attempted, but SQLite returns
12433  **   SQLITE_CONSTRAINT, the conflict-handler function is invoked with
12434  **   [SQLITE_CHANGESET_CONSTRAINT] passed as the second argument.
12435  **   This includes the case where the UPDATE operation is attempted after
12436  **   an earlier call to the conflict handler function returned
12437  **   [SQLITE_CHANGESET_REPLACE].
12438  ** </dl>
12439  **
12440  ** It is safe to execute SQL statements, including those that write to the
12441  ** table that the callback related to, from within the xConflict callback.
12442  ** This can be used to further customize the application's conflict
12443  ** resolution strategy.
12444  **
12445  ** All changes made by these functions are enclosed in a savepoint transaction.
12446  ** If any other error (aside from a constraint failure when attempting to
12447  ** write to the target database) occurs, then the savepoint transaction is
12448  ** rolled back, restoring the target database to its original state, and an
12449  ** SQLite error code returned.
12450  **
12451  ** If the output parameters (ppRebase) and (pnRebase) are non-NULL and
12452  ** the input is a changeset (not a patchset), then sqlite3changeset_apply_v2()
12453  ** may set (*ppRebase) to point to a "rebase" that may be used with the
12454  ** sqlite3_rebaser APIs buffer before returning. In this case (*pnRebase)
12455  ** is set to the size of the buffer in bytes. It is the responsibility of the
12456  ** caller to eventually free any such buffer using sqlite3_free(). The buffer
12457  ** is only allocated and populated if one or more conflicts were encountered
12458  ** while applying the patchset. See comments surrounding the sqlite3_rebaser
12459  ** APIs for further details.
12460  **
12461  ** The behavior of sqlite3changeset_apply_v2() and its streaming equivalent
12462  ** may be modified by passing a combination of
12463  ** [SQLITE_CHANGESETAPPLY_NOSAVEPOINT | supported flags] as the 9th parameter.
12464  **
12465  ** Note that the sqlite3changeset_apply_v2() API is still <b>experimental</b>
12466  ** and therefore subject to change.
12467  */
12468  SQLITE_API int sqlite3changeset_apply(
12469    sqlite3 *db,                    /* Apply change to "main" db of this handle */
12470    int nChangeset,                 /* Size of changeset in bytes */
12471    void *pChangeset,               /* Changeset blob */
12472    int(*xFilter)(
12473      void *pCtx,                   /* Copy of sixth arg to _apply() */
12474      const char *zTab              /* Table name */
12475    ),
12476    int(*xConflict)(
12477      void *pCtx,                   /* Copy of sixth arg to _apply() */
12478      int eConflict,                /* DATA, MISSING, CONFLICT, CONSTRAINT */
12479      sqlite3_changeset_iter *p     /* Handle describing change and conflict */
12480    ),
12481    void *pCtx                      /* First argument passed to xConflict */
12482  );
12483  SQLITE_API int sqlite3changeset_apply_v2(
12484    sqlite3 *db,                    /* Apply change to "main" db of this handle */
12485    int nChangeset,                 /* Size of changeset in bytes */
12486    void *pChangeset,               /* Changeset blob */
12487    int(*xFilter)(
12488      void *pCtx,                   /* Copy of sixth arg to _apply() */
12489      const char *zTab              /* Table name */
12490    ),
12491    int(*xConflict)(
12492      void *pCtx,                   /* Copy of sixth arg to _apply() */
12493      int eConflict,                /* DATA, MISSING, CONFLICT, CONSTRAINT */
12494      sqlite3_changeset_iter *p     /* Handle describing change and conflict */
12495    ),
12496    void *pCtx,                     /* First argument passed to xConflict */
12497    void **ppRebase, int *pnRebase, /* OUT: Rebase data */
12498    int flags                       /* SESSION_CHANGESETAPPLY_* flags */
12499  );
12500  
12501  /*
12502  ** CAPI3REF: Flags for sqlite3changeset_apply_v2
12503  **
12504  ** The following flags may passed via the 9th parameter to
12505  ** [sqlite3changeset_apply_v2] and [sqlite3changeset_apply_v2_strm]:
12506  **
12507  ** <dl>
12508  ** <dt>SQLITE_CHANGESETAPPLY_NOSAVEPOINT <dd>
12509  **   Usually, the sessions module encloses all operations performed by
12510  **   a single call to apply_v2() or apply_v2_strm() in a [SAVEPOINT]. The
12511  **   SAVEPOINT is committed if the changeset or patchset is successfully
12512  **   applied, or rolled back if an error occurs. Specifying this flag
12513  **   causes the sessions module to omit this savepoint. In this case, if the
12514  **   caller has an open transaction or savepoint when apply_v2() is called,
12515  **   it may revert the partially applied changeset by rolling it back.
12516  **
12517  ** <dt>SQLITE_CHANGESETAPPLY_INVERT <dd>
12518  **   Invert the changeset before applying it. This is equivalent to inverting
12519  **   a changeset using sqlite3changeset_invert() before applying it. It is
12520  **   an error to specify this flag with a patchset.
12521  **
12522  ** <dt>SQLITE_CHANGESETAPPLY_IGNORENOOP <dd>
12523  **   Do not invoke the conflict handler callback for any changes that
12524  **   would not actually modify the database even if they were applied.
12525  **   Specifically, this means that the conflict handler is not invoked
12526  **   for:
12527  **    <ul>
12528  **    <li>a delete change if the row being deleted cannot be found,
12529  **    <li>an update change if the modified fields are already set to
12530  **        their new values in the conflicting row, or
12531  **    <li>an insert change if all fields of the conflicting row match
12532  **        the row being inserted.
12533  **    </ul>
12534  **
12535  ** <dt>SQLITE_CHANGESETAPPLY_FKNOACTION <dd>
12536  **   If this flag it set, then all foreign key constraints in the target
12537  **   database behave as if they were declared with "ON UPDATE NO ACTION ON
12538  **   DELETE NO ACTION", even if they are actually CASCADE, RESTRICT, SET NULL
12539  **   or SET DEFAULT.
12540  */
12541  #define SQLITE_CHANGESETAPPLY_NOSAVEPOINT   0x0001
12542  #define SQLITE_CHANGESETAPPLY_INVERT        0x0002
12543  #define SQLITE_CHANGESETAPPLY_IGNORENOOP    0x0004
12544  #define SQLITE_CHANGESETAPPLY_FKNOACTION    0x0008
12545  
12546  /*
12547  ** CAPI3REF: Constants Passed To The Conflict Handler
12548  **
12549  ** Values that may be passed as the second argument to a conflict-handler.
12550  **
12551  ** <dl>
12552  ** <dt>SQLITE_CHANGESET_DATA<dd>
12553  **   The conflict handler is invoked with CHANGESET_DATA as the second argument
12554  **   when processing a DELETE or UPDATE change if a row with the required
12555  **   PRIMARY KEY fields is present in the database, but one or more other
12556  **   (non primary-key) fields modified by the update do not contain the
12557  **   expected "before" values.
12558  **
12559  **   The conflicting row, in this case, is the database row with the matching
12560  **   primary key.
12561  **
12562  ** <dt>SQLITE_CHANGESET_NOTFOUND<dd>
12563  **   The conflict handler is invoked with CHANGESET_NOTFOUND as the second
12564  **   argument when processing a DELETE or UPDATE change if a row with the
12565  **   required PRIMARY KEY fields is not present in the database.
12566  **
12567  **   There is no conflicting row in this case. The results of invoking the
12568  **   sqlite3changeset_conflict() API are undefined.
12569  **
12570  ** <dt>SQLITE_CHANGESET_CONFLICT<dd>
12571  **   CHANGESET_CONFLICT is passed as the second argument to the conflict
12572  **   handler while processing an INSERT change if the operation would result
12573  **   in duplicate primary key values.
12574  **
12575  **   The conflicting row in this case is the database row with the matching
12576  **   primary key.
12577  **
12578  ** <dt>SQLITE_CHANGESET_FOREIGN_KEY<dd>
12579  **   If foreign key handling is enabled, and applying a changeset leaves the
12580  **   database in a state containing foreign key violations, the conflict
12581  **   handler is invoked with CHANGESET_FOREIGN_KEY as the second argument
12582  **   exactly once before the changeset is committed. If the conflict handler
12583  **   returns CHANGESET_OMIT, the changes, including those that caused the
12584  **   foreign key constraint violation, are committed. Or, if it returns
12585  **   CHANGESET_ABORT, the changeset is rolled back.
12586  **
12587  **   No current or conflicting row information is provided. The only function
12588  **   it is possible to call on the supplied sqlite3_changeset_iter handle
12589  **   is sqlite3changeset_fk_conflicts().
12590  **
12591  ** <dt>SQLITE_CHANGESET_CONSTRAINT<dd>
12592  **   If any other constraint violation occurs while applying a change (i.e.
12593  **   a UNIQUE, CHECK or NOT NULL constraint), the conflict handler is
12594  **   invoked with CHANGESET_CONSTRAINT as the second argument.
12595  **
12596  **   There is no conflicting row in this case. The results of invoking the
12597  **   sqlite3changeset_conflict() API are undefined.
12598  **
12599  ** </dl>
12600  */
12601  #define SQLITE_CHANGESET_DATA        1
12602  #define SQLITE_CHANGESET_NOTFOUND    2
12603  #define SQLITE_CHANGESET_CONFLICT    3
12604  #define SQLITE_CHANGESET_CONSTRAINT  4
12605  #define SQLITE_CHANGESET_FOREIGN_KEY 5
12606  
12607  /*
12608  ** CAPI3REF: Constants Returned By The Conflict Handler
12609  **
12610  ** A conflict handler callback must return one of the following three values.
12611  **
12612  ** <dl>
12613  ** <dt>SQLITE_CHANGESET_OMIT<dd>
12614  **   If a conflict handler returns this value no special action is taken. The
12615  **   change that caused the conflict is not applied. The session module
12616  **   continues to the next change in the changeset.
12617  **
12618  ** <dt>SQLITE_CHANGESET_REPLACE<dd>
12619  **   This value may only be returned if the second argument to the conflict
12620  **   handler was SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If this
12621  **   is not the case, any changes applied so far are rolled back and the
12622  **   call to sqlite3changeset_apply() returns SQLITE_MISUSE.
12623  **
12624  **   If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_DATA conflict
12625  **   handler, then the conflicting row is either updated or deleted, depending
12626  **   on the type of change.
12627  **
12628  **   If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_CONFLICT conflict
12629  **   handler, then the conflicting row is removed from the database and a
12630  **   second attempt to apply the change is made. If this second attempt fails,
12631  **   the original row is restored to the database before continuing.
12632  **
12633  ** <dt>SQLITE_CHANGESET_ABORT<dd>
12634  **   If this value is returned, any changes applied so far are rolled back
12635  **   and the call to sqlite3changeset_apply() returns SQLITE_ABORT.
12636  ** </dl>
12637  */
12638  #define SQLITE_CHANGESET_OMIT       0
12639  #define SQLITE_CHANGESET_REPLACE    1
12640  #define SQLITE_CHANGESET_ABORT      2
12641  
12642  /*
12643  ** CAPI3REF: Rebasing changesets
12644  ** EXPERIMENTAL
12645  **
12646  ** Suppose there is a site hosting a database in state S0. And that
12647  ** modifications are made that move that database to state S1 and a
12648  ** changeset recorded (the "local" changeset). Then, a changeset based
12649  ** on S0 is received from another site (the "remote" changeset) and
12650  ** applied to the database. The database is then in state
12651  ** (S1+"remote"), where the exact state depends on any conflict
12652  ** resolution decisions (OMIT or REPLACE) made while applying "remote".
12653  ** Rebasing a changeset is to update it to take those conflict
12654  ** resolution decisions into account, so that the same conflicts
12655  ** do not have to be resolved elsewhere in the network.
12656  **
12657  ** For example, if both the local and remote changesets contain an
12658  ** INSERT of the same key on "CREATE TABLE t1(a PRIMARY KEY, b)":
12659  **
12660  **   local:  INSERT INTO t1 VALUES(1, 'v1');
12661  **   remote: INSERT INTO t1 VALUES(1, 'v2');
12662  **
12663  ** and the conflict resolution is REPLACE, then the INSERT change is
12664  ** removed from the local changeset (it was overridden). Or, if the
12665  ** conflict resolution was "OMIT", then the local changeset is modified
12666  ** to instead contain:
12667  **
12668  **           UPDATE t1 SET b = 'v2' WHERE a=1;
12669  **
12670  ** Changes within the local changeset are rebased as follows:
12671  **
12672  ** <dl>
12673  ** <dt>Local INSERT<dd>
12674  **   This may only conflict with a remote INSERT. If the conflict
12675  **   resolution was OMIT, then add an UPDATE change to the rebased
12676  **   changeset. Or, if the conflict resolution was REPLACE, add
12677  **   nothing to the rebased changeset.
12678  **
12679  ** <dt>Local DELETE<dd>
12680  **   This may conflict with a remote UPDATE or DELETE. In both cases the
12681  **   only possible resolution is OMIT. If the remote operation was a
12682  **   DELETE, then add no change to the rebased changeset. If the remote
12683  **   operation was an UPDATE, then the old.* fields of change are updated
12684  **   to reflect the new.* values in the UPDATE.
12685  **
12686  ** <dt>Local UPDATE<dd>
12687  **   This may conflict with a remote UPDATE or DELETE. If it conflicts
12688  **   with a DELETE, and the conflict resolution was OMIT, then the update
12689  **   is changed into an INSERT. Any undefined values in the new.* record
12690  **   from the update change are filled in using the old.* values from
12691  **   the conflicting DELETE. Or, if the conflict resolution was REPLACE,
12692  **   the UPDATE change is simply omitted from the rebased changeset.
12693  **
12694  **   If conflict is with a remote UPDATE and the resolution is OMIT, then
12695  **   the old.* values are rebased using the new.* values in the remote
12696  **   change. Or, if the resolution is REPLACE, then the change is copied
12697  **   into the rebased changeset with updates to columns also updated by
12698  **   the conflicting remote UPDATE removed. If this means no columns would
12699  **   be updated, the change is omitted.
12700  ** </dl>
12701  **
12702  ** A local change may be rebased against multiple remote changes
12703  ** simultaneously. If a single key is modified by multiple remote
12704  ** changesets, they are combined as follows before the local changeset
12705  ** is rebased:
12706  **
12707  ** <ul>
12708  **    <li> If there has been one or more REPLACE resolutions on a
12709  **         key, it is rebased according to a REPLACE.
12710  **
12711  **    <li> If there have been no REPLACE resolutions on a key, then
12712  **         the local changeset is rebased according to the most recent
12713  **         of the OMIT resolutions.
12714  ** </ul>
12715  **
12716  ** Note that conflict resolutions from multiple remote changesets are
12717  ** combined on a per-field basis, not per-row. This means that in the
12718  ** case of multiple remote UPDATE operations, some fields of a single
12719  ** local change may be rebased for REPLACE while others are rebased for
12720  ** OMIT.
12721  **
12722  ** In order to rebase a local changeset, the remote changeset must first
12723  ** be applied to the local database using sqlite3changeset_apply_v2() and
12724  ** the buffer of rebase information captured. Then:
12725  **
12726  ** <ol>
12727  **   <li> An sqlite3_rebaser object is created by calling
12728  **        sqlite3rebaser_create().
12729  **   <li> The new object is configured with the rebase buffer obtained from
12730  **        sqlite3changeset_apply_v2() by calling sqlite3rebaser_configure().
12731  **        If the local changeset is to be rebased against multiple remote
12732  **        changesets, then sqlite3rebaser_configure() should be called
12733  **        multiple times, in the same order that the multiple
12734  **        sqlite3changeset_apply_v2() calls were made.
12735  **   <li> Each local changeset is rebased by calling sqlite3rebaser_rebase().
12736  **   <li> The sqlite3_rebaser object is deleted by calling
12737  **        sqlite3rebaser_delete().
12738  ** </ol>
12739  */
12740  typedef struct sqlite3_rebaser sqlite3_rebaser;
12741  
12742  /*
12743  ** CAPI3REF: Create a changeset rebaser object.
12744  ** EXPERIMENTAL
12745  **
12746  ** Allocate a new changeset rebaser object. If successful, set (*ppNew) to
12747  ** point to the new object and return SQLITE_OK. Otherwise, if an error
12748  ** occurs, return an SQLite error code (e.g. SQLITE_NOMEM) and set (*ppNew)
12749  ** to NULL.
12750  */
12751  SQLITE_API int sqlite3rebaser_create(sqlite3_rebaser **ppNew);
12752  
12753  /*
12754  ** CAPI3REF: Configure a changeset rebaser object.
12755  ** EXPERIMENTAL
12756  **
12757  ** Configure the changeset rebaser object to rebase changesets according
12758  ** to the conflict resolutions described by buffer pRebase (size nRebase
12759  ** bytes), which must have been obtained from a previous call to
12760  ** sqlite3changeset_apply_v2().
12761  */
12762  SQLITE_API int sqlite3rebaser_configure(
12763    sqlite3_rebaser*,
12764    int nRebase, const void *pRebase
12765  );
12766  
12767  /*
12768  ** CAPI3REF: Rebase a changeset
12769  ** EXPERIMENTAL
12770  **
12771  ** Argument pIn must point to a buffer containing a changeset nIn bytes
12772  ** in size. This function allocates and populates a buffer with a copy
12773  ** of the changeset rebased according to the configuration of the
12774  ** rebaser object passed as the first argument. If successful, (*ppOut)
12775  ** is set to point to the new buffer containing the rebased changeset and
12776  ** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the
12777  ** responsibility of the caller to eventually free the new buffer using
12778  ** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut)
12779  ** are set to zero and an SQLite error code returned.
12780  */
12781  SQLITE_API int sqlite3rebaser_rebase(
12782    sqlite3_rebaser*,
12783    int nIn, const void *pIn,
12784    int *pnOut, void **ppOut
12785  );
12786  
12787  /*
12788  ** CAPI3REF: Delete a changeset rebaser object.
12789  ** EXPERIMENTAL
12790  **
12791  ** Delete the changeset rebaser object and all associated resources. There
12792  ** should be one call to this function for each successful invocation
12793  ** of sqlite3rebaser_create().
12794  */
12795  SQLITE_API void sqlite3rebaser_delete(sqlite3_rebaser *p);
12796  
12797  /*
12798  ** CAPI3REF: Streaming Versions of API functions.
12799  **
12800  ** The six streaming API xxx_strm() functions serve similar purposes to the
12801  ** corresponding non-streaming API functions:
12802  **
12803  ** <table border=1 style="margin-left:8ex;margin-right:8ex">
12804  **   <tr><th>Streaming function<th>Non-streaming equivalent</th>
12805  **   <tr><td>sqlite3changeset_apply_strm<td>[sqlite3changeset_apply]
12806  **   <tr><td>sqlite3changeset_apply_strm_v2<td>[sqlite3changeset_apply_v2]
12807  **   <tr><td>sqlite3changeset_concat_strm<td>[sqlite3changeset_concat]
12808  **   <tr><td>sqlite3changeset_invert_strm<td>[sqlite3changeset_invert]
12809  **   <tr><td>sqlite3changeset_start_strm<td>[sqlite3changeset_start]
12810  **   <tr><td>sqlite3session_changeset_strm<td>[sqlite3session_changeset]
12811  **   <tr><td>sqlite3session_patchset_strm<td>[sqlite3session_patchset]
12812  ** </table>
12813  **
12814  ** Non-streaming functions that accept changesets (or patchsets) as input
12815  ** require that the entire changeset be stored in a single buffer in memory.
12816  ** Similarly, those that return a changeset or patchset do so by returning
12817  ** a pointer to a single large buffer allocated using sqlite3_malloc().
12818  ** Normally this is convenient. However, if an application running in a
12819  ** low-memory environment is required to handle very large changesets, the
12820  ** large contiguous memory allocations required can become onerous.
12821  **
12822  ** In order to avoid this problem, instead of a single large buffer, input
12823  ** is passed to a streaming API functions by way of a callback function that
12824  ** the sessions module invokes to incrementally request input data as it is
12825  ** required. In all cases, a pair of API function parameters such as
12826  **
12827  **  <pre>
12828  **  &nbsp;     int nChangeset,
12829  **  &nbsp;     void *pChangeset,
12830  **  </pre>
12831  **
12832  ** Is replaced by:
12833  **
12834  **  <pre>
12835  **  &nbsp;     int (*xInput)(void *pIn, void *pData, int *pnData),
12836  **  &nbsp;     void *pIn,
12837  **  </pre>
12838  **
12839  ** Each time the xInput callback is invoked by the sessions module, the first
12840  ** argument passed is a copy of the supplied pIn context pointer. The second
12841  ** argument, pData, points to a buffer (*pnData) bytes in size. Assuming no
12842  ** error occurs the xInput method should copy up to (*pnData) bytes of data
12843  ** into the buffer and set (*pnData) to the actual number of bytes copied
12844  ** before returning SQLITE_OK. If the input is completely exhausted, (*pnData)
12845  ** should be set to zero to indicate this. Or, if an error occurs, an SQLite
12846  ** error code should be returned. In all cases, if an xInput callback returns
12847  ** an error, all processing is abandoned and the streaming API function
12848  ** returns a copy of the error code to the caller.
12849  **
12850  ** In the case of sqlite3changeset_start_strm(), the xInput callback may be
12851  ** invoked by the sessions module at any point during the lifetime of the
12852  ** iterator. If such an xInput callback returns an error, the iterator enters
12853  ** an error state, whereby all subsequent calls to iterator functions
12854  ** immediately fail with the same error code as returned by xInput.
12855  **
12856  ** Similarly, streaming API functions that return changesets (or patchsets)
12857  ** return them in chunks by way of a callback function instead of via a
12858  ** pointer to a single large buffer. In this case, a pair of parameters such
12859  ** as:
12860  **
12861  **  <pre>
12862  **  &nbsp;     int *pnChangeset,
12863  **  &nbsp;     void **ppChangeset,
12864  **  </pre>
12865  **
12866  ** Is replaced by:
12867  **
12868  **  <pre>
12869  **  &nbsp;     int (*xOutput)(void *pOut, const void *pData, int nData),
12870  **  &nbsp;     void *pOut
12871  **  </pre>
12872  **
12873  ** The xOutput callback is invoked zero or more times to return data to
12874  ** the application. The first parameter passed to each call is a copy of the
12875  ** pOut pointer supplied by the application. The second parameter, pData,
12876  ** points to a buffer nData bytes in size containing the chunk of output
12877  ** data being returned. If the xOutput callback successfully processes the
12878  ** supplied data, it should return SQLITE_OK to indicate success. Otherwise,
12879  ** it should return some other SQLite error code. In this case processing
12880  ** is immediately abandoned and the streaming API function returns a copy
12881  ** of the xOutput error code to the application.
12882  **
12883  ** The sessions module never invokes an xOutput callback with the third
12884  ** parameter set to a value less than or equal to zero. Other than this,
12885  ** no guarantees are made as to the size of the chunks of data returned.
12886  */
12887  SQLITE_API int sqlite3changeset_apply_strm(
12888    sqlite3 *db,                    /* Apply change to "main" db of this handle */
12889    int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
12890    void *pIn,                                          /* First arg for xInput */
12891    int(*xFilter)(
12892      void *pCtx,                   /* Copy of sixth arg to _apply() */
12893      const char *zTab              /* Table name */
12894    ),
12895    int(*xConflict)(
12896      void *pCtx,                   /* Copy of sixth arg to _apply() */
12897      int eConflict,                /* DATA, MISSING, CONFLICT, CONSTRAINT */
12898      sqlite3_changeset_iter *p     /* Handle describing change and conflict */
12899    ),
12900    void *pCtx                      /* First argument passed to xConflict */
12901  );
12902  SQLITE_API int sqlite3changeset_apply_v2_strm(
12903    sqlite3 *db,                    /* Apply change to "main" db of this handle */
12904    int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
12905    void *pIn,                                          /* First arg for xInput */
12906    int(*xFilter)(
12907      void *pCtx,                   /* Copy of sixth arg to _apply() */
12908      const char *zTab              /* Table name */
12909    ),
12910    int(*xConflict)(
12911      void *pCtx,                   /* Copy of sixth arg to _apply() */
12912      int eConflict,                /* DATA, MISSING, CONFLICT, CONSTRAINT */
12913      sqlite3_changeset_iter *p     /* Handle describing change and conflict */
12914    ),
12915    void *pCtx,                     /* First argument passed to xConflict */
12916    void **ppRebase, int *pnRebase,
12917    int flags
12918  );
12919  SQLITE_API int sqlite3changeset_concat_strm(
12920    int (*xInputA)(void *pIn, void *pData, int *pnData),
12921    void *pInA,
12922    int (*xInputB)(void *pIn, void *pData, int *pnData),
12923    void *pInB,
12924    int (*xOutput)(void *pOut, const void *pData, int nData),
12925    void *pOut
12926  );
12927  SQLITE_API int sqlite3changeset_invert_strm(
12928    int (*xInput)(void *pIn, void *pData, int *pnData),
12929    void *pIn,
12930    int (*xOutput)(void *pOut, const void *pData, int nData),
12931    void *pOut
12932  );
12933  SQLITE_API int sqlite3changeset_start_strm(
12934    sqlite3_changeset_iter **pp,
12935    int (*xInput)(void *pIn, void *pData, int *pnData),
12936    void *pIn
12937  );
12938  SQLITE_API int sqlite3changeset_start_v2_strm(
12939    sqlite3_changeset_iter **pp,
12940    int (*xInput)(void *pIn, void *pData, int *pnData),
12941    void *pIn,
12942    int flags
12943  );
12944  SQLITE_API int sqlite3session_changeset_strm(
12945    sqlite3_session *pSession,
12946    int (*xOutput)(void *pOut, const void *pData, int nData),
12947    void *pOut
12948  );
12949  SQLITE_API int sqlite3session_patchset_strm(
12950    sqlite3_session *pSession,
12951    int (*xOutput)(void *pOut, const void *pData, int nData),
12952    void *pOut
12953  );
12954  SQLITE_API int sqlite3changegroup_add_strm(sqlite3_changegroup*,
12955      int (*xInput)(void *pIn, void *pData, int *pnData),
12956      void *pIn
12957  );
12958  SQLITE_API int sqlite3changegroup_output_strm(sqlite3_changegroup*,
12959      int (*xOutput)(void *pOut, const void *pData, int nData),
12960      void *pOut
12961  );
12962  SQLITE_API int sqlite3rebaser_rebase_strm(
12963    sqlite3_rebaser *pRebaser,
12964    int (*xInput)(void *pIn, void *pData, int *pnData),
12965    void *pIn,
12966    int (*xOutput)(void *pOut, const void *pData, int nData),
12967    void *pOut
12968  );
12969  
12970  /*
12971  ** CAPI3REF: Configure global parameters
12972  **
12973  ** The sqlite3session_config() interface is used to make global configuration
12974  ** changes to the sessions module in order to tune it to the specific needs
12975  ** of the application.
12976  **
12977  ** The sqlite3session_config() interface is not threadsafe. If it is invoked
12978  ** while any other thread is inside any other sessions method then the
12979  ** results are undefined. Furthermore, if it is invoked after any sessions
12980  ** related objects have been created, the results are also undefined.
12981  **
12982  ** The first argument to the sqlite3session_config() function must be one
12983  ** of the SQLITE_SESSION_CONFIG_XXX constants defined below. The
12984  ** interpretation of the (void*) value passed as the second parameter and
12985  ** the effect of calling this function depends on the value of the first
12986  ** parameter.
12987  **
12988  ** <dl>
12989  ** <dt>SQLITE_SESSION_CONFIG_STRMSIZE<dd>
12990  **    By default, the sessions module streaming interfaces attempt to input
12991  **    and output data in approximately 1 KiB chunks. This operand may be used
12992  **    to set and query the value of this configuration setting. The pointer
12993  **    passed as the second argument must point to a value of type (int).
12994  **    If this value is greater than 0, it is used as the new streaming data
12995  **    chunk size for both input and output. Before returning, the (int) value
12996  **    pointed to by pArg is set to the final value of the streaming interface
12997  **    chunk size.
12998  ** </dl>
12999  **
13000  ** This function returns SQLITE_OK if successful, or an SQLite error code
13001  ** otherwise.
13002  */
13003  SQLITE_API int sqlite3session_config(int op, void *pArg);
13004  
13005  /*
13006  ** CAPI3REF: Values for sqlite3session_config().
13007  */
13008  #define SQLITE_SESSION_CONFIG_STRMSIZE 1
13009  
13010  /*
13011  ** Make sure we can call this stuff from C++.
13012  */
13013  #ifdef __cplusplus
13014  }
13015  #endif
13016  
13017  #endif  /* !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION) */
13018  
13019  /******** End of sqlite3session.h *********/
13020  /******** Begin file fts5.h *********/
13021  /*
13022  ** 2014 May 31
13023  **
13024  ** The author disclaims copyright to this source code.  In place of
13025  ** a legal notice, here is a blessing:
13026  **
13027  **    May you do good and not evil.
13028  **    May you find forgiveness for yourself and forgive others.
13029  **    May you share freely, never taking more than you give.
13030  **
13031  ******************************************************************************
13032  **
13033  ** Interfaces to extend FTS5. Using the interfaces defined in this file,
13034  ** FTS5 may be extended with:
13035  **
13036  **     * custom tokenizers, and
13037  **     * custom auxiliary functions.
13038  */
13039  
13040  
13041  #ifndef _FTS5_H
13042  #define _FTS5_H
13043  
13044  
13045  #ifdef __cplusplus
13046  extern "C" {
13047  #endif
13048  
13049  /*************************************************************************
13050  ** CUSTOM AUXILIARY FUNCTIONS
13051  **
13052  ** Virtual table implementations may overload SQL functions by implementing
13053  ** the sqlite3_module.xFindFunction() method.
13054  */
13055  
13056  typedef struct Fts5ExtensionApi Fts5ExtensionApi;
13057  typedef struct Fts5Context Fts5Context;
13058  typedef struct Fts5PhraseIter Fts5PhraseIter;
13059  
13060  typedef void (*fts5_extension_function)(
13061    const Fts5ExtensionApi *pApi,   /* API offered by current FTS version */
13062    Fts5Context *pFts,              /* First arg to pass to pApi functions */
13063    sqlite3_context *pCtx,          /* Context for returning result/error */
13064    int nVal,                       /* Number of values in apVal[] array */
13065    sqlite3_value **apVal           /* Array of trailing arguments */
13066  );
13067  
13068  struct Fts5PhraseIter {
13069    const unsigned char *a;
13070    const unsigned char *b;
13071  };
13072  
13073  /*
13074  ** EXTENSION API FUNCTIONS
13075  **
13076  ** xUserData(pFts):
13077  **   Return a copy of the pUserData pointer passed to the xCreateFunction()
13078  **   API when the extension function was registered.
13079  **
13080  ** xColumnTotalSize(pFts, iCol, pnToken):
13081  **   If parameter iCol is less than zero, set output variable *pnToken
13082  **   to the total number of tokens in the FTS5 table. Or, if iCol is
13083  **   non-negative but less than the number of columns in the table, return
13084  **   the total number of tokens in column iCol, considering all rows in
13085  **   the FTS5 table.
13086  **
13087  **   If parameter iCol is greater than or equal to the number of columns
13088  **   in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.
13089  **   an OOM condition or IO error), an appropriate SQLite error code is
13090  **   returned.
13091  **
13092  ** xColumnCount(pFts):
13093  **   Return the number of columns in the table.
13094  **
13095  ** xColumnSize(pFts, iCol, pnToken):
13096  **   If parameter iCol is less than zero, set output variable *pnToken
13097  **   to the total number of tokens in the current row. Or, if iCol is
13098  **   non-negative but less than the number of columns in the table, set
13099  **   *pnToken to the number of tokens in column iCol of the current row.
13100  **
13101  **   If parameter iCol is greater than or equal to the number of columns
13102  **   in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.
13103  **   an OOM condition or IO error), an appropriate SQLite error code is
13104  **   returned.
13105  **
13106  **   This function may be quite inefficient if used with an FTS5 table
13107  **   created with the "columnsize=0" option.
13108  **
13109  ** xColumnText:
13110  **   If parameter iCol is less than zero, or greater than or equal to the
13111  **   number of columns in the table, SQLITE_RANGE is returned.
13112  **
13113  **   Otherwise, this function attempts to retrieve the text of column iCol of
13114  **   the current document. If successful, (*pz) is set to point to a buffer
13115  **   containing the text in utf-8 encoding, (*pn) is set to the size in bytes
13116  **   (not characters) of the buffer and SQLITE_OK is returned. Otherwise,
13117  **   if an error occurs, an SQLite error code is returned and the final values
13118  **   of (*pz) and (*pn) are undefined.
13119  **
13120  ** xPhraseCount:
13121  **   Returns the number of phrases in the current query expression.
13122  **
13123  ** xPhraseSize:
13124  **   If parameter iCol is less than zero, or greater than or equal to the
13125  **   number of phrases in the current query, as returned by xPhraseCount,
13126  **   0 is returned. Otherwise, this function returns the number of tokens in
13127  **   phrase iPhrase of the query. Phrases are numbered starting from zero.
13128  **
13129  ** xInstCount:
13130  **   Set *pnInst to the total number of occurrences of all phrases within
13131  **   the query within the current row. Return SQLITE_OK if successful, or
13132  **   an error code (i.e. SQLITE_NOMEM) if an error occurs.
13133  **
13134  **   This API can be quite slow if used with an FTS5 table created with the
13135  **   "detail=none" or "detail=column" option. If the FTS5 table is created
13136  **   with either "detail=none" or "detail=column" and "content=" option
13137  **   (i.e. if it is a contentless table), then this API always returns 0.
13138  **
13139  ** xInst:
13140  **   Query for the details of phrase match iIdx within the current row.
13141  **   Phrase matches are numbered starting from zero, so the iIdx argument
13142  **   should be greater than or equal to zero and smaller than the value
13143  **   output by xInstCount(). If iIdx is less than zero or greater than
13144  **   or equal to the value returned by xInstCount(), SQLITE_RANGE is returned.
13145  **
13146  **   Otherwise, output parameter *piPhrase is set to the phrase number, *piCol
13147  **   to the column in which it occurs and *piOff the token offset of the
13148  **   first token of the phrase. SQLITE_OK is returned if successful, or an
13149  **   error code (i.e. SQLITE_NOMEM) if an error occurs.
13150  **
13151  **   This API can be quite slow if used with an FTS5 table created with the
13152  **   "detail=none" or "detail=column" option.
13153  **
13154  ** xRowid:
13155  **   Returns the rowid of the current row.
13156  **
13157  ** xTokenize:
13158  **   Tokenize text using the tokenizer belonging to the FTS5 table.
13159  **
13160  ** xQueryPhrase(pFts5, iPhrase, pUserData, xCallback):
13161  **   This API function is used to query the FTS table for phrase iPhrase
13162  **   of the current query. Specifically, a query equivalent to:
13163  **
13164  **       ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid
13165  **
13166  **   with $p set to a phrase equivalent to the phrase iPhrase of the
13167  **   current query is executed. Any column filter that applies to
13168  **   phrase iPhrase of the current query is included in $p. For each
13169  **   row visited, the callback function passed as the fourth argument
13170  **   is invoked. The context and API objects passed to the callback
13171  **   function may be used to access the properties of each matched row.
13172  **   Invoking Api.xUserData() returns a copy of the pointer passed as
13173  **   the third argument to pUserData.
13174  **
13175  **   If parameter iPhrase is less than zero, or greater than or equal to
13176  **   the number of phrases in the query, as returned by xPhraseCount(),
13177  **   this function returns SQLITE_RANGE.
13178  **
13179  **   If the callback function returns any value other than SQLITE_OK, the
13180  **   query is abandoned and the xQueryPhrase function returns immediately.
13181  **   If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK.
13182  **   Otherwise, the error code is propagated upwards.
13183  **
13184  **   If the query runs to completion without incident, SQLITE_OK is returned.
13185  **   Or, if some error occurs before the query completes or is aborted by
13186  **   the callback, an SQLite error code is returned.
13187  **
13188  **
13189  ** xSetAuxdata(pFts5, pAux, xDelete)
13190  **
13191  **   Save the pointer passed as the second argument as the extension function's
13192  **   "auxiliary data". The pointer may then be retrieved by the current or any
13193  **   future invocation of the same fts5 extension function made as part of
13194  **   the same MATCH query using the xGetAuxdata() API.
13195  **
13196  **   Each extension function is allocated a single auxiliary data slot for
13197  **   each FTS query (MATCH expression). If the extension function is invoked
13198  **   more than once for a single FTS query, then all invocations share a
13199  **   single auxiliary data context.
13200  **
13201  **   If there is already an auxiliary data pointer when this function is
13202  **   invoked, then it is replaced by the new pointer. If an xDelete callback
13203  **   was specified along with the original pointer, it is invoked at this
13204  **   point.
13205  **
13206  **   The xDelete callback, if one is specified, is also invoked on the
13207  **   auxiliary data pointer after the FTS5 query has finished.
13208  **
13209  **   If an error (e.g. an OOM condition) occurs within this function,
13210  **   the auxiliary data is set to NULL and an error code returned. If the
13211  **   xDelete parameter was not NULL, it is invoked on the auxiliary data
13212  **   pointer before returning.
13213  **
13214  **
13215  ** xGetAuxdata(pFts5, bClear)
13216  **
13217  **   Returns the current auxiliary data pointer for the fts5 extension
13218  **   function. See the xSetAuxdata() method for details.
13219  **
13220  **   If the bClear argument is non-zero, then the auxiliary data is cleared
13221  **   (set to NULL) before this function returns. In this case the xDelete,
13222  **   if any, is not invoked.
13223  **
13224  **
13225  ** xRowCount(pFts5, pnRow)
13226  **
13227  **   This function is used to retrieve the total number of rows in the table.
13228  **   In other words, the same value that would be returned by:
13229  **
13230  **        SELECT count(*) FROM ftstable;
13231  **
13232  ** xPhraseFirst()
13233  **   This function is used, along with type Fts5PhraseIter and the xPhraseNext
13234  **   method, to iterate through all instances of a single query phrase within
13235  **   the current row. This is the same information as is accessible via the
13236  **   xInstCount/xInst APIs. While the xInstCount/xInst APIs are more convenient
13237  **   to use, this API may be faster under some circumstances. To iterate
13238  **   through instances of phrase iPhrase, use the following code:
13239  **
13240  **       Fts5PhraseIter iter;
13241  **       int iCol, iOff;
13242  **       for(pApi->xPhraseFirst(pFts, iPhrase, &iter, &iCol, &iOff);
13243  **           iCol>=0;
13244  **           pApi->xPhraseNext(pFts, &iter, &iCol, &iOff)
13245  **       ){
13246  **         // An instance of phrase iPhrase at offset iOff of column iCol
13247  **       }
13248  **
13249  **   The Fts5PhraseIter structure is defined above. Applications should not
13250  **   modify this structure directly - it should only be used as shown above
13251  **   with the xPhraseFirst() and xPhraseNext() API methods (and by
13252  **   xPhraseFirstColumn() and xPhraseNextColumn() as illustrated below).
13253  **
13254  **   This API can be quite slow if used with an FTS5 table created with the
13255  **   "detail=none" or "detail=column" option. If the FTS5 table is created
13256  **   with either "detail=none" or "detail=column" and "content=" option
13257  **   (i.e. if it is a contentless table), then this API always iterates
13258  **   through an empty set (all calls to xPhraseFirst() set iCol to -1).
13259  **
13260  **   In all cases, matches are visited in (column ASC, offset ASC) order.
13261  **   i.e. all those in column 0, sorted by offset, followed by those in
13262  **   column 1, etc.
13263  **
13264  ** xPhraseNext()
13265  **   See xPhraseFirst above.
13266  **
13267  ** xPhraseFirstColumn()
13268  **   This function and xPhraseNextColumn() are similar to the xPhraseFirst()
13269  **   and xPhraseNext() APIs described above. The difference is that instead
13270  **   of iterating through all instances of a phrase in the current row, these
13271  **   APIs are used to iterate through the set of columns in the current row
13272  **   that contain one or more instances of a specified phrase. For example:
13273  **
13274  **       Fts5PhraseIter iter;
13275  **       int iCol;
13276  **       for(pApi->xPhraseFirstColumn(pFts, iPhrase, &iter, &iCol);
13277  **           iCol>=0;
13278  **           pApi->xPhraseNextColumn(pFts, &iter, &iCol)
13279  **       ){
13280  **         // Column iCol contains at least one instance of phrase iPhrase
13281  **       }
13282  **
13283  **   This API can be quite slow if used with an FTS5 table created with the
13284  **   "detail=none" option. If the FTS5 table is created with either
13285  **   "detail=none" "content=" option (i.e. if it is a contentless table),
13286  **   then this API always iterates through an empty set (all calls to
13287  **   xPhraseFirstColumn() set iCol to -1).
13288  **
13289  **   The information accessed using this API and its companion
13290  **   xPhraseFirstColumn() may also be obtained using xPhraseFirst/xPhraseNext
13291  **   (or xInst/xInstCount). The chief advantage of this API is that it is
13292  **   significantly more efficient than those alternatives when used with
13293  **   "detail=column" tables.
13294  **
13295  ** xPhraseNextColumn()
13296  **   See xPhraseFirstColumn above.
13297  **
13298  ** xQueryToken(pFts5, iPhrase, iToken, ppToken, pnToken)
13299  **   This is used to access token iToken of phrase iPhrase of the current
13300  **   query. Before returning, output parameter *ppToken is set to point
13301  **   to a buffer containing the requested token, and *pnToken to the
13302  **   size of this buffer in bytes.
13303  **
13304  **   If iPhrase or iToken are less than zero, or if iPhrase is greater than
13305  **   or equal to the number of phrases in the query as reported by
13306  **   xPhraseCount(), or if iToken is equal to or greater than the number of
13307  **   tokens in the phrase, SQLITE_RANGE is returned and *ppToken and *pnToken
13308       are both zeroed.
13309  **
13310  **   The output text is not a copy of the query text that specified the
13311  **   token. It is the output of the tokenizer module. For tokendata=1
13312  **   tables, this includes any embedded 0x00 and trailing data.
13313  **
13314  ** xInstToken(pFts5, iIdx, iToken, ppToken, pnToken)
13315  **   This is used to access token iToken of phrase hit iIdx within the
13316  **   current row. If iIdx is less than zero or greater than or equal to the
13317  **   value returned by xInstCount(), SQLITE_RANGE is returned.  Otherwise,
13318  **   output variable (*ppToken) is set to point to a buffer containing the
13319  **   matching document token, and (*pnToken) to the size of that buffer in
13320  **   bytes.
13321  **
13322  **   The output text is not a copy of the document text that was tokenized.
13323  **   It is the output of the tokenizer module. For tokendata=1 tables, this
13324  **   includes any embedded 0x00 and trailing data.
13325  **
13326  **   This API may be slow in some cases if the token identified by parameters
13327  **   iIdx and iToken matched a prefix token in the query. In most cases, the
13328  **   first call to this API for each prefix token in the query is forced
13329  **   to scan the portion of the full-text index that matches the prefix
13330  **   token to collect the extra data required by this API. If the prefix
13331  **   token matches a large number of token instances in the document set,
13332  **   this may be a performance problem.
13333  **
13334  **   If the user knows in advance that a query may use this API for a
13335  **   prefix token, FTS5 may be configured to collect all required data as part
13336  **   of the initial querying of the full-text index, avoiding the second scan
13337  **   entirely. This also causes prefix queries that do not use this API to
13338  **   run more slowly and use more memory. FTS5 may be configured in this way
13339  **   either on a per-table basis using the [FTS5 insttoken | 'insttoken']
13340  **   option, or on a per-query basis using the
13341  **   [fts5_insttoken | fts5_insttoken()] user function.
13342  **
13343  **   This API can be quite slow if used with an FTS5 table created with the
13344  **   "detail=none" or "detail=column" option.
13345  **
13346  ** xColumnLocale(pFts5, iIdx, pzLocale, pnLocale)
13347  **   If parameter iCol is less than zero, or greater than or equal to the
13348  **   number of columns in the table, SQLITE_RANGE is returned.
13349  **
13350  **   Otherwise, this function attempts to retrieve the locale associated
13351  **   with column iCol of the current row. Usually, there is no associated
13352  **   locale, and output parameters (*pzLocale) and (*pnLocale) are set
13353  **   to NULL and 0, respectively. However, if the fts5_locale() function
13354  **   was used to associate a locale with the value when it was inserted
13355  **   into the fts5 table, then (*pzLocale) is set to point to a nul-terminated
13356  **   buffer containing the name of the locale in utf-8 encoding. (*pnLocale)
13357  **   is set to the size in bytes of the buffer, not including the
13358  **   nul-terminator.
13359  **
13360  **   If successful, SQLITE_OK is returned. Or, if an error occurs, an
13361  **   SQLite error code is returned. The final value of the output parameters
13362  **   is undefined in this case.
13363  **
13364  ** xTokenize_v2:
13365  **   Tokenize text using the tokenizer belonging to the FTS5 table. This
13366  **   API is the same as the xTokenize() API, except that it allows a tokenizer
13367  **   locale to be specified.
13368  */
13369  struct Fts5ExtensionApi {
13370    int iVersion;                   /* Currently always set to 4 */
13371  
13372    void *(*xUserData)(Fts5Context*);
13373  
13374    int (*xColumnCount)(Fts5Context*);
13375    int (*xRowCount)(Fts5Context*, sqlite3_int64 *pnRow);
13376    int (*xColumnTotalSize)(Fts5Context*, int iCol, sqlite3_int64 *pnToken);
13377  
13378    int (*xTokenize)(Fts5Context*,
13379      const char *pText, int nText, /* Text to tokenize */
13380      void *pCtx,                   /* Context passed to xToken() */
13381      int (*xToken)(void*, int, const char*, int, int, int)       /* Callback */
13382    );
13383  
13384    int (*xPhraseCount)(Fts5Context*);
13385    int (*xPhraseSize)(Fts5Context*, int iPhrase);
13386  
13387    int (*xInstCount)(Fts5Context*, int *pnInst);
13388    int (*xInst)(Fts5Context*, int iIdx, int *piPhrase, int *piCol, int *piOff);
13389  
13390    sqlite3_int64 (*xRowid)(Fts5Context*);
13391    int (*xColumnText)(Fts5Context*, int iCol, const char **pz, int *pn);
13392    int (*xColumnSize)(Fts5Context*, int iCol, int *pnToken);
13393  
13394    int (*xQueryPhrase)(Fts5Context*, int iPhrase, void *pUserData,
13395      int(*)(const Fts5ExtensionApi*,Fts5Context*,void*)
13396    );
13397    int (*xSetAuxdata)(Fts5Context*, void *pAux, void(*xDelete)(void*));
13398    void *(*xGetAuxdata)(Fts5Context*, int bClear);
13399  
13400    int (*xPhraseFirst)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*, int*);
13401    void (*xPhraseNext)(Fts5Context*, Fts5PhraseIter*, int *piCol, int *piOff);
13402  
13403    int (*xPhraseFirstColumn)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*);
13404    void (*xPhraseNextColumn)(Fts5Context*, Fts5PhraseIter*, int *piCol);
13405  
13406    /* Below this point are iVersion>=3 only */
13407    int (*xQueryToken)(Fts5Context*,
13408        int iPhrase, int iToken,
13409        const char **ppToken, int *pnToken
13410    );
13411    int (*xInstToken)(Fts5Context*, int iIdx, int iToken, const char**, int*);
13412  
13413    /* Below this point are iVersion>=4 only */
13414    int (*xColumnLocale)(Fts5Context*, int iCol, const char **pz, int *pn);
13415    int (*xTokenize_v2)(Fts5Context*,
13416      const char *pText, int nText,      /* Text to tokenize */
13417      const char *pLocale, int nLocale,  /* Locale to pass to tokenizer */
13418      void *pCtx,                        /* Context passed to xToken() */
13419      int (*xToken)(void*, int, const char*, int, int, int)       /* Callback */
13420    );
13421  };
13422  
13423  /*
13424  ** CUSTOM AUXILIARY FUNCTIONS
13425  *************************************************************************/
13426  
13427  /*************************************************************************
13428  ** CUSTOM TOKENIZERS
13429  **
13430  ** Applications may also register custom tokenizer types. A tokenizer
13431  ** is registered by providing fts5 with a populated instance of the
13432  ** following structure. All structure methods must be defined, setting
13433  ** any member of the fts5_tokenizer struct to NULL leads to undefined
13434  ** behaviour. The structure methods are expected to function as follows:
13435  **
13436  ** xCreate:
13437  **   This function is used to allocate and initialize a tokenizer instance.
13438  **   A tokenizer instance is required to actually tokenize text.
13439  **
13440  **   The first argument passed to this function is a copy of the (void*)
13441  **   pointer provided by the application when the fts5_tokenizer_v2 object
13442  **   was registered with FTS5 (the third argument to xCreateTokenizer()).
13443  **   The second and third arguments are an array of nul-terminated strings
13444  **   containing the tokenizer arguments, if any, specified following the
13445  **   tokenizer name as part of the CREATE VIRTUAL TABLE statement used
13446  **   to create the FTS5 table.
13447  **
13448  **   The final argument is an output variable. If successful, (*ppOut)
13449  **   should be set to point to the new tokenizer handle and SQLITE_OK
13450  **   returned. If an error occurs, some value other than SQLITE_OK should
13451  **   be returned. In this case, fts5 assumes that the final value of *ppOut
13452  **   is undefined.
13453  **
13454  ** xDelete:
13455  **   This function is invoked to delete a tokenizer handle previously
13456  **   allocated using xCreate(). Fts5 guarantees that this function will
13457  **   be invoked exactly once for each successful call to xCreate().
13458  **
13459  ** xTokenize:
13460  **   This function is expected to tokenize the nText byte string indicated
13461  **   by argument pText. pText may or may not be nul-terminated. The first
13462  **   argument passed to this function is a pointer to an Fts5Tokenizer object
13463  **   returned by an earlier call to xCreate().
13464  **
13465  **   The third argument indicates the reason that FTS5 is requesting
13466  **   tokenization of the supplied text. This is always one of the following
13467  **   four values:
13468  **
13469  **   <ul><li> <b>FTS5_TOKENIZE_DOCUMENT</b> - A document is being inserted into
13470  **            or removed from the FTS table. The tokenizer is being invoked to
13471  **            determine the set of tokens to add to (or delete from) the
13472  **            FTS index.
13473  **
13474  **       <li> <b>FTS5_TOKENIZE_QUERY</b> - A MATCH query is being executed
13475  **            against the FTS index. The tokenizer is being called to tokenize
13476  **            a bareword or quoted string specified as part of the query.
13477  **
13478  **       <li> <b>(FTS5_TOKENIZE_QUERY | FTS5_TOKENIZE_PREFIX)</b> - Same as
13479  **            FTS5_TOKENIZE_QUERY, except that the bareword or quoted string is
13480  **            followed by a "*" character, indicating that the last token
13481  **            returned by the tokenizer will be treated as a token prefix.
13482  **
13483  **       <li> <b>FTS5_TOKENIZE_AUX</b> - The tokenizer is being invoked to
13484  **            satisfy an fts5_api.xTokenize() request made by an auxiliary
13485  **            function. Or an fts5_api.xColumnSize() request made by the same
13486  **            on a columnsize=0 database.
13487  **   </ul>
13488  **
13489  **   The sixth and seventh arguments passed to xTokenize() - pLocale and
13490  **   nLocale - are a pointer to a buffer containing the locale to use for
13491  **   tokenization (e.g. "en_US") and its size in bytes, respectively. The
13492  **   pLocale buffer is not nul-terminated. pLocale may be passed NULL (in
13493  **   which case nLocale is always 0) to indicate that the tokenizer should
13494  **   use its default locale.
13495  **
13496  **   For each token in the input string, the supplied callback xToken() must
13497  **   be invoked. The first argument to it should be a copy of the pointer
13498  **   passed as the second argument to xTokenize(). The third and fourth
13499  **   arguments are a pointer to a buffer containing the token text, and the
13500  **   size of the token in bytes. The 4th and 5th arguments are the byte offsets
13501  **   of the first byte of and first byte immediately following the text from
13502  **   which the token is derived within the input.
13503  **
13504  **   The second argument passed to the xToken() callback ("tflags") should
13505  **   normally be set to 0. The exception is if the tokenizer supports
13506  **   synonyms. In this case see the discussion below for details.
13507  **
13508  **   FTS5 assumes the xToken() callback is invoked for each token in the
13509  **   order that they occur within the input text.
13510  **
13511  **   If an xToken() callback returns any value other than SQLITE_OK, then
13512  **   the tokenization should be abandoned and the xTokenize() method should
13513  **   immediately return a copy of the xToken() return value. Or, if the
13514  **   input buffer is exhausted, xTokenize() should return SQLITE_OK. Finally,
13515  **   if an error occurs with the xTokenize() implementation itself, it
13516  **   may abandon the tokenization and return any error code other than
13517  **   SQLITE_OK or SQLITE_DONE.
13518  **
13519  **   If the tokenizer is registered using an fts5_tokenizer_v2 object,
13520  **   then the xTokenize() method has two additional arguments - pLocale
13521  **   and nLocale. These specify the locale that the tokenizer should use
13522  **   for the current request. If pLocale and nLocale are both 0, then the
13523  **   tokenizer should use its default locale. Otherwise, pLocale points to
13524  **   an nLocale byte buffer containing the name of the locale to use as utf-8
13525  **   text. pLocale is not nul-terminated.
13526  **
13527  ** FTS5_TOKENIZER
13528  **
13529  ** There is also an fts5_tokenizer object. This is an older, deprecated,
13530  ** version of fts5_tokenizer_v2. It is similar except that:
13531  **
13532  **  <ul>
13533  **    <li> There is no "iVersion" field, and
13534  **    <li> The xTokenize() method does not take a locale argument.
13535  **  </ul>
13536  **
13537  ** Legacy fts5_tokenizer tokenizers must be registered using the
13538  ** legacy xCreateTokenizer() function, instead of xCreateTokenizer_v2().
13539  **
13540  ** Tokenizer implementations registered using either API may be retrieved
13541  ** using both xFindTokenizer() and xFindTokenizer_v2().
13542  **
13543  ** SYNONYM SUPPORT
13544  **
13545  **   Custom tokenizers may also support synonyms. Consider a case in which a
13546  **   user wishes to query for a phrase such as "first place". Using the
13547  **   built-in tokenizers, the FTS5 query 'first + place' will match instances
13548  **   of "first place" within the document set, but not alternative forms
13549  **   such as "1st place". In some applications, it would be better to match
13550  **   all instances of "first place" or "1st place" regardless of which form
13551  **   the user specified in the MATCH query text.
13552  **
13553  **   There are several ways to approach this in FTS5:
13554  **
13555  **   <ol><li> By mapping all synonyms to a single token. In this case, using
13556  **            the above example, this means that the tokenizer returns the
13557  **            same token for inputs "first" and "1st". Say that token is in
13558  **            fact "first", so that when the user inserts the document "I won
13559  **            1st place" entries are added to the index for tokens "i", "won",
13560  **            "first" and "place". If the user then queries for '1st + place',
13561  **            the tokenizer substitutes "first" for "1st" and the query works
13562  **            as expected.
13563  **
13564  **       <li> By querying the index for all synonyms of each query term
13565  **            separately. In this case, when tokenizing query text, the
13566  **            tokenizer may provide multiple synonyms for a single term
13567  **            within the document. FTS5 then queries the index for each
13568  **            synonym individually. For example, faced with the query:
13569  **
13570  **   <codeblock>
13571  **     ... MATCH 'first place'</codeblock>
13572  **
13573  **            the tokenizer offers both "1st" and "first" as synonyms for the
13574  **            first token in the MATCH query and FTS5 effectively runs a query
13575  **            similar to:
13576  **
13577  **   <codeblock>
13578  **     ... MATCH '(first OR 1st) place'</codeblock>
13579  **
13580  **            except that, for the purposes of auxiliary functions, the query
13581  **            still appears to contain just two phrases - "(first OR 1st)"
13582  **            being treated as a single phrase.
13583  **
13584  **       <li> By adding multiple synonyms for a single term to the FTS index.
13585  **            Using this method, when tokenizing document text, the tokenizer
13586  **            provides multiple synonyms for each token. So that when a
13587  **            document such as "I won first place" is tokenized, entries are
13588  **            added to the FTS index for "i", "won", "first", "1st" and
13589  **            "place".
13590  **
13591  **            This way, even if the tokenizer does not provide synonyms
13592  **            when tokenizing query text (it should not - to do so would be
13593  **            inefficient), it doesn't matter if the user queries for
13594  **            'first + place' or '1st + place', as there are entries in the
13595  **            FTS index corresponding to both forms of the first token.
13596  **   </ol>
13597  **
13598  **   Whether it is parsing document or query text, any call to xToken that
13599  **   specifies a <i>tflags</i> argument with the FTS5_TOKEN_COLOCATED bit
13600  **   is considered to supply a synonym for the previous token. For example,
13601  **   when parsing the document "I won first place", a tokenizer that supports
13602  **   synonyms would call xToken() 5 times, as follows:
13603  **
13604  **   <codeblock>
13605  **       xToken(pCtx, 0, "i",                      1,  0,  1);
13606  **       xToken(pCtx, 0, "won",                    3,  2,  5);
13607  **       xToken(pCtx, 0, "first",                  5,  6, 11);
13608  **       xToken(pCtx, FTS5_TOKEN_COLOCATED, "1st", 3,  6, 11);
13609  **       xToken(pCtx, 0, "place",                  5, 12, 17);
13610  **</codeblock>
13611  **
13612  **   It is an error to specify the FTS5_TOKEN_COLOCATED flag the first time
13613  **   xToken() is called. Multiple synonyms may be specified for a single token
13614  **   by making multiple calls to xToken(FTS5_TOKEN_COLOCATED) in sequence.
13615  **   There is no limit to the number of synonyms that may be provided for a
13616  **   single token.
13617  **
13618  **   In many cases, method (1) above is the best approach. It does not add
13619  **   extra data to the FTS index or require FTS5 to query for multiple terms,
13620  **   so it is efficient in terms of disk space and query speed. However, it
13621  **   does not support prefix queries very well. If, as suggested above, the
13622  **   token "first" is substituted for "1st" by the tokenizer, then the query:
13623  **
13624  **   <codeblock>
13625  **     ... MATCH '1s*'</codeblock>
13626  **
13627  **   will not match documents that contain the token "1st" (as the tokenizer
13628  **   will probably not map "1s" to any prefix of "first").
13629  **
13630  **   For full prefix support, method (3) may be preferred. In this case,
13631  **   because the index contains entries for both "first" and "1st", prefix
13632  **   queries such as 'fi*' or '1s*' will match correctly. However, because
13633  **   extra entries are added to the FTS index, this method uses more space
13634  **   within the database.
13635  **
13636  **   Method (2) offers a midpoint between (1) and (3). Using this method,
13637  **   a query such as '1s*' will match documents that contain the literal
13638  **   token "1st", but not "first" (assuming the tokenizer is not able to
13639  **   provide synonyms for prefixes). However, a non-prefix query like '1st'
13640  **   will match against "1st" and "first". This method does not require
13641  **   extra disk space, as no extra entries are added to the FTS index.
13642  **   On the other hand, it may require more CPU cycles to run MATCH queries,
13643  **   as separate queries of the FTS index are required for each synonym.
13644  **
13645  **   When using methods (2) or (3), it is important that the tokenizer only
13646  **   provide synonyms when tokenizing document text (method (3)) or query
13647  **   text (method (2)), not both. Doing so will not cause any errors, but is
13648  **   inefficient.
13649  */
13650  typedef struct Fts5Tokenizer Fts5Tokenizer;
13651  typedef struct fts5_tokenizer_v2 fts5_tokenizer_v2;
13652  struct fts5_tokenizer_v2 {
13653    int iVersion;             /* Currently always 2 */
13654  
13655    int (*xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut);
13656    void (*xDelete)(Fts5Tokenizer*);
13657    int (*xTokenize)(Fts5Tokenizer*,
13658        void *pCtx,
13659        int flags,            /* Mask of FTS5_TOKENIZE_* flags */
13660        const char *pText, int nText,
13661        const char *pLocale, int nLocale,
13662        int (*xToken)(
13663          void *pCtx,         /* Copy of 2nd argument to xTokenize() */
13664          int tflags,         /* Mask of FTS5_TOKEN_* flags */
13665          const char *pToken, /* Pointer to buffer containing token */
13666          int nToken,         /* Size of token in bytes */
13667          int iStart,         /* Byte offset of token within input text */
13668          int iEnd            /* Byte offset of end of token within input text */
13669        )
13670    );
13671  };
13672  
13673  /*
13674  ** New code should use the fts5_tokenizer_v2 type to define tokenizer
13675  ** implementations. The following type is included for legacy applications
13676  ** that still use it.
13677  */
13678  typedef struct fts5_tokenizer fts5_tokenizer;
13679  struct fts5_tokenizer {
13680    int (*xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut);
13681    void (*xDelete)(Fts5Tokenizer*);
13682    int (*xTokenize)(Fts5Tokenizer*,
13683        void *pCtx,
13684        int flags,            /* Mask of FTS5_TOKENIZE_* flags */
13685        const char *pText, int nText,
13686        int (*xToken)(
13687          void *pCtx,         /* Copy of 2nd argument to xTokenize() */
13688          int tflags,         /* Mask of FTS5_TOKEN_* flags */
13689          const char *pToken, /* Pointer to buffer containing token */
13690          int nToken,         /* Size of token in bytes */
13691          int iStart,         /* Byte offset of token within input text */
13692          int iEnd            /* Byte offset of end of token within input text */
13693        )
13694    );
13695  };
13696  
13697  
13698  /* Flags that may be passed as the third argument to xTokenize() */
13699  #define FTS5_TOKENIZE_QUERY     0x0001
13700  #define FTS5_TOKENIZE_PREFIX    0x0002
13701  #define FTS5_TOKENIZE_DOCUMENT  0x0004
13702  #define FTS5_TOKENIZE_AUX       0x0008
13703  
13704  /* Flags that may be passed by the tokenizer implementation back to FTS5
13705  ** as the third argument to the supplied xToken callback. */
13706  #define FTS5_TOKEN_COLOCATED    0x0001      /* Same position as prev. token */
13707  
13708  /*
13709  ** END OF CUSTOM TOKENIZERS
13710  *************************************************************************/
13711  
13712  /*************************************************************************
13713  ** FTS5 EXTENSION REGISTRATION API
13714  */
13715  typedef struct fts5_api fts5_api;
13716  struct fts5_api {
13717    int iVersion;                   /* Currently always set to 3 */
13718  
13719    /* Create a new tokenizer */
13720    int (*xCreateTokenizer)(
13721      fts5_api *pApi,
13722      const char *zName,
13723      void *pUserData,
13724      fts5_tokenizer *pTokenizer,
13725      void (*xDestroy)(void*)
13726    );
13727  
13728    /* Find an existing tokenizer */
13729    int (*xFindTokenizer)(
13730      fts5_api *pApi,
13731      const char *zName,
13732      void **ppUserData,
13733      fts5_tokenizer *pTokenizer
13734    );
13735  
13736    /* Create a new auxiliary function */
13737    int (*xCreateFunction)(
13738      fts5_api *pApi,
13739      const char *zName,
13740      void *pUserData,
13741      fts5_extension_function xFunction,
13742      void (*xDestroy)(void*)
13743    );
13744  
13745    /* APIs below this point are only available if iVersion>=3 */
13746  
13747    /* Create a new tokenizer */
13748    int (*xCreateTokenizer_v2)(
13749      fts5_api *pApi,
13750      const char *zName,
13751      void *pUserData,
13752      fts5_tokenizer_v2 *pTokenizer,
13753      void (*xDestroy)(void*)
13754    );
13755  
13756    /* Find an existing tokenizer */
13757    int (*xFindTokenizer_v2)(
13758      fts5_api *pApi,
13759      const char *zName,
13760      void **ppUserData,
13761      fts5_tokenizer_v2 **ppTokenizer
13762    );
13763  };
13764  
13765  /*
13766  ** END OF REGISTRATION API
13767  *************************************************************************/
13768  
13769  #ifdef __cplusplus
13770  }  /* end of the 'extern "C"' block */
13771  #endif
13772  
13773  #endif /* _FTS5_H */
13774  
13775  /******** End of fts5.h *********/
13776  #endif /* SQLITE3_H */
13777  #else // USE_LIBSQLITE3
13778   // If users really want to link against the system sqlite3 we
13779  // need to make this file a noop.
13780   #endif