/*1** 2001-09-152**3** The author disclaims copyright to this source code. In place of4** a legal notice, here is a blessing:5**6** May you do good and not evil.7** May you find forgiveness for yourself and forgive others.8** May you share freely, never taking more than you give.9**10*************************************************************************11** This header file defines the interface that the SQLite library12** presents to client programs. If a C-function, structure, datatype,13** or constant definition does not appear in this file, then it is14** not a published API of SQLite, is subject to change without15** notice, and should not be referenced by programs that use SQLite.16**17** Some of the definitions that are in this file are marked as18** "experimental". Experimental interfaces are normally new19** features recently added to SQLite. We do not anticipate changes20** to experimental interfaces but reserve the right to make minor changes21** if experience from use "in the wild" suggest such changes are prudent.22**23** The official C-language API documentation for SQLite is derived24** from comments in this file. This file is the authoritative source25** on how SQLite interfaces are supposed to operate.26**27** The name of this file under configuration management is "sqlite.h.in".28** The makefile makes some minor changes to this file (such as inserting29** the version number) and changes its name to "sqlite3.h" as30** part of the build process.31*/32#ifndef SQLITE3_H33#define SQLITE3_H34#include <stdarg.h> /* Needed for the definition of va_list */3536/*37** Make sure we can call this stuff from C++.38*/39#ifdef __cplusplus40extern "C" {41#endif424344/*45** Facilitate override of interface linkage and calling conventions.46** Be aware that these macros may not be used within this particular47** translation of the amalgamation and its associated header file.48**49** The SQLITE_EXTERN and SQLITE_API macros are used to instruct the50** compiler that the target identifier should have external linkage.51**52** The SQLITE_CDECL macro is used to set the calling convention for53** public functions that accept a variable number of arguments.54**55** The SQLITE_APICALL macro is used to set the calling convention for56** public functions that accept a fixed number of arguments.57**58** The SQLITE_STDCALL macro is no longer used and is now deprecated.59**60** The SQLITE_CALLBACK macro is used to set the calling convention for61** function pointers.62**63** The SQLITE_SYSAPI macro is used to set the calling convention for64** functions provided by the operating system.65**66** Currently, the SQLITE_CDECL, SQLITE_APICALL, SQLITE_CALLBACK, and67** SQLITE_SYSAPI macros are used only when building for environments68** that require non-default calling conventions.69*/70#ifndef SQLITE_EXTERN71# define SQLITE_EXTERN extern72#endif73#ifndef SQLITE_API74# define SQLITE_API75#endif76#ifndef SQLITE_CDECL77# define SQLITE_CDECL78#endif79#ifndef SQLITE_APICALL80# define SQLITE_APICALL81#endif82#ifndef SQLITE_STDCALL83# define SQLITE_STDCALL SQLITE_APICALL84#endif85#ifndef SQLITE_CALLBACK86# define SQLITE_CALLBACK87#endif88#ifndef SQLITE_SYSAPI89# define SQLITE_SYSAPI90#endif9192/*93** These no-op macros are used in front of interfaces to mark those94** interfaces as either deprecated or experimental. New applications95** should not use deprecated interfaces - they are supported for backwards96** compatibility only. Application writers should be aware that97** experimental interfaces are subject to change in point releases.98**99** These macros used to resolve to various kinds of compiler magic that100** would generate warning messages when they were used. But that101** compiler magic ended up generating such a flurry of bug reports102** that we have taken it all out and gone back to using simple103** noop macros.104*/105#define SQLITE_DEPRECATED106#define SQLITE_EXPERIMENTAL107108/*109** Ensure these symbols were not defined by some previous header file.110*/111#ifdef SQLITE_VERSION112# undef SQLITE_VERSION113#endif114#ifdef SQLITE_VERSION_NUMBER115# undef SQLITE_VERSION_NUMBER116#endif117118/*119** CAPI3REF: Compile-Time Library Version Numbers120**121** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header122** evaluates to a string literal that is the SQLite version in the123** format "X.Y.Z" where X is the major version number (always 3 for124** SQLite3) and Y is the minor version number and Z is the release number.)^125** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer126** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same127** numbers used in [SQLITE_VERSION].)^128** The SQLITE_VERSION_NUMBER for any given release of SQLite will also129** be larger than the release from which it is derived. Either Y will130** be held constant and Z will be incremented or else Y will be incremented131** and Z will be reset to zero.132**133** Since [version 3.6.18] ([dateof:3.6.18]),134** SQLite source code has been stored in the135** <a href="http://fossil-scm.org/">Fossil configuration management136** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to137** a string which identifies a particular check-in of SQLite138** within its configuration management system. ^The SQLITE_SOURCE_ID139** string contains the date and time of the check-in (UTC) and a SHA1140** or SHA3-256 hash of the entire source tree. If the source code has141** been edited in any way since it was last checked in, then the last142** four hexadecimal digits of the hash may be modified.143**144** See also: [sqlite3_libversion()],145** [sqlite3_libversion_number()], [sqlite3_sourceid()],146** [sqlite_version()] and [sqlite_source_id()].147*/148#define SQLITE_VERSION "3.51.1"149#define SQLITE_VERSION_NUMBER 3051001150#define SQLITE_SOURCE_ID "2025-11-28 17:28:25 281fc0e9afc38674b9b0991943b9e9d1e64c6cbdb133d35f6f5c87ff6af38a88"151#define SQLITE_SCM_BRANCH "branch-3.51"152#define SQLITE_SCM_TAGS "release version-3.51.1"153#define SQLITE_SCM_DATETIME "2025-11-28T17:28:25.933Z"154155/*156** CAPI3REF: Run-Time Library Version Numbers157** KEYWORDS: sqlite3_version sqlite3_sourceid158**159** These interfaces provide the same information as the [SQLITE_VERSION],160** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros161** but are associated with the library instead of the header file. ^(Cautious162** programmers might include assert() statements in their application to163** verify that values returned by these interfaces match the macros in164** the header, and thus ensure that the application is165** compiled with matching library and header files.166**167** <blockquote><pre>168** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );169** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 );170** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );171** </pre></blockquote>)^172**173** ^The sqlite3_version[] string constant contains the text of the174** [SQLITE_VERSION] macro. ^The sqlite3_libversion() function returns a175** pointer to the sqlite3_version[] string constant. The sqlite3_libversion()176** function is provided for use in DLLs since DLL users usually do not have177** direct access to string constants within the DLL. ^The178** sqlite3_libversion_number() function returns an integer equal to179** [SQLITE_VERSION_NUMBER]. ^(The sqlite3_sourceid() function returns180** a pointer to a string constant whose value is the same as the181** [SQLITE_SOURCE_ID] C preprocessor macro. Except if SQLite is built182** using an edited copy of [the amalgamation], then the last four characters183** of the hash might be different from [SQLITE_SOURCE_ID].)^184**185** See also: [sqlite_version()] and [sqlite_source_id()].186*/187SQLITE_API SQLITE_EXTERN const char sqlite3_version[];188SQLITE_API const char *sqlite3_libversion(void);189SQLITE_API const char *sqlite3_sourceid(void);190SQLITE_API int sqlite3_libversion_number(void);191192/*193** CAPI3REF: Run-Time Library Compilation Options Diagnostics194**195** ^The sqlite3_compileoption_used() function returns 0 or 1196** indicating whether the specified option was defined at197** compile time. ^The SQLITE_ prefix may be omitted from the198** option name passed to sqlite3_compileoption_used().199**200** ^The sqlite3_compileoption_get() function allows iterating201** over the list of options that were defined at compile time by202** returning the N-th compile time option string. ^If N is out of range,203** sqlite3_compileoption_get() returns a NULL pointer. ^The SQLITE_204** prefix is omitted from any strings returned by205** sqlite3_compileoption_get().206**207** ^Support for the diagnostic functions sqlite3_compileoption_used()208** and sqlite3_compileoption_get() may be omitted by specifying the209** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.210**211** See also: SQL functions [sqlite_compileoption_used()] and212** [sqlite_compileoption_get()] and the [compile_options pragma].213*/214#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS215SQLITE_API int sqlite3_compileoption_used(const char *zOptName);216SQLITE_API const char *sqlite3_compileoption_get(int N);217#else218# define sqlite3_compileoption_used(X) 0219# define sqlite3_compileoption_get(X) ((void*)0)220#endif221222/*223** CAPI3REF: Test To See If The Library Is Threadsafe224**225** ^The sqlite3_threadsafe() function returns zero if and only if226** SQLite was compiled with mutexing code omitted due to the227** [SQLITE_THREADSAFE] compile-time option being set to 0.228**229** SQLite can be compiled with or without mutexes. When230** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes231** are enabled and SQLite is threadsafe. When the232** [SQLITE_THREADSAFE] macro is 0,233** the mutexes are omitted. Without the mutexes, it is not safe234** to use SQLite concurrently from more than one thread.235**236** Enabling mutexes incurs a measurable performance penalty.237** So if speed is of utmost importance, it makes sense to disable238** the mutexes. But for maximum safety, mutexes should be enabled.239** ^The default behavior is for mutexes to be enabled.240**241** This interface can be used by an application to make sure that the242** version of SQLite that it is linking against was compiled with243** the desired setting of the [SQLITE_THREADSAFE] macro.244**245** This interface only reports on the compile-time mutex setting246** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with247** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but248** can be fully or partially disabled using a call to [sqlite3_config()]249** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],250** or [SQLITE_CONFIG_SERIALIZED]. ^(The return value of the251** sqlite3_threadsafe() function shows only the compile-time setting of252** thread safety, not any run-time changes to that setting made by253** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()254** is unchanged by calls to sqlite3_config().)^255**256** See the [threading mode] documentation for additional information.257*/258SQLITE_API int sqlite3_threadsafe(void);259260/*261** CAPI3REF: Database Connection Handle262** KEYWORDS: {database connection} {database connections}263**264** Each open SQLite database is represented by a pointer to an instance of265** the opaque structure named "sqlite3". It is useful to think of an sqlite3266** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and267** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]268** and [sqlite3_close_v2()] are its destructors. There are many other269** interfaces (such as270** [sqlite3_prepare_v2()], [sqlite3_create_function()], and271** [sqlite3_busy_timeout()] to name but three) that are methods on an272** sqlite3 object.273*/274typedef struct sqlite3 sqlite3;275276/*277** CAPI3REF: 64-Bit Integer Types278** KEYWORDS: sqlite_int64 sqlite_uint64279**280** Because there is no cross-platform way to specify 64-bit integer types281** SQLite includes typedefs for 64-bit signed and unsigned integers.282**283** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions.284** The sqlite_int64 and sqlite_uint64 types are supported for backwards285** compatibility only.286**287** ^The sqlite3_int64 and sqlite_int64 types can store integer values288** between -9223372036854775808 and +9223372036854775807 inclusive. ^The289** sqlite3_uint64 and sqlite_uint64 types can store integer values290** between 0 and +18446744073709551615 inclusive.291*/292#ifdef SQLITE_INT64_TYPE293typedef SQLITE_INT64_TYPE sqlite_int64;294# ifdef SQLITE_UINT64_TYPE295typedef SQLITE_UINT64_TYPE sqlite_uint64;296# else297typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;298# endif299#elif defined(_MSC_VER) || defined(__BORLANDC__)300typedef __int64 sqlite_int64;301typedef unsigned __int64 sqlite_uint64;302#else303typedef long long int sqlite_int64;304typedef unsigned long long int sqlite_uint64;305#endif306typedef sqlite_int64 sqlite3_int64;307typedef sqlite_uint64 sqlite3_uint64;308309/*310** If compiling for a processor that lacks floating point support,311** substitute integer for floating-point.312*/313#ifdef SQLITE_OMIT_FLOATING_POINT314# define double sqlite3_int64315#endif316317/*318** CAPI3REF: Closing A Database Connection319** DESTRUCTOR: sqlite3320**321** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors322** for the [sqlite3] object.323** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if324** the [sqlite3] object is successfully destroyed and all associated325** resources are deallocated.326**327** Ideally, applications should [sqlite3_finalize | finalize] all328** [prepared statements], [sqlite3_blob_close | close] all [BLOB handles], and329** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated330** with the [sqlite3] object prior to attempting to close the object.331** ^If the database connection is associated with unfinalized prepared332** statements, BLOB handlers, and/or unfinished sqlite3_backup objects then333** sqlite3_close() will leave the database connection open and return334** [SQLITE_BUSY]. ^If sqlite3_close_v2() is called with unfinalized prepared335** statements, unclosed BLOB handlers, and/or unfinished sqlite3_backups,336** it returns [SQLITE_OK] regardless, but instead of deallocating the database337** connection immediately, it marks the database connection as an unusable338** "zombie" and makes arrangements to automatically deallocate the database339** connection after all prepared statements are finalized, all BLOB handles340** are closed, and all backups have finished. The sqlite3_close_v2() interface341** is intended for use with host languages that are garbage collected, and342** where the order in which destructors are called is arbitrary.343**344** ^If an [sqlite3] object is destroyed while a transaction is open,345** the transaction is automatically rolled back.346**347** The C parameter to [sqlite3_close(C)] and [sqlite3_close_v2(C)]348** must be either a NULL349** pointer or an [sqlite3] object pointer obtained350** from [sqlite3_open()], [sqlite3_open16()], or351** [sqlite3_open_v2()], and not previously closed.352** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer353** argument is a harmless no-op.354*/355SQLITE_API int sqlite3_close(sqlite3*);356SQLITE_API int sqlite3_close_v2(sqlite3*);357358/*359** The type for a callback function.360** This is legacy and deprecated. It is included for historical361** compatibility and is not documented.362*/363typedef int (*sqlite3_callback)(void*,int,char**, char**);364365/*366** CAPI3REF: One-Step Query Execution Interface367** METHOD: sqlite3368**369** The sqlite3_exec() interface is a convenience wrapper around370** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],371** that allows an application to run multiple statements of SQL372** without having to use a lot of C code.373**374** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,375** semicolon-separated SQL statements passed into its 2nd argument,376** in the context of the [database connection] passed in as its 1st377** argument. ^If the callback function of the 3rd argument to378** sqlite3_exec() is not NULL, then it is invoked for each result row379** coming out of the evaluated SQL statements. ^The 4th argument to380** sqlite3_exec() is relayed through to the 1st argument of each381** callback invocation. ^If the callback pointer to sqlite3_exec()382** is NULL, then no callback is ever invoked and result rows are383** ignored.384**385** ^If an error occurs while evaluating the SQL statements passed into386** sqlite3_exec(), then execution of the current statement stops and387** subsequent statements are skipped. ^If the 5th parameter to sqlite3_exec()388** is not NULL then any error message is written into memory obtained389** from [sqlite3_malloc()] and passed back through the 5th parameter.390** To avoid memory leaks, the application should invoke [sqlite3_free()]391** on error message strings returned through the 5th parameter of392** sqlite3_exec() after the error message string is no longer needed.393** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors394** occur, then sqlite3_exec() sets the pointer in its 5th parameter to395** NULL before returning.396**397** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec()398** routine returns SQLITE_ABORT without invoking the callback again and399** without running any subsequent SQL statements.400**401** ^The 2nd argument to the sqlite3_exec() callback function is the402** number of columns in the result. ^The 3rd argument to the sqlite3_exec()403** callback is an array of pointers to strings obtained as if from404** [sqlite3_column_text()], one for each column. ^If an element of a405** result row is NULL then the corresponding string pointer for the406** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the407** sqlite3_exec() callback is an array of pointers to strings where each408** entry represents the name of a corresponding result column as obtained409** from [sqlite3_column_name()].410**411** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer412** to an empty string, or a pointer that contains only whitespace and/or413** SQL comments, then no SQL statements are evaluated and the database414** is not changed.415**416** Restrictions:417**418** <ul>419** <li> The application must ensure that the 1st parameter to sqlite3_exec()420** is a valid and open [database connection].421** <li> The application must not close the [database connection] specified by422** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.423** <li> The application must not modify the SQL statement text passed into424** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.425** <li> The application must not dereference the arrays or string pointers426** passed as the 3rd and 4th callback parameters after it returns.427** </ul>428*/429SQLITE_API int sqlite3_exec(430sqlite3*, /* An open database */431const char *sql, /* SQL to be evaluated */432int (*callback)(void*,int,char**,char**), /* Callback function */433void *, /* 1st argument to callback */434char **errmsg /* Error msg written here */435);436437/*438** CAPI3REF: Result Codes439** KEYWORDS: {result code definitions}440**441** Many SQLite functions return an integer result code from the set shown442** here in order to indicate success or failure.443**444** New error codes may be added in future versions of SQLite.445**446** See also: [extended result code definitions]447*/448#define SQLITE_OK 0 /* Successful result */449/* beginning-of-error-codes */450#define SQLITE_ERROR 1 /* Generic error */451#define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */452#define SQLITE_PERM 3 /* Access permission denied */453#define SQLITE_ABORT 4 /* Callback routine requested an abort */454#define SQLITE_BUSY 5 /* The database file is locked */455#define SQLITE_LOCKED 6 /* A table in the database is locked */456#define SQLITE_NOMEM 7 /* A malloc() failed */457#define SQLITE_READONLY 8 /* Attempt to write a readonly database */458#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/459#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */460#define SQLITE_CORRUPT 11 /* The database disk image is malformed */461#define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */462#define SQLITE_FULL 13 /* Insertion failed because database is full */463#define SQLITE_CANTOPEN 14 /* Unable to open the database file */464#define SQLITE_PROTOCOL 15 /* Database lock protocol error */465#define SQLITE_EMPTY 16 /* Internal use only */466#define SQLITE_SCHEMA 17 /* The database schema changed */467#define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */468#define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */469#define SQLITE_MISMATCH 20 /* Data type mismatch */470#define SQLITE_MISUSE 21 /* Library used incorrectly */471#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */472#define SQLITE_AUTH 23 /* Authorization denied */473#define SQLITE_FORMAT 24 /* Not used */474#define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */475#define SQLITE_NOTADB 26 /* File opened that is not a database file */476#define SQLITE_NOTICE 27 /* Notifications from sqlite3_log() */477#define SQLITE_WARNING 28 /* Warnings from sqlite3_log() */478#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */479#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */480/* end-of-error-codes */481482/*483** CAPI3REF: Extended Result Codes484** KEYWORDS: {extended result code definitions}485**486** In its default configuration, SQLite API routines return one of 30 integer487** [result codes]. However, experience has shown that many of488** these result codes are too coarse-grained. They do not provide as489** much information about problems as programmers might like. In an effort to490** address this, newer versions of SQLite (version 3.3.8 [dateof:3.3.8]491** and later) include492** support for additional result codes that provide more detailed information493** about errors. These [extended result codes] are enabled or disabled494** on a per database connection basis using the495** [sqlite3_extended_result_codes()] API. Or, the extended code for496** the most recent error can be obtained using497** [sqlite3_extended_errcode()].498*/499#define SQLITE_ERROR_MISSING_COLLSEQ (SQLITE_ERROR | (1<<8))500#define SQLITE_ERROR_RETRY (SQLITE_ERROR | (2<<8))501#define SQLITE_ERROR_SNAPSHOT (SQLITE_ERROR | (3<<8))502#define SQLITE_ERROR_RESERVESIZE (SQLITE_ERROR | (4<<8))503#define SQLITE_ERROR_KEY (SQLITE_ERROR | (5<<8))504#define SQLITE_ERROR_UNABLE (SQLITE_ERROR | (6<<8))505#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8))506#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8))507#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8))508#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8))509#define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8))510#define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8))511#define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8))512#define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8))513#define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8))514#define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8))515#define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8))516#define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8))517#define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8))518#define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))519#define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8))520#define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8))521#define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8))522#define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8))523#define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8))524#define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8))525#define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8))526#define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))527#define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8))528#define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))529#define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8))530#define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8))531#define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8))532#define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8))533#define SQLITE_IOERR_BEGIN_ATOMIC (SQLITE_IOERR | (29<<8))534#define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8))535#define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8))536#define SQLITE_IOERR_DATA (SQLITE_IOERR | (32<<8))537#define SQLITE_IOERR_CORRUPTFS (SQLITE_IOERR | (33<<8))538#define SQLITE_IOERR_IN_PAGE (SQLITE_IOERR | (34<<8))539#define SQLITE_IOERR_BADKEY (SQLITE_IOERR | (35<<8))540#define SQLITE_IOERR_CODEC (SQLITE_IOERR | (36<<8))541#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))542#define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8))543#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))544#define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))545#define SQLITE_BUSY_TIMEOUT (SQLITE_BUSY | (3<<8))546#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))547#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))548#define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))549#define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))550#define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */551#define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8))552#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))553#define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8))554#define SQLITE_CORRUPT_INDEX (SQLITE_CORRUPT | (3<<8))555#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))556#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))557#define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))558#define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))559#define SQLITE_READONLY_CANTINIT (SQLITE_READONLY | (5<<8))560#define SQLITE_READONLY_DIRECTORY (SQLITE_READONLY | (6<<8))561#define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))562#define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))563#define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))564#define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))565#define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))566#define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8))567#define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8))568#define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))569#define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))570#define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))571#define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))572#define SQLITE_CONSTRAINT_PINNED (SQLITE_CONSTRAINT |(11<<8))573#define SQLITE_CONSTRAINT_DATATYPE (SQLITE_CONSTRAINT |(12<<8))574#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))575#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))576#define SQLITE_NOTICE_RBU (SQLITE_NOTICE | (3<<8))577#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))578#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))579#define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))580#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */581582/*583** CAPI3REF: Flags For File Open Operations584**585** These bit values are intended for use in the586** 3rd parameter to the [sqlite3_open_v2()] interface and587** in the 4th parameter to the [sqlite3_vfs.xOpen] method.588**589** Only those flags marked as "Ok for sqlite3_open_v2()" may be590** used as the third argument to the [sqlite3_open_v2()] interface.591** The other flags have historically been ignored by sqlite3_open_v2(),592** though future versions of SQLite might change so that an error is593** raised if any of the disallowed bits are passed into sqlite3_open_v2().594** Applications should not depend on the historical behavior.595**596** Note in particular that passing the SQLITE_OPEN_EXCLUSIVE flag into597** [sqlite3_open_v2()] does *not* cause the underlying database file598** to be opened using O_EXCL. Passing SQLITE_OPEN_EXCLUSIVE into599** [sqlite3_open_v2()] has historically been a no-op and might become an600** error in future versions of SQLite.601*/602#define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */603#define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */604#define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */605#define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */606#define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */607#define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */608#define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */609#define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */610#define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */611#define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */612#define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */613#define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */614#define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */615#define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */616#define SQLITE_OPEN_SUPER_JOURNAL 0x00004000 /* VFS only */617#define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */618#define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */619#define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */620#define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */621#define SQLITE_OPEN_WAL 0x00080000 /* VFS only */622#define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */623#define SQLITE_OPEN_EXRESCODE 0x02000000 /* Extended result codes */624625/* Reserved: 0x00F00000 */626/* Legacy compatibility: */627#define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */628629630/*631** CAPI3REF: Device Characteristics632**633** The xDeviceCharacteristics method of the [sqlite3_io_methods]634** object returns an integer which is a vector of these635** bit values expressing I/O characteristics of the mass storage636** device that holds the file that the [sqlite3_io_methods]637** refers to.638**639** The SQLITE_IOCAP_ATOMIC property means that all writes of640** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values641** mean that writes of blocks that are nnn bytes in size and642** are aligned to an address which is an integer multiple of643** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means644** that when data is appended to a file, the data is appended645** first then the size of the file is extended, never the other646** way around. The SQLITE_IOCAP_SEQUENTIAL property means that647** information is written to disk in the same order as calls648** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that649** after reboot following a crash or power loss, the only bytes in a650** file that were written at the application level might have changed651** and that adjacent bytes, even bytes within the same sector are652** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN653** flag indicates that a file cannot be deleted when open. The654** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on655** read-only media and cannot be changed even by processes with656** elevated privileges.657**658** The SQLITE_IOCAP_BATCH_ATOMIC property means that the underlying659** filesystem supports doing multiple write operations atomically when those660** write operations are bracketed by [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] and661** [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE].662**663** The SQLITE_IOCAP_SUBPAGE_READ property means that it is ok to read664** from the database file in amounts that are not a multiple of the665** page size and that do not begin at a page boundary. Without this666** property, SQLite is careful to only do full-page reads and write667** on aligned pages, with the one exception that it will do a sub-page668** read of the first page to access the database header.669*/670#define SQLITE_IOCAP_ATOMIC 0x00000001671#define SQLITE_IOCAP_ATOMIC512 0x00000002672#define SQLITE_IOCAP_ATOMIC1K 0x00000004673#define SQLITE_IOCAP_ATOMIC2K 0x00000008674#define SQLITE_IOCAP_ATOMIC4K 0x00000010675#define SQLITE_IOCAP_ATOMIC8K 0x00000020676#define SQLITE_IOCAP_ATOMIC16K 0x00000040677#define SQLITE_IOCAP_ATOMIC32K 0x00000080678#define SQLITE_IOCAP_ATOMIC64K 0x00000100679#define SQLITE_IOCAP_SAFE_APPEND 0x00000200680#define SQLITE_IOCAP_SEQUENTIAL 0x00000400681#define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800682#define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000683#define SQLITE_IOCAP_IMMUTABLE 0x00002000684#define SQLITE_IOCAP_BATCH_ATOMIC 0x00004000685#define SQLITE_IOCAP_SUBPAGE_READ 0x00008000686687/*688** CAPI3REF: File Locking Levels689**690** SQLite uses one of these integer values as the second691** argument to calls it makes to the xLock() and xUnlock() methods692** of an [sqlite3_io_methods] object. These values are ordered from693** least restrictive to most restrictive.694**695** The argument to xLock() is always SHARED or higher. The argument to696** xUnlock is either SHARED or NONE.697*/698#define SQLITE_LOCK_NONE 0 /* xUnlock() only */699#define SQLITE_LOCK_SHARED 1 /* xLock() or xUnlock() */700#define SQLITE_LOCK_RESERVED 2 /* xLock() only */701#define SQLITE_LOCK_PENDING 3 /* xLock() only */702#define SQLITE_LOCK_EXCLUSIVE 4 /* xLock() only */703704/*705** CAPI3REF: Synchronization Type Flags706**707** When SQLite invokes the xSync() method of an708** [sqlite3_io_methods] object it uses a combination of709** these integer values as the second argument.710**711** When the SQLITE_SYNC_DATAONLY flag is used, it means that the712** sync operation only needs to flush data to mass storage. Inode713** information need not be flushed. If the lower four bits of the flag714** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics.715** If the lower four bits equal SQLITE_SYNC_FULL, that means716** to use Mac OS X style fullsync instead of fsync().717**718** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags719** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL720** settings. The [synchronous pragma] determines when calls to the721** xSync VFS method occur and applies uniformly across all platforms.722** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how723** energetic or rigorous or forceful the sync operations are and724** only make a difference on Mac OSX for the default SQLite code.725** (Third-party VFS implementations might also make the distinction726** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the727** operating systems natively supported by SQLite, only Mac OSX728** cares about the difference.)729*/730#define SQLITE_SYNC_NORMAL 0x00002731#define SQLITE_SYNC_FULL 0x00003732#define SQLITE_SYNC_DATAONLY 0x00010733734/*735** CAPI3REF: OS Interface Open File Handle736**737** An [sqlite3_file] object represents an open file in the738** [sqlite3_vfs | OS interface layer]. Individual OS interface739** implementations will740** want to subclass this object by appending additional fields741** for their own use. The pMethods entry is a pointer to an742** [sqlite3_io_methods] object that defines methods for performing743** I/O operations on the open file.744*/745typedef struct sqlite3_file sqlite3_file;746struct sqlite3_file {747const struct sqlite3_io_methods *pMethods; /* Methods for an open file */748};749750/*751** CAPI3REF: OS Interface File Virtual Methods Object752**753** Every file opened by the [sqlite3_vfs.xOpen] method populates an754** [sqlite3_file] object (or, more commonly, a subclass of the755** [sqlite3_file] object) with a pointer to an instance of this object.756** This object defines the methods used to perform various operations757** against the open file represented by the [sqlite3_file] object.758**759** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element760** to a non-NULL pointer, then the sqlite3_io_methods.xClose method761** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The762** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen]763** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element764** to NULL.765**766** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or767** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().768** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY]769** flag may be ORed in to indicate that only the data of the file770** and not its inode needs to be synced.771**772** The integer values to xLock() and xUnlock() are one of773** <ul>774** <li> [SQLITE_LOCK_NONE],775** <li> [SQLITE_LOCK_SHARED],776** <li> [SQLITE_LOCK_RESERVED],777** <li> [SQLITE_LOCK_PENDING], or778** <li> [SQLITE_LOCK_EXCLUSIVE].779** </ul>780** xLock() upgrades the database file lock. In other words, xLock() moves the781** database file lock in the direction NONE toward EXCLUSIVE. The argument to782** xLock() is always one of SHARED, RESERVED, PENDING, or EXCLUSIVE, never783** SQLITE_LOCK_NONE. If the database file lock is already at or above the784** requested lock, then the call to xLock() is a no-op.785** xUnlock() downgrades the database file lock to either SHARED or NONE.786** If the lock is already at or below the requested lock state, then the call787** to xUnlock() is a no-op.788** The xCheckReservedLock() method checks whether any database connection,789** either in this process or in some other process, is holding a RESERVED,790** PENDING, or EXCLUSIVE lock on the file. It returns, via its output791** pointer parameter, true if such a lock exists and false otherwise.792**793** The xFileControl() method is a generic interface that allows custom794** VFS implementations to directly control an open file using the795** [sqlite3_file_control()] interface. The second "op" argument is an796** integer opcode. The third argument is a generic pointer intended to797** point to a structure that may contain arguments or space in which to798** write return values. Potential uses for xFileControl() might be799** functions to enable blocking locks with timeouts, to change the800** locking strategy (for example to use dot-file locks), to inquire801** about the status of a lock, or to break stale locks. The SQLite802** core reserves all opcodes less than 100 for its own use.803** A [file control opcodes | list of opcodes] less than 100 is available.804** Applications that define a custom xFileControl method should use opcodes805** greater than 100 to avoid conflicts. VFS implementations should806** return [SQLITE_NOTFOUND] for file control opcodes that they do not807** recognize.808**809** The xSectorSize() method returns the sector size of the810** device that underlies the file. The sector size is the811** minimum write that can be performed without disturbing812** other bytes in the file. The xDeviceCharacteristics()813** method returns a bit vector describing behaviors of the814** underlying device:815**816** <ul>817** <li> [SQLITE_IOCAP_ATOMIC]818** <li> [SQLITE_IOCAP_ATOMIC512]819** <li> [SQLITE_IOCAP_ATOMIC1K]820** <li> [SQLITE_IOCAP_ATOMIC2K]821** <li> [SQLITE_IOCAP_ATOMIC4K]822** <li> [SQLITE_IOCAP_ATOMIC8K]823** <li> [SQLITE_IOCAP_ATOMIC16K]824** <li> [SQLITE_IOCAP_ATOMIC32K]825** <li> [SQLITE_IOCAP_ATOMIC64K]826** <li> [SQLITE_IOCAP_SAFE_APPEND]827** <li> [SQLITE_IOCAP_SEQUENTIAL]828** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]829** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]830** <li> [SQLITE_IOCAP_IMMUTABLE]831** <li> [SQLITE_IOCAP_BATCH_ATOMIC]832** <li> [SQLITE_IOCAP_SUBPAGE_READ]833** </ul>834**835** The SQLITE_IOCAP_ATOMIC property means that all writes of836** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values837** mean that writes of blocks that are nnn bytes in size and838** are aligned to an address which is an integer multiple of839** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means840** that when data is appended to a file, the data is appended841** first then the size of the file is extended, never the other842** way around. The SQLITE_IOCAP_SEQUENTIAL property means that843** information is written to disk in the same order as calls844** to xWrite().845**846** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill847** in the unread portions of the buffer with zeros. A VFS that848** fails to zero-fill short reads might seem to work. However,849** failure to zero-fill short reads will eventually lead to850** database corruption.851*/852typedef struct sqlite3_io_methods sqlite3_io_methods;853struct sqlite3_io_methods {854int iVersion;855int (*xClose)(sqlite3_file*);856int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);857int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);858int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);859int (*xSync)(sqlite3_file*, int flags);860int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);861int (*xLock)(sqlite3_file*, int);862int (*xUnlock)(sqlite3_file*, int);863int (*xCheckReservedLock)(sqlite3_file*, int *pResOut);864int (*xFileControl)(sqlite3_file*, int op, void *pArg);865int (*xSectorSize)(sqlite3_file*);866int (*xDeviceCharacteristics)(sqlite3_file*);867/* Methods above are valid for version 1 */868int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**);869int (*xShmLock)(sqlite3_file*, int offset, int n, int flags);870void (*xShmBarrier)(sqlite3_file*);871int (*xShmUnmap)(sqlite3_file*, int deleteFlag);872/* Methods above are valid for version 2 */873int (*xFetch)(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp);874int (*xUnfetch)(sqlite3_file*, sqlite3_int64 iOfst, void *p);875/* Methods above are valid for version 3 */876/* Additional methods may be added in future releases */877};878879/*880** CAPI3REF: Standard File Control Opcodes881** KEYWORDS: {file control opcodes} {file control opcode}882**883** These integer constants are opcodes for the xFileControl method884** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]885** interface.886**887** <ul>888** <li>[[SQLITE_FCNTL_LOCKSTATE]]889** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This890** opcode causes the xFileControl method to write the current state of891** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],892** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])893** into an integer that the pArg argument points to.894** This capability is only available if SQLite is compiled with [SQLITE_DEBUG].895**896** <li>[[SQLITE_FCNTL_SIZE_HINT]]897** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS898** layer a hint of how large the database file will grow to be during the899** current transaction. This hint is not guaranteed to be accurate but it900** is often close. The underlying VFS might choose to preallocate database901** file space based on this hint in order to help writes to the database902** file run faster.903**904** <li>[[SQLITE_FCNTL_SIZE_LIMIT]]905** The [SQLITE_FCNTL_SIZE_LIMIT] opcode is used by in-memory VFS that906** implements [sqlite3_deserialize()] to set an upper bound on the size907** of the in-memory database. The argument is a pointer to a [sqlite3_int64].908** If the integer pointed to is negative, then it is filled in with the909** current limit. Otherwise the limit is set to the larger of the value910** of the integer pointed to and the current database size. The integer911** pointed to is set to the new limit.912**913** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]914** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS915** extends and truncates the database file in chunks of a size specified916** by the user. The fourth argument to [sqlite3_file_control()] should917** point to an integer (type int) containing the new chunk-size to use918** for the nominated database. Allocating database file space in large919** chunks (say 1MB at a time), may reduce file-system fragmentation and920** improve performance on some systems.921**922** <li>[[SQLITE_FCNTL_FILE_POINTER]]923** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer924** to the [sqlite3_file] object associated with a particular database925** connection. See also [SQLITE_FCNTL_JOURNAL_POINTER].926**927** <li>[[SQLITE_FCNTL_JOURNAL_POINTER]]928** The [SQLITE_FCNTL_JOURNAL_POINTER] opcode is used to obtain a pointer929** to the [sqlite3_file] object associated with the journal file (either930** the [rollback journal] or the [write-ahead log]) for a particular database931** connection. See also [SQLITE_FCNTL_FILE_POINTER].932**933** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]934** The SQLITE_FCNTL_SYNC_OMITTED file-control is no longer used.935**936** <li>[[SQLITE_FCNTL_SYNC]]937** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and938** sent to the VFS immediately before the xSync method is invoked on a939** database file descriptor. Or, if the xSync method is not invoked940** because the user has configured SQLite with941** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place942** of the xSync method. In most cases, the pointer argument passed with943** this file-control is NULL. However, if the database file is being synced944** as part of a multi-database commit, the argument points to a nul-terminated945** string containing the transactions super-journal file name. VFSes that946** do not need this signal should silently ignore this opcode. Applications947** should not call [sqlite3_file_control()] with this opcode as doing so may948** disrupt the operation of the specialized VFSes that do require it.949**950** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]951** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite952** and sent to the VFS after a transaction has been committed immediately953** but before the database is unlocked. VFSes that do not need this signal954** should silently ignore this opcode. Applications should not call955** [sqlite3_file_control()] with this opcode as doing so may disrupt the956** operation of the specialized VFSes that do require it.957**958** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]959** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic960** retry counts and intervals for certain disk I/O operations for the961** windows [VFS] in order to provide robustness in the presence of962** anti-virus programs. By default, the windows VFS will retry file read,963** file write, and file delete operations up to 10 times, with a delay964** of 25 milliseconds before the first retry and with the delay increasing965** by an additional 25 milliseconds with each subsequent retry. This966** opcode allows these two values (10 retries and 25 milliseconds of delay)967** to be adjusted. The values are changed for all database connections968** within the same process. The argument is a pointer to an array of two969** integers where the first integer is the new retry count and the second970** integer is the delay. If either integer is negative, then the setting971** is not changed but instead the prior value of that setting is written972** into the array entry, allowing the current retry settings to be973** interrogated. The zDbName parameter is ignored.974**975** <li>[[SQLITE_FCNTL_PERSIST_WAL]]976** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the977** persistent [WAL | Write Ahead Log] setting. By default, the auxiliary978** write ahead log ([WAL file]) and shared memory979** files used for transaction control980** are automatically deleted when the latest connection to the database981** closes. Setting persistent WAL mode causes those files to persist after982** close. Persisting the files is useful when other processes that do not983** have write permission on the directory containing the database file want984** to read the database file, as the WAL and shared memory files must exist985** in order for the database to be readable. The fourth parameter to986** [sqlite3_file_control()] for this opcode should be a pointer to an integer.987** That integer is 0 to disable persistent WAL mode or 1 to enable persistent988** WAL mode. If the integer is -1, then it is overwritten with the current989** WAL persistence setting.990**991** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]]992** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the993** persistent "powersafe-overwrite" or "PSOW" setting. The PSOW setting994** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the995** xDeviceCharacteristics methods. The fourth parameter to996** [sqlite3_file_control()] for this opcode should be a pointer to an integer.997** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage998** mode. If the integer is -1, then it is overwritten with the current999** zero-damage mode setting.1000**1001** <li>[[SQLITE_FCNTL_OVERWRITE]]1002** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening1003** a write transaction to indicate that, unless it is rolled back for some1004** reason, the entire database file will be overwritten by the current1005** transaction. This is used by VACUUM operations.1006**1007** <li>[[SQLITE_FCNTL_VFSNAME]]1008** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of1009** all [VFSes] in the VFS stack. The names of all VFS shims and the1010** final bottom-level VFS are written into memory obtained from1011** [sqlite3_malloc()] and the result is stored in the char* variable1012** that the fourth parameter of [sqlite3_file_control()] points to.1013** The caller is responsible for freeing the memory when done. As with1014** all file-control actions, there is no guarantee that this will actually1015** do anything. Callers should initialize the char* variable to a NULL1016** pointer in case this file-control is not implemented. This file-control1017** is intended for diagnostic use only.1018**1019** <li>[[SQLITE_FCNTL_VFS_POINTER]]1020** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level1021** [VFSes] currently in use. ^(The argument X in1022** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be1023** of type "[sqlite3_vfs] **". This opcode will set *X1024** to a pointer to the top-level VFS.)^1025** ^When there are multiple VFS shims in the stack, this opcode finds the1026** upper-most shim only.1027**1028** <li>[[SQLITE_FCNTL_PRAGMA]]1029** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA]1030** file control is sent to the open [sqlite3_file] object corresponding1031** to the database file to which the pragma statement refers. ^The argument1032** to the [SQLITE_FCNTL_PRAGMA] file control is an array of1033** pointers to strings (char**) in which the second element of the array1034** is the name of the pragma and the third element is the argument to the1035** pragma or NULL if the pragma has no argument. ^The handler for an1036** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element1037** of the char** argument point to a string obtained from [sqlite3_mprintf()]1038** or the equivalent and that string will become the result of the pragma or1039** the error message if the pragma fails. ^If the1040** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal1041** [PRAGMA] processing continues. ^If the [SQLITE_FCNTL_PRAGMA]1042** file control returns [SQLITE_OK], then the parser assumes that the1043** VFS has handled the PRAGMA itself and the parser generates a no-op1044** prepared statement if result string is NULL, or that returns a copy1045** of the result string if the string is non-NULL.1046** ^If the [SQLITE_FCNTL_PRAGMA] file control returns1047** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means1048** that the VFS encountered an error while handling the [PRAGMA] and the1049** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA]1050** file control occurs at the beginning of pragma statement analysis and so1051** it is able to override built-in [PRAGMA] statements.1052**1053** <li>[[SQLITE_FCNTL_BUSYHANDLER]]1054** ^The [SQLITE_FCNTL_BUSYHANDLER]1055** file-control may be invoked by SQLite on the database file handle1056** shortly after it is opened in order to provide a custom VFS with access1057** to the connection's busy-handler callback. The argument is of type (void**)1058** - an array of two (void *) values. The first (void *) actually points1059** to a function of type (int (*)(void *)). In order to invoke the connection's1060** busy-handler, this function should be invoked with the second (void *) in1061** the array as the only argument. If it returns non-zero, then the operation1062** should be retried. If it returns zero, the custom VFS should abandon the1063** current operation.1064**1065** <li>[[SQLITE_FCNTL_TEMPFILENAME]]1066** ^Applications can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control1067** to have SQLite generate a1068** temporary filename using the same algorithm that is followed to generate1069** temporary filenames for TEMP tables and other internal uses. The1070** argument should be a char** which will be filled with the filename1071** written into memory obtained from [sqlite3_malloc()]. The caller should1072** invoke [sqlite3_free()] on the result to avoid a memory leak.1073**1074** <li>[[SQLITE_FCNTL_MMAP_SIZE]]1075** The [SQLITE_FCNTL_MMAP_SIZE] file control is used to query or set the1076** maximum number of bytes that will be used for memory-mapped I/O.1077** The argument is a pointer to a value of type sqlite3_int64 that1078** is an advisory maximum number of bytes in the file to memory map. The1079** pointer is overwritten with the old value. The limit is not changed if1080** the value originally pointed to is negative, and so the current limit1081** can be queried by passing in a pointer to a negative number. This1082** file-control is used internally to implement [PRAGMA mmap_size].1083**1084** <li>[[SQLITE_FCNTL_TRACE]]1085** The [SQLITE_FCNTL_TRACE] file control provides advisory information1086** to the VFS about what the higher layers of the SQLite stack are doing.1087** This file control is used by some VFS activity tracing [shims].1088** The argument is a zero-terminated string. Higher layers in the1089** SQLite stack may generate instances of this file control if1090** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.1091**1092** <li>[[SQLITE_FCNTL_HAS_MOVED]]1093** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a1094** pointer to an integer and it writes a boolean into that integer depending1095** on whether or not the file has been renamed, moved, or deleted since it1096** was first opened.1097**1098** <li>[[SQLITE_FCNTL_WIN32_GET_HANDLE]]1099** The [SQLITE_FCNTL_WIN32_GET_HANDLE] opcode can be used to obtain the1100** underlying native file handle associated with a file handle. This file1101** control interprets its argument as a pointer to a native file handle and1102** writes the resulting value there.1103**1104** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]]1105** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This1106** opcode causes the xFileControl method to swap the file handle with the one1107** pointed to by the pArg argument. This capability is used during testing1108** and only needs to be supported when SQLITE_TEST is defined.1109**1110** <li>[[SQLITE_FCNTL_NULL_IO]]1111** The [SQLITE_FCNTL_NULL_IO] opcode sets the low-level file descriptor1112** or file handle for the [sqlite3_file] object such that it will no longer1113** read or write to the database file.1114**1115** <li>[[SQLITE_FCNTL_WAL_BLOCK]]1116** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might1117** be advantageous to block on the next WAL lock if the lock is not immediately1118** available. The WAL subsystem issues this signal during rare1119** circumstances in order to fix a problem with priority inversion.1120** Applications should <em>not</em> use this file-control.1121**1122** <li>[[SQLITE_FCNTL_ZIPVFS]]1123** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other1124** VFS should return SQLITE_NOTFOUND for this opcode.1125**1126** <li>[[SQLITE_FCNTL_RBU]]1127** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by1128** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for1129** this opcode.1130**1131** <li>[[SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]]1132** If the [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] opcode returns SQLITE_OK, then1133** the file descriptor is placed in "batch write mode", which1134** means all subsequent write operations will be deferred and done1135** atomically at the next [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]. Systems1136** that do not support batch atomic writes will return SQLITE_NOTFOUND.1137** ^Following a successful SQLITE_FCNTL_BEGIN_ATOMIC_WRITE and prior to1138** the closing [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] or1139** [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE], SQLite will make1140** no VFS interface calls on the same [sqlite3_file] file descriptor1141** except for calls to the xWrite method and the xFileControl method1142** with [SQLITE_FCNTL_SIZE_HINT].1143**1144** <li>[[SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]]1145** The [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] opcode causes all write1146** operations since the previous successful call to1147** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be performed atomically.1148** This file control returns [SQLITE_OK] if and only if the writes were1149** all performed successfully and have been committed to persistent storage.1150** ^Regardless of whether or not it is successful, this file control takes1151** the file descriptor out of batch write mode so that all subsequent1152** write operations are independent.1153** ^SQLite will never invoke SQLITE_FCNTL_COMMIT_ATOMIC_WRITE without1154** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].1155**1156** <li>[[SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE]]1157** The [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE] opcode causes all write1158** operations since the previous successful call to1159** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be rolled back.1160** ^This file control takes the file descriptor out of batch write mode1161** so that all subsequent write operations are independent.1162** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without1163** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].1164**1165** <li>[[SQLITE_FCNTL_LOCK_TIMEOUT]]1166** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode is used to configure a VFS1167** to block for up to M milliseconds before failing when attempting to1168** obtain a file lock using the xLock or xShmLock methods of the VFS.1169** The parameter is a pointer to a 32-bit signed integer that contains1170** the value that M is to be set to. Before returning, the 32-bit signed1171** integer is overwritten with the previous value of M.1172**1173** <li>[[SQLITE_FCNTL_BLOCK_ON_CONNECT]]1174** The [SQLITE_FCNTL_BLOCK_ON_CONNECT] opcode is used to configure the1175** VFS to block when taking a SHARED lock to connect to a wal mode database.1176** This is used to implement the functionality associated with1177** SQLITE_SETLK_BLOCK_ON_CONNECT.1178**1179** <li>[[SQLITE_FCNTL_DATA_VERSION]]1180** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to1181** a database file. The argument is a pointer to a 32-bit unsigned integer.1182** The "data version" for the pager is written into the pointer. The1183** "data version" changes whenever any change occurs to the corresponding1184** database file, either through SQL statements on the same database1185** connection or through transactions committed by separate database1186** connections possibly in other processes. The [sqlite3_total_changes()]1187** interface can be used to find if any database on the connection has changed,1188** but that interface responds to changes on TEMP as well as MAIN and does1189** not provide a mechanism to detect changes to MAIN only. Also, the1190** [sqlite3_total_changes()] interface responds to internal changes only and1191** omits changes made by other database connections. The1192** [PRAGMA data_version] command provides a mechanism to detect changes to1193** a single attached database that occur due to other database connections,1194** but omits changes implemented by the database connection on which it is1195** called. This file control is the only mechanism to detect changes that1196** happen either internally or externally and that are associated with1197** a particular attached database.1198**1199** <li>[[SQLITE_FCNTL_CKPT_START]]1200** The [SQLITE_FCNTL_CKPT_START] opcode is invoked from within a checkpoint1201** in wal mode before the client starts to copy pages from the wal1202** file to the database file.1203**1204** <li>[[SQLITE_FCNTL_CKPT_DONE]]1205** The [SQLITE_FCNTL_CKPT_DONE] opcode is invoked from within a checkpoint1206** in wal mode after the client has finished copying pages from the wal1207** file to the database file, but before the *-shm file is updated to1208** record the fact that the pages have been checkpointed.1209**1210** <li>[[SQLITE_FCNTL_EXTERNAL_READER]]1211** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect1212** whether or not there is a database client in another process with a wal-mode1213** transaction open on the database or not. It is only available on unix. The1214** (void*) argument passed with this file-control should be a pointer to a1215** value of type (int). The integer value is set to 1 if the database is a wal1216** mode database and there exists at least one client in another process that1217** currently has an SQL transaction open on the database. It is set to 0 if1218** the database is not a wal-mode db, or if there is no such connection in any1219** other process. This opcode cannot be used to detect transactions opened1220** by clients within the current process, only within other processes.1221**1222** <li>[[SQLITE_FCNTL_CKSM_FILE]]1223** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use internally by the1224** [checksum VFS shim] only.1225**1226** <li>[[SQLITE_FCNTL_RESET_CACHE]]1227** If there is currently no transaction open on the database, and the1228** database is not a temp db, then the [SQLITE_FCNTL_RESET_CACHE] file-control1229** purges the contents of the in-memory page cache. If there is an open1230** transaction, or if the db is a temp-db, this opcode is a no-op, not an error.1231**1232** <li>[[SQLITE_FCNTL_FILESTAT]]1233** The [SQLITE_FCNTL_FILESTAT] opcode returns low-level diagnostic information1234** about the [sqlite3_file] objects used access the database and journal files1235** for the given schema. The fourth parameter to [sqlite3_file_control()]1236** should be an initialized [sqlite3_str] pointer. JSON text describing1237** various aspects of the sqlite3_file object is appended to the sqlite3_str.1238** The SQLITE_FCNTL_FILESTAT opcode is usually a no-op, unless compile-time1239** options are used to enable it.1240** </ul>1241*/1242#define SQLITE_FCNTL_LOCKSTATE 11243#define SQLITE_FCNTL_GET_LOCKPROXYFILE 21244#define SQLITE_FCNTL_SET_LOCKPROXYFILE 31245#define SQLITE_FCNTL_LAST_ERRNO 41246#define SQLITE_FCNTL_SIZE_HINT 51247#define SQLITE_FCNTL_CHUNK_SIZE 61248#define SQLITE_FCNTL_FILE_POINTER 71249#define SQLITE_FCNTL_SYNC_OMITTED 81250#define SQLITE_FCNTL_WIN32_AV_RETRY 91251#define SQLITE_FCNTL_PERSIST_WAL 101252#define SQLITE_FCNTL_OVERWRITE 111253#define SQLITE_FCNTL_VFSNAME 121254#define SQLITE_FCNTL_POWERSAFE_OVERWRITE 131255#define SQLITE_FCNTL_PRAGMA 141256#define SQLITE_FCNTL_BUSYHANDLER 151257#define SQLITE_FCNTL_TEMPFILENAME 161258#define SQLITE_FCNTL_MMAP_SIZE 181259#define SQLITE_FCNTL_TRACE 191260#define SQLITE_FCNTL_HAS_MOVED 201261#define SQLITE_FCNTL_SYNC 211262#define SQLITE_FCNTL_COMMIT_PHASETWO 221263#define SQLITE_FCNTL_WIN32_SET_HANDLE 231264#define SQLITE_FCNTL_WAL_BLOCK 241265#define SQLITE_FCNTL_ZIPVFS 251266#define SQLITE_FCNTL_RBU 261267#define SQLITE_FCNTL_VFS_POINTER 271268#define SQLITE_FCNTL_JOURNAL_POINTER 281269#define SQLITE_FCNTL_WIN32_GET_HANDLE 291270#define SQLITE_FCNTL_PDB 301271#define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 311272#define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 321273#define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 331274#define SQLITE_FCNTL_LOCK_TIMEOUT 341275#define SQLITE_FCNTL_DATA_VERSION 351276#define SQLITE_FCNTL_SIZE_LIMIT 361277#define SQLITE_FCNTL_CKPT_DONE 371278#define SQLITE_FCNTL_RESERVE_BYTES 381279#define SQLITE_FCNTL_CKPT_START 391280#define SQLITE_FCNTL_EXTERNAL_READER 401281#define SQLITE_FCNTL_CKSM_FILE 411282#define SQLITE_FCNTL_RESET_CACHE 421283#define SQLITE_FCNTL_NULL_IO 431284#define SQLITE_FCNTL_BLOCK_ON_CONNECT 441285#define SQLITE_FCNTL_FILESTAT 4512861287/* deprecated names */1288#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE1289#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE1290#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO129112921293/*1294** CAPI3REF: Mutex Handle1295**1296** The mutex module within SQLite defines [sqlite3_mutex] to be an1297** abstract type for a mutex object. The SQLite core never looks1298** at the internal representation of an [sqlite3_mutex]. It only1299** deals with pointers to the [sqlite3_mutex] object.1300**1301** Mutexes are created using [sqlite3_mutex_alloc()].1302*/1303typedef struct sqlite3_mutex sqlite3_mutex;13041305/*1306** CAPI3REF: Loadable Extension Thunk1307**1308** A pointer to the opaque sqlite3_api_routines structure is passed as1309** the third parameter to entry points of [loadable extensions]. This1310** structure must be typedefed in order to work around compiler warnings1311** on some platforms.1312*/1313typedef struct sqlite3_api_routines sqlite3_api_routines;13141315/*1316** CAPI3REF: File Name1317**1318** Type [sqlite3_filename] is used by SQLite to pass filenames to the1319** xOpen method of a [VFS]. It may be cast to (const char*) and treated1320** as a normal, nul-terminated, UTF-8 buffer containing the filename, but1321** may also be passed to special APIs such as:1322**1323** <ul>1324** <li> sqlite3_filename_database()1325** <li> sqlite3_filename_journal()1326** <li> sqlite3_filename_wal()1327** <li> sqlite3_uri_parameter()1328** <li> sqlite3_uri_boolean()1329** <li> sqlite3_uri_int64()1330** <li> sqlite3_uri_key()1331** </ul>1332*/1333typedef const char *sqlite3_filename;13341335/*1336** CAPI3REF: OS Interface Object1337**1338** An instance of the sqlite3_vfs object defines the interface between1339** the SQLite core and the underlying operating system. The "vfs"1340** in the name of the object stands for "virtual file system". See1341** the [VFS | VFS documentation] for further information.1342**1343** The VFS interface is sometimes extended by adding new methods onto1344** the end. Each time such an extension occurs, the iVersion field1345** is incremented. The iVersion value started out as 1 in1346** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 21347** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased1348** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6]. Additional fields1349** may be appended to the sqlite3_vfs object and the iVersion value1350** may increase again in future versions of SQLite.1351** Note that due to an oversight, the structure1352** of the sqlite3_vfs object changed in the transition from1353** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0]1354** and yet the iVersion field was not increased.1355**1356** The szOsFile field is the size of the subclassed [sqlite3_file]1357** structure used by this VFS. mxPathname is the maximum length of1358** a pathname in this VFS.1359**1360** Registered sqlite3_vfs objects are kept on a linked list formed by1361** the pNext pointer. The [sqlite3_vfs_register()]1362** and [sqlite3_vfs_unregister()] interfaces manage this list1363** in a thread-safe way. The [sqlite3_vfs_find()] interface1364** searches the list. Neither the application code nor the VFS1365** implementation should use the pNext pointer.1366**1367** The pNext field is the only field in the sqlite3_vfs1368** structure that SQLite will ever modify. SQLite will only access1369** or modify this field while holding a particular static mutex.1370** The application should never modify anything within the sqlite3_vfs1371** object once the object has been registered.1372**1373** The zName field holds the name of the VFS module. The name must1374** be unique across all VFS modules.1375**1376** [[sqlite3_vfs.xOpen]]1377** ^SQLite guarantees that the zFilename parameter to xOpen1378** is either a NULL pointer or string obtained1379** from xFullPathname() with an optional suffix added.1380** ^If a suffix is added to the zFilename parameter, it will1381** consist of a single "-" character followed by no more than1382** 11 alphanumeric and/or "-" characters.1383** ^SQLite further guarantees that1384** the string will be valid and unchanged until xClose() is1385** called. Because of the previous sentence,1386** the [sqlite3_file] can safely store a pointer to the1387** filename if it needs to remember the filename for some reason.1388** If the zFilename parameter to xOpen is a NULL pointer then xOpen1389** must invent its own temporary name for the file. ^Whenever the1390** xFilename parameter is NULL it will also be the case that the1391** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].1392**1393** The flags argument to xOpen() includes all bits set in1394** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()]1395** or [sqlite3_open16()] is used, then flags includes at least1396** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].1397** If xOpen() opens a file read-only then it sets *pOutFlags to1398** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set.1399**1400** ^(SQLite will also add one of the following flags to the xOpen()1401** call, depending on the object being opened:1402**1403** <ul>1404** <li> [SQLITE_OPEN_MAIN_DB]1405** <li> [SQLITE_OPEN_MAIN_JOURNAL]1406** <li> [SQLITE_OPEN_TEMP_DB]1407** <li> [SQLITE_OPEN_TEMP_JOURNAL]1408** <li> [SQLITE_OPEN_TRANSIENT_DB]1409** <li> [SQLITE_OPEN_SUBJOURNAL]1410** <li> [SQLITE_OPEN_SUPER_JOURNAL]1411** <li> [SQLITE_OPEN_WAL]1412** </ul>)^1413**1414** The file I/O implementation can use the object type flags to1415** change the way it deals with files. For example, an application1416** that does not care about crash recovery or rollback might make1417** the open of a journal file a no-op. Writes to this journal would1418** also be no-ops, and any attempt to read the journal would return1419** SQLITE_IOERR. Or the implementation might recognize that a database1420** file will be doing page-aligned sector reads and writes in a random1421** order and set up its I/O subsystem accordingly.1422**1423** SQLite might also add one of the following flags to the xOpen method:1424**1425** <ul>1426** <li> [SQLITE_OPEN_DELETEONCLOSE]1427** <li> [SQLITE_OPEN_EXCLUSIVE]1428** </ul>1429**1430** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be1431** deleted when it is closed. ^The [SQLITE_OPEN_DELETEONCLOSE]1432** will be set for TEMP databases and their journals, transient1433** databases, and subjournals.1434**1435** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction1436** with the [SQLITE_OPEN_CREATE] flag, which are both directly1437** analogous to the O_EXCL and O_CREAT flags of the POSIX open()1438** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the1439** SQLITE_OPEN_CREATE, is used to indicate that file should always1440** be created, and that it is an error if it already exists.1441** It is <i>not</i> used to indicate the file should be opened1442** for exclusive access.1443**1444** ^At least szOsFile bytes of memory are allocated by SQLite1445** to hold the [sqlite3_file] structure passed as the third1446** argument to xOpen. The xOpen method does not have to1447** allocate the structure; it should just fill it in. Note that1448** the xOpen method must set the sqlite3_file.pMethods to either1449** a valid [sqlite3_io_methods] object or to NULL. xOpen must do1450** this even if the open fails. SQLite expects that the sqlite3_file.pMethods1451** element will be valid after xOpen returns regardless of the success1452** or failure of the xOpen call.1453**1454** [[sqlite3_vfs.xAccess]]1455** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]1456** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to1457** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]1458** to test whether a file is at least readable. The SQLITE_ACCESS_READ1459** flag is never actually used and is not implemented in the built-in1460** VFSes of SQLite. The file is named by the second argument and can be a1461** directory. The xAccess method returns [SQLITE_OK] on success or some1462** non-zero error code if there is an I/O error or if the name of1463** the file given in the second argument is illegal. If SQLITE_OK1464** is returned, then non-zero or zero is written into *pResOut to indicate1465** whether or not the file is accessible.1466**1467** ^SQLite will always allocate at least mxPathname+1 bytes for the1468** output buffer xFullPathname. The exact size of the output buffer1469** is also passed as a parameter to both methods. If the output buffer1470** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is1471** handled as a fatal error by SQLite, vfs implementations should endeavor1472** to prevent this by setting mxPathname to a sufficiently large value.1473**1474** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()1475** interfaces are not strictly a part of the filesystem, but they are1476** included in the VFS structure for completeness.1477** The xRandomness() function attempts to return nBytes bytes1478** of good-quality randomness into zOut. The return value is1479** the actual number of bytes of randomness obtained.1480** The xSleep() method causes the calling thread to sleep for at1481** least the number of microseconds given. ^The xCurrentTime()1482** method returns a Julian Day Number for the current date and time as1483** a floating point value.1484** ^The xCurrentTimeInt64() method returns, as an integer, the Julian1485** Day Number multiplied by 86400000 (the number of milliseconds in1486** a 24-hour day).1487** ^SQLite will use the xCurrentTimeInt64() method to get the current1488** date and time if that method is available (if iVersion is 2 or1489** greater and the function pointer is not NULL) and will fall back1490** to xCurrentTime() if xCurrentTimeInt64() is unavailable.1491**1492** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces1493** are not used by the SQLite core. These optional interfaces are provided1494** by some VFSes to facilitate testing of the VFS code. By overriding1495** system calls with functions under its control, a test program can1496** simulate faults and error conditions that would otherwise be difficult1497** or impossible to induce. The set of system calls that can be overridden1498** varies from one VFS to another, and from one version of the same VFS to the1499** next. Applications that use these interfaces must be prepared for any1500** or all of these interfaces to be NULL or for their behavior to change1501** from one release to the next. Applications must not attempt to access1502** any of these methods if the iVersion of the VFS is less than 3.1503*/1504typedef struct sqlite3_vfs sqlite3_vfs;1505typedef void (*sqlite3_syscall_ptr)(void);1506struct sqlite3_vfs {1507int iVersion; /* Structure version number (currently 3) */1508int szOsFile; /* Size of subclassed sqlite3_file */1509int mxPathname; /* Maximum file pathname length */1510sqlite3_vfs *pNext; /* Next registered VFS */1511const char *zName; /* Name of this virtual file system */1512void *pAppData; /* Pointer to application-specific data */1513int (*xOpen)(sqlite3_vfs*, sqlite3_filename zName, sqlite3_file*,1514int flags, int *pOutFlags);1515int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);1516int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);1517int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);1518void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);1519void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);1520void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void);1521void (*xDlClose)(sqlite3_vfs*, void*);1522int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);1523int (*xSleep)(sqlite3_vfs*, int microseconds);1524int (*xCurrentTime)(sqlite3_vfs*, double*);1525int (*xGetLastError)(sqlite3_vfs*, int, char *);1526/*1527** The methods above are in version 1 of the sqlite_vfs object1528** definition. Those that follow are added in version 2 or later1529*/1530int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);1531/*1532** The methods above are in versions 1 and 2 of the sqlite_vfs object.1533** Those below are for version 3 and greater.1534*/1535int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr);1536sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName);1537const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName);1538/*1539** The methods above are in versions 1 through 3 of the sqlite_vfs object.1540** New fields may be appended in future versions. The iVersion1541** value will increment whenever this happens.1542*/1543};15441545/*1546** CAPI3REF: Flags for the xAccess VFS method1547**1548** These integer constants can be used as the third parameter to1549** the xAccess method of an [sqlite3_vfs] object. They determine1550** what kind of permissions the xAccess method is looking for.1551** With SQLITE_ACCESS_EXISTS, the xAccess method1552** simply checks whether the file exists.1553** With SQLITE_ACCESS_READWRITE, the xAccess method1554** checks whether the named directory is both readable and writable1555** (in other words, if files can be added, removed, and renamed within1556** the directory).1557** The SQLITE_ACCESS_READWRITE constant is currently used only by the1558** [temp_store_directory pragma], though this could change in a future1559** release of SQLite.1560** With SQLITE_ACCESS_READ, the xAccess method1561** checks whether the file is readable. The SQLITE_ACCESS_READ constant is1562** currently unused, though it might be used in a future release of1563** SQLite.1564*/1565#define SQLITE_ACCESS_EXISTS 01566#define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */1567#define SQLITE_ACCESS_READ 2 /* Unused */15681569/*1570** CAPI3REF: Flags for the xShmLock VFS method1571**1572** These integer constants define the various locking operations1573** allowed by the xShmLock method of [sqlite3_io_methods]. The1574** following are the only legal combinations of flags to the1575** xShmLock method:1576**1577** <ul>1578** <li> SQLITE_SHM_LOCK | SQLITE_SHM_SHARED1579** <li> SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE1580** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED1581** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE1582** </ul>1583**1584** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as1585** was given on the corresponding lock.1586**1587** The xShmLock method can transition between unlocked and SHARED or1588** between unlocked and EXCLUSIVE. It cannot transition between SHARED1589** and EXCLUSIVE.1590*/1591#define SQLITE_SHM_UNLOCK 11592#define SQLITE_SHM_LOCK 21593#define SQLITE_SHM_SHARED 41594#define SQLITE_SHM_EXCLUSIVE 815951596/*1597** CAPI3REF: Maximum xShmLock index1598**1599** The xShmLock method on [sqlite3_io_methods] may use values1600** between 0 and this upper bound as its "offset" argument.1601** The SQLite core will never attempt to acquire or release a1602** lock outside of this range1603*/1604#define SQLITE_SHM_NLOCK 8160516061607/*1608** CAPI3REF: Initialize The SQLite Library1609**1610** ^The sqlite3_initialize() routine initializes the1611** SQLite library. ^The sqlite3_shutdown() routine1612** deallocates any resources that were allocated by sqlite3_initialize().1613** These routines are designed to aid in process initialization and1614** shutdown on embedded systems. Workstation applications using1615** SQLite normally do not need to invoke either of these routines.1616**1617** A call to sqlite3_initialize() is an "effective" call if it is1618** the first time sqlite3_initialize() is invoked during the lifetime of1619** the process, or if it is the first time sqlite3_initialize() is invoked1620** following a call to sqlite3_shutdown(). ^(Only an effective call1621** of sqlite3_initialize() does any initialization. All other calls1622** are harmless no-ops.)^1623**1624** A call to sqlite3_shutdown() is an "effective" call if it is the first1625** call to sqlite3_shutdown() since the last sqlite3_initialize(). ^(Only1626** an effective call to sqlite3_shutdown() does any deinitialization.1627** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^1628**1629** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown()1630** is not. The sqlite3_shutdown() interface must only be called from a1631** single thread. All open [database connections] must be closed and all1632** other SQLite resources must be deallocated prior to invoking1633** sqlite3_shutdown().1634**1635** Among other things, ^sqlite3_initialize() will invoke1636** sqlite3_os_init(). Similarly, ^sqlite3_shutdown()1637** will invoke sqlite3_os_end().1638**1639** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success.1640** ^If for some reason, sqlite3_initialize() is unable to initialize1641** the library (perhaps it is unable to allocate a needed resource such1642** as a mutex) it returns an [error code] other than [SQLITE_OK].1643**1644** ^The sqlite3_initialize() routine is called internally by many other1645** SQLite interfaces so that an application usually does not need to1646** invoke sqlite3_initialize() directly. For example, [sqlite3_open()]1647** calls sqlite3_initialize() so the SQLite library will be automatically1648** initialized when [sqlite3_open()] is called if it has not been initialized1649** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]1650** compile-time option, then the automatic calls to sqlite3_initialize()1651** are omitted and the application must call sqlite3_initialize() directly1652** prior to using any other SQLite interface. For maximum portability,1653** it is recommended that applications always invoke sqlite3_initialize()1654** directly prior to using any other SQLite interface. Future releases1655** of SQLite may require this. In other words, the behavior exhibited1656** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the1657** default behavior in some future release of SQLite.1658**1659** The sqlite3_os_init() routine does operating-system specific1660** initialization of the SQLite library. The sqlite3_os_end()1661** routine undoes the effect of sqlite3_os_init(). Typical tasks1662** performed by these routines include allocation or deallocation1663** of static resources, initialization of global variables,1664** setting up a default [sqlite3_vfs] module, or setting up1665** a default configuration using [sqlite3_config()].1666**1667** The application should never invoke either sqlite3_os_init()1668** or sqlite3_os_end() directly. The application should only invoke1669** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init()1670** interface is called automatically by sqlite3_initialize() and1671** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate1672** implementations for sqlite3_os_init() and sqlite3_os_end()1673** are built into SQLite when it is compiled for Unix, Windows, or OS/2.1674** When [custom builds | built for other platforms]1675** (using the [SQLITE_OS_OTHER=1] compile-time1676** option) the application must supply a suitable implementation for1677** sqlite3_os_init() and sqlite3_os_end(). An application-supplied1678** implementation of sqlite3_os_init() or sqlite3_os_end()1679** must return [SQLITE_OK] on success and some other [error code] upon1680** failure.1681*/1682SQLITE_API int sqlite3_initialize(void);1683SQLITE_API int sqlite3_shutdown(void);1684SQLITE_API int sqlite3_os_init(void);1685SQLITE_API int sqlite3_os_end(void);16861687/*1688** CAPI3REF: Configuring The SQLite Library1689**1690** The sqlite3_config() interface is used to make global configuration1691** changes to SQLite in order to tune SQLite to the specific needs of1692** the application. The default configuration is recommended for most1693** applications and so this routine is usually not necessary. It is1694** provided to support rare applications with unusual needs.1695**1696** <b>The sqlite3_config() interface is not threadsafe. The application1697** must ensure that no other SQLite interfaces are invoked by other1698** threads while sqlite3_config() is running.</b>1699**1700** The first argument to sqlite3_config() is an integer1701** [configuration option] that determines1702** what property of SQLite is to be configured. Subsequent arguments1703** vary depending on the [configuration option]1704** in the first argument.1705**1706** For most configuration options, the sqlite3_config() interface1707** may only be invoked prior to library initialization using1708** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].1709** The exceptional configuration options that may be invoked at any time1710** are called "anytime configuration options".1711** ^If sqlite3_config() is called after [sqlite3_initialize()] and before1712** [sqlite3_shutdown()] with a first argument that is not an anytime1713** configuration option, then the sqlite3_config() call will return SQLITE_MISUSE.1714** Note, however, that ^sqlite3_config() can be called as part of the1715** implementation of an application-defined [sqlite3_os_init()].1716**1717** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].1718** ^If the option is unknown or SQLite is unable to set the option1719** then this routine returns a non-zero [error code].1720*/1721SQLITE_API int sqlite3_config(int, ...);17221723/*1724** CAPI3REF: Configure database connections1725** METHOD: sqlite31726**1727** The sqlite3_db_config() interface is used to make configuration1728** changes to a [database connection]. The interface is similar to1729** [sqlite3_config()] except that the changes apply to a single1730** [database connection] (specified in the first argument).1731**1732** The second argument to sqlite3_db_config(D,V,...) is the1733** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code1734** that indicates what aspect of the [database connection] is being configured.1735** Subsequent arguments vary depending on the configuration verb.1736**1737** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if1738** the call is considered successful.1739*/1740SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);17411742/*1743** CAPI3REF: Memory Allocation Routines1744**1745** An instance of this object defines the interface between SQLite1746** and low-level memory allocation routines.1747**1748** This object is used in only one place in the SQLite interface.1749** A pointer to an instance of this object is the argument to1750** [sqlite3_config()] when the configuration option is1751** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC].1752** By creating an instance of this object1753** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC])1754** during configuration, an application can specify an alternative1755** memory allocation subsystem for SQLite to use for all of its1756** dynamic memory needs.1757**1758** Note that SQLite comes with several [built-in memory allocators]1759** that are perfectly adequate for the overwhelming majority of applications1760** and that this object is only useful to a tiny minority of applications1761** with specialized memory allocation requirements. This object is1762** also used during testing of SQLite in order to specify an alternative1763** memory allocator that simulates memory out-of-memory conditions in1764** order to verify that SQLite recovers gracefully from such1765** conditions.1766**1767** The xMalloc, xRealloc, and xFree methods must work like the1768** malloc(), realloc() and free() functions from the standard C library.1769** ^SQLite guarantees that the second argument to1770** xRealloc is always a value returned by a prior call to xRoundup.1771**1772** xSize should return the allocated size of a memory allocation1773** previously obtained from xMalloc or xRealloc. The allocated size1774** is always at least as big as the requested size but may be larger.1775**1776** The xRoundup method returns what would be the allocated size of1777** a memory allocation given a particular requested size. Most memory1778** allocators round up memory allocations at least to the next multiple1779** of 8. Some allocators round up to a larger multiple or to a power of 2.1780** Every memory allocation request coming in through [sqlite3_malloc()]1781** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,1782** that causes the corresponding memory allocation to fail.1783**1784** The xInit method initializes the memory allocator. For example,1785** it might allocate any required mutexes or initialize internal data1786** structures. The xShutdown method is invoked (indirectly) by1787** [sqlite3_shutdown()] and should deallocate any resources acquired1788** by xInit. The pAppData pointer is used as the only parameter to1789** xInit and xShutdown.1790**1791** SQLite holds the [SQLITE_MUTEX_STATIC_MAIN] mutex when it invokes1792** the xInit method, so the xInit method need not be threadsafe. The1793** xShutdown method is only called from [sqlite3_shutdown()] so it does1794** not need to be threadsafe either. For all other methods, SQLite1795** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the1796** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which1797** it is by default) and so the methods are automatically serialized.1798** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other1799** methods must be threadsafe or else make their own arrangements for1800** serialization.1801**1802** SQLite will never invoke xInit() more than once without an intervening1803** call to xShutdown().1804*/1805typedef struct sqlite3_mem_methods sqlite3_mem_methods;1806struct sqlite3_mem_methods {1807void *(*xMalloc)(int); /* Memory allocation function */1808void (*xFree)(void*); /* Free a prior allocation */1809void *(*xRealloc)(void*,int); /* Resize an allocation */1810int (*xSize)(void*); /* Return the size of an allocation */1811int (*xRoundup)(int); /* Round up request size to allocation size */1812int (*xInit)(void*); /* Initialize the memory allocator */1813void (*xShutdown)(void*); /* Deinitialize the memory allocator */1814void *pAppData; /* Argument to xInit() and xShutdown() */1815};18161817/*1818** CAPI3REF: Configuration Options1819** KEYWORDS: {configuration option}1820**1821** These constants are the available integer configuration options that1822** can be passed as the first argument to the [sqlite3_config()] interface.1823**1824** Most of the configuration options for sqlite3_config()1825** will only work if invoked prior to [sqlite3_initialize()] or after1826** [sqlite3_shutdown()]. The few exceptions to this rule are called1827** "anytime configuration options".1828** ^Calling [sqlite3_config()] with a first argument that is not an1829** anytime configuration option in between calls to [sqlite3_initialize()] and1830** [sqlite3_shutdown()] is a no-op that returns SQLITE_MISUSE.1831**1832** The set of anytime configuration options can change (by insertions1833** and/or deletions) from one release of SQLite to the next.1834** As of SQLite version 3.42.0, the complete set of anytime configuration1835** options is:1836** <ul>1837** <li> SQLITE_CONFIG_LOG1838** <li> SQLITE_CONFIG_PCACHE_HDRSZ1839** </ul>1840**1841** New configuration options may be added in future releases of SQLite.1842** Existing configuration options might be discontinued. Applications1843** should check the return code from [sqlite3_config()] to make sure that1844** the call worked. The [sqlite3_config()] interface will return a1845** non-zero [error code] if a discontinued or unsupported configuration option1846** is invoked.1847**1848** <dl>1849** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt>1850** <dd>There are no arguments to this option. ^This option sets the1851** [threading mode] to Single-thread. In other words, it disables1852** all mutexing and puts SQLite into a mode where it can only be used1853** by a single thread. ^If SQLite is compiled with1854** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then1855** it is not possible to change the [threading mode] from its default1856** value of Single-thread and so [sqlite3_config()] will return1857** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD1858** configuration option.</dd>1859**1860** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt>1861** <dd>There are no arguments to this option. ^This option sets the1862** [threading mode] to Multi-thread. In other words, it disables1863** mutexing on [database connection] and [prepared statement] objects.1864** The application is responsible for serializing access to1865** [database connections] and [prepared statements]. But other mutexes1866** are enabled so that SQLite will be safe to use in a multi-threaded1867** environment as long as no two threads attempt to use the same1868** [database connection] at the same time. ^If SQLite is compiled with1869** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then1870** it is not possible to set the Multi-thread [threading mode] and1871** [sqlite3_config()] will return [SQLITE_ERROR] if called with the1872** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>1873**1874** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt>1875** <dd>There are no arguments to this option. ^This option sets the1876** [threading mode] to Serialized. In other words, this option enables1877** all mutexes including the recursive1878** mutexes on [database connection] and [prepared statement] objects.1879** In this mode (which is the default when SQLite is compiled with1880** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access1881** to [database connections] and [prepared statements] so that the1882** application is free to use the same [database connection] or the1883** same [prepared statement] in different threads at the same time.1884** ^If SQLite is compiled with1885** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then1886** it is not possible to set the Serialized [threading mode] and1887** [sqlite3_config()] will return [SQLITE_ERROR] if called with the1888** SQLITE_CONFIG_SERIALIZED configuration option.</dd>1889**1890** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>1891** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is1892** a pointer to an instance of the [sqlite3_mem_methods] structure.1893** The argument specifies1894** alternative low-level memory allocation routines to be used in place of1895** the memory allocation routines built into SQLite.)^ ^SQLite makes1896** its own private copy of the content of the [sqlite3_mem_methods] structure1897** before the [sqlite3_config()] call returns.</dd>1898**1899** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>1900** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which1901** is a pointer to an instance of the [sqlite3_mem_methods] structure.1902** The [sqlite3_mem_methods]1903** structure is filled with the currently defined memory allocation routines.)^1904** This option can be used to overload the default memory allocation1905** routines with a wrapper that simulates memory allocation failure or1906** tracks memory usage, for example. </dd>1907**1908** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt>1909** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes a single argument of1910** type int, interpreted as a boolean, which if true provides a hint to1911** SQLite that it should avoid large memory allocations if possible.1912** SQLite will run faster if it is free to make large memory allocations,1913** but some applications might prefer to run slower in exchange for1914** guarantees about memory fragmentation that are possible if large1915** allocations are avoided. This hint is normally off.1916** </dd>1917**1918** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>1919** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes a single argument of type int,1920** interpreted as a boolean, which enables or disables the collection of1921** memory allocation statistics. ^(When memory allocation statistics are1922** disabled, the following SQLite interfaces become non-operational:1923** <ul>1924** <li> [sqlite3_hard_heap_limit64()]1925** <li> [sqlite3_memory_used()]1926** <li> [sqlite3_memory_highwater()]1927** <li> [sqlite3_soft_heap_limit64()]1928** <li> [sqlite3_status64()]1929** </ul>)^1930** ^Memory allocation statistics are enabled by default unless SQLite is1931** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory1932** allocation statistics are disabled by default.1933** </dd>1934**1935** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>1936** <dd> The SQLITE_CONFIG_SCRATCH option is no longer used.1937** </dd>1938**1939** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>1940** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool1941** that SQLite can use for the database page cache with the default page1942** cache implementation.1943** This configuration option is a no-op if an application-defined page1944** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2].1945** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to1946** 8-byte aligned memory (pMem), the size of each page cache line (sz),1947** and the number of cache lines (N).1948** The sz argument should be the size of the largest database page1949** (a power of two between 512 and 65536) plus some extra bytes for each1950** page header. ^The number of extra bytes needed by the page header1951** can be determined using [SQLITE_CONFIG_PCACHE_HDRSZ].1952** ^It is harmless, apart from the wasted memory,1953** for the sz parameter to be larger than necessary. The pMem1954** argument must be either a NULL pointer or a pointer to an 8-byte1955** aligned block of memory of at least sz*N bytes, otherwise1956** subsequent behavior is undefined.1957** ^When pMem is not NULL, SQLite will strive to use the memory provided1958** to satisfy page cache needs, falling back to [sqlite3_malloc()] if1959** a page cache line is larger than sz bytes or if all of the pMem buffer1960** is exhausted.1961** ^If pMem is NULL and N is non-zero, then each database connection1962** does an initial bulk allocation for page cache memory1963** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or1964** of -1024*N bytes if N is negative. ^If additional1965** page cache memory is needed beyond what is provided by the initial1966** allocation, then SQLite goes to [sqlite3_malloc()] separately for each1967** additional cache line. </dd>1968**1969** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>1970** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer1971** that SQLite will use for all of its dynamic memory allocation needs1972** beyond those provided for by [SQLITE_CONFIG_PAGECACHE].1973** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled1974** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns1975** [SQLITE_ERROR] if invoked otherwise.1976** ^There are three arguments to SQLITE_CONFIG_HEAP:1977** An 8-byte aligned pointer to the memory,1978** the number of bytes in the memory buffer, and the minimum allocation size.1979** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts1980** to using its default memory allocator (the system malloc() implementation),1981** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the1982** memory pointer is not NULL then the alternative memory1983** allocator is engaged to handle all of SQLites memory allocation needs.1984** The first pointer (the memory pointer) must be aligned to an 8-byte1985** boundary or subsequent behavior of SQLite will be undefined.1986** The minimum allocation size is capped at 2**12. Reasonable values1987** for the minimum allocation size are 2**5 through 2**8.</dd>1988**1989** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>1990** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a1991** pointer to an instance of the [sqlite3_mutex_methods] structure.1992** The argument specifies alternative low-level mutex routines to be used1993** in place of the mutex routines built into SQLite.)^ ^SQLite makes a copy of1994** the content of the [sqlite3_mutex_methods] structure before the call to1995** [sqlite3_config()] returns. ^If SQLite is compiled with1996** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then1997** the entire mutexing subsystem is omitted from the build and hence calls to1998** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will1999** return [SQLITE_ERROR].</dd>2000**2001** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>2002** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which2003** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The2004** [sqlite3_mutex_methods]2005** structure is filled with the currently defined mutex routines.)^2006** This option can be used to overload the default mutex allocation2007** routines with a wrapper used to track mutex usage for performance2008** profiling or testing, for example. ^If SQLite is compiled with2009** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then2010** the entire mutexing subsystem is omitted from the build and hence calls to2011** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will2012** return [SQLITE_ERROR].</dd>2013**2014** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>2015** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine2016** the default size of [lookaside memory] on each [database connection].2017** The first argument is the2018** size of each lookaside buffer slot ("sz") and the second is the number of2019** slots allocated to each database connection ("cnt").)^2020** ^(SQLITE_CONFIG_LOOKASIDE sets the <i>default</i> lookaside size.2021** The [SQLITE_DBCONFIG_LOOKASIDE] option to [sqlite3_db_config()] can2022** be used to change the lookaside configuration on individual connections.)^2023** The [-DSQLITE_DEFAULT_LOOKASIDE] option can be used to change the2024** default lookaside configuration at compile-time.2025** </dd>2026**2027** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>2028** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is2029** a pointer to an [sqlite3_pcache_methods2] object. This object specifies2030** the interface to a custom page cache implementation.)^2031** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>2032**2033** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>2034** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which2035** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies off2036** the current page cache implementation into that object.)^ </dd>2037**2038** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>2039** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite2040** global [error log].2041** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a2042** function with a call signature of void(*)(void*,int,const char*),2043** and a pointer to void. ^If the function pointer is not NULL, it is2044** invoked by [sqlite3_log()] to process each logging event. ^If the2045** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.2046** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is2047** passed through as the first parameter to the application-defined logger2048** function whenever that function is invoked. ^The second parameter to2049** the logger function is a copy of the first parameter to the corresponding2050** [sqlite3_log()] call and is intended to be a [result code] or an2051** [extended result code]. ^The third parameter passed to the logger is2052** a log message after formatting via [sqlite3_snprintf()].2053** The SQLite logging interface is not reentrant; the logger function2054** supplied by the application must not invoke any SQLite interface.2055** In a multi-threaded application, the application-defined logger2056** function must be threadsafe. </dd>2057**2058** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI2059** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int.2060** If non-zero, then URI handling is globally enabled. If the parameter is zero,2061** then URI handling is globally disabled.)^ ^If URI handling is globally2062** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()],2063** [sqlite3_open16()] or2064** specified as part of [ATTACH] commands are interpreted as URIs, regardless2065** of whether or not the [SQLITE_OPEN_URI] flag is set when the database2066** connection is opened. ^If it is globally disabled, filenames are2067** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the2068** database connection is opened. ^(By default, URI handling is globally2069** disabled. The default value may be changed by compiling with the2070** [SQLITE_USE_URI] symbol defined.)^2071**2072** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN2073** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer2074** argument which is interpreted as a boolean in order to enable or disable2075** the use of covering indices for full table scans in the query optimizer.2076** ^The default setting is determined2077** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"2078** if that compile-time option is omitted.2079** The ability to disable the use of covering indices for full table scans2080** is because some incorrectly coded legacy applications might malfunction2081** when the optimization is enabled. Providing the ability to2082** disable the optimization allows the older, buggy application code to work2083** without change even with newer versions of SQLite.2084**2085** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]]2086** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE2087** <dd> These options are obsolete and should not be used by new code.2088** They are retained for backwards compatibility but are now no-ops.2089** </dd>2090**2091** [[SQLITE_CONFIG_SQLLOG]]2092** <dt>SQLITE_CONFIG_SQLLOG2093** <dd>This option is only available if sqlite is compiled with the2094** [SQLITE_ENABLE_SQLLOG] pre-processor macro defined. The first argument should2095** be a pointer to a function of type void(*)(void*,sqlite3*,const char*, int).2096** The second should be of type (void*). The callback is invoked by the library2097** in three separate circumstances, identified by the value passed as the2098** fourth parameter. If the fourth parameter is 0, then the database connection2099** passed as the second argument has just been opened. The third argument2100** points to a buffer containing the name of the main database file. If the2101** fourth parameter is 1, then the SQL statement that the third parameter2102** points to has just been executed. Or, if the fourth parameter is 2, then2103** the connection being passed as the second parameter is being closed. The2104** third parameter is passed NULL In this case. An example of using this2105** configuration option can be seen in the "test_sqllog.c" source file in2106** the canonical SQLite source tree.</dd>2107**2108** [[SQLITE_CONFIG_MMAP_SIZE]]2109** <dt>SQLITE_CONFIG_MMAP_SIZE2110** <dd>^SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values2111** that are the default mmap size limit (the default setting for2112** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.2113** ^The default setting can be overridden by each database connection using2114** either the [PRAGMA mmap_size] command, or by using the2115** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size2116** will be silently truncated if necessary so that it does not exceed the2117** compile-time maximum mmap size set by the2118** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^2119** ^If either argument to this option is negative, then that argument is2120** changed to its compile-time default.2121**2122** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]2123** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE2124** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is2125** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro2126** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value2127** that specifies the maximum size of the created heap.2128**2129** [[SQLITE_CONFIG_PCACHE_HDRSZ]]2130** <dt>SQLITE_CONFIG_PCACHE_HDRSZ2131** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which2132** is a pointer to an integer and writes into that integer the number of extra2133** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].2134** The amount of extra space required can change depending on the compiler,2135** target platform, and SQLite version.2136**2137** [[SQLITE_CONFIG_PMASZ]]2138** <dt>SQLITE_CONFIG_PMASZ2139** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which2140** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded2141** sorter to that integer. The default minimum PMA Size is set by the2142** [SQLITE_SORTER_PMASZ] compile-time option. New threads are launched2143** to help with sort operations when multithreaded sorting2144** is enabled (using the [PRAGMA threads] command) and the amount of content2145** to be sorted exceeds the page size times the minimum of the2146** [PRAGMA cache_size] setting and this value.2147**2148** [[SQLITE_CONFIG_STMTJRNL_SPILL]]2149** <dt>SQLITE_CONFIG_STMTJRNL_SPILL2150** <dd>^The SQLITE_CONFIG_STMTJRNL_SPILL option takes a single parameter which2151** becomes the [statement journal] spill-to-disk threshold.2152** [Statement journals] are held in memory until their size (in bytes)2153** exceeds this threshold, at which point they are written to disk.2154** Or if the threshold is -1, statement journals are always held2155** exclusively in memory.2156** Since many statement journals never become large, setting the spill2157** threshold to a value such as 64KiB can greatly reduce the amount of2158** I/O required to support statement rollback.2159** The default value for this setting is controlled by the2160** [SQLITE_STMTJRNL_SPILL] compile-time option.2161**2162** [[SQLITE_CONFIG_SORTERREF_SIZE]]2163** <dt>SQLITE_CONFIG_SORTERREF_SIZE2164** <dd>The SQLITE_CONFIG_SORTERREF_SIZE option accepts a single parameter2165** of type (int) - the new value of the sorter-reference size threshold.2166** Usually, when SQLite uses an external sort to order records according2167** to an ORDER BY clause, all fields required by the caller are present in the2168** sorted records. However, if SQLite determines based on the declared type2169** of a table column that its values are likely to be very large - larger2170** than the configured sorter-reference size threshold - then a reference2171** is stored in each sorted record and the required column values loaded2172** from the database as records are returned in sorted order. The default2173** value for this option is to never use this optimization. Specifying a2174** negative value for this option restores the default behavior.2175** This option is only available if SQLite is compiled with the2176** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option.2177**2178** [[SQLITE_CONFIG_MEMDB_MAXSIZE]]2179** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE2180** <dd>The SQLITE_CONFIG_MEMDB_MAXSIZE option accepts a single parameter2181** [sqlite3_int64] parameter which is the default maximum size for an in-memory2182** database created using [sqlite3_deserialize()]. This default maximum2183** size can be adjusted up or down for individual databases using the2184** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control]. If this2185** configuration setting is never used, then the default maximum is determined2186** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that2187** compile-time option is not set, then the default maximum is 1073741824.2188**2189** [[SQLITE_CONFIG_ROWID_IN_VIEW]]2190** <dt>SQLITE_CONFIG_ROWID_IN_VIEW2191** <dd>The SQLITE_CONFIG_ROWID_IN_VIEW option enables or disables the ability2192** for VIEWs to have a ROWID. The capability can only be enabled if SQLite is2193** compiled with -DSQLITE_ALLOW_ROWID_IN_VIEW, in which case the capability2194** defaults to on. This configuration option queries the current setting or2195** changes the setting to off or on. The argument is a pointer to an integer.2196** If that integer initially holds a value of 1, then the ability for VIEWs to2197** have ROWIDs is activated. If the integer initially holds zero, then the2198** ability is deactivated. Any other initial value for the integer leaves the2199** setting unchanged. After changes, if any, the integer is written with2200** a 1 or 0, if the ability for VIEWs to have ROWIDs is on or off. If SQLite2201** is compiled without -DSQLITE_ALLOW_ROWID_IN_VIEW (which is the usual and2202** recommended case) then the integer is always filled with zero, regardless2203** if its initial value.2204** </dl>2205*/2206#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */2207#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */2208#define SQLITE_CONFIG_SERIALIZED 3 /* nil */2209#define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */2210#define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */2211#define SQLITE_CONFIG_SCRATCH 6 /* No longer used */2212#define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */2213#define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */2214#define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */2215#define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */2216#define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */2217/* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */2218#define SQLITE_CONFIG_LOOKASIDE 13 /* int int */2219#define SQLITE_CONFIG_PCACHE 14 /* no-op */2220#define SQLITE_CONFIG_GETPCACHE 15 /* no-op */2221#define SQLITE_CONFIG_LOG 16 /* xFunc, void* */2222#define SQLITE_CONFIG_URI 17 /* int */2223#define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */2224#define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */2225#define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */2226#define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */2227#define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */2228#define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */2229#define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */2230#define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */2231#define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */2232#define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */2233#define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */2234#define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */2235#define SQLITE_CONFIG_ROWID_IN_VIEW 30 /* int* */22362237/*2238** CAPI3REF: Database Connection Configuration Options2239**2240** These constants are the available integer configuration options that2241** can be passed as the second parameter to the [sqlite3_db_config()] interface.2242**2243** The [sqlite3_db_config()] interface is a var-args function. It takes a2244** variable number of parameters, though always at least two. The number of2245** parameters passed into sqlite3_db_config() depends on which of these2246** constants is given as the second parameter. This documentation page2247** refers to parameters beyond the second as "arguments". Thus, when this2248** page says "the N-th argument" it means "the N-th parameter past the2249** configuration option" or "the (N+2)-th parameter to sqlite3_db_config()".2250**2251** New configuration options may be added in future releases of SQLite.2252** Existing configuration options might be discontinued. Applications2253** should check the return code from [sqlite3_db_config()] to make sure that2254** the call worked. ^The [sqlite3_db_config()] interface will return a2255** non-zero [error code] if a discontinued or unsupported configuration option2256** is invoked.2257**2258** <dl>2259** [[SQLITE_DBCONFIG_LOOKASIDE]]2260** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>2261** <dd> The SQLITE_DBCONFIG_LOOKASIDE option is used to adjust the2262** configuration of the [lookaside memory allocator] within a database2263** connection.2264** The arguments to the SQLITE_DBCONFIG_LOOKASIDE option are <i>not</i>2265** in the [DBCONFIG arguments|usual format].2266** The SQLITE_DBCONFIG_LOOKASIDE option takes three arguments, not two,2267** so that a call to [sqlite3_db_config()] that uses SQLITE_DBCONFIG_LOOKASIDE2268** should have a total of five parameters.2269** <ol>2270** <li><p>The first argument ("buf") is a2271** pointer to a memory buffer to use for lookaside memory.2272** The first argument may be NULL in which case SQLite will allocate the2273** lookaside buffer itself using [sqlite3_malloc()].2274** <li><P>The second argument ("sz") is the2275** size of each lookaside buffer slot. Lookaside is disabled if "sz"2276** is less than 8. The "sz" argument should be a multiple of 8 less than2277** 65536. If "sz" does not meet this constraint, it is reduced in size until2278** it does.2279** <li><p>The third argument ("cnt") is the number of slots. Lookaside is disabled2280** if "cnt"is less than 1. The "cnt" value will be reduced, if necessary, so2281** that the product of "sz" and "cnt" does not exceed 2,147,418,112. The "cnt"2282** parameter is usually chosen so that the product of "sz" and "cnt" is less2283** than 1,000,000.2284** </ol>2285** <p>If the "buf" argument is not NULL, then it must2286** point to a memory buffer with a size that is greater than2287** or equal to the product of "sz" and "cnt".2288** The buffer must be aligned to an 8-byte boundary.2289** The lookaside memory2290** configuration for a database connection can only be changed when that2291** connection is not currently using lookaside memory, or in other words2292** when the value returned by [SQLITE_DBSTATUS_LOOKASIDE_USED] is zero.2293** Any attempt to change the lookaside memory configuration when lookaside2294** memory is in use leaves the configuration unchanged and returns2295** [SQLITE_BUSY].2296** If the "buf" argument is NULL and an attempt2297** to allocate memory based on "sz" and "cnt" fails, then2298** lookaside is silently disabled.2299** <p>2300** The [SQLITE_CONFIG_LOOKASIDE] configuration option can be used to set the2301** default lookaside configuration at initialization. The2302** [-DSQLITE_DEFAULT_LOOKASIDE] option can be used to set the default lookaside2303** configuration at compile-time. Typical values for lookaside are 1200 for2304** "sz" and 40 to 100 for "cnt".2305** </dd>2306**2307** [[SQLITE_DBCONFIG_ENABLE_FKEY]]2308** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>2309** <dd> ^This option is used to enable or disable the enforcement of2310** [foreign key constraints]. This is the same setting that is2311** enabled or disabled by the [PRAGMA foreign_keys] statement.2312** The first argument is an integer which is 0 to disable FK enforcement,2313** positive to enable FK enforcement or negative to leave FK enforcement2314** unchanged. The second parameter is a pointer to an integer into which2315** is written 0 or 1 to indicate whether FK enforcement is off or on2316** following this call. The second parameter may be a NULL pointer, in2317** which case the FK enforcement setting is not reported back. </dd>2318**2319** [[SQLITE_DBCONFIG_ENABLE_TRIGGER]]2320** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>2321** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].2322** There should be two additional arguments.2323** The first argument is an integer which is 0 to disable triggers,2324** positive to enable triggers or negative to leave the setting unchanged.2325** The second parameter is a pointer to an integer into which2326** is written 0 or 1 to indicate whether triggers are disabled or enabled2327** following this call. The second parameter may be a NULL pointer, in2328** which case the trigger setting is not reported back.2329**2330** <p>Originally this option disabled all triggers. ^(However, since2331** SQLite version 3.35.0, TEMP triggers are still allowed even if2332** this option is off. So, in other words, this option now only disables2333** triggers in the main database schema or in the schemas of [ATTACH]-ed2334** databases.)^ </dd>2335**2336** [[SQLITE_DBCONFIG_ENABLE_VIEW]]2337** <dt>SQLITE_DBCONFIG_ENABLE_VIEW</dt>2338** <dd> ^This option is used to enable or disable [CREATE VIEW | views].2339** There must be two additional arguments.2340** The first argument is an integer which is 0 to disable views,2341** positive to enable views or negative to leave the setting unchanged.2342** The second parameter is a pointer to an integer into which2343** is written 0 or 1 to indicate whether views are disabled or enabled2344** following this call. The second parameter may be a NULL pointer, in2345** which case the view setting is not reported back.2346**2347** <p>Originally this option disabled all views. ^(However, since2348** SQLite version 3.35.0, TEMP views are still allowed even if2349** this option is off. So, in other words, this option now only disables2350** views in the main database schema or in the schemas of ATTACH-ed2351** databases.)^ </dd>2352**2353** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]2354** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>2355** <dd> ^This option is used to enable or disable using the2356** [fts3_tokenizer()] function - part of the [FTS3] full-text search engine2357** extension - without using bound parameters as the parameters. Doing so2358** is disabled by default. There must be two additional arguments. The first2359** argument is an integer. If it is passed 0, then using fts3_tokenizer()2360** without bound parameters is disabled. If it is passed a positive value,2361** then calling fts3_tokenizer without bound parameters is enabled. If it2362** is passed a negative value, this setting is not modified - this can be2363** used to query for the current setting. The second parameter is a pointer2364** to an integer into which is written 0 or 1 to indicate the current value2365** of this setting (after it is modified, if applicable). The second2366** parameter may be a NULL pointer, in which case the value of the setting2367** is not reported back. Refer to [FTS3] documentation for further details.2368** </dd>2369**2370** [[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION]]2371** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>2372** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]2373** interface independently of the [load_extension()] SQL function.2374** The [sqlite3_enable_load_extension()] API enables or disables both the2375** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].2376** There must be two additional arguments.2377** When the first argument to this interface is 1, then only the C-API is2378** enabled and the SQL function remains disabled. If the first argument to2379** this interface is 0, then both the C-API and the SQL function are disabled.2380** If the first argument is -1, then no changes are made to the state of either2381** the C-API or the SQL function.2382** The second parameter is a pointer to an integer into which2383** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface2384** is disabled or enabled following this call. The second parameter may2385** be a NULL pointer, in which case the new setting is not reported back.2386** </dd>2387**2388** [[SQLITE_DBCONFIG_MAINDBNAME]] <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>2389** <dd> ^This option is used to change the name of the "main" database2390** schema. This option does not follow the2391** [DBCONFIG arguments|usual SQLITE_DBCONFIG argument format].2392** This option takes exactly one additional argument so that the2393** [sqlite3_db_config()] call has a total of three parameters. The2394** extra argument must be a pointer to a constant UTF8 string which2395** will become the new schema name in place of "main". ^SQLite does2396** not make a copy of the new main schema name string, so the application2397** must ensure that the argument passed into SQLITE_DBCONFIG MAINDBNAME2398** is unchanged until after the database connection closes.2399** </dd>2400**2401** [[SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE]]2402** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>2403** <dd> Usually, when a database in [WAL mode] is closed or detached from a2404** database handle, SQLite checks if if there are other connections to the2405** same database, and if there are no other database connection (if the2406** connection being closed is the last open connection to the database),2407** then SQLite performs a [checkpoint] before closing the connection and2408** deletes the WAL file. The SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE option can2409** be used to override that behavior. The first argument passed to this2410** operation (the third parameter to [sqlite3_db_config()]) is an integer2411** which is positive to disable checkpoints-on-close, or zero (the default)2412** to enable them, and negative to leave the setting unchanged.2413** The second argument (the fourth parameter) is a pointer to an integer2414** into which is written 0 or 1 to indicate whether checkpoints-on-close2415** have been disabled - 0 if they are not disabled, 1 if they are.2416** </dd>2417**2418** [[SQLITE_DBCONFIG_ENABLE_QPSG]] <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>2419** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates2420** the [query planner stability guarantee] (QPSG). When the QPSG is active,2421** a single SQL query statement will always use the same algorithm regardless2422** of values of [bound parameters].)^ The QPSG disables some query optimizations2423** that look at the values of bound parameters, which can make some queries2424** slower. But the QPSG has the advantage of more predictable behavior. With2425** the QPSG active, SQLite will always use the same query plan in the field as2426** was used during testing in the lab.2427** The first argument to this setting is an integer which is 0 to disable2428** the QPSG, positive to enable QPSG, or negative to leave the setting2429** unchanged. The second parameter is a pointer to an integer into which2430** is written 0 or 1 to indicate whether the QPSG is disabled or enabled2431** following this call.2432** </dd>2433**2434** [[SQLITE_DBCONFIG_TRIGGER_EQP]] <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt>2435** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not2436** include output for any operations performed by trigger programs. This2437** option is used to set or clear (the default) a flag that governs this2438** behavior. The first parameter passed to this operation is an integer -2439** positive to enable output for trigger programs, or zero to disable it,2440** or negative to leave the setting unchanged.2441** The second parameter is a pointer to an integer into which is written2442** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if2443** it is not disabled, 1 if it is.2444** </dd>2445**2446** [[SQLITE_DBCONFIG_RESET_DATABASE]] <dt>SQLITE_DBCONFIG_RESET_DATABASE</dt>2447** <dd> Set the SQLITE_DBCONFIG_RESET_DATABASE flag and then run2448** [VACUUM] in order to reset a database back to an empty database2449** with no schema and no content. The following process works even for2450** a badly corrupted database file:2451** <ol>2452** <li> If the database connection is newly opened, make sure it has read the2453** database schema by preparing then discarding some query against the2454** database, or calling sqlite3_table_column_metadata(), ignoring any2455** errors. This step is only necessary if the application desires to keep2456** the database in WAL mode after the reset if it was in WAL mode before2457** the reset.2458** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0);2459** <li> [sqlite3_exec](db, "[VACUUM]", 0, 0, 0);2460** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);2461** </ol>2462** Because resetting a database is destructive and irreversible, the2463** process requires the use of this obscure API and multiple steps to2464** help ensure that it does not happen by accident. Because this2465** feature must be capable of resetting corrupt databases, and2466** shutting down virtual tables may require access to that corrupt2467** storage, the library must abandon any installed virtual tables2468** without calling their xDestroy() methods.2469**2470** [[SQLITE_DBCONFIG_DEFENSIVE]] <dt>SQLITE_DBCONFIG_DEFENSIVE</dt>2471** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the2472** "defensive" flag for a database connection. When the defensive2473** flag is enabled, language features that allow ordinary SQL to2474** deliberately corrupt the database file are disabled. The disabled2475** features include but are not limited to the following:2476** <ul>2477** <li> The [PRAGMA writable_schema=ON] statement.2478** <li> The [PRAGMA journal_mode=OFF] statement.2479** <li> The [PRAGMA schema_version=N] statement.2480** <li> Writes to the [sqlite_dbpage] virtual table.2481** <li> Direct writes to [shadow tables].2482** </ul>2483** </dd>2484**2485** [[SQLITE_DBCONFIG_WRITABLE_SCHEMA]] <dt>SQLITE_DBCONFIG_WRITABLE_SCHEMA</dt>2486** <dd>The SQLITE_DBCONFIG_WRITABLE_SCHEMA option activates or deactivates the2487** "writable_schema" flag. This has the same effect and is logically equivalent2488** to setting [PRAGMA writable_schema=ON] or [PRAGMA writable_schema=OFF].2489** The first argument to this setting is an integer which is 0 to disable2490** the writable_schema, positive to enable writable_schema, or negative to2491** leave the setting unchanged. The second parameter is a pointer to an2492** integer into which is written 0 or 1 to indicate whether the writable_schema2493** is enabled or disabled following this call.2494** </dd>2495**2496** [[SQLITE_DBCONFIG_LEGACY_ALTER_TABLE]]2497** <dt>SQLITE_DBCONFIG_LEGACY_ALTER_TABLE</dt>2498** <dd>The SQLITE_DBCONFIG_LEGACY_ALTER_TABLE option activates or deactivates2499** the legacy behavior of the [ALTER TABLE RENAME] command such that it2500** behaves as it did prior to [version 3.24.0] (2018-06-04). See the2501** "Compatibility Notice" on the [ALTER TABLE RENAME documentation] for2502** additional information. This feature can also be turned on and off2503** using the [PRAGMA legacy_alter_table] statement.2504** </dd>2505**2506** [[SQLITE_DBCONFIG_DQS_DML]]2507** <dt>SQLITE_DBCONFIG_DQS_DML</dt>2508** <dd>The SQLITE_DBCONFIG_DQS_DML option activates or deactivates2509** the legacy [double-quoted string literal] misfeature for DML statements2510** only, that is DELETE, INSERT, SELECT, and UPDATE statements. The2511** default value of this setting is determined by the [-DSQLITE_DQS]2512** compile-time option.2513** </dd>2514**2515** [[SQLITE_DBCONFIG_DQS_DDL]]2516** <dt>SQLITE_DBCONFIG_DQS_DDL</dt>2517** <dd>The SQLITE_DBCONFIG_DQS option activates or deactivates2518** the legacy [double-quoted string literal] misfeature for DDL statements,2519** such as CREATE TABLE and CREATE INDEX. The2520** default value of this setting is determined by the [-DSQLITE_DQS]2521** compile-time option.2522** </dd>2523**2524** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]2525** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</dt>2526** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to2527** assume that database schemas are untainted by malicious content.2528** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite2529** takes additional defensive steps to protect the application from harm2530** including:2531** <ul>2532** <li> Prohibit the use of SQL functions inside triggers, views,2533** CHECK constraints, DEFAULT clauses, expression indexes,2534** partial indexes, or generated columns2535** unless those functions are tagged with [SQLITE_INNOCUOUS].2536** <li> Prohibit the use of virtual tables inside of triggers or views2537** unless those virtual tables are tagged with [SQLITE_VTAB_INNOCUOUS].2538** </ul>2539** This setting defaults to "on" for legacy compatibility, however2540** all applications are advised to turn it off if possible. This setting2541** can also be controlled using the [PRAGMA trusted_schema] statement.2542** </dd>2543**2544** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]2545** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</dt>2546** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates2547** the legacy file format flag. When activated, this flag causes all newly2548** created database files to have a schema format version number (the 4-byte2549** integer found at offset 44 into the database header) of 1. This in turn2550** means that the resulting database file will be readable and writable by2551** any SQLite version back to 3.0.0 ([dateof:3.0.0]). Without this setting,2552** newly created databases are generally not understandable by SQLite versions2553** prior to 3.3.0 ([dateof:3.3.0]). As these words are written, there2554** is now scarcely any need to generate database files that are compatible2555** all the way back to version 3.0.0, and so this setting is of little2556** practical use, but is provided so that SQLite can continue to claim the2557** ability to generate new database files that are compatible with version2558** 3.0.0.2559** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on,2560** the [VACUUM] command will fail with an obscure error when attempting to2561** process a table with generated columns and a descending index. This is2562** not considered a bug since SQLite versions 3.3.0 and earlier do not support2563** either generated columns or descending indexes.2564** </dd>2565**2566** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]]2567** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt>2568** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in2569** SQLITE_ENABLE_STMT_SCANSTATUS builds. In this case, it sets or clears2570** a flag that enables collection of the sqlite3_stmt_scanstatus_v2()2571** statistics. For statistics to be collected, the flag must be set on2572** the database handle both when the SQL statement is prepared and when it2573** is stepped. The flag is set (collection of statistics is enabled)2574** by default. <p>This option takes two arguments: an integer and a pointer to2575** an integer. The first argument is 1, 0, or -1 to enable, disable, or2576** leave unchanged the statement scanstatus option. If the second argument2577** is not NULL, then the value of the statement scanstatus setting after2578** processing the first argument is written into the integer that the second2579** argument points to.2580** </dd>2581**2582** [[SQLITE_DBCONFIG_REVERSE_SCANORDER]]2583** <dt>SQLITE_DBCONFIG_REVERSE_SCANORDER</dt>2584** <dd>The SQLITE_DBCONFIG_REVERSE_SCANORDER option changes the default order2585** in which tables and indexes are scanned so that the scans start at the end2586** and work toward the beginning rather than starting at the beginning and2587** working toward the end. Setting SQLITE_DBCONFIG_REVERSE_SCANORDER is the2588** same as setting [PRAGMA reverse_unordered_selects]. <p>This option takes2589** two arguments which are an integer and a pointer to an integer. The first2590** argument is 1, 0, or -1 to enable, disable, or leave unchanged the2591** reverse scan order flag, respectively. If the second argument is not NULL,2592** then 0 or 1 is written into the integer that the second argument points to2593** depending on if the reverse scan order flag is set after processing the2594** first argument.2595** </dd>2596**2597** [[SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE]]2598** <dt>SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE</dt>2599** <dd>The SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE option enables or disables2600** the ability of the [ATTACH DATABASE] SQL command to create a new database2601** file if the database filed named in the ATTACH command does not already2602** exist. This ability of ATTACH to create a new database is enabled by2603** default. Applications can disable or reenable the ability for ATTACH to2604** create new database files using this DBCONFIG option.<p>2605** This option takes two arguments which are an integer and a pointer2606** to an integer. The first argument is 1, 0, or -1 to enable, disable, or2607** leave unchanged the attach-create flag, respectively. If the second2608** argument is not NULL, then 0 or 1 is written into the integer that the2609** second argument points to depending on if the attach-create flag is set2610** after processing the first argument.2611** </dd>2612**2613** [[SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE]]2614** <dt>SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE</dt>2615** <dd>The SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE option enables or disables the2616** ability of the [ATTACH DATABASE] SQL command to open a database for writing.2617** This capability is enabled by default. Applications can disable or2618** reenable this capability using the current DBCONFIG option. If2619** this capability is disabled, the [ATTACH] command will still work,2620** but the database will be opened read-only. If this option is disabled,2621** then the ability to create a new database using [ATTACH] is also disabled,2622** regardless of the value of the [SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE]2623** option.<p>2624** This option takes two arguments which are an integer and a pointer2625** to an integer. The first argument is 1, 0, or -1 to enable, disable, or2626** leave unchanged the ability to ATTACH another database for writing,2627** respectively. If the second argument is not NULL, then 0 or 1 is written2628** into the integer to which the second argument points, depending on whether2629** the ability to ATTACH a read/write database is enabled or disabled2630** after processing the first argument.2631** </dd>2632**2633** [[SQLITE_DBCONFIG_ENABLE_COMMENTS]]2634** <dt>SQLITE_DBCONFIG_ENABLE_COMMENTS</dt>2635** <dd>The SQLITE_DBCONFIG_ENABLE_COMMENTS option enables or disables the2636** ability to include comments in SQL text. Comments are enabled by default.2637** An application can disable or reenable comments in SQL text using this2638** DBCONFIG option.<p>2639** This option takes two arguments which are an integer and a pointer2640** to an integer. The first argument is 1, 0, or -1 to enable, disable, or2641** leave unchanged the ability to use comments in SQL text,2642** respectively. If the second argument is not NULL, then 0 or 1 is written2643** into the integer that the second argument points to depending on if2644** comments are allowed in SQL text after processing the first argument.2645** </dd>2646**2647** </dl>2648**2649** [[DBCONFIG arguments]] <h3>Arguments To SQLITE_DBCONFIG Options</h3>2650**2651** <p>Most of the SQLITE_DBCONFIG options take two arguments, so that the2652** overall call to [sqlite3_db_config()] has a total of four parameters.2653** The first argument (the third parameter to sqlite3_db_config()) is an integer.2654** The second argument is a pointer to an integer. If the first argument is 1,2655** then the option becomes enabled. If the first integer argument is 0, then the2656** option is disabled. If the first argument is -1, then the option setting2657** is unchanged. The second argument, the pointer to an integer, may be NULL.2658** If the second argument is not NULL, then a value of 0 or 1 is written into2659** the integer to which the second argument points, depending on whether the2660** setting is disabled or enabled after applying any changes specified by2661** the first argument.2662**2663** <p>While most SQLITE_DBCONFIG options use the argument format2664** described in the previous paragraph, the [SQLITE_DBCONFIG_MAINDBNAME]2665** and [SQLITE_DBCONFIG_LOOKASIDE] options are different. See the2666** documentation of those exceptional options for details.2667*/2668#define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */2669#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */2670#define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */2671#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */2672#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */2673#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */2674#define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */2675#define SQLITE_DBCONFIG_ENABLE_QPSG 1007 /* int int* */2676#define SQLITE_DBCONFIG_TRIGGER_EQP 1008 /* int int* */2677#define SQLITE_DBCONFIG_RESET_DATABASE 1009 /* int int* */2678#define SQLITE_DBCONFIG_DEFENSIVE 1010 /* int int* */2679#define SQLITE_DBCONFIG_WRITABLE_SCHEMA 1011 /* int int* */2680#define SQLITE_DBCONFIG_LEGACY_ALTER_TABLE 1012 /* int int* */2681#define SQLITE_DBCONFIG_DQS_DML 1013 /* int int* */2682#define SQLITE_DBCONFIG_DQS_DDL 1014 /* int int* */2683#define SQLITE_DBCONFIG_ENABLE_VIEW 1015 /* int int* */2684#define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT 1016 /* int int* */2685#define SQLITE_DBCONFIG_TRUSTED_SCHEMA 1017 /* int int* */2686#define SQLITE_DBCONFIG_STMT_SCANSTATUS 1018 /* int int* */2687#define SQLITE_DBCONFIG_REVERSE_SCANORDER 1019 /* int int* */2688#define SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE 1020 /* int int* */2689#define SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE 1021 /* int int* */2690#define SQLITE_DBCONFIG_ENABLE_COMMENTS 1022 /* int int* */2691#define SQLITE_DBCONFIG_MAX 1022 /* Largest DBCONFIG */26922693/*2694** CAPI3REF: Enable Or Disable Extended Result Codes2695** METHOD: sqlite32696**2697** ^The sqlite3_extended_result_codes() routine enables or disables the2698** [extended result codes] feature of SQLite. ^The extended result2699** codes are disabled by default for historical compatibility.2700*/2701SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);27022703/*2704** CAPI3REF: Last Insert Rowid2705** METHOD: sqlite32706**2707** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)2708** has a unique 64-bit signed2709** integer key called the [ROWID | "rowid"]. ^The rowid is always available2710** as an undeclared column named ROWID, OID, or _ROWID_ as long as those2711** names are not also used by explicitly declared columns. ^If2712** the table has a column of type [INTEGER PRIMARY KEY] then that column2713** is another alias for the rowid.2714**2715** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of2716** the most recent successful [INSERT] into a rowid table or [virtual table]2717** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not2718** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred2719** on the database connection D, then sqlite3_last_insert_rowid(D) returns2720** zero.2721**2722** As well as being set automatically as rows are inserted into database2723** tables, the value returned by this function may be set explicitly by2724** [sqlite3_set_last_insert_rowid()]2725**2726** Some virtual table implementations may INSERT rows into rowid tables as2727** part of committing a transaction (e.g. to flush data accumulated in memory2728** to disk). In this case subsequent calls to this function return the rowid2729** associated with these internal INSERT operations, which leads to2730** unintuitive results. Virtual table implementations that do write to rowid2731** tables in this way can avoid this problem by restoring the original2732** rowid value using [sqlite3_set_last_insert_rowid()] before returning2733** control to the user.2734**2735** ^(If an [INSERT] occurs within a trigger then this routine will2736** return the [rowid] of the inserted row as long as the trigger is2737** running. Once the trigger program ends, the value returned2738** by this routine reverts to what it was before the trigger was fired.)^2739**2740** ^An [INSERT] that fails due to a constraint violation is not a2741** successful [INSERT] and does not change the value returned by this2742** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,2743** and INSERT OR ABORT make no changes to the return value of this2744** routine when their insertion fails. ^(When INSERT OR REPLACE2745** encounters a constraint violation, it does not fail. The2746** INSERT continues to completion after deleting rows that caused2747** the constraint problem so INSERT OR REPLACE will always change2748** the return value of this interface.)^2749**2750** ^For the purposes of this routine, an [INSERT] is considered to2751** be successful even if it is subsequently rolled back.2752**2753** This function is accessible to SQL statements via the2754** [last_insert_rowid() SQL function].2755**2756** If a separate thread performs a new [INSERT] on the same2757** database connection while the [sqlite3_last_insert_rowid()]2758** function is running and thus changes the last insert [rowid],2759** then the value returned by [sqlite3_last_insert_rowid()] is2760** unpredictable and might not equal either the old or the new2761** last insert [rowid].2762*/2763SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);27642765/*2766** CAPI3REF: Set the Last Insert Rowid value.2767** METHOD: sqlite32768**2769** The sqlite3_set_last_insert_rowid(D, R) method allows the application to2770** set the value returned by calling sqlite3_last_insert_rowid(D) to R2771** without inserting a row into the database.2772*/2773SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64);27742775/*2776** CAPI3REF: Count The Number Of Rows Modified2777** METHOD: sqlite32778**2779** ^These functions return the number of rows modified, inserted or2780** deleted by the most recently completed INSERT, UPDATE or DELETE2781** statement on the database connection specified by the only parameter.2782** The two functions are identical except for the type of the return value2783** and that if the number of rows modified by the most recent INSERT, UPDATE,2784** or DELETE is greater than the maximum value supported by type "int", then2785** the return value of sqlite3_changes() is undefined. ^Executing any other2786** type of SQL statement does not modify the value returned by these functions.2787** For the purposes of this interface, a CREATE TABLE AS SELECT statement2788** does not count as an INSERT, UPDATE or DELETE statement and hence the rows2789** added to the new table by the CREATE TABLE AS SELECT statement are not2790** counted.2791**2792** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are2793** considered - auxiliary changes caused by [CREATE TRIGGER | triggers],2794** [foreign key actions] or [REPLACE] constraint resolution are not counted.2795**2796** Changes to a view that are intercepted by2797** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value2798** returned by sqlite3_changes() immediately after an INSERT, UPDATE or2799** DELETE statement run on a view is always zero. Only changes made to real2800** tables are counted.2801**2802** Things are more complicated if the sqlite3_changes() function is2803** executed while a trigger program is running. This may happen if the2804** program uses the [changes() SQL function], or if some other callback2805** function invokes sqlite3_changes() directly. Essentially:2806**2807** <ul>2808** <li> ^(Before entering a trigger program the value returned by2809** sqlite3_changes() function is saved. After the trigger program2810** has finished, the original value is restored.)^2811**2812** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE2813** statement sets the value returned by sqlite3_changes()2814** upon completion as normal. Of course, this value will not include2815** any changes performed by sub-triggers, as the sqlite3_changes()2816** value will be saved and restored after each sub-trigger has run.)^2817** </ul>2818**2819** ^This means that if the changes() SQL function (or similar) is used2820** by the first INSERT, UPDATE or DELETE statement within a trigger, it2821** returns the value as set when the calling statement began executing.2822** ^If it is used by the second or subsequent such statement within a trigger2823** program, the value returned reflects the number of rows modified by the2824** previous INSERT, UPDATE or DELETE statement within the same trigger.2825**2826** If a separate thread makes changes on the same database connection2827** while [sqlite3_changes()] is running then the value returned2828** is unpredictable and not meaningful.2829**2830** See also:2831** <ul>2832** <li> the [sqlite3_total_changes()] interface2833** <li> the [count_changes pragma]2834** <li> the [changes() SQL function]2835** <li> the [data_version pragma]2836** </ul>2837*/2838SQLITE_API int sqlite3_changes(sqlite3*);2839SQLITE_API sqlite3_int64 sqlite3_changes64(sqlite3*);28402841/*2842** CAPI3REF: Total Number Of Rows Modified2843** METHOD: sqlite32844**2845** ^These functions return the total number of rows inserted, modified or2846** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed2847** since the database connection was opened, including those executed as2848** part of trigger programs. The two functions are identical except for the2849** type of the return value and that if the number of rows modified by the2850** connection exceeds the maximum value supported by type "int", then2851** the return value of sqlite3_total_changes() is undefined. ^Executing2852** any other type of SQL statement does not affect the value returned by2853** sqlite3_total_changes().2854**2855** ^Changes made as part of [foreign key actions] are included in the2856** count, but those made as part of REPLACE constraint resolution are2857** not. ^Changes to a view that are intercepted by INSTEAD OF triggers2858** are not counted.2859**2860** The [sqlite3_total_changes(D)] interface only reports the number2861** of rows that changed due to SQL statement run against database2862** connection D. Any changes by other database connections are ignored.2863** To detect changes against a database file from other database2864** connections use the [PRAGMA data_version] command or the2865** [SQLITE_FCNTL_DATA_VERSION] [file control].2866**2867** If a separate thread makes changes on the same database connection2868** while [sqlite3_total_changes()] is running then the value2869** returned is unpredictable and not meaningful.2870**2871** See also:2872** <ul>2873** <li> the [sqlite3_changes()] interface2874** <li> the [count_changes pragma]2875** <li> the [changes() SQL function]2876** <li> the [data_version pragma]2877** <li> the [SQLITE_FCNTL_DATA_VERSION] [file control]2878** </ul>2879*/2880SQLITE_API int sqlite3_total_changes(sqlite3*);2881SQLITE_API sqlite3_int64 sqlite3_total_changes64(sqlite3*);28822883/*2884** CAPI3REF: Interrupt A Long-Running Query2885** METHOD: sqlite32886**2887** ^This function causes any pending database operation to abort and2888** return at its earliest opportunity. This routine is typically2889** called in response to a user action such as pressing "Cancel"2890** or Ctrl-C where the user wants a long query operation to halt2891** immediately.2892**2893** ^It is safe to call this routine from a thread different from the2894** thread that is currently running the database operation. But it2895** is not safe to call this routine with a [database connection] that2896** is closed or might close before sqlite3_interrupt() returns.2897**2898** ^If an SQL operation is very nearly finished at the time when2899** sqlite3_interrupt() is called, then it might not have an opportunity2900** to be interrupted and might continue to completion.2901**2902** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT].2903** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE2904** that is inside an explicit transaction, then the entire transaction2905** will be rolled back automatically.2906**2907** ^The sqlite3_interrupt(D) call is in effect until all currently running2908** SQL statements on [database connection] D complete. ^Any new SQL statements2909** that are started after the sqlite3_interrupt() call and before the2910** running statement count reaches zero are interrupted as if they had been2911** running prior to the sqlite3_interrupt() call. ^New SQL statements2912** that are started after the running statement count reaches zero are2913** not effected by the sqlite3_interrupt().2914** ^A call to sqlite3_interrupt(D) that occurs when there are no running2915** SQL statements is a no-op and has no effect on SQL statements2916** that are started after the sqlite3_interrupt() call returns.2917**2918** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether2919** or not an interrupt is currently in effect for [database connection] D.2920** It returns 1 if an interrupt is currently in effect, or 0 otherwise.2921*/2922SQLITE_API void sqlite3_interrupt(sqlite3*);2923SQLITE_API int sqlite3_is_interrupted(sqlite3*);29242925/*2926** CAPI3REF: Determine If An SQL Statement Is Complete2927**2928** These routines are useful during command-line input to determine if the2929** currently entered text seems to form a complete SQL statement or2930** if additional input is needed before sending the text into2931** SQLite for parsing. ^These routines return 1 if the input string2932** appears to be a complete SQL statement. ^A statement is judged to be2933** complete if it ends with a semicolon token and is not a prefix of a2934** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within2935** string literals or quoted identifier names or comments are not2936** independent tokens (they are part of the token in which they are2937** embedded) and thus do not count as a statement terminator. ^Whitespace2938** and comments that follow the final semicolon are ignored.2939**2940** ^These routines return 0 if the statement is incomplete. ^If a2941** memory allocation fails, then SQLITE_NOMEM is returned.2942**2943** ^These routines do not parse the SQL statements and thus2944** will not detect syntactically incorrect SQL.2945**2946** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior2947** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked2948** automatically by sqlite3_complete16(). If that initialization fails,2949** then the return value from sqlite3_complete16() will be non-zero2950** regardless of whether or not the input SQL is complete.)^2951**2952** The input to [sqlite3_complete()] must be a zero-terminated2953** UTF-8 string.2954**2955** The input to [sqlite3_complete16()] must be a zero-terminated2956** UTF-16 string in native byte order.2957*/2958SQLITE_API int sqlite3_complete(const char *sql);2959SQLITE_API int sqlite3_complete16(const void *sql);29602961/*2962** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors2963** KEYWORDS: {busy-handler callback} {busy handler}2964** METHOD: sqlite32965**2966** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X2967** that might be invoked with argument P whenever2968** an attempt is made to access a database table associated with2969** [database connection] D when another thread2970** or process has the table locked.2971** The sqlite3_busy_handler() interface is used to implement2972** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout].2973**2974** ^If the busy callback is NULL, then [SQLITE_BUSY]2975** is returned immediately upon encountering the lock. ^If the busy callback2976** is not NULL, then the callback might be invoked with two arguments.2977**2978** ^The first argument to the busy handler is a copy of the void* pointer which2979** is the third argument to sqlite3_busy_handler(). ^The second argument to2980** the busy handler callback is the number of times that the busy handler has2981** been invoked previously for the same locking event. ^If the2982** busy callback returns 0, then no additional attempts are made to2983** access the database and [SQLITE_BUSY] is returned2984** to the application.2985** ^If the callback returns non-zero, then another attempt2986** is made to access the database and the cycle repeats.2987**2988** The presence of a busy handler does not guarantee that it will be invoked2989** when there is lock contention. ^If SQLite determines that invoking the busy2990** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]2991** to the application instead of invoking the2992** busy handler.2993** Consider a scenario where one process is holding a read lock that2994** it is trying to promote to a reserved lock and2995** a second process is holding a reserved lock that it is trying2996** to promote to an exclusive lock. The first process cannot proceed2997** because it is blocked by the second and the second process cannot2998** proceed because it is blocked by the first. If both processes2999** invoke the busy handlers, neither will make any progress. Therefore,3000** SQLite returns [SQLITE_BUSY] for the first process, hoping that this3001** will induce the first process to release its read lock and allow3002** the second process to proceed.3003**3004** ^The default busy callback is NULL.3005**3006** ^(There can only be a single busy handler defined for each3007** [database connection]. Setting a new busy handler clears any3008** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()]3009** or evaluating [PRAGMA busy_timeout=N] will change the3010** busy handler and thus clear any previously set busy handler.3011**3012** The busy callback should not take any actions which modify the3013** database connection that invoked the busy handler. In other words,3014** the busy handler is not reentrant. Any such actions3015** result in undefined behavior.3016**3017** A busy handler must not close the database connection3018** or [prepared statement] that invoked the busy handler.3019*/3020SQLITE_API int sqlite3_busy_handler(sqlite3*,int(*)(void*,int),void*);30213022/*3023** CAPI3REF: Set A Busy Timeout3024** METHOD: sqlite33025**3026** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps3027** for a specified amount of time when a table is locked. ^The handler3028** will sleep multiple times until at least "ms" milliseconds of sleeping3029** have accumulated. ^After at least "ms" milliseconds of sleeping,3030** the handler returns 0 which causes [sqlite3_step()] to return3031** [SQLITE_BUSY].3032**3033** ^Calling this routine with an argument less than or equal to zero3034** turns off all busy handlers.3035**3036** ^(There can only be a single busy handler for a particular3037** [database connection] at any given moment. If another busy handler3038** was defined (using [sqlite3_busy_handler()]) prior to calling3039** this routine, that other busy handler is cleared.)^3040**3041** See also: [PRAGMA busy_timeout]3042*/3043SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);30443045/*3046** CAPI3REF: Set the Setlk Timeout3047** METHOD: sqlite33048**3049** This routine is only useful in SQLITE_ENABLE_SETLK_TIMEOUT builds. If3050** the VFS supports blocking locks, it sets the timeout in ms used by3051** eligible locks taken on wal mode databases by the specified database3052** handle. In non-SQLITE_ENABLE_SETLK_TIMEOUT builds, or if the VFS does3053** not support blocking locks, this function is a no-op.3054**3055** Passing 0 to this function disables blocking locks altogether. Passing3056** -1 to this function requests that the VFS blocks for a long time -3057** indefinitely if possible. The results of passing any other negative value3058** are undefined.3059**3060** Internally, each SQLite database handle stores two timeout values - the3061** busy-timeout (used for rollback mode databases, or if the VFS does not3062** support blocking locks) and the setlk-timeout (used for blocking locks3063** on wal-mode databases). The sqlite3_busy_timeout() method sets both3064** values, this function sets only the setlk-timeout value. Therefore,3065** to configure separate busy-timeout and setlk-timeout values for a single3066** database handle, call sqlite3_busy_timeout() followed by this function.3067**3068** Whenever the number of connections to a wal mode database falls from3069** 1 to 0, the last connection takes an exclusive lock on the database,3070** then checkpoints and deletes the wal file. While it is doing this, any3071** new connection that tries to read from the database fails with an3072** SQLITE_BUSY error. Or, if the SQLITE_SETLK_BLOCK_ON_CONNECT flag is3073** passed to this API, the new connection blocks until the exclusive lock3074** has been released.3075*/3076SQLITE_API int sqlite3_setlk_timeout(sqlite3*, int ms, int flags);30773078/*3079** CAPI3REF: Flags for sqlite3_setlk_timeout()3080*/3081#define SQLITE_SETLK_BLOCK_ON_CONNECT 0x0130823083/*3084** CAPI3REF: Convenience Routines For Running Queries3085** METHOD: sqlite33086**3087** This is a legacy interface that is preserved for backwards compatibility.3088** Use of this interface is not recommended.3089**3090** Definition: A <b>result table</b> is a memory data structure created by the3091** [sqlite3_get_table()] interface. A result table records the3092** complete query results from one or more queries.3093**3094** The table conceptually has a number of rows and columns. But3095** these numbers are not part of the result table itself. These3096** numbers are obtained separately. Let N be the number of rows3097** and M be the number of columns.3098**3099** A result table is an array of pointers to zero-terminated UTF-8 strings.3100** There are (N+1)*M elements in the array. The first M pointers point3101** to zero-terminated strings that contain the names of the columns.3102** The remaining entries all point to query results. NULL values result3103** in NULL pointers. All other values are in their UTF-8 zero-terminated3104** string representation as returned by [sqlite3_column_text()].3105**3106** A result table might consist of one or more memory allocations.3107** It is not safe to pass a result table directly to [sqlite3_free()].3108** A result table should be deallocated using [sqlite3_free_table()].3109**3110** ^(As an example of the result table format, suppose a query result3111** is as follows:3112**3113** <blockquote><pre>3114** Name | Age3115** -----------------------3116** Alice | 433117** Bob | 283118** Cindy | 213119** </pre></blockquote>3120**3121** There are two columns (M==2) and three rows (N==3). Thus the3122** result table has 8 entries. Suppose the result table is stored3123** in an array named azResult. Then azResult holds this content:3124**3125** <blockquote><pre>3126** azResult[0] = "Name";3127** azResult[1] = "Age";3128** azResult[2] = "Alice";3129** azResult[3] = "43";3130** azResult[4] = "Bob";3131** azResult[5] = "28";3132** azResult[6] = "Cindy";3133** azResult[7] = "21";3134** </pre></blockquote>)^3135**3136** ^The sqlite3_get_table() function evaluates one or more3137** semicolon-separated SQL statements in the zero-terminated UTF-83138** string of its 2nd parameter and returns a result table to the3139** pointer given in its 3rd parameter.3140**3141** After the application has finished with the result from sqlite3_get_table(),3142** it must pass the result table pointer to sqlite3_free_table() in order to3143** release the memory that was malloced. Because of the way the3144** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling3145** function must not try to call [sqlite3_free()] directly. Only3146** [sqlite3_free_table()] is able to release the memory properly and safely.3147**3148** The sqlite3_get_table() interface is implemented as a wrapper around3149** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access3150** to any internal data structures of SQLite. It uses only the public3151** interface defined here. As a consequence, errors that occur in the3152** wrapper layer outside of the internal [sqlite3_exec()] call are not3153** reflected in subsequent calls to [sqlite3_errcode()] or3154** [sqlite3_errmsg()].3155*/3156SQLITE_API int sqlite3_get_table(3157sqlite3 *db, /* An open database */3158const char *zSql, /* SQL to be evaluated */3159char ***pazResult, /* Results of the query */3160int *pnRow, /* Number of result rows written here */3161int *pnColumn, /* Number of result columns written here */3162char **pzErrmsg /* Error msg written here */3163);3164SQLITE_API void sqlite3_free_table(char **result);31653166/*3167** CAPI3REF: Formatted String Printing Functions3168**3169** These routines are work-alikes of the "printf()" family of functions3170** from the standard C library.3171** These routines understand most of the common formatting options from3172** the standard library printf()3173** plus some additional non-standard formats ([%q], [%Q], [%w], and [%z]).3174** See the [built-in printf()] documentation for details.3175**3176** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their3177** results into memory obtained from [sqlite3_malloc64()].3178** The strings returned by these two routines should be3179** released by [sqlite3_free()]. ^Both routines return a3180** NULL pointer if [sqlite3_malloc64()] is unable to allocate enough3181** memory to hold the resulting string.3182**3183** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from3184** the standard C library. The result is written into the3185** buffer supplied as the second parameter whose size is given by3186** the first parameter. Note that the order of the3187** first two parameters is reversed from snprintf().)^ This is an3188** historical accident that cannot be fixed without breaking3189** backwards compatibility. ^(Note also that sqlite3_snprintf()3190** returns a pointer to its buffer instead of the number of3191** characters actually written into the buffer.)^ We admit that3192** the number of characters written would be a more useful return3193** value but we cannot change the implementation of sqlite3_snprintf()3194** now without breaking compatibility.3195**3196** ^As long as the buffer size is greater than zero, sqlite3_snprintf()3197** guarantees that the buffer is always zero-terminated. ^The first3198** parameter "n" is the total size of the buffer, including space for3199** the zero terminator. So the longest string that can be completely3200** written will be n-1 characters.3201**3202** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().3203**3204** See also: [built-in printf()], [printf() SQL function]3205*/3206SQLITE_API char *sqlite3_mprintf(const char*,...);3207SQLITE_API char *sqlite3_vmprintf(const char*, va_list);3208SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);3209SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);32103211/*3212** CAPI3REF: Memory Allocation Subsystem3213**3214** The SQLite core uses these three routines for all of its own3215** internal memory allocation needs. "Core" in the previous sentence3216** does not include operating-system specific [VFS] implementation. The3217** Windows VFS uses native malloc() and free() for some operations.3218**3219** ^The sqlite3_malloc() routine returns a pointer to a block3220** of memory at least N bytes in length, where N is the parameter.3221** ^If sqlite3_malloc() is unable to obtain sufficient free3222** memory, it returns a NULL pointer. ^If the parameter N to3223** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns3224** a NULL pointer.3225**3226** ^The sqlite3_malloc64(N) routine works just like3227** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead3228** of a signed 32-bit integer.3229**3230** ^Calling sqlite3_free() with a pointer previously returned3231** by sqlite3_malloc() or sqlite3_realloc() releases that memory so3232** that it might be reused. ^The sqlite3_free() routine is3233** a no-op if it is called with a NULL pointer. Passing a NULL pointer3234** to sqlite3_free() is harmless. After being freed, memory3235** should neither be read nor written. Even reading previously freed3236** memory might result in a segmentation fault or other severe error.3237** Memory corruption, a segmentation fault, or other severe error3238** might result if sqlite3_free() is called with a non-NULL pointer that3239** was not obtained from sqlite3_malloc() or sqlite3_realloc().3240**3241** ^The sqlite3_realloc(X,N) interface attempts to resize a3242** prior memory allocation X to be at least N bytes.3243** ^If the X parameter to sqlite3_realloc(X,N)3244** is a NULL pointer then its behavior is identical to calling3245** sqlite3_malloc(N).3246** ^If the N parameter to sqlite3_realloc(X,N) is zero or3247** negative then the behavior is exactly the same as calling3248** sqlite3_free(X).3249** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation3250** of at least N bytes in size or NULL if insufficient memory is available.3251** ^If M is the size of the prior allocation, then min(N,M) bytes of the3252** prior allocation are copied into the beginning of the buffer returned3253** by sqlite3_realloc(X,N) and the prior allocation is freed.3254** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the3255** prior allocation is not freed.3256**3257** ^The sqlite3_realloc64(X,N) interface works the same as3258** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead3259** of a 32-bit signed integer.3260**3261** ^If X is a memory allocation previously obtained from sqlite3_malloc(),3262** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then3263** sqlite3_msize(X) returns the size of that memory allocation in bytes.3264** ^The value returned by sqlite3_msize(X) might be larger than the number3265** of bytes requested when X was allocated. ^If X is a NULL pointer then3266** sqlite3_msize(X) returns zero. If X points to something that is not3267** the beginning of memory allocation, or if it points to a formerly3268** valid memory allocation that has now been freed, then the behavior3269** of sqlite3_msize(X) is undefined and possibly harmful.3270**3271** ^The memory returned by sqlite3_malloc(), sqlite3_realloc(),3272** sqlite3_malloc64(), and sqlite3_realloc64()3273** is always aligned to at least an 8 byte boundary, or to a3274** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time3275** option is used.3276**3277** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]3278** must be either NULL or else pointers obtained from a prior3279** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have3280** not yet been released.3281**3282** The application must not read or write any part of3283** a block of memory after it has been released using3284** [sqlite3_free()] or [sqlite3_realloc()].3285*/3286SQLITE_API void *sqlite3_malloc(int);3287SQLITE_API void *sqlite3_malloc64(sqlite3_uint64);3288SQLITE_API void *sqlite3_realloc(void*, int);3289SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64);3290SQLITE_API void sqlite3_free(void*);3291SQLITE_API sqlite3_uint64 sqlite3_msize(void*);32923293/*3294** CAPI3REF: Memory Allocator Statistics3295**3296** SQLite provides these two interfaces for reporting on the status3297** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()]3298** routines, which form the built-in memory allocation subsystem.3299**3300** ^The [sqlite3_memory_used()] routine returns the number of bytes3301** of memory currently outstanding (malloced but not freed).3302** ^The [sqlite3_memory_highwater()] routine returns the maximum3303** value of [sqlite3_memory_used()] since the high-water mark3304** was last reset. ^The values returned by [sqlite3_memory_used()] and3305** [sqlite3_memory_highwater()] include any overhead3306** added by SQLite in its implementation of [sqlite3_malloc()],3307** but not overhead added by any underlying system library3308** routines that [sqlite3_malloc()] may call.3309**3310** ^The memory high-water mark is reset to the current value of3311** [sqlite3_memory_used()] if and only if the parameter to3312** [sqlite3_memory_highwater()] is true. ^The value returned3313** by [sqlite3_memory_highwater(1)] is the high-water mark3314** prior to the reset.3315*/3316SQLITE_API sqlite3_int64 sqlite3_memory_used(void);3317SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag);33183319/*3320** CAPI3REF: Pseudo-Random Number Generator3321**3322** SQLite contains a high-quality pseudo-random number generator (PRNG) used to3323** select random [ROWID | ROWIDs] when inserting new records into a table that3324** already uses the largest possible [ROWID]. The PRNG is also used for3325** the built-in random() and randomblob() SQL functions. This interface allows3326** applications to access the same PRNG for other purposes.3327**3328** ^A call to this routine stores N bytes of randomness into buffer P.3329** ^The P parameter can be a NULL pointer.3330**3331** ^If this routine has not been previously called or if the previous3332** call had N less than one or a NULL pointer for P, then the PRNG is3333** seeded using randomness obtained from the xRandomness method of3334** the default [sqlite3_vfs] object.3335** ^If the previous call to this routine had an N of 1 or more and a3336** non-NULL P then the pseudo-randomness is generated3337** internally and without recourse to the [sqlite3_vfs] xRandomness3338** method.3339*/3340SQLITE_API void sqlite3_randomness(int N, void *P);33413342/*3343** CAPI3REF: Compile-Time Authorization Callbacks3344** METHOD: sqlite33345** KEYWORDS: {authorizer callback}3346**3347** ^This routine registers an authorizer callback with a particular3348** [database connection], supplied in the first argument.3349** ^The authorizer callback is invoked as SQL statements are being compiled3350** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],3351** [sqlite3_prepare_v3()], [sqlite3_prepare16()], [sqlite3_prepare16_v2()],3352** and [sqlite3_prepare16_v3()]. ^At various3353** points during the compilation process, as logic is being created3354** to perform various actions, the authorizer callback is invoked to3355** see if those actions are allowed. ^The authorizer callback should3356** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the3357** specific action but allow the SQL statement to continue to be3358** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be3359** rejected with an error. ^If the authorizer callback returns3360** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY]3361** then the [sqlite3_prepare_v2()] or equivalent call that triggered3362** the authorizer will fail with an error message.3363**3364** When the callback returns [SQLITE_OK], that means the operation3365** requested is ok. ^When the callback returns [SQLITE_DENY], the3366** [sqlite3_prepare_v2()] or equivalent call that triggered the3367** authorizer will fail with an error message explaining that3368** access is denied.3369**3370** ^The first parameter to the authorizer callback is a copy of the third3371** parameter to the sqlite3_set_authorizer() interface. ^The second parameter3372** to the callback is an integer [SQLITE_COPY | action code] that specifies3373** the particular action to be authorized. ^The third through sixth parameters3374** to the callback are either NULL pointers or zero-terminated strings3375** that contain additional details about the action to be authorized.3376** Applications must always be prepared to encounter a NULL pointer in any3377** of the third through the sixth parameters of the authorization callback.3378**3379** ^If the action code is [SQLITE_READ]3380** and the callback returns [SQLITE_IGNORE] then the3381** [prepared statement] statement is constructed to substitute3382** a NULL value in place of the table column that would have3383** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE]3384** return can be used to deny an untrusted user access to individual3385** columns of a table.3386** ^When a table is referenced by a [SELECT] but no column values are3387** extracted from that table (for example in a query like3388** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback3389** is invoked once for that table with a column name that is an empty string.3390** ^If the action code is [SQLITE_DELETE] and the callback returns3391** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the3392** [truncate optimization] is disabled and all rows are deleted individually.3393**3394** An authorizer is used when [sqlite3_prepare | preparing]3395** SQL statements from an untrusted source, to ensure that the SQL statements3396** do not try to access data they are not allowed to see, or that they do not3397** try to execute malicious statements that damage the database. For3398** example, an application may allow a user to enter arbitrary3399** SQL queries for evaluation by a database. But the application does3400** not want the user to be able to make arbitrary changes to the3401** database. An authorizer could then be put in place while the3402** user-entered SQL is being [sqlite3_prepare | prepared] that3403** disallows everything except [SELECT] statements.3404**3405** Applications that need to process SQL from untrusted sources3406** might also consider lowering resource limits using [sqlite3_limit()]3407** and limiting database size using the [max_page_count] [PRAGMA]3408** in addition to using an authorizer.3409**3410** ^(Only a single authorizer can be in place on a database connection3411** at a time. Each call to sqlite3_set_authorizer overrides the3412** previous call.)^ ^Disable the authorizer by installing a NULL callback.3413** The authorizer is disabled by default.3414**3415** The authorizer callback must not do anything that will modify3416** the database connection that invoked the authorizer callback.3417** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their3418** database connections for the meaning of "modify" in this paragraph.3419**3420** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the3421** statement might be re-prepared during [sqlite3_step()] due to a3422** schema change. Hence, the application should ensure that the3423** correct authorizer callback remains in place during the [sqlite3_step()].3424**3425** ^Note that the authorizer callback is invoked only during3426** [sqlite3_prepare()] or its variants. Authorization is not3427** performed during statement evaluation in [sqlite3_step()], unless3428** as stated in the previous paragraph, sqlite3_step() invokes3429** sqlite3_prepare_v2() to reprepare a statement after a schema change.3430*/3431SQLITE_API int sqlite3_set_authorizer(3432sqlite3*,3433int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),3434void *pUserData3435);34363437/*3438** CAPI3REF: Authorizer Return Codes3439**3440** The [sqlite3_set_authorizer | authorizer callback function] must3441** return either [SQLITE_OK] or one of these two constants in order3442** to signal SQLite whether or not the action is permitted. See the3443** [sqlite3_set_authorizer | authorizer documentation] for additional3444** information.3445**3446** Note that SQLITE_IGNORE is also used as a [conflict resolution mode]3447** returned from the [sqlite3_vtab_on_conflict()] interface.3448*/3449#define SQLITE_DENY 1 /* Abort the SQL statement with an error */3450#define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */34513452/*3453** CAPI3REF: Authorizer Action Codes3454**3455** The [sqlite3_set_authorizer()] interface registers a callback function3456** that is invoked to authorize certain SQL statement actions. The3457** second parameter to the callback is an integer code that specifies3458** what action is being authorized. These are the integer action codes that3459** the authorizer callback may be passed.3460**3461** These action code values signify what kind of operation is to be3462** authorized. The 3rd and 4th parameters to the authorization3463** callback function will be parameters or NULL depending on which of these3464** codes is used as the second parameter. ^(The 5th parameter to the3465** authorizer callback is the name of the database ("main", "temp",3466** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback3467** is the name of the inner-most trigger or view that is responsible for3468** the access attempt or NULL if this access attempt is directly from3469** top-level SQL code.3470*/3471/******************************************* 3rd ************ 4th ***********/3472#define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */3473#define SQLITE_CREATE_TABLE 2 /* Table Name NULL */3474#define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */3475#define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */3476#define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */3477#define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */3478#define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */3479#define SQLITE_CREATE_VIEW 8 /* View Name NULL */3480#define SQLITE_DELETE 9 /* Table Name NULL */3481#define SQLITE_DROP_INDEX 10 /* Index Name Table Name */3482#define SQLITE_DROP_TABLE 11 /* Table Name NULL */3483#define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */3484#define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */3485#define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */3486#define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */3487#define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */3488#define SQLITE_DROP_VIEW 17 /* View Name NULL */3489#define SQLITE_INSERT 18 /* Table Name NULL */3490#define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */3491#define SQLITE_READ 20 /* Table Name Column Name */3492#define SQLITE_SELECT 21 /* NULL NULL */3493#define SQLITE_TRANSACTION 22 /* Operation NULL */3494#define SQLITE_UPDATE 23 /* Table Name Column Name */3495#define SQLITE_ATTACH 24 /* Filename NULL */3496#define SQLITE_DETACH 25 /* Database Name NULL */3497#define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */3498#define SQLITE_REINDEX 27 /* Index Name NULL */3499#define SQLITE_ANALYZE 28 /* Table Name NULL */3500#define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */3501#define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */3502#define SQLITE_FUNCTION 31 /* NULL Function Name */3503#define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */3504#define SQLITE_COPY 0 /* No longer used */3505#define SQLITE_RECURSIVE 33 /* NULL NULL */35063507/*3508** CAPI3REF: Deprecated Tracing And Profiling Functions3509** DEPRECATED3510**3511** These routines are deprecated. Use the [sqlite3_trace_v2()] interface3512** instead of the routines described here.3513**3514** These routines register callback functions that can be used for3515** tracing and profiling the execution of SQL statements.3516**3517** ^The callback function registered by sqlite3_trace() is invoked at3518** various times when an SQL statement is being run by [sqlite3_step()].3519** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the3520** SQL statement text as the statement first begins executing.3521** ^(Additional sqlite3_trace() callbacks might occur3522** as each triggered subprogram is entered. The callbacks for triggers3523** contain a UTF-8 SQL comment that identifies the trigger.)^3524**3525** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit3526** the length of [bound parameter] expansion in the output of sqlite3_trace().3527**3528** ^The callback function registered by sqlite3_profile() is invoked3529** as each SQL statement finishes. ^The profile callback contains3530** the original statement text and an estimate of wall-clock time3531** of how long that statement took to run. ^The profile callback3532** time is in units of nanoseconds, however the current implementation3533** is only capable of millisecond resolution so the six least significant3534** digits in the time are meaningless. Future versions of SQLite3535** might provide greater resolution on the profiler callback. Invoking3536** either [sqlite3_trace()] or [sqlite3_trace_v2()] will cancel the3537** profile callback.3538*/3539SQLITE_API SQLITE_DEPRECATED void *sqlite3_trace(sqlite3*,3540void(*xTrace)(void*,const char*), void*);3541SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3*,3542void(*xProfile)(void*,const char*,sqlite3_uint64), void*);35433544/*3545** CAPI3REF: SQL Trace Event Codes3546** KEYWORDS: SQLITE_TRACE3547**3548** These constants identify classes of events that can be monitored3549** using the [sqlite3_trace_v2()] tracing logic. The M argument3550** to [sqlite3_trace_v2(D,M,X,P)] is an OR-ed combination of one or more of3551** the following constants. ^The first argument to the trace callback3552** is one of the following constants.3553**3554** New tracing constants may be added in future releases.3555**3556** ^A trace callback has four arguments: xCallback(T,C,P,X).3557** ^The T argument is one of the integer type codes above.3558** ^The C argument is a copy of the context pointer passed in as the3559** fourth argument to [sqlite3_trace_v2()].3560** The P and X arguments are pointers whose meanings depend on T.3561**3562** <dl>3563** [[SQLITE_TRACE_STMT]] <dt>SQLITE_TRACE_STMT</dt>3564** <dd>^An SQLITE_TRACE_STMT callback is invoked when a prepared statement3565** first begins running and possibly at other times during the3566** execution of the prepared statement, such as at the start of each3567** trigger subprogram. ^The P argument is a pointer to the3568** [prepared statement]. ^The X argument is a pointer to a string which3569** is the unexpanded SQL text of the prepared statement or an SQL comment3570** that indicates the invocation of a trigger. ^The callback can compute3571** the same text that would have been returned by the legacy [sqlite3_trace()]3572** interface by using the X argument when X begins with "--" and invoking3573** [sqlite3_expanded_sql(P)] otherwise.3574**3575** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt>3576** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same3577** information as is provided by the [sqlite3_profile()] callback.3578** ^The P argument is a pointer to the [prepared statement] and the3579** X argument points to a 64-bit integer which is approximately3580** the number of nanoseconds that the prepared statement took to run.3581** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.3582**3583** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt>3584** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared3585** statement generates a single row of result.3586** ^The P argument is a pointer to the [prepared statement] and the3587** X argument is unused.3588**3589** [[SQLITE_TRACE_CLOSE]] <dt>SQLITE_TRACE_CLOSE</dt>3590** <dd>^An SQLITE_TRACE_CLOSE callback is invoked when a database3591** connection closes.3592** ^The P argument is a pointer to the [database connection] object3593** and the X argument is unused.3594** </dl>3595*/3596#define SQLITE_TRACE_STMT 0x013597#define SQLITE_TRACE_PROFILE 0x023598#define SQLITE_TRACE_ROW 0x043599#define SQLITE_TRACE_CLOSE 0x0836003601/*3602** CAPI3REF: SQL Trace Hook3603** METHOD: sqlite33604**3605** ^The sqlite3_trace_v2(D,M,X,P) interface registers a trace callback3606** function X against [database connection] D, using property mask M3607** and context pointer P. ^If the X callback is3608** NULL or if the M mask is zero, then tracing is disabled. The3609** M argument should be the bitwise OR-ed combination of3610** zero or more [SQLITE_TRACE] constants.3611**3612** ^Each call to either sqlite3_trace(D,X,P) or sqlite3_trace_v2(D,M,X,P)3613** overrides (cancels) all prior calls to sqlite3_trace(D,X,P) or3614** sqlite3_trace_v2(D,M,X,P) for the [database connection] D. Each3615** database connection may have at most one trace callback.3616**3617** ^The X callback is invoked whenever any of the events identified by3618** mask M occur. ^The integer return value from the callback is currently3619** ignored, though this may change in future releases. Callback3620** implementations should return zero to ensure future compatibility.3621**3622** ^A trace callback is invoked with four arguments: callback(T,C,P,X).3623** ^The T argument is one of the [SQLITE_TRACE]3624** constants to indicate why the callback was invoked.3625** ^The C argument is a copy of the context pointer.3626** The P and X arguments are pointers whose meanings depend on T.3627**3628** The sqlite3_trace_v2() interface is intended to replace the legacy3629** interfaces [sqlite3_trace()] and [sqlite3_profile()], both of which3630** are deprecated.3631*/3632SQLITE_API int sqlite3_trace_v2(3633sqlite3*,3634unsigned uMask,3635int(*xCallback)(unsigned,void*,void*,void*),3636void *pCtx3637);36383639/*3640** CAPI3REF: Query Progress Callbacks3641** METHOD: sqlite33642**3643** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback3644** function X to be invoked periodically during long running calls to3645** [sqlite3_step()] and [sqlite3_prepare()] and similar for3646** database connection D. An example use for this3647** interface is to keep a GUI updated during a large query.3648**3649** ^The parameter P is passed through as the only parameter to the3650** callback function X. ^The parameter N is the approximate number of3651** [virtual machine instructions] that are evaluated between successive3652** invocations of the callback X. ^If N is less than one then the progress3653** handler is disabled.3654**3655** ^Only a single progress handler may be defined at one time per3656** [database connection]; setting a new progress handler cancels the3657** old one. ^Setting parameter X to NULL disables the progress handler.3658** ^The progress handler is also disabled by setting N to a value less3659** than 1.3660**3661** ^If the progress callback returns non-zero, the operation is3662** interrupted. This feature can be used to implement a3663** "Cancel" button on a GUI progress dialog box.3664**3665** The progress handler callback must not do anything that will modify3666** the database connection that invoked the progress handler.3667** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their3668** database connections for the meaning of "modify" in this paragraph.3669**3670** The progress handler callback would originally only be invoked from the3671** bytecode engine. It still might be invoked during [sqlite3_prepare()]3672** and similar because those routines might force a reparse of the schema3673** which involves running the bytecode engine. However, beginning with3674** SQLite version 3.41.0, the progress handler callback might also be3675** invoked directly from [sqlite3_prepare()] while analyzing and generating3676** code for complex queries.3677*/3678SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);36793680/*3681** CAPI3REF: Opening A New Database Connection3682** CONSTRUCTOR: sqlite33683**3684** ^These routines open an SQLite database file as specified by the3685** filename argument. ^The filename argument is interpreted as UTF-8 for3686** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte3687** order for sqlite3_open16(). ^(A [database connection] handle is usually3688** returned in *ppDb, even if an error occurs. The only exception is that3689** if SQLite is unable to allocate memory to hold the [sqlite3] object,3690** a NULL will be written into *ppDb instead of a pointer to the [sqlite3]3691** object.)^ ^(If the database is opened (and/or created) successfully, then3692** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The3693** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain3694** an English language description of the error following a failure of any3695** of the sqlite3_open() routines.3696**3697** ^The default encoding will be UTF-8 for databases created using3698** sqlite3_open() or sqlite3_open_v2(). ^The default encoding for databases3699** created using sqlite3_open16() will be UTF-16 in the native byte order.3700**3701** Whether or not an error occurs when it is opened, resources3702** associated with the [database connection] handle should be released by3703** passing it to [sqlite3_close()] when it is no longer required.3704**3705** The sqlite3_open_v2() interface works like sqlite3_open()3706** except that it accepts two additional parameters for additional control3707** over the new database connection. ^(The flags parameter to3708** sqlite3_open_v2() must include, at a minimum, one of the following3709** three flag combinations:)^3710**3711** <dl>3712** ^(<dt>[SQLITE_OPEN_READONLY]</dt>3713** <dd>The database is opened in read-only mode. If the database does3714** not already exist, an error is returned.</dd>)^3715**3716** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>3717** <dd>The database is opened for reading and writing if possible, or3718** reading only if the file is write protected by the operating3719** system. In either case the database must already exist, otherwise3720** an error is returned. For historical reasons, if opening in3721** read-write mode fails due to OS-level permissions, an attempt is3722** made to open it in read-only mode. [sqlite3_db_readonly()] can be3723** used to determine whether the database is actually3724** read-write.</dd>)^3725**3726** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>3727** <dd>The database is opened for reading and writing, and is created if3728** it does not already exist. This is the behavior that is always used for3729** sqlite3_open() and sqlite3_open16().</dd>)^3730** </dl>3731**3732** In addition to the required flags, the following optional flags are3733** also supported:3734**3735** <dl>3736** ^(<dt>[SQLITE_OPEN_URI]</dt>3737** <dd>The filename can be interpreted as a URI if this flag is set.</dd>)^3738**3739** ^(<dt>[SQLITE_OPEN_MEMORY]</dt>3740** <dd>The database will be opened as an in-memory database. The database3741** is named by the "filename" argument for the purposes of cache-sharing,3742** if shared cache mode is enabled, but the "filename" is otherwise ignored.3743** </dd>)^3744**3745** ^(<dt>[SQLITE_OPEN_NOMUTEX]</dt>3746** <dd>The new database connection will use the "multi-thread"3747** [threading mode].)^ This means that separate threads are allowed3748** to use SQLite at the same time, as long as each thread is using3749** a different [database connection].3750**3751** ^(<dt>[SQLITE_OPEN_FULLMUTEX]</dt>3752** <dd>The new database connection will use the "serialized"3753** [threading mode].)^ This means the multiple threads can safely3754** attempt to use the same database connection at the same time.3755** (Mutexes will block any actual concurrency, but in this mode3756** there is no harm in trying.)3757**3758** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt>3759** <dd>The database is opened with [shared cache] enabled, overriding3760** the default shared cache setting provided by3761** [sqlite3_enable_shared_cache()].)^3762** The [use of shared cache mode is discouraged] and hence shared cache3763** capabilities may be omitted from many builds of SQLite. In such cases,3764** this option is a no-op.3765**3766** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>3767** <dd>The database is opened with [shared cache] disabled, overriding3768** the default shared cache setting provided by3769** [sqlite3_enable_shared_cache()].)^3770**3771** [[OPEN_EXRESCODE]] ^(<dt>[SQLITE_OPEN_EXRESCODE]</dt>3772** <dd>The database connection comes up in "extended result code mode".3773** In other words, the database behaves as if3774** [sqlite3_extended_result_codes(db,1)] were called on the database3775** connection as soon as the connection is created. In addition to setting3776** the extended result code mode, this flag also causes [sqlite3_open_v2()]3777** to return an extended result code.</dd>3778**3779** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>3780** <dd>The database filename is not allowed to contain a symbolic link</dd>3781** </dl>)^3782**3783** If the 3rd parameter to sqlite3_open_v2() is not one of the3784** required combinations shown above optionally combined with other3785** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]3786** then the behavior is undefined. Historic versions of SQLite3787** have silently ignored surplus bits in the flags parameter to3788** sqlite3_open_v2(), however that behavior might not be carried through3789** into future versions of SQLite and so applications should not rely3790** upon it. Note in particular that the SQLITE_OPEN_EXCLUSIVE flag is a no-op3791** for sqlite3_open_v2(). The SQLITE_OPEN_EXCLUSIVE does *not* cause3792** the open to fail if the database already exists. The SQLITE_OPEN_EXCLUSIVE3793** flag is intended for use by the [sqlite3_vfs|VFS interface] only, and not3794** by sqlite3_open_v2().3795**3796** ^The fourth parameter to sqlite3_open_v2() is the name of the3797** [sqlite3_vfs] object that defines the operating system interface that3798** the new database connection should use. ^If the fourth parameter is3799** a NULL pointer then the default [sqlite3_vfs] object is used.3800**3801** ^If the filename is ":memory:", then a private, temporary in-memory database3802** is created for the connection. ^This in-memory database will vanish when3803** the database connection is closed. Future versions of SQLite might3804** make use of additional special filenames that begin with the ":" character.3805** It is recommended that when a database filename actually does begin with3806** a ":" character you should prefix the filename with a pathname such as3807** "./" to avoid ambiguity.3808**3809** ^If the filename is an empty string, then a private, temporary3810** on-disk database will be created. ^This private database will be3811** automatically deleted as soon as the database connection is closed.3812**3813** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>3814**3815** ^If [URI filename] interpretation is enabled, and the filename argument3816** begins with "file:", then the filename is interpreted as a URI. ^URI3817** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is3818** set in the third argument to sqlite3_open_v2(), or if it has3819** been enabled globally using the [SQLITE_CONFIG_URI] option with the3820** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.3821** URI filename interpretation is turned off3822** by default, but future releases of SQLite might enable URI filename3823** interpretation by default. See "[URI filenames]" for additional3824** information.3825**3826** URI filenames are parsed according to RFC 3986. ^If the URI contains an3827** authority, then it must be either an empty string or the string3828** "localhost". ^If the authority is not an empty string or "localhost", an3829** error is returned to the caller. ^The fragment component of a URI, if3830** present, is ignored.3831**3832** ^SQLite uses the path component of the URI as the name of the disk file3833** which contains the database. ^If the path begins with a '/' character,3834** then it is interpreted as an absolute path. ^If the path does not begin3835** with a '/' (meaning that the authority section is omitted from the URI)3836** then the path is interpreted as a relative path.3837** ^(On windows, the first component of an absolute path3838** is a drive specification (e.g. "C:").)^3839**3840** [[core URI query parameters]]3841** The query component of a URI may contain parameters that are interpreted3842** either by SQLite itself, or by a [VFS | custom VFS implementation].3843** SQLite and its built-in [VFSes] interpret the3844** following query parameters:3845**3846** <ul>3847** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of3848** a VFS object that provides the operating system interface that should3849** be used to access the database file on disk. ^If this option is set to3850** an empty string the default VFS object is used. ^Specifying an unknown3851** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is3852** present, then the VFS specified by the option takes precedence over3853** the value passed as the fourth parameter to sqlite3_open_v2().3854**3855** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",3856** "rwc", or "memory". Attempting to set it to any other value is3857** an error)^.3858** ^If "ro" is specified, then the database is opened for read-only3859** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the3860** third argument to sqlite3_open_v2(). ^If the mode option is set to3861** "rw", then the database is opened for read-write (but not create)3862** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had3863** been set. ^Value "rwc" is equivalent to setting both3864** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is3865** set to "memory" then a pure [in-memory database] that never reads3866** or writes from disk is used. ^It is an error to specify a value for3867** the mode parameter that is less restrictive than that specified by3868** the flags passed in the third parameter to sqlite3_open_v2().3869**3870** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or3871** "private". ^Setting it to "shared" is equivalent to setting the3872** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to3873** sqlite3_open_v2(). ^Setting the cache parameter to "private" is3874** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.3875** ^If sqlite3_open_v2() is used and the "cache" parameter is present in3876** a URI filename, its value overrides any behavior requested by setting3877** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.3878**3879** <li> <b>psow</b>: ^The psow parameter indicates whether or not the3880** [powersafe overwrite] property does or does not apply to the3881** storage media on which the database file resides.3882**3883** <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter3884** which if set disables file locking in rollback journal modes. This3885** is useful for accessing a database on a filesystem that does not3886** support locking. Caution: Database corruption might result if two3887** or more processes write to the same database and any one of those3888** processes uses nolock=1.3889**3890** <li> <b>immutable</b>: ^The immutable parameter is a boolean query3891** parameter that indicates that the database file is stored on3892** read-only media. ^When immutable is set, SQLite assumes that the3893** database file cannot be changed, even by a process with higher3894** privilege, and so the database is opened read-only and all locking3895** and change detection is disabled. Caution: Setting the immutable3896** property on a database file that does in fact change can result3897** in incorrect query results and/or [SQLITE_CORRUPT] errors.3898** See also: [SQLITE_IOCAP_IMMUTABLE].3899**3900** </ul>3901**3902** ^Specifying an unknown parameter in the query component of a URI is not an3903** error. Future versions of SQLite might understand additional query3904** parameters. See "[query parameters with special meaning to SQLite]" for3905** additional information.3906**3907** [[URI filename examples]] <h3>URI filename examples</h3>3908**3909** <table border="1" align=center cellpadding=5>3910** <tr><th> URI filenames <th> Results3911** <tr><td> file:data.db <td>3912** Open the file "data.db" in the current directory.3913** <tr><td> file:/home/fred/data.db<br>3914** file:///home/fred/data.db <br>3915** file://localhost/home/fred/data.db <br> <td>3916** Open the database file "/home/fred/data.db".3917** <tr><td> file://darkstar/home/fred/data.db <td>3918** An error. "darkstar" is not a recognized authority.3919** <tr><td style="white-space:nowrap">3920** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db3921** <td> Windows only: Open the file "data.db" on fred's desktop on drive3922** C:. Note that the %20 escaping in this example is not strictly3923** necessary - space characters can be used literally3924** in URI filenames.3925** <tr><td> file:data.db?mode=ro&cache=private <td>3926** Open file "data.db" in the current directory for read-only access.3927** Regardless of whether or not shared-cache mode is enabled by3928** default, use a private cache.3929** <tr><td> file:/home/fred/data.db?vfs=unix-dotfile <td>3930** Open file "/home/fred/data.db". Use the special VFS "unix-dotfile"3931** that uses dot-files in place of posix advisory locking.3932** <tr><td> file:data.db?mode=readonly <td>3933** An error. "readonly" is not a valid option for the "mode" parameter.3934** Use "ro" instead: "file:data.db?mode=ro".3935** </table>3936**3937** ^URI hexadecimal escape sequences (%HH) are supported within the path and3938** query components of a URI. A hexadecimal escape sequence consists of a3939** percent sign - "%" - followed by exactly two hexadecimal digits3940** specifying an octet value. ^Before the path or query components of a3941** URI filename are interpreted, they are encoded using UTF-8 and all3942** hexadecimal escape sequences replaced by a single byte containing the3943** corresponding octet. If this process generates an invalid UTF-8 encoding,3944** the results are undefined.3945**3946** <b>Note to Windows users:</b> The encoding used for the filename argument3947** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever3948** codepage is currently defined. Filenames containing international3949** characters must be converted to UTF-8 prior to passing them into3950** sqlite3_open() or sqlite3_open_v2().3951**3952** <b>Note to Windows Runtime users:</b> The temporary directory must be set3953** prior to calling sqlite3_open() or sqlite3_open_v2(). Otherwise, various3954** features that require the use of temporary files may fail.3955**3956** See also: [sqlite3_temp_directory]3957*/3958SQLITE_API int sqlite3_open(3959const char *filename, /* Database filename (UTF-8) */3960sqlite3 **ppDb /* OUT: SQLite db handle */3961);3962SQLITE_API int sqlite3_open16(3963const void *filename, /* Database filename (UTF-16) */3964sqlite3 **ppDb /* OUT: SQLite db handle */3965);3966SQLITE_API int sqlite3_open_v2(3967const char *filename, /* Database filename (UTF-8) */3968sqlite3 **ppDb, /* OUT: SQLite db handle */3969int flags, /* Flags */3970const char *zVfs /* Name of VFS module to use */3971);39723973/*3974** CAPI3REF: Obtain Values For URI Parameters3975**3976** These are utility routines, useful to [VFS|custom VFS implementations],3977** that check if a database file was a URI that contained a specific query3978** parameter, and if so obtains the value of that query parameter.3979**3980** The first parameter to these interfaces (hereafter referred to3981** as F) must be one of:3982** <ul>3983** <li> A database filename pointer created by the SQLite core and3984** passed into the xOpen() method of a VFS implementation, or3985** <li> A filename obtained from [sqlite3_db_filename()], or3986** <li> A new filename constructed using [sqlite3_create_filename()].3987** </ul>3988** If the F parameter is not one of the above, then the behavior is3989** undefined and probably undesirable. Older versions of SQLite were3990** more tolerant of invalid F parameters than newer versions.3991**3992** If F is a suitable filename (as described in the previous paragraph)3993** and if P is the name of the query parameter, then3994** sqlite3_uri_parameter(F,P) returns the value of the P3995** parameter if it exists or a NULL pointer if P does not appear as a3996** query parameter on F. If P is a query parameter of F and it3997** has no explicit value, then sqlite3_uri_parameter(F,P) returns3998** a pointer to an empty string.3999**4000** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean4001** parameter and returns true (1) or false (0) according to the value4002** of P. The sqlite3_uri_boolean(F,P,B) routine returns true (1) if the4003** value of query parameter P is one of "yes", "true", or "on" in any4004** case or if the value begins with a non-zero number. The4005** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of4006** query parameter P is one of "no", "false", or "off" in any case or4007** if the value begins with a numeric zero. If P is not a query4008** parameter on F or if the value of P does not match any of the4009** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).4010**4011** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a4012** 64-bit signed integer and returns that integer, or D if P does not4013** exist. If the value of P is something other than an integer, then4014** zero is returned.4015**4016** The sqlite3_uri_key(F,N) returns a pointer to the name (not4017** the value) of the N-th query parameter for filename F, or a NULL4018** pointer if N is less than zero or greater than the number of query4019** parameters minus 1. The N value is zero-based so N should be 0 to obtain4020** the name of the first query parameter, 1 for the second parameter, and4021** so forth.4022**4023** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and4024** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and4025** is not a database file pathname pointer that the SQLite core passed4026** into the xOpen VFS method, then the behavior of this routine is undefined4027** and probably undesirable.4028**4029** Beginning with SQLite [version 3.31.0] ([dateof:3.31.0]) the input F4030** parameter can also be the name of a rollback journal file or WAL file4031** in addition to the main database file. Prior to version 3.31.0, these4032** routines would only work if F was the name of the main database file.4033** When the F parameter is the name of the rollback journal or WAL file,4034** it has access to all the same query parameters as were found on the4035** main database file.4036**4037** See the [URI filename] documentation for additional information.4038*/4039SQLITE_API const char *sqlite3_uri_parameter(sqlite3_filename z, const char *zParam);4040SQLITE_API int sqlite3_uri_boolean(sqlite3_filename z, const char *zParam, int bDefault);4041SQLITE_API sqlite3_int64 sqlite3_uri_int64(sqlite3_filename, const char*, sqlite3_int64);4042SQLITE_API const char *sqlite3_uri_key(sqlite3_filename z, int N);40434044/*4045** CAPI3REF: Translate filenames4046**4047** These routines are available to [VFS|custom VFS implementations] for4048** translating filenames between the main database file, the journal file,4049** and the WAL file.4050**4051** If F is the name of an sqlite database file, journal file, or WAL file4052** passed by the SQLite core into the VFS, then sqlite3_filename_database(F)4053** returns the name of the corresponding database file.4054**4055** If F is the name of an sqlite database file, journal file, or WAL file4056** passed by the SQLite core into the VFS, or if F is a database filename4057** obtained from [sqlite3_db_filename()], then sqlite3_filename_journal(F)4058** returns the name of the corresponding rollback journal file.4059**4060** If F is the name of an sqlite database file, journal file, or WAL file4061** that was passed by the SQLite core into the VFS, or if F is a database4062** filename obtained from [sqlite3_db_filename()], then4063** sqlite3_filename_wal(F) returns the name of the corresponding4064** WAL file.4065**4066** In all of the above, if F is not the name of a database, journal or WAL4067** filename passed into the VFS from the SQLite core and F is not the4068** return value from [sqlite3_db_filename()], then the result is4069** undefined and is likely a memory access violation.4070*/4071SQLITE_API const char *sqlite3_filename_database(sqlite3_filename);4072SQLITE_API const char *sqlite3_filename_journal(sqlite3_filename);4073SQLITE_API const char *sqlite3_filename_wal(sqlite3_filename);40744075/*4076** CAPI3REF: Database File Corresponding To A Journal4077**4078** ^If X is the name of a rollback or WAL-mode journal file that is4079** passed into the xOpen method of [sqlite3_vfs], then4080** sqlite3_database_file_object(X) returns a pointer to the [sqlite3_file]4081** object that represents the main database file.4082**4083** This routine is intended for use in custom [VFS] implementations4084** only. It is not a general-purpose interface.4085** The argument sqlite3_file_object(X) must be a filename pointer that4086** has been passed into [sqlite3_vfs].xOpen method where the4087** flags parameter to xOpen contains one of the bits4088** [SQLITE_OPEN_MAIN_JOURNAL] or [SQLITE_OPEN_WAL]. Any other use4089** of this routine results in undefined and probably undesirable4090** behavior.4091*/4092SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*);40934094/*4095** CAPI3REF: Create and Destroy VFS Filenames4096**4097** These interfaces are provided for use by [VFS shim] implementations and4098** are not useful outside of that context.4099**4100** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of4101** database filename D with corresponding journal file J and WAL file W and4102** an array P of N URI Key/Value pairs. The result from4103** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that4104** is safe to pass to routines like:4105** <ul>4106** <li> [sqlite3_uri_parameter()],4107** <li> [sqlite3_uri_boolean()],4108** <li> [sqlite3_uri_int64()],4109** <li> [sqlite3_uri_key()],4110** <li> [sqlite3_filename_database()],4111** <li> [sqlite3_filename_journal()], or4112** <li> [sqlite3_filename_wal()].4113** </ul>4114** If a memory allocation error occurs, sqlite3_create_filename() might4115** return a NULL pointer. The memory obtained from sqlite3_create_filename(X)4116** must be released by a corresponding call to sqlite3_free_filename(Y).4117**4118** The P parameter in sqlite3_create_filename(D,J,W,N,P) should be an array4119** of 2*N pointers to strings. Each pair of pointers in this array corresponds4120** to a key and value for a query parameter. The P parameter may be a NULL4121** pointer if N is zero. None of the 2*N pointers in the P array may be4122** NULL pointers and key pointers should not be empty strings.4123** None of the D, J, or W parameters to sqlite3_create_filename(D,J,W,N,P) may4124** be NULL pointers, though they can be empty strings.4125**4126** The sqlite3_free_filename(Y) routine releases a memory allocation4127** previously obtained from sqlite3_create_filename(). Invoking4128** sqlite3_free_filename(Y) where Y is a NULL pointer is a harmless no-op.4129**4130** If the Y parameter to sqlite3_free_filename(Y) is anything other4131** than a NULL pointer or a pointer previously acquired from4132** sqlite3_create_filename(), then bad things such as heap4133** corruption or segfaults may occur. The value Y should not be4134** used again after sqlite3_free_filename(Y) has been called. This means4135** that if the [sqlite3_vfs.xOpen()] method of a VFS has been called using Y,4136** then the corresponding [sqlite3_module.xClose() method should also be4137** invoked prior to calling sqlite3_free_filename(Y).4138*/4139SQLITE_API sqlite3_filename sqlite3_create_filename(4140const char *zDatabase,4141const char *zJournal,4142const char *zWal,4143int nParam,4144const char **azParam4145);4146SQLITE_API void sqlite3_free_filename(sqlite3_filename);41474148/*4149** CAPI3REF: Error Codes And Messages4150** METHOD: sqlite34151**4152** ^If the most recent sqlite3_* API call associated with4153** [database connection] D failed, then the sqlite3_errcode(D) interface4154** returns the numeric [result code] or [extended result code] for that4155** API call.4156** ^The sqlite3_extended_errcode()4157** interface is the same except that it always returns the4158** [extended result code] even when extended result codes are4159** disabled.4160**4161** The values returned by sqlite3_errcode() and/or4162** sqlite3_extended_errcode() might change with each API call.4163** Except, there are some interfaces that are guaranteed to never4164** change the value of the error code. The error-code preserving4165** interfaces include the following:4166**4167** <ul>4168** <li> sqlite3_errcode()4169** <li> sqlite3_extended_errcode()4170** <li> sqlite3_errmsg()4171** <li> sqlite3_errmsg16()4172** <li> sqlite3_error_offset()4173** </ul>4174**4175** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language4176** text that describes the error, as either UTF-8 or UTF-16 respectively,4177** or NULL if no error message is available.4178** (See how SQLite handles [invalid UTF] for exceptions to this rule.)4179** ^(Memory to hold the error message string is managed internally.4180** The application does not need to worry about freeing the result.4181** However, the error string might be overwritten or deallocated by4182** subsequent calls to other SQLite interface functions.)^4183**4184** ^The sqlite3_errstr(E) interface returns the English-language text4185** that describes the [result code] E, as UTF-8, or NULL if E is not a4186** result code for which a text error message is available.4187** ^(Memory to hold the error message string is managed internally4188** and must not be freed by the application)^.4189**4190** ^If the most recent error references a specific token in the input4191** SQL, the sqlite3_error_offset() interface returns the byte offset4192** of the start of that token. ^The byte offset returned by4193** sqlite3_error_offset() assumes that the input SQL is UTF-8.4194** ^If the most recent error does not reference a specific token in the input4195** SQL, then the sqlite3_error_offset() function returns -1.4196**4197** When the serialized [threading mode] is in use, it might be the4198** case that a second error occurs on a separate thread in between4199** the time of the first error and the call to these interfaces.4200** When that happens, the second error will be reported since these4201** interfaces always report the most recent result. To avoid4202** this, each thread can obtain exclusive use of the [database connection] D4203** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning4204** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after4205** all calls to the interfaces listed here are completed.4206**4207** If an interface fails with SQLITE_MISUSE, that means the interface4208** was invoked incorrectly by the application. In that case, the4209** error code and message may or may not be set.4210*/4211SQLITE_API int sqlite3_errcode(sqlite3 *db);4212SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);4213SQLITE_API const char *sqlite3_errmsg(sqlite3*);4214SQLITE_API const void *sqlite3_errmsg16(sqlite3*);4215SQLITE_API const char *sqlite3_errstr(int);4216SQLITE_API int sqlite3_error_offset(sqlite3 *db);42174218/*4219** CAPI3REF: Set Error Codes And Message4220** METHOD: sqlite34221**4222** Set the error code of the database handle passed as the first argument4223** to errcode, and the error message to a copy of nul-terminated string4224** zErrMsg. If zErrMsg is passed NULL, then the error message is set to4225** the default message associated with the supplied error code. Subsequent4226** calls to [sqlite3_errcode()] and [sqlite3_errmsg()] and similar will4227** return the values set by this routine in place of what was previously4228** set by SQLite itself.4229**4230** This function returns SQLITE_OK if the error code and error message are4231** successfully set, SQLITE_NOMEM if an OOM occurs, and SQLITE_MISUSE if4232** the database handle is NULL or invalid.4233**4234** The error code and message set by this routine remains in effect until4235** they are changed, either by another call to this routine or until they are4236** changed to by SQLite itself to reflect the result of some subsquent4237** API call.4238**4239** This function is intended for use by SQLite extensions or wrappers. The4240** idea is that an extension or wrapper can use this routine to set error4241** messages and error codes and thus behave more like a core SQLite4242** feature from the point of view of an application.4243*/4244SQLITE_API int sqlite3_set_errmsg(sqlite3 *db, int errcode, const char *zErrMsg);42454246/*4247** CAPI3REF: Prepared Statement Object4248** KEYWORDS: {prepared statement} {prepared statements}4249**4250** An instance of this object represents a single SQL statement that4251** has been compiled into binary form and is ready to be evaluated.4252**4253** Think of each SQL statement as a separate computer program. The4254** original SQL text is source code. A prepared statement object4255** is the compiled object code. All SQL must be converted into a4256** prepared statement before it can be run.4257**4258** The life-cycle of a prepared statement object usually goes like this:4259**4260** <ol>4261** <li> Create the prepared statement object using [sqlite3_prepare_v2()].4262** <li> Bind values to [parameters] using the sqlite3_bind_*()4263** interfaces.4264** <li> Run the SQL by calling [sqlite3_step()] one or more times.4265** <li> Reset the prepared statement using [sqlite3_reset()] then go back4266** to step 2. Do this zero or more times.4267** <li> Destroy the object using [sqlite3_finalize()].4268** </ol>4269*/4270typedef struct sqlite3_stmt sqlite3_stmt;42714272/*4273** CAPI3REF: Run-time Limits4274** METHOD: sqlite34275**4276** ^(This interface allows the size of various constructs to be limited4277** on a connection by connection basis. The first parameter is the4278** [database connection] whose limit is to be set or queried. The4279** second parameter is one of the [limit categories] that define a4280** class of constructs to be size limited. The third parameter is the4281** new limit for that construct.)^4282**4283** ^If the new limit is a negative number, the limit is unchanged.4284** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a4285** [limits | hard upper bound]4286** set at compile-time by a C preprocessor macro called4287** [limits | SQLITE_MAX_<i>NAME</i>].4288** (The "_LIMIT_" in the name is changed to "_MAX_".))^4289** ^Attempts to increase a limit above its hard upper bound are4290** silently truncated to the hard upper bound.4291**4292** ^Regardless of whether or not the limit was changed, the4293** [sqlite3_limit()] interface returns the prior value of the limit.4294** ^Hence, to find the current value of a limit without changing it,4295** simply invoke this interface with the third parameter set to -1.4296**4297** Run-time limits are intended for use in applications that manage4298** both their own internal database and also databases that are controlled4299** by untrusted external sources. An example application might be a4300** web browser that has its own databases for storing history and4301** separate databases controlled by JavaScript applications downloaded4302** off the Internet. The internal databases can be given the4303** large, default limits. Databases managed by external sources can4304** be given much smaller limits designed to prevent a denial of service4305** attack. Developers might also want to use the [sqlite3_set_authorizer()]4306** interface to further control untrusted SQL. The size of the database4307** created by an untrusted script can be contained using the4308** [max_page_count] [PRAGMA].4309**4310** New run-time limit categories may be added in future releases.4311*/4312SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);43134314/*4315** CAPI3REF: Run-Time Limit Categories4316** KEYWORDS: {limit category} {*limit categories}4317**4318** These constants define various performance limits4319** that can be lowered at run-time using [sqlite3_limit()].4320** A concise description of these limits follows, and additional information4321** is available at [limits | Limits in SQLite].4322**4323** <dl>4324** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>4325** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^4326**4327** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>4328** <dd>The maximum length of an SQL statement, in bytes.</dd>)^4329**4330** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt>4331** <dd>The maximum number of columns in a table definition or in the4332** result set of a [SELECT] or the maximum number of columns in an index4333** or in an ORDER BY or GROUP BY clause.</dd>)^4334**4335** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>4336** <dd>The maximum depth of the parse tree on any expression.</dd>)^4337**4338** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>4339** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^4340**4341** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>4342** <dd>The maximum number of instructions in a virtual machine program4343** used to implement an SQL statement. If [sqlite3_prepare_v2()] or4344** the equivalent tries to allocate space for more than this many opcodes4345** in a single prepared statement, an SQLITE_NOMEM error is returned.</dd>)^4346**4347** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>4348** <dd>The maximum number of arguments on a function.</dd>)^4349**4350** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>4351** <dd>The maximum number of [ATTACH | attached databases].)^</dd>4352**4353** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]]4354** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>4355** <dd>The maximum length of the pattern argument to the [LIKE] or4356** [GLOB] operators.</dd>)^4357**4358** [[SQLITE_LIMIT_VARIABLE_NUMBER]]4359** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>4360** <dd>The maximum index number of any [parameter] in an SQL statement.)^4361**4362** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>4363** <dd>The maximum depth of recursion for triggers.</dd>)^4364**4365** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>4366** <dd>The maximum number of auxiliary worker threads that a single4367** [prepared statement] may start.</dd>)^4368** </dl>4369*/4370#define SQLITE_LIMIT_LENGTH 04371#define SQLITE_LIMIT_SQL_LENGTH 14372#define SQLITE_LIMIT_COLUMN 24373#define SQLITE_LIMIT_EXPR_DEPTH 34374#define SQLITE_LIMIT_COMPOUND_SELECT 44375#define SQLITE_LIMIT_VDBE_OP 54376#define SQLITE_LIMIT_FUNCTION_ARG 64377#define SQLITE_LIMIT_ATTACHED 74378#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 84379#define SQLITE_LIMIT_VARIABLE_NUMBER 94380#define SQLITE_LIMIT_TRIGGER_DEPTH 104381#define SQLITE_LIMIT_WORKER_THREADS 1143824383/*4384** CAPI3REF: Prepare Flags4385**4386** These constants define various flags that can be passed into the4387** "prepFlags" parameter of the [sqlite3_prepare_v3()] and4388** [sqlite3_prepare16_v3()] interfaces.4389**4390** New flags may be added in future releases of SQLite.4391**4392** <dl>4393** [[SQLITE_PREPARE_PERSISTENT]] ^(<dt>SQLITE_PREPARE_PERSISTENT</dt>4394** <dd>The SQLITE_PREPARE_PERSISTENT flag is a hint to the query planner4395** that the prepared statement will be retained for a long time and4396** probably reused many times.)^ ^Without this flag, [sqlite3_prepare_v3()]4397** and [sqlite3_prepare16_v3()] assume that the prepared statement will4398** be used just once or at most a few times and then destroyed using4399** [sqlite3_finalize()] relatively soon. The current implementation acts4400** on this hint by avoiding the use of [lookaside memory] so as not to4401** deplete the limited store of lookaside memory. Future versions of4402** SQLite may act on this hint differently.4403**4404** [[SQLITE_PREPARE_NORMALIZE]] <dt>SQLITE_PREPARE_NORMALIZE</dt>4405** <dd>The SQLITE_PREPARE_NORMALIZE flag is a no-op. This flag used4406** to be required for any prepared statement that wanted to use the4407** [sqlite3_normalized_sql()] interface. However, the4408** [sqlite3_normalized_sql()] interface is now available to all4409** prepared statements, regardless of whether or not they use this4410** flag.4411**4412** [[SQLITE_PREPARE_NO_VTAB]] <dt>SQLITE_PREPARE_NO_VTAB</dt>4413** <dd>The SQLITE_PREPARE_NO_VTAB flag causes the SQL compiler4414** to return an error (error code SQLITE_ERROR) if the statement uses4415** any virtual tables.4416**4417** [[SQLITE_PREPARE_DONT_LOG]] <dt>SQLITE_PREPARE_DONT_LOG</dt>4418** <dd>The SQLITE_PREPARE_DONT_LOG flag prevents SQL compiler4419** errors from being sent to the error log defined by4420** [SQLITE_CONFIG_LOG]. This can be used, for example, to do test4421** compiles to see if some SQL syntax is well-formed, without generating4422** messages on the global error log when it is not. If the test compile4423** fails, the sqlite3_prepare_v3() call returns the same error indications4424** with or without this flag; it just omits the call to [sqlite3_log()] that4425** logs the error.4426** </dl>4427*/4428#define SQLITE_PREPARE_PERSISTENT 0x014429#define SQLITE_PREPARE_NORMALIZE 0x024430#define SQLITE_PREPARE_NO_VTAB 0x044431#define SQLITE_PREPARE_DONT_LOG 0x1044324433/*4434** CAPI3REF: Compiling An SQL Statement4435** KEYWORDS: {SQL statement compiler}4436** METHOD: sqlite34437** CONSTRUCTOR: sqlite3_stmt4438**4439** To execute an SQL statement, it must first be compiled into a byte-code4440** program using one of these routines. Or, in other words, these routines4441** are constructors for the [prepared statement] object.4442**4443** The preferred routine to use is [sqlite3_prepare_v2()]. The4444** [sqlite3_prepare()] interface is legacy and should be avoided.4445** [sqlite3_prepare_v3()] has an extra "prepFlags" option that is used4446** for special purposes.4447**4448** The use of the UTF-8 interfaces is preferred, as SQLite currently4449** does all parsing using UTF-8. The UTF-16 interfaces are provided4450** as a convenience. The UTF-16 interfaces work by converting the4451** input text into UTF-8, then invoking the corresponding UTF-8 interface.4452**4453** The first argument, "db", is a [database connection] obtained from a4454** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or4455** [sqlite3_open16()]. The database connection must not have been closed.4456**4457** The second argument, "zSql", is the statement to be compiled, encoded4458** as either UTF-8 or UTF-16. The sqlite3_prepare(), sqlite3_prepare_v2(),4459** and sqlite3_prepare_v3()4460** interfaces use UTF-8, and sqlite3_prepare16(), sqlite3_prepare16_v2(),4461** and sqlite3_prepare16_v3() use UTF-16.4462**4463** ^If the nByte argument is negative, then zSql is read up to the4464** first zero terminator. ^If nByte is positive, then it is the maximum4465** number of bytes read from zSql. When nByte is positive, zSql is read4466** up to the first zero terminator or until the nByte bytes have been read,4467** whichever comes first. ^If nByte is zero, then no prepared4468** statement is generated.4469** If the caller knows that the supplied string is nul-terminated, then4470** there is a small performance advantage to passing an nByte parameter that4471** is the number of bytes in the input string <i>including</i>4472** the nul-terminator.4473** Note that nByte measures the length of the input in bytes, not4474** characters, even for the UTF-16 interfaces.4475**4476** ^If pzTail is not NULL then *pzTail is made to point to the first byte4477** past the end of the first SQL statement in zSql. These routines only4478** compile the first statement in zSql, so *pzTail is left pointing to4479** what remains uncompiled.4480**4481** ^*ppStmt is left pointing to a compiled [prepared statement] that can be4482** executed using [sqlite3_step()]. ^If there is an error, *ppStmt is set4483** to NULL. ^If the input text contains no SQL (if the input is an empty4484** string or a comment) then *ppStmt is set to NULL.4485** The calling procedure is responsible for deleting the compiled4486** SQL statement using [sqlite3_finalize()] after it has finished with it.4487** ppStmt may not be NULL.4488**4489** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK];4490** otherwise an [error code] is returned.4491**4492** The sqlite3_prepare_v2(), sqlite3_prepare_v3(), sqlite3_prepare16_v2(),4493** and sqlite3_prepare16_v3() interfaces are recommended for all new programs.4494** The older interfaces (sqlite3_prepare() and sqlite3_prepare16())4495** are retained for backwards compatibility, but their use is discouraged.4496** ^In the "vX" interfaces, the prepared statement4497** that is returned (the [sqlite3_stmt] object) contains a copy of the4498** original SQL text. This causes the [sqlite3_step()] interface to4499** behave differently in three ways:4500**4501** <ol>4502** <li>4503** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it4504** always used to do, [sqlite3_step()] will automatically recompile the SQL4505** statement and try to run it again. As many as [SQLITE_MAX_SCHEMA_RETRY]4506** retries will occur before sqlite3_step() gives up and returns an error.4507** </li>4508**4509** <li>4510** ^When an error occurs, [sqlite3_step()] will return one of the detailed4511** [error codes] or [extended error codes]. ^The legacy behavior was that4512** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code4513** and the application would have to make a second call to [sqlite3_reset()]4514** in order to find the underlying cause of the problem. With the "v2" prepare4515** interfaces, the underlying reason for the error is returned immediately.4516** </li>4517**4518** <li>4519** ^If the specific value bound to a [parameter | host parameter] in the4520** WHERE clause might influence the choice of query plan for a statement,4521** then the statement will be automatically recompiled, as if there had been4522** a schema change, on the first [sqlite3_step()] call following any change4523** to the [sqlite3_bind_text | bindings] of that [parameter].4524** ^The specific value of a WHERE-clause [parameter] might influence the4525** choice of query plan if the parameter is the left-hand side of a [LIKE]4526** or [GLOB] operator or if the parameter is compared to an indexed column4527** and the [SQLITE_ENABLE_STAT4] compile-time option is enabled.4528** </li>4529** </ol>4530**4531** <p>^sqlite3_prepare_v3() differs from sqlite3_prepare_v2() only in having4532** the extra prepFlags parameter, which is a bit array consisting of zero or4533** more of the [SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_*] flags. ^The4534** sqlite3_prepare_v2() interface works exactly the same as4535** sqlite3_prepare_v3() with a zero prepFlags parameter.4536*/4537SQLITE_API int sqlite3_prepare(4538sqlite3 *db, /* Database handle */4539const char *zSql, /* SQL statement, UTF-8 encoded */4540int nByte, /* Maximum length of zSql in bytes. */4541sqlite3_stmt **ppStmt, /* OUT: Statement handle */4542const char **pzTail /* OUT: Pointer to unused portion of zSql */4543);4544SQLITE_API int sqlite3_prepare_v2(4545sqlite3 *db, /* Database handle */4546const char *zSql, /* SQL statement, UTF-8 encoded */4547int nByte, /* Maximum length of zSql in bytes. */4548sqlite3_stmt **ppStmt, /* OUT: Statement handle */4549const char **pzTail /* OUT: Pointer to unused portion of zSql */4550);4551SQLITE_API int sqlite3_prepare_v3(4552sqlite3 *db, /* Database handle */4553const char *zSql, /* SQL statement, UTF-8 encoded */4554int nByte, /* Maximum length of zSql in bytes. */4555unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */4556sqlite3_stmt **ppStmt, /* OUT: Statement handle */4557const char **pzTail /* OUT: Pointer to unused portion of zSql */4558);4559SQLITE_API int sqlite3_prepare16(4560sqlite3 *db, /* Database handle */4561const void *zSql, /* SQL statement, UTF-16 encoded */4562int nByte, /* Maximum length of zSql in bytes. */4563sqlite3_stmt **ppStmt, /* OUT: Statement handle */4564const void **pzTail /* OUT: Pointer to unused portion of zSql */4565);4566SQLITE_API int sqlite3_prepare16_v2(4567sqlite3 *db, /* Database handle */4568const void *zSql, /* SQL statement, UTF-16 encoded */4569int nByte, /* Maximum length of zSql in bytes. */4570sqlite3_stmt **ppStmt, /* OUT: Statement handle */4571const void **pzTail /* OUT: Pointer to unused portion of zSql */4572);4573SQLITE_API int sqlite3_prepare16_v3(4574sqlite3 *db, /* Database handle */4575const void *zSql, /* SQL statement, UTF-16 encoded */4576int nByte, /* Maximum length of zSql in bytes. */4577unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */4578sqlite3_stmt **ppStmt, /* OUT: Statement handle */4579const void **pzTail /* OUT: Pointer to unused portion of zSql */4580);45814582/*4583** CAPI3REF: Retrieving Statement SQL4584** METHOD: sqlite3_stmt4585**4586** ^The sqlite3_sql(P) interface returns a pointer to a copy of the UTF-84587** SQL text used to create [prepared statement] P if P was4588** created by [sqlite3_prepare_v2()], [sqlite3_prepare_v3()],4589** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()].4590** ^The sqlite3_expanded_sql(P) interface returns a pointer to a UTF-84591** string containing the SQL text of prepared statement P with4592** [bound parameters] expanded.4593** ^The sqlite3_normalized_sql(P) interface returns a pointer to a UTF-84594** string containing the normalized SQL text of prepared statement P. The4595** semantics used to normalize a SQL statement are unspecified and subject4596** to change. At a minimum, literal values will be replaced with suitable4597** placeholders.4598**4599** ^(For example, if a prepared statement is created using the SQL4600** text "SELECT $abc,:xyz" and if parameter $abc is bound to integer 23454601** and parameter :xyz is unbound, then sqlite3_sql() will return4602** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()4603** will return "SELECT 2345,NULL".)^4604**4605** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory4606** is available to hold the result, or if the result would exceed the4607** maximum string length determined by the [SQLITE_LIMIT_LENGTH].4608**4609** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of4610** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time4611** option causes sqlite3_expanded_sql() to always return NULL.4612**4613** ^The strings returned by sqlite3_sql(P) and sqlite3_normalized_sql(P)4614** are managed by SQLite and are automatically freed when the prepared4615** statement is finalized.4616** ^The string returned by sqlite3_expanded_sql(P), on the other hand,4617** is obtained from [sqlite3_malloc()] and must be freed by the application4618** by passing it to [sqlite3_free()].4619**4620** ^The sqlite3_normalized_sql() interface is only available if4621** the [SQLITE_ENABLE_NORMALIZE] compile-time option is defined.4622*/4623SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);4624SQLITE_API char *sqlite3_expanded_sql(sqlite3_stmt *pStmt);4625#ifdef SQLITE_ENABLE_NORMALIZE4626SQLITE_API const char *sqlite3_normalized_sql(sqlite3_stmt *pStmt);4627#endif46284629/*4630** CAPI3REF: Determine If An SQL Statement Writes The Database4631** METHOD: sqlite3_stmt4632**4633** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if4634** and only if the [prepared statement] X makes no direct changes to4635** the content of the database file.4636**4637** Note that [application-defined SQL functions] or4638** [virtual tables] might change the database indirectly as a side effect.4639** ^(For example, if an application defines a function "eval()" that4640** calls [sqlite3_exec()], then the following SQL statement would4641** change the database file through side-effects:4642**4643** <blockquote><pre>4644** SELECT eval('DELETE FROM t1') FROM t2;4645** </pre></blockquote>4646**4647** But because the [SELECT] statement does not change the database file4648** directly, sqlite3_stmt_readonly() would still return true.)^4649**4650** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],4651** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,4652** since the statements themselves do not actually modify the database but4653** rather they control the timing of when other statements modify the4654** database. ^The [ATTACH] and [DETACH] statements also cause4655** sqlite3_stmt_readonly() to return true since, while those statements4656** change the configuration of a database connection, they do not make4657** changes to the content of the database files on disk.4658** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since4659** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and4660** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so4661** sqlite3_stmt_readonly() returns false for those commands.4662**4663** ^This routine returns false if there is any possibility that the4664** statement might change the database file. ^A false return does4665** not guarantee that the statement will change the database file.4666** ^For example, an UPDATE statement might have a WHERE clause that4667** makes it a no-op, but the sqlite3_stmt_readonly() result would still4668** be false. ^Similarly, a CREATE TABLE IF NOT EXISTS statement is a4669** read-only no-op if the table already exists, but4670** sqlite3_stmt_readonly() still returns false for such a statement.4671**4672** ^If prepared statement X is an [EXPLAIN] or [EXPLAIN QUERY PLAN]4673** statement, then sqlite3_stmt_readonly(X) returns the same value as4674** if the EXPLAIN or EXPLAIN QUERY PLAN prefix were omitted.4675*/4676SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);46774678/*4679** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement4680** METHOD: sqlite3_stmt4681**4682** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the4683** prepared statement S is an EXPLAIN statement, or 2 if the4684** statement S is an EXPLAIN QUERY PLAN.4685** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is4686** an ordinary statement or a NULL pointer.4687*/4688SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt);46894690/*4691** CAPI3REF: Change The EXPLAIN Setting For A Prepared Statement4692** METHOD: sqlite3_stmt4693**4694** The sqlite3_stmt_explain(S,E) interface changes the EXPLAIN4695** setting for [prepared statement] S. If E is zero, then S becomes4696** a normal prepared statement. If E is 1, then S behaves as if4697** its SQL text began with "[EXPLAIN]". If E is 2, then S behaves as if4698** its SQL text began with "[EXPLAIN QUERY PLAN]".4699**4700** Calling sqlite3_stmt_explain(S,E) might cause S to be reprepared.4701** SQLite tries to avoid a reprepare, but a reprepare might be necessary4702** on the first transition into EXPLAIN or EXPLAIN QUERY PLAN mode.4703**4704** Because of the potential need to reprepare, a call to4705** sqlite3_stmt_explain(S,E) will fail with SQLITE_ERROR if S cannot be4706** reprepared because it was created using [sqlite3_prepare()] instead of4707** the newer [sqlite3_prepare_v2()] or [sqlite3_prepare_v3()] interfaces and4708** hence has no saved SQL text with which to reprepare.4709**4710** Changing the explain setting for a prepared statement does not change4711** the original SQL text for the statement. Hence, if the SQL text originally4712** began with EXPLAIN or EXPLAIN QUERY PLAN, but sqlite3_stmt_explain(S,0)4713** is called to convert the statement into an ordinary statement, the EXPLAIN4714** or EXPLAIN QUERY PLAN keywords will still appear in the sqlite3_sql(S)4715** output, even though the statement now acts like a normal SQL statement.4716**4717** This routine returns SQLITE_OK if the explain mode is successfully4718** changed, or an error code if the explain mode could not be changed.4719** The explain mode cannot be changed while a statement is active.4720** Hence, it is good practice to call [sqlite3_reset(S)]4721** immediately prior to calling sqlite3_stmt_explain(S,E).4722*/4723SQLITE_API int sqlite3_stmt_explain(sqlite3_stmt *pStmt, int eMode);47244725/*4726** CAPI3REF: Determine If A Prepared Statement Has Been Reset4727** METHOD: sqlite3_stmt4728**4729** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the4730** [prepared statement] S has been stepped at least once using4731** [sqlite3_step(S)] but has neither run to completion (returned4732** [SQLITE_DONE] from [sqlite3_step(S)]) nor4733** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)4734** interface returns false if S is a NULL pointer. If S is not a4735** NULL pointer and is not a pointer to a valid [prepared statement]4736** object, then the behavior is undefined and probably undesirable.4737**4738** This interface can be used in combination [sqlite3_next_stmt()]4739** to locate all prepared statements associated with a database4740** connection that are in need of being reset. This can be used,4741** for example, in diagnostic routines to search for prepared4742** statements that are holding a transaction open.4743*/4744SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*);47454746/*4747** CAPI3REF: Dynamically Typed Value Object4748** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}4749**4750** SQLite uses the sqlite3_value object to represent all values4751** that can be stored in a database table. SQLite uses dynamic typing4752** for the values it stores. ^Values stored in sqlite3_value objects4753** can be integers, floating point values, strings, BLOBs, or NULL.4754**4755** An sqlite3_value object may be either "protected" or "unprotected".4756** Some interfaces require a protected sqlite3_value. Other interfaces4757** will accept either a protected or an unprotected sqlite3_value.4758** Every interface that accepts sqlite3_value arguments specifies4759** whether or not it requires a protected sqlite3_value. The4760** [sqlite3_value_dup()] interface can be used to construct a new4761** protected sqlite3_value from an unprotected sqlite3_value.4762**4763** The terms "protected" and "unprotected" refer to whether or not4764** a mutex is held. An internal mutex is held for a protected4765** sqlite3_value object but no mutex is held for an unprotected4766** sqlite3_value object. If SQLite is compiled to be single-threaded4767** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)4768** or if SQLite is run in one of reduced mutex modes4769** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]4770** then there is no distinction between protected and unprotected4771** sqlite3_value objects and they can be used interchangeably. However,4772** for maximum code portability it is recommended that applications4773** still make the distinction between protected and unprotected4774** sqlite3_value objects even when not strictly required.4775**4776** ^The sqlite3_value objects that are passed as parameters into the4777** implementation of [application-defined SQL functions] are protected.4778** ^The sqlite3_value objects returned by [sqlite3_vtab_rhs_value()]4779** are protected.4780** ^The sqlite3_value object returned by4781** [sqlite3_column_value()] is unprotected.4782** Unprotected sqlite3_value objects may only be used as arguments4783** to [sqlite3_result_value()], [sqlite3_bind_value()], and4784** [sqlite3_value_dup()].4785** The [sqlite3_value_blob | sqlite3_value_type()] family of4786** interfaces require protected sqlite3_value objects.4787*/4788typedef struct sqlite3_value sqlite3_value;47894790/*4791** CAPI3REF: SQL Function Context Object4792**4793** The context in which an SQL function executes is stored in an4794** sqlite3_context object. ^A pointer to an sqlite3_context object4795** is always the first parameter to [application-defined SQL functions].4796** The application-defined SQL function implementation will pass this4797** pointer through into calls to [sqlite3_result_int | sqlite3_result()],4798** [sqlite3_aggregate_context()], [sqlite3_user_data()],4799** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],4800** and/or [sqlite3_set_auxdata()].4801*/4802typedef struct sqlite3_context sqlite3_context;48034804/*4805** CAPI3REF: Binding Values To Prepared Statements4806** KEYWORDS: {host parameter} {host parameters} {host parameter name}4807** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}4808** METHOD: sqlite3_stmt4809**4810** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,4811** literals may be replaced by a [parameter] that matches one of the following4812** templates:4813**4814** <ul>4815** <li> ?4816** <li> ?NNN4817** <li> :VVV4818** <li> @VVV4819** <li> $VVV4820** </ul>4821**4822** In the templates above, NNN represents an integer literal,4823** and VVV represents an alphanumeric identifier.)^ ^The values of these4824** parameters (also called "host parameter names" or "SQL parameters")4825** can be set using the sqlite3_bind_*() routines defined here.4826**4827** ^The first argument to the sqlite3_bind_*() routines is always4828** a pointer to the [sqlite3_stmt] object returned from4829** [sqlite3_prepare_v2()] or its variants.4830**4831** ^The second argument is the index of the SQL parameter to be set.4832** ^The leftmost SQL parameter has an index of 1. ^When the same named4833** SQL parameter is used more than once, second and subsequent4834** occurrences have the same index as the first occurrence.4835** ^The index for named parameters can be looked up using the4836** [sqlite3_bind_parameter_index()] API if desired. ^The index4837** for "?NNN" parameters is the value of NNN.4838** ^The NNN value must be between 1 and the [sqlite3_limit()]4839** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 32766).4840**4841** ^The third argument is the value to bind to the parameter.4842** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16()4843** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter4844** is ignored and the end result is the same as sqlite3_bind_null().4845** ^If the third parameter to sqlite3_bind_text() is not NULL, then4846** it should be a pointer to well-formed UTF8 text.4847** ^If the third parameter to sqlite3_bind_text16() is not NULL, then4848** it should be a pointer to well-formed UTF16 text.4849** ^If the third parameter to sqlite3_bind_text64() is not NULL, then4850** it should be a pointer to a well-formed unicode string that is4851** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF164852** otherwise.4853**4854** [[byte-order determination rules]] ^The byte-order of4855** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF)4856** found in the first character, which is removed, or in the absence of a BOM4857** the byte order is the native byte order of the host4858** machine for sqlite3_bind_text16() or the byte order specified in4859** the 6th parameter for sqlite3_bind_text64().)^4860** ^If UTF16 input text contains invalid unicode4861** characters, then SQLite might change those invalid characters4862** into the unicode replacement character: U+FFFD.4863**4864** ^(In those routines that have a fourth argument, its value is the4865** number of bytes in the parameter. To be clear: the value is the4866** number of <u>bytes</u> in the value, not the number of characters.)^4867** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()4868** is negative, then the length of the string is4869** the number of bytes up to the first zero terminator.4870** If the fourth parameter to sqlite3_bind_blob() is negative, then4871** the behavior is undefined.4872** If a non-negative fourth parameter is provided to sqlite3_bind_text()4873** or sqlite3_bind_text16() or sqlite3_bind_text64() then4874** that parameter must be the byte offset4875** where the NUL terminator would occur assuming the string were NUL4876** terminated. If any NUL characters occur at byte offsets less than4877** the value of the fourth parameter then the resulting string value will4878** contain embedded NULs. The result of expressions involving strings4879** with embedded NULs is undefined.4880**4881** ^The fifth argument to the BLOB and string binding interfaces controls4882** or indicates the lifetime of the object referenced by the third parameter.4883** These three options exist:4884** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished4885** with it may be passed. ^It is called to dispose of the BLOB or string even4886** if the call to the bind API fails, except the destructor is not called if4887** the third parameter is a NULL pointer or the fourth parameter is negative.4888** ^ (2) The special constant, [SQLITE_STATIC], may be passed to indicate that4889** the application remains responsible for disposing of the object. ^In this4890** case, the object and the provided pointer to it must remain valid until4891** either the prepared statement is finalized or the same SQL parameter is4892** bound to something else, whichever occurs sooner.4893** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the4894** object is to be copied prior to the return from sqlite3_bind_*(). ^The4895** object and pointer to it must remain valid until then. ^SQLite will then4896** manage the lifetime of its private copy.4897**4898** ^The sixth argument to sqlite3_bind_text64() must be one of4899** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]4900** to specify the encoding of the text in the third parameter. If4901** the sixth argument to sqlite3_bind_text64() is not one of the4902** allowed values shown above, or if the text encoding is different4903** from the encoding specified by the sixth parameter, then the behavior4904** is undefined.4905**4906** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that4907** is filled with zeroes. ^A zeroblob uses a fixed amount of memory4908** (just an integer to hold its size) while it is being processed.4909** Zeroblobs are intended to serve as placeholders for BLOBs whose4910** content is later written using4911** [sqlite3_blob_open | incremental BLOB I/O] routines.4912** ^A negative value for the zeroblob results in a zero-length BLOB.4913**4914** ^The sqlite3_bind_pointer(S,I,P,T,D) routine causes the I-th parameter in4915** [prepared statement] S to have an SQL value of NULL, but to also be4916** associated with the pointer P of type T. ^D is either a NULL pointer or4917** a pointer to a destructor function for P. ^SQLite will invoke the4918** destructor D with a single argument of P when it is finished using4919** P, even if the call to sqlite3_bind_pointer() fails. Due to a4920** historical design quirk, results are undefined if D is4921** SQLITE_TRANSIENT. The T parameter should be a static string,4922** preferably a string literal. The sqlite3_bind_pointer() routine is4923** part of the [pointer passing interface] added for SQLite 3.20.0.4924**4925** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer4926** for the [prepared statement] or with a prepared statement for which4927** [sqlite3_step()] has been called more recently than [sqlite3_reset()],4928** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_()4929** routine is passed a [prepared statement] that has been finalized, the4930** result is undefined and probably harmful.4931**4932** ^Bindings are not cleared by the [sqlite3_reset()] routine.4933** ^Unbound parameters are interpreted as NULL.4934**4935** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an4936** [error code] if anything goes wrong.4937** ^[SQLITE_TOOBIG] might be returned if the size of a string or BLOB4938** exceeds limits imposed by [sqlite3_limit]([SQLITE_LIMIT_LENGTH]) or4939** [SQLITE_MAX_LENGTH].4940** ^[SQLITE_RANGE] is returned if the parameter4941** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails.4942**4943** See also: [sqlite3_bind_parameter_count()],4944** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].4945*/4946SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));4947SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,4948void(*)(void*));4949SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);4950SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);4951SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);4952SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);4953SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));4954SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));4955SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,4956void(*)(void*), unsigned char encoding);4957SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);4958SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt*, int, void*, const char*,void(*)(void*));4959SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);4960SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);49614962/*4963** CAPI3REF: Number Of SQL Parameters4964** METHOD: sqlite3_stmt4965**4966** ^This routine can be used to find the number of [SQL parameters]4967** in a [prepared statement]. SQL parameters are tokens of the4968** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as4969** placeholders for values that are [sqlite3_bind_blob | bound]4970** to the parameters at a later time.4971**4972** ^(This routine actually returns the index of the largest (rightmost)4973** parameter. For all forms except ?NNN, this will correspond to the4974** number of unique parameters. If parameters of the ?NNN form are used,4975** there may be gaps in the list.)^4976**4977** See also: [sqlite3_bind_blob|sqlite3_bind()],4978** [sqlite3_bind_parameter_name()], and4979** [sqlite3_bind_parameter_index()].4980*/4981SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*);49824983/*4984** CAPI3REF: Name Of A Host Parameter4985** METHOD: sqlite3_stmt4986**4987** ^The sqlite3_bind_parameter_name(P,N) interface returns4988** the name of the N-th [SQL parameter] in the [prepared statement] P.4989** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"4990** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"4991** respectively.4992** In other words, the initial ":" or "$" or "@" or "?"4993** is included as part of the name.)^4994** ^Parameters of the form "?" without a following integer have no name4995** and are referred to as "nameless" or "anonymous parameters".4996**4997** ^The first host parameter has an index of 1, not 0.4998**4999** ^If the value N is out of range or if the N-th parameter is5000** nameless, then NULL is returned. ^The returned string is5001** always in UTF-8 encoding even if the named parameter was5002** originally specified as UTF-16 in [sqlite3_prepare16()],5003** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()].5004**5005** See also: [sqlite3_bind_blob|sqlite3_bind()],5006** [sqlite3_bind_parameter_count()], and5007** [sqlite3_bind_parameter_index()].5008*/5009SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);50105011/*5012** CAPI3REF: Index Of A Parameter With A Given Name5013** METHOD: sqlite3_stmt5014**5015** ^Return the index of an SQL parameter given its name. ^The5016** index value returned is suitable for use as the second5017** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero5018** is returned if no matching parameter is found. ^The parameter5019** name must be given in UTF-8 even if the original statement5020** was prepared from UTF-16 text using [sqlite3_prepare16_v2()] or5021** [sqlite3_prepare16_v3()].5022**5023** See also: [sqlite3_bind_blob|sqlite3_bind()],5024** [sqlite3_bind_parameter_count()], and5025** [sqlite3_bind_parameter_name()].5026*/5027SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);50285029/*5030** CAPI3REF: Reset All Bindings On A Prepared Statement5031** METHOD: sqlite3_stmt5032**5033** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset5034** the [sqlite3_bind_blob | bindings] on a [prepared statement].5035** ^Use this routine to reset all host parameters to NULL.5036*/5037SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*);50385039/*5040** CAPI3REF: Number Of Columns In A Result Set5041** METHOD: sqlite3_stmt5042**5043** ^Return the number of columns in the result set returned by the5044** [prepared statement]. ^If this routine returns 0, that means the5045** [prepared statement] returns no data (for example an [UPDATE]).5046** ^However, just because this routine returns a positive number does not5047** mean that one or more rows of data will be returned. ^A SELECT statement5048** will always have a positive sqlite3_column_count() but depending on the5049** WHERE clause constraints and the table content, it might return no rows.5050**5051** See also: [sqlite3_data_count()]5052*/5053SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);50545055/*5056** CAPI3REF: Column Names In A Result Set5057** METHOD: sqlite3_stmt5058**5059** ^These routines return the name assigned to a particular column5060** in the result set of a [SELECT] statement. ^The sqlite3_column_name()5061** interface returns a pointer to a zero-terminated UTF-8 string5062** and sqlite3_column_name16() returns a pointer to a zero-terminated5063** UTF-16 string. ^The first parameter is the [prepared statement]5064** that implements the [SELECT] statement. ^The second parameter is the5065** column number. ^The leftmost column is number 0.5066**5067** ^The returned string pointer is valid until either the [prepared statement]5068** is destroyed by [sqlite3_finalize()] or until the statement is automatically5069** reprepared by the first call to [sqlite3_step()] for a particular run5070** or until the next call to5071** sqlite3_column_name() or sqlite3_column_name16() on the same column.5072**5073** ^If sqlite3_malloc() fails during the processing of either routine5074** (for example during a conversion from UTF-8 to UTF-16) then a5075** NULL pointer is returned.5076**5077** ^The name of a result column is the value of the "AS" clause for5078** that column, if there is an AS clause. If there is no AS clause5079** then the name of the column is unspecified and may change from5080** one release of SQLite to the next.5081*/5082SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N);5083SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N);50845085/*5086** CAPI3REF: Source Of Data In A Query Result5087** METHOD: sqlite3_stmt5088**5089** ^These routines provide a means to determine the database, table, and5090** table column that is the origin of a particular result column in a5091** [SELECT] statement.5092** ^The name of the database or table or column can be returned as5093** either a UTF-8 or UTF-16 string. ^The _database_ routines return5094** the database name, the _table_ routines return the table name, and5095** the origin_ routines return the column name.5096** ^The returned string is valid until the [prepared statement] is destroyed5097** using [sqlite3_finalize()] or until the statement is automatically5098** reprepared by the first call to [sqlite3_step()] for a particular run5099** or until the same information is requested5100** again in a different encoding.5101**5102** ^The names returned are the original un-aliased names of the5103** database, table, and column.5104**5105** ^The first argument to these interfaces is a [prepared statement].5106** ^These functions return information about the Nth result column returned by5107** the statement, where N is the second function argument.5108** ^The left-most column is column 0 for these routines.5109**5110** ^If the Nth column returned by the statement is an expression or5111** subquery and is not a column value, then all of these functions return5112** NULL. ^These routines might also return NULL if a memory allocation error5113** occurs. ^Otherwise, they return the name of the attached database, table,5114** or column that query result column was extracted from.5115**5116** ^As with all other SQLite APIs, those whose names end with "16" return5117** UTF-16 encoded strings and the other functions return UTF-8.5118**5119** ^These APIs are only available if the library was compiled with the5120** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.5121**5122** If two or more threads call one or more5123** [sqlite3_column_database_name | column metadata interfaces]5124** for the same [prepared statement] and result column5125** at the same time then the results are undefined.5126*/5127SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int);5128SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int);5129SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int);5130SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int);5131SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int);5132SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);51335134/*5135** CAPI3REF: Declared Datatype Of A Query Result5136** METHOD: sqlite3_stmt5137**5138** ^(The first parameter is a [prepared statement].5139** If this statement is a [SELECT] statement and the Nth column of the5140** returned result set of that [SELECT] is a table column (not an5141** expression or subquery) then the declared type of the table5142** column is returned.)^ ^If the Nth column of the result set is an5143** expression or subquery, then a NULL pointer is returned.5144** ^The returned string is always UTF-8 encoded.5145**5146** ^(For example, given the database schema:5147**5148** CREATE TABLE t1(c1 VARIANT);5149**5150** and the following statement to be compiled:5151**5152** SELECT c1 + 1, c1 FROM t1;5153**5154** this routine would return the string "VARIANT" for the second result5155** column (i==1), and a NULL pointer for the first result column (i==0).)^5156**5157** ^SQLite uses dynamic run-time typing. ^So just because a column5158** is declared to contain a particular type does not mean that the5159** data stored in that column is of the declared type. SQLite is5160** strongly typed, but the typing is dynamic not static. ^Type5161** is associated with individual values, not with the containers5162** used to hold those values.5163*/5164SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int);5165SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int);51665167/*5168** CAPI3REF: Evaluate An SQL Statement5169** METHOD: sqlite3_stmt5170**5171** After a [prepared statement] has been prepared using any of5172** [sqlite3_prepare_v2()], [sqlite3_prepare_v3()], [sqlite3_prepare16_v2()],5173** or [sqlite3_prepare16_v3()] or one of the legacy5174** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function5175** must be called one or more times to evaluate the statement.5176**5177** The details of the behavior of the sqlite3_step() interface depend5178** on whether the statement was prepared using the newer "vX" interfaces5179** [sqlite3_prepare_v3()], [sqlite3_prepare_v2()], [sqlite3_prepare16_v3()],5180** [sqlite3_prepare16_v2()] or the older legacy5181** interfaces [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the5182** new "vX" interface is recommended for new applications but the legacy5183** interface will continue to be supported.5184**5185** ^In the legacy interface, the return value will be either [SQLITE_BUSY],5186** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].5187** ^With the "v2" interface, any of the other [result codes] or5188** [extended result codes] might be returned as well.5189**5190** ^[SQLITE_BUSY] means that the database engine was unable to acquire the5191** database locks it needs to do its job. ^If the statement is a [COMMIT]5192** or occurs outside of an explicit transaction, then you can retry the5193** statement. If the statement is not a [COMMIT] and occurs within an5194** explicit transaction then you should rollback the transaction before5195** continuing.5196**5197** ^[SQLITE_DONE] means that the statement has finished executing5198** successfully. sqlite3_step() should not be called again on this virtual5199** machine without first calling [sqlite3_reset()] to reset the virtual5200** machine back to its initial state.5201**5202** ^If the SQL statement being executed returns any data, then [SQLITE_ROW]5203** is returned each time a new row of data is ready for processing by the5204** caller. The values may be accessed using the [column access functions].5205** sqlite3_step() is called again to retrieve the next row of data.5206**5207** ^[SQLITE_ERROR] means that a run-time error (such as a constraint5208** violation) has occurred. sqlite3_step() should not be called again on5209** the VM. More information may be found by calling [sqlite3_errmsg()].5210** ^With the legacy interface, a more specific error code (for example,5211** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)5212** can be obtained by calling [sqlite3_reset()] on the5213** [prepared statement]. ^In the "v2" interface,5214** the more specific error code is returned directly by sqlite3_step().5215**5216** [SQLITE_MISUSE] means that the this routine was called inappropriately.5217** Perhaps it was called on a [prepared statement] that has5218** already been [sqlite3_finalize | finalized] or on one that had5219** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could5220** be the case that the same database connection is being used by two or5221** more threads at the same moment in time.5222**5223** For all versions of SQLite up to and including 3.6.23.1, a call to5224** [sqlite3_reset()] was required after sqlite3_step() returned anything5225** other than [SQLITE_ROW] before any subsequent invocation of5226** sqlite3_step(). Failure to reset the prepared statement using5227** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from5228** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1]),5229** sqlite3_step() began5230** calling [sqlite3_reset()] automatically in this circumstance rather5231** than returning [SQLITE_MISUSE]. This is not considered a compatibility5232** break because any application that ever receives an SQLITE_MISUSE error5233** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option5234** can be used to restore the legacy behavior.5235**5236** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step()5237** API always returns a generic error code, [SQLITE_ERROR], following any5238** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call5239** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the5240** specific [error codes] that better describes the error.5241** We admit that this is a goofy design. The problem has been fixed5242** with the "v2" interface. If you prepare all of your SQL statements5243** using [sqlite3_prepare_v3()] or [sqlite3_prepare_v2()]5244** or [sqlite3_prepare16_v2()] or [sqlite3_prepare16_v3()] instead5245** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces,5246** then the more specific [error codes] are returned directly5247** by sqlite3_step(). The use of the "vX" interfaces is recommended.5248*/5249SQLITE_API int sqlite3_step(sqlite3_stmt*);52505251/*5252** CAPI3REF: Number of columns in a result set5253** METHOD: sqlite3_stmt5254**5255** ^The sqlite3_data_count(P) interface returns the number of columns in the5256** current row of the result set of [prepared statement] P.5257** ^If prepared statement P does not have results ready to return5258** (via calls to the [sqlite3_column_int | sqlite3_column()] family of5259** interfaces) then sqlite3_data_count(P) returns 0.5260** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.5261** ^The sqlite3_data_count(P) routine returns 0 if the previous call to5262** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P)5263** will return non-zero if previous call to [sqlite3_step](P) returned5264** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum]5265** where it always returns zero since each step of that multi-step5266** pragma returns 0 columns of data.5267**5268** See also: [sqlite3_column_count()]5269*/5270SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);52715272/*5273** CAPI3REF: Fundamental Datatypes5274** KEYWORDS: SQLITE_TEXT5275**5276** ^(Every value in SQLite has one of five fundamental datatypes:5277**5278** <ul>5279** <li> 64-bit signed integer5280** <li> 64-bit IEEE floating point number5281** <li> string5282** <li> BLOB5283** <li> NULL5284** </ul>)^5285**5286** These constants are codes for each of those types.5287**5288** Note that the SQLITE_TEXT constant was also used in SQLite version 25289** for a completely different meaning. Software that links against both5290** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not5291** SQLITE_TEXT.5292*/5293#define SQLITE_INTEGER 15294#define SQLITE_FLOAT 25295#define SQLITE_BLOB 45296#define SQLITE_NULL 55297#ifdef SQLITE_TEXT5298# undef SQLITE_TEXT5299#else5300# define SQLITE_TEXT 35301#endif5302#define SQLITE3_TEXT 353035304/*5305** CAPI3REF: Result Values From A Query5306** KEYWORDS: {column access functions}5307** METHOD: sqlite3_stmt5308**5309** <b>Summary:</b>5310** <blockquote><table border=0 cellpadding=0 cellspacing=0>5311** <tr><td><b>sqlite3_column_blob</b><td>→<td>BLOB result5312** <tr><td><b>sqlite3_column_double</b><td>→<td>REAL result5313** <tr><td><b>sqlite3_column_int</b><td>→<td>32-bit INTEGER result5314** <tr><td><b>sqlite3_column_int64</b><td>→<td>64-bit INTEGER result5315** <tr><td><b>sqlite3_column_text</b><td>→<td>UTF-8 TEXT result5316** <tr><td><b>sqlite3_column_text16</b><td>→<td>UTF-16 TEXT result5317** <tr><td><b>sqlite3_column_value</b><td>→<td>The result as an5318** [sqlite3_value|unprotected sqlite3_value] object.5319** <tr><td> <td> <td> 5320** <tr><td><b>sqlite3_column_bytes</b><td>→<td>Size of a BLOB5321** or a UTF-8 TEXT result in bytes5322** <tr><td><b>sqlite3_column_bytes16 </b>5323** <td>→ <td>Size of UTF-165324** TEXT in bytes5325** <tr><td><b>sqlite3_column_type</b><td>→<td>Default5326** datatype of the result5327** </table></blockquote>5328**5329** <b>Details:</b>5330**5331** ^These routines return information about a single column of the current5332** result row of a query. ^In every case the first argument is a pointer5333** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*]5334** that was returned from [sqlite3_prepare_v2()] or one of its variants)5335** and the second argument is the index of the column for which information5336** should be returned. ^The leftmost column of the result set has the index 0.5337** ^The number of columns in the result can be determined using5338** [sqlite3_column_count()].5339**5340** If the SQL statement does not currently point to a valid row, or if the5341** column index is out of range, the result is undefined.5342** These routines may only be called when the most recent call to5343** [sqlite3_step()] has returned [SQLITE_ROW] and neither5344** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently.5345** If any of these routines are called after [sqlite3_reset()] or5346** [sqlite3_finalize()] or after [sqlite3_step()] has returned5347** something other than [SQLITE_ROW], the results are undefined.5348** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()]5349** are called from a different thread while any of these routines5350** are pending, then the results are undefined.5351**5352** The first six interfaces (_blob, _double, _int, _int64, _text, and _text16)5353** each return the value of a result column in a specific data format. If5354** the result column is not initially in the requested format (for example,5355** if the query returns an integer but the sqlite3_column_text() interface5356** is used to extract the value) then an automatic type conversion is performed.5357**5358** ^The sqlite3_column_type() routine returns the5359** [SQLITE_INTEGER | datatype code] for the initial data type5360** of the result column. ^The returned value is one of [SQLITE_INTEGER],5361** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].5362** The return value of sqlite3_column_type() can be used to decide which5363** of the first six interface should be used to extract the column value.5364** The value returned by sqlite3_column_type() is only meaningful if no5365** automatic type conversions have occurred for the value in question.5366** After a type conversion, the result of calling sqlite3_column_type()5367** is undefined, though harmless. Future5368** versions of SQLite may change the behavior of sqlite3_column_type()5369** following a type conversion.5370**5371** If the result is a BLOB or a TEXT string, then the sqlite3_column_bytes()5372** or sqlite3_column_bytes16() interfaces can be used to determine the size5373** of that BLOB or string.5374**5375** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes()5376** routine returns the number of bytes in that BLOB or string.5377** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts5378** the string to UTF-8 and then returns the number of bytes.5379** ^If the result is a numeric value then sqlite3_column_bytes() uses5380** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns5381** the number of bytes in that string.5382** ^If the result is NULL, then sqlite3_column_bytes() returns zero.5383**5384** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16()5385** routine returns the number of bytes in that BLOB or string.5386** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts5387** the string to UTF-16 and then returns the number of bytes.5388** ^If the result is a numeric value then sqlite3_column_bytes16() uses5389** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns5390** the number of bytes in that string.5391** ^If the result is NULL, then sqlite3_column_bytes16() returns zero.5392**5393** ^The values returned by [sqlite3_column_bytes()] and5394** [sqlite3_column_bytes16()] do not include the zero terminators at the end5395** of the string. ^For clarity: the values returned by5396** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of5397** bytes in the string, not the number of characters.5398**5399** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),5400** even empty strings, are always zero-terminated. ^The return5401** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.5402**5403** ^Strings returned by sqlite3_column_text16() always have the endianness5404** which is native to the platform, regardless of the text encoding set5405** for the database.5406**5407** <b>Warning:</b> ^The object returned by [sqlite3_column_value()] is an5408** [unprotected sqlite3_value] object. In a multithreaded environment,5409** an unprotected sqlite3_value object may only be used safely with5410** [sqlite3_bind_value()] and [sqlite3_result_value()].5411** If the [unprotected sqlite3_value] object returned by5412** [sqlite3_column_value()] is used in any other way, including calls5413** to routines like [sqlite3_value_int()], [sqlite3_value_text()],5414** or [sqlite3_value_bytes()], the behavior is not threadsafe.5415** Hence, the sqlite3_column_value() interface5416** is normally only useful within the implementation of5417** [application-defined SQL functions] or [virtual tables], not within5418** top-level application code.5419**5420** These routines may attempt to convert the datatype of the result.5421** ^For example, if the internal representation is FLOAT and a text result5422** is requested, [sqlite3_snprintf()] is used internally to perform the5423** conversion automatically. ^(The following table details the conversions5424** that are applied:5425**5426** <blockquote>5427** <table border="1">5428** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion5429**5430** <tr><td> NULL <td> INTEGER <td> Result is 05431** <tr><td> NULL <td> FLOAT <td> Result is 0.05432** <tr><td> NULL <td> TEXT <td> Result is a NULL pointer5433** <tr><td> NULL <td> BLOB <td> Result is a NULL pointer5434** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float5435** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer5436** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT5437** <tr><td> FLOAT <td> INTEGER <td> [CAST] to INTEGER5438** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float5439** <tr><td> FLOAT <td> BLOB <td> [CAST] to BLOB5440** <tr><td> TEXT <td> INTEGER <td> [CAST] to INTEGER5441** <tr><td> TEXT <td> FLOAT <td> [CAST] to REAL5442** <tr><td> TEXT <td> BLOB <td> No change5443** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER5444** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL5445** <tr><td> BLOB <td> TEXT <td> [CAST] to TEXT, ensure zero terminator5446** </table>5447** </blockquote>)^5448**5449** Note that when type conversions occur, pointers returned by prior5450** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or5451** sqlite3_column_text16() may be invalidated.5452** Type conversions and pointer invalidations might occur5453** in the following cases:5454**5455** <ul>5456** <li> The initial content is a BLOB and sqlite3_column_text() or5457** sqlite3_column_text16() is called. A zero-terminator might5458** need to be added to the string.</li>5459** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or5460** sqlite3_column_text16() is called. The content must be converted5461** to UTF-16.</li>5462** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or5463** sqlite3_column_text() is called. The content must be converted5464** to UTF-8.</li>5465** </ul>5466**5467** ^Conversions between UTF-16be and UTF-16le are always done in place and do5468** not invalidate a prior pointer, though of course the content of the buffer5469** that the prior pointer references will have been modified. Other kinds5470** of conversion are done in place when it is possible, but sometimes they5471** are not possible and in those cases prior pointers are invalidated.5472**5473** The safest policy is to invoke these routines5474** in one of the following ways:5475**5476** <ul>5477** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>5478** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>5479** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>5480** </ul>5481**5482** In other words, you should call sqlite3_column_text(),5483** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result5484** into the desired format, then invoke sqlite3_column_bytes() or5485** sqlite3_column_bytes16() to find the size of the result. Do not mix calls5486** to sqlite3_column_text() or sqlite3_column_blob() with calls to5487** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16()5488** with calls to sqlite3_column_bytes().5489**5490** ^The pointers returned are valid until a type conversion occurs as5491** described above, or until [sqlite3_step()] or [sqlite3_reset()] or5492** [sqlite3_finalize()] is called. ^The memory space used to hold strings5493** and BLOBs is freed automatically. Do not pass the pointers returned5494** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into5495** [sqlite3_free()].5496**5497** As long as the input parameters are correct, these routines will only5498** fail if an out-of-memory error occurs during a format conversion.5499** Only the following subset of interfaces are subject to out-of-memory5500** errors:5501**5502** <ul>5503** <li> sqlite3_column_blob()5504** <li> sqlite3_column_text()5505** <li> sqlite3_column_text16()5506** <li> sqlite3_column_bytes()5507** <li> sqlite3_column_bytes16()5508** </ul>5509**5510** If an out-of-memory error occurs, then the return value from these5511** routines is the same as if the column had contained an SQL NULL value.5512** Valid SQL NULL returns can be distinguished from out-of-memory errors5513** by invoking the [sqlite3_errcode()] immediately after the suspect5514** return value is obtained and before any5515** other SQLite interface is called on the same [database connection].5516*/5517SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);5518SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol);5519SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol);5520SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);5521SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);5522SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);5523SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);5524SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol);5525SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);5526SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol);55275528/*5529** CAPI3REF: Destroy A Prepared Statement Object5530** DESTRUCTOR: sqlite3_stmt5531**5532** ^The sqlite3_finalize() function is called to delete a [prepared statement].5533** ^If the most recent evaluation of the statement encountered no errors5534** or if the statement has never been evaluated, then sqlite3_finalize() returns5535** SQLITE_OK. ^If the most recent evaluation of statement S failed, then5536** sqlite3_finalize(S) returns the appropriate [error code] or5537** [extended error code].5538**5539** ^The sqlite3_finalize(S) routine can be called at any point during5540** the life cycle of [prepared statement] S:5541** before statement S is ever evaluated, after5542** one or more calls to [sqlite3_reset()], or after any call5543** to [sqlite3_step()] regardless of whether or not the statement has5544** completed execution.5545**5546** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op.5547**5548** The application must finalize every [prepared statement] in order to avoid5549** resource leaks. It is a grievous error for the application to try to use5550** a prepared statement after it has been finalized. Any use of a prepared5551** statement after it has been finalized can result in undefined and5552** undesirable behavior such as segfaults and heap corruption.5553*/5554SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);55555556/*5557** CAPI3REF: Reset A Prepared Statement Object5558** METHOD: sqlite3_stmt5559**5560** The sqlite3_reset() function is called to reset a [prepared statement]5561** object back to its initial state, ready to be re-executed.5562** ^Any SQL statement variables that had values bound to them using5563** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.5564** Use [sqlite3_clear_bindings()] to reset the bindings.5565**5566** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S5567** back to the beginning of its program.5568**5569** ^The return code from [sqlite3_reset(S)] indicates whether or not5570** the previous evaluation of prepared statement S completed successfully.5571** ^If [sqlite3_step(S)] has never before been called on S or if5572** [sqlite3_step(S)] has not been called since the previous call5573** to [sqlite3_reset(S)], then [sqlite3_reset(S)] will return5574** [SQLITE_OK].5575**5576** ^If the most recent call to [sqlite3_step(S)] for the5577** [prepared statement] S indicated an error, then5578** [sqlite3_reset(S)] returns an appropriate [error code].5579** ^The [sqlite3_reset(S)] interface might also return an [error code]5580** if there were no prior errors but the process of resetting5581** the prepared statement caused a new error. ^For example, if an5582** [INSERT] statement with a [RETURNING] clause is only stepped one time,5583** that one call to [sqlite3_step(S)] might return SQLITE_ROW but5584** the overall statement might still fail and the [sqlite3_reset(S)] call5585** might return SQLITE_BUSY if locking constraints prevent the5586** database change from committing. Therefore, it is important that5587** applications check the return code from [sqlite3_reset(S)] even if5588** no prior call to [sqlite3_step(S)] indicated a problem.5589**5590** ^The [sqlite3_reset(S)] interface does not change the values5591** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.5592*/5593SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);559455955596/*5597** CAPI3REF: Create Or Redefine SQL Functions5598** KEYWORDS: {function creation routines}5599** METHOD: sqlite35600**5601** ^These functions (collectively known as "function creation routines")5602** are used to add SQL functions or aggregates or to redefine the behavior5603** of existing SQL functions or aggregates. The only differences between5604** the three "sqlite3_create_function*" routines are the text encoding5605** expected for the second parameter (the name of the function being5606** created) and the presence or absence of a destructor callback for5607** the application data pointer. Function sqlite3_create_window_function()5608** is similar, but allows the user to supply the extra callback functions5609** needed by [aggregate window functions].5610**5611** ^The first parameter is the [database connection] to which the SQL5612** function is to be added. ^If an application uses more than one database5613** connection then application-defined SQL functions must be added5614** to each database connection separately.5615**5616** ^The second parameter is the name of the SQL function to be created or5617** redefined. ^The length of the name is limited to 255 bytes in a UTF-85618** representation, exclusive of the zero-terminator. ^Note that the name5619** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes.5620** ^Any attempt to create a function with a longer name5621** will result in [SQLITE_MISUSE] being returned.5622**5623** ^The third parameter (nArg)5624** is the number of arguments that the SQL function or5625** aggregate takes. ^If this parameter is -1, then the SQL function or5626** aggregate may take any number of arguments between 0 and the limit5627** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third5628** parameter is less than -1 or greater than 127 then the behavior is5629** undefined.5630**5631** ^The fourth parameter, eTextRep, specifies what5632** [SQLITE_UTF8 | text encoding] this SQL function prefers for5633** its parameters. The application should set this parameter to5634** [SQLITE_UTF16LE] if the function implementation invokes5635** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the5636** implementation invokes [sqlite3_value_text16be()] on an input, or5637** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8]5638** otherwise. ^The same SQL function may be registered multiple times using5639** different preferred text encodings, with different implementations for5640** each encoding.5641** ^When multiple implementations of the same function are available, SQLite5642** will pick the one that involves the least amount of data conversion.5643**5644** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC]5645** to signal that the function will always return the same result given5646** the same inputs within a single SQL statement. Most SQL functions are5647** deterministic. The built-in [random()] SQL function is an example of a5648** function that is not deterministic. The SQLite query planner is able to5649** perform additional optimizations on deterministic functions, so use5650** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.5651**5652** ^The fourth parameter may also optionally include the [SQLITE_DIRECTONLY]5653** flag, which if present prevents the function from being invoked from5654** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions,5655** index expressions, or the WHERE clause of partial indexes.5656**5657** For best security, the [SQLITE_DIRECTONLY] flag is recommended for5658** all application-defined SQL functions that do not need to be5659** used inside of triggers, views, CHECK constraints, or other elements of5660** the database schema. This flag is especially recommended for SQL5661** functions that have side effects or reveal internal application state.5662** Without this flag, an attacker might be able to modify the schema of5663** a database file to include invocations of the function with parameters5664** chosen by the attacker, which the application will then execute when5665** the database file is opened and read.5666**5667** ^(The fifth parameter is an arbitrary pointer. The implementation of the5668** function can gain access to this pointer using [sqlite3_user_data()].)^5669**5670** ^The sixth, seventh and eighth parameters passed to the three5671** "sqlite3_create_function*" functions, xFunc, xStep and xFinal, are5672** pointers to C-language functions that implement the SQL function or5673** aggregate. ^A scalar SQL function requires an implementation of the xFunc5674** callback only; NULL pointers must be passed as the xStep and xFinal5675** parameters. ^An aggregate SQL function requires an implementation of xStep5676** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing5677** SQL function or aggregate, pass NULL pointers for all three function5678** callbacks.5679**5680** ^The sixth, seventh, eighth and ninth parameters (xStep, xFinal, xValue5681** and xInverse) passed to sqlite3_create_window_function are pointers to5682** C-language callbacks that implement the new function. xStep and xFinal5683** must both be non-NULL. xValue and xInverse may either both be NULL, in5684** which case a regular aggregate function is created, or must both be5685** non-NULL, in which case the new function may be used as either an aggregate5686** or aggregate window function. More details regarding the implementation5687** of aggregate window functions are5688** [user-defined window functions|available here].5689**5690** ^(If the final parameter to sqlite3_create_function_v2() or5691** sqlite3_create_window_function() is not NULL, then it is the destructor for5692** the application data pointer. The destructor is invoked when the function5693** is deleted, either by being overloaded or when the database connection5694** closes.)^ ^The destructor is also invoked if the call to5695** sqlite3_create_function_v2() fails. ^When the destructor callback is5696** invoked, it is passed a single argument which is a copy of the application5697** data pointer which was the fifth parameter to sqlite3_create_function_v2().5698**5699** ^It is permitted to register multiple implementations of the same5700** functions with the same name but with either differing numbers of5701** arguments or differing preferred text encodings. ^SQLite will use5702** the implementation that most closely matches the way in which the5703** SQL function is used. ^A function implementation with a non-negative5704** nArg parameter is a better match than a function implementation with5705** a negative nArg. ^A function where the preferred text encoding5706** matches the database encoding is a better5707** match than a function where the encoding is different.5708** ^A function where the encoding difference is between UTF16le and UTF16be5709** is a closer match than a function where the encoding difference is5710** between UTF8 and UTF16.5711**5712** ^Built-in functions may be overloaded by new application-defined functions.5713**5714** ^An application-defined function is permitted to call other5715** SQLite interfaces. However, such calls must not5716** close the database connection nor finalize or reset the prepared5717** statement in which the function is running.5718*/5719SQLITE_API int sqlite3_create_function(5720sqlite3 *db,5721const char *zFunctionName,5722int nArg,5723int eTextRep,5724void *pApp,5725void (*xFunc)(sqlite3_context*,int,sqlite3_value**),5726void (*xStep)(sqlite3_context*,int,sqlite3_value**),5727void (*xFinal)(sqlite3_context*)5728);5729SQLITE_API int sqlite3_create_function16(5730sqlite3 *db,5731const void *zFunctionName,5732int nArg,5733int eTextRep,5734void *pApp,5735void (*xFunc)(sqlite3_context*,int,sqlite3_value**),5736void (*xStep)(sqlite3_context*,int,sqlite3_value**),5737void (*xFinal)(sqlite3_context*)5738);5739SQLITE_API int sqlite3_create_function_v2(5740sqlite3 *db,5741const char *zFunctionName,5742int nArg,5743int eTextRep,5744void *pApp,5745void (*xFunc)(sqlite3_context*,int,sqlite3_value**),5746void (*xStep)(sqlite3_context*,int,sqlite3_value**),5747void (*xFinal)(sqlite3_context*),5748void(*xDestroy)(void*)5749);5750SQLITE_API int sqlite3_create_window_function(5751sqlite3 *db,5752const char *zFunctionName,5753int nArg,5754int eTextRep,5755void *pApp,5756void (*xStep)(sqlite3_context*,int,sqlite3_value**),5757void (*xFinal)(sqlite3_context*),5758void (*xValue)(sqlite3_context*),5759void (*xInverse)(sqlite3_context*,int,sqlite3_value**),5760void(*xDestroy)(void*)5761);57625763/*5764** CAPI3REF: Text Encodings5765**5766** These constants define integer codes that represent the various5767** text encodings supported by SQLite.5768*/5769#define SQLITE_UTF8 1 /* IMP: R-37514-35566 */5770#define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */5771#define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */5772#define SQLITE_UTF16 4 /* Use native byte order */5773#define SQLITE_ANY 5 /* Deprecated */5774#define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */57755776/*5777** CAPI3REF: Function Flags5778**5779** These constants may be ORed together with the5780** [SQLITE_UTF8 | preferred text encoding] as the fourth argument5781** to [sqlite3_create_function()], [sqlite3_create_function16()], or5782** [sqlite3_create_function_v2()].5783**5784** <dl>5785** [[SQLITE_DETERMINISTIC]] <dt>SQLITE_DETERMINISTIC</dt><dd>5786** The SQLITE_DETERMINISTIC flag means that the new function always gives5787** the same output when the input parameters are the same.5788** The [abs|abs() function] is deterministic, for example, but5789** [randomblob|randomblob()] is not. Functions must5790** be deterministic in order to be used in certain contexts such as5791** with the WHERE clause of [partial indexes] or in [generated columns].5792** SQLite might also optimize deterministic functions by factoring them5793** out of inner loops.5794** </dd>5795**5796** [[SQLITE_DIRECTONLY]] <dt>SQLITE_DIRECTONLY</dt><dd>5797** The SQLITE_DIRECTONLY flag means that the function may only be invoked5798** from top-level SQL, and cannot be used in VIEWs or TRIGGERs nor in5799** schema structures such as [CHECK constraints], [DEFAULT clauses],5800** [expression indexes], [partial indexes], or [generated columns].5801** <p>5802** The SQLITE_DIRECTONLY flag is recommended for any5803** [application-defined SQL function]5804** that has side-effects or that could potentially leak sensitive information.5805** This will prevent attacks in which an application is tricked5806** into using a database file that has had its schema surreptitiously5807** modified to invoke the application-defined function in ways that are5808** harmful.5809** <p>5810** Some people say it is good practice to set SQLITE_DIRECTONLY on all5811** [application-defined SQL functions], regardless of whether or not they5812** are security sensitive, as doing so prevents those functions from being used5813** inside of the database schema, and thus ensures that the database5814** can be inspected and modified using generic tools (such as the [CLI])5815** that do not have access to the application-defined functions.5816** </dd>5817**5818** [[SQLITE_INNOCUOUS]] <dt>SQLITE_INNOCUOUS</dt><dd>5819** The SQLITE_INNOCUOUS flag means that the function is unlikely5820** to cause problems even if misused. An innocuous function should have5821** no side effects and should not depend on any values other than its5822** input parameters. The [abs|abs() function] is an example of an5823** innocuous function.5824** The [load_extension() SQL function] is not innocuous because of its5825** side effects.5826** <p> SQLITE_INNOCUOUS is similar to SQLITE_DETERMINISTIC, but is not5827** exactly the same. The [random|random() function] is an example of a5828** function that is innocuous but not deterministic.5829** <p>Some heightened security settings5830** ([SQLITE_DBCONFIG_TRUSTED_SCHEMA] and [PRAGMA trusted_schema=OFF])5831** disable the use of SQL functions inside views and triggers and in5832** schema structures such as [CHECK constraints], [DEFAULT clauses],5833** [expression indexes], [partial indexes], and [generated columns] unless5834** the function is tagged with SQLITE_INNOCUOUS. Most built-in functions5835** are innocuous. Developers are advised to avoid using the5836** SQLITE_INNOCUOUS flag for application-defined functions unless the5837** function has been carefully audited and found to be free of potentially5838** security-adverse side-effects and information-leaks.5839** </dd>5840**5841** [[SQLITE_SUBTYPE]] <dt>SQLITE_SUBTYPE</dt><dd>5842** The SQLITE_SUBTYPE flag indicates to SQLite that a function might call5843** [sqlite3_value_subtype()] to inspect the sub-types of its arguments.5844** This flag instructs SQLite to omit some corner-case optimizations that5845** might disrupt the operation of the [sqlite3_value_subtype()] function,5846** causing it to return zero rather than the correct subtype().5847** All SQL functions that invoke [sqlite3_value_subtype()] should have this5848** property. If the SQLITE_SUBTYPE property is omitted, then the return5849** value from [sqlite3_value_subtype()] might sometimes be zero even though5850** a non-zero subtype was specified by the function argument expression.5851**5852** [[SQLITE_RESULT_SUBTYPE]] <dt>SQLITE_RESULT_SUBTYPE</dt><dd>5853** The SQLITE_RESULT_SUBTYPE flag indicates to SQLite that a function might call5854** [sqlite3_result_subtype()] to cause a sub-type to be associated with its5855** result.5856** Every function that invokes [sqlite3_result_subtype()] should have this5857** property. If it does not, then the call to [sqlite3_result_subtype()]5858** might become a no-op if the function is used as a term in an5859** [expression index]. On the other hand, SQL functions that never invoke5860** [sqlite3_result_subtype()] should avoid setting this property, as the5861** purpose of this property is to disable certain optimizations that are5862** incompatible with subtypes.5863**5864** [[SQLITE_SELFORDER1]] <dt>SQLITE_SELFORDER1</dt><dd>5865** The SQLITE_SELFORDER1 flag indicates that the function is an aggregate5866** that internally orders the values provided to the first argument. The5867** ordered-set aggregate SQL notation with a single ORDER BY term can be5868** used to invoke this function. If the ordered-set aggregate notation is5869** used on a function that lacks this flag, then an error is raised. Note5870** that the ordered-set aggregate syntax is only available if SQLite is5871** built using the -DSQLITE_ENABLE_ORDERED_SET_AGGREGATES compile-time option.5872** </dd>5873** </dl>5874*/5875#define SQLITE_DETERMINISTIC 0x0000008005876#define SQLITE_DIRECTONLY 0x0000800005877#define SQLITE_SUBTYPE 0x0001000005878#define SQLITE_INNOCUOUS 0x0002000005879#define SQLITE_RESULT_SUBTYPE 0x0010000005880#define SQLITE_SELFORDER1 0x00200000058815882/*5883** CAPI3REF: Deprecated Functions5884** DEPRECATED5885**5886** These functions are [deprecated]. In order to maintain5887** backwards compatibility with older code, these functions continue5888** to be supported. However, new applications should avoid5889** the use of these functions. To encourage programmers to avoid5890** these functions, we will not explain what they do.5891*/5892#ifndef SQLITE_OMIT_DEPRECATED5893SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);5894SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);5895SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);5896SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void);5897SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);5898SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),5899void*,sqlite3_int64);5900#endif59015902/*5903** CAPI3REF: Obtaining SQL Values5904** METHOD: sqlite3_value5905**5906** <b>Summary:</b>5907** <blockquote><table border=0 cellpadding=0 cellspacing=0>5908** <tr><td><b>sqlite3_value_blob</b><td>→<td>BLOB value5909** <tr><td><b>sqlite3_value_double</b><td>→<td>REAL value5910** <tr><td><b>sqlite3_value_int</b><td>→<td>32-bit INTEGER value5911** <tr><td><b>sqlite3_value_int64</b><td>→<td>64-bit INTEGER value5912** <tr><td><b>sqlite3_value_pointer</b><td>→<td>Pointer value5913** <tr><td><b>sqlite3_value_text</b><td>→<td>UTF-8 TEXT value5914** <tr><td><b>sqlite3_value_text16</b><td>→<td>UTF-16 TEXT value in5915** the native byteorder5916** <tr><td><b>sqlite3_value_text16be</b><td>→<td>UTF-16be TEXT value5917** <tr><td><b>sqlite3_value_text16le</b><td>→<td>UTF-16le TEXT value5918** <tr><td> <td> <td> 5919** <tr><td><b>sqlite3_value_bytes</b><td>→<td>Size of a BLOB5920** or a UTF-8 TEXT in bytes5921** <tr><td><b>sqlite3_value_bytes16 </b>5922** <td>→ <td>Size of UTF-165923** TEXT in bytes5924** <tr><td><b>sqlite3_value_type</b><td>→<td>Default5925** datatype of the value5926** <tr><td><b>sqlite3_value_numeric_type </b>5927** <td>→ <td>Best numeric datatype of the value5928** <tr><td><b>sqlite3_value_nochange </b>5929** <td>→ <td>True if the column is unchanged in an UPDATE5930** against a virtual table.5931** <tr><td><b>sqlite3_value_frombind </b>5932** <td>→ <td>True if value originated from a [bound parameter]5933** </table></blockquote>5934**5935** <b>Details:</b>5936**5937** These routines extract type, size, and content information from5938** [protected sqlite3_value] objects. Protected sqlite3_value objects5939** are used to pass parameter information into the functions that5940** implement [application-defined SQL functions] and [virtual tables].5941**5942** These routines work only with [protected sqlite3_value] objects.5943** Any attempt to use these routines on an [unprotected sqlite3_value]5944** is not threadsafe.5945**5946** ^These routines work just like the corresponding [column access functions]5947** except that these routines take a single [protected sqlite3_value] object5948** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.5949**5950** ^The sqlite3_value_text16() interface extracts a UTF-16 string5951** in the native byte-order of the host machine. ^The5952** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces5953** extract UTF-16 strings as big-endian and little-endian respectively.5954**5955** ^If [sqlite3_value] object V was initialized5956** using [sqlite3_bind_pointer(S,I,P,X,D)] or [sqlite3_result_pointer(C,P,X,D)]5957** and if X and Y are strings that compare equal according to strcmp(X,Y),5958** then sqlite3_value_pointer(V,Y) will return the pointer P. ^Otherwise,5959** sqlite3_value_pointer(V,Y) returns a NULL. The sqlite3_bind_pointer()5960** routine is part of the [pointer passing interface] added for SQLite 3.20.0.5961**5962** ^(The sqlite3_value_type(V) interface returns the5963** [SQLITE_INTEGER | datatype code] for the initial datatype of the5964** [sqlite3_value] object V. The returned value is one of [SQLITE_INTEGER],5965** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].)^5966** Other interfaces might change the datatype for an sqlite3_value object.5967** For example, if the datatype is initially SQLITE_INTEGER and5968** sqlite3_value_text(V) is called to extract a text value for that5969** integer, then subsequent calls to sqlite3_value_type(V) might return5970** SQLITE_TEXT. Whether or not a persistent internal datatype conversion5971** occurs is undefined and may change from one release of SQLite to the next.5972**5973** ^(The sqlite3_value_numeric_type() interface attempts to apply5974** numeric affinity to the value. This means that an attempt is5975** made to convert the value to an integer or floating point. If5976** such a conversion is possible without loss of information (in other5977** words, if the value is a string that looks like a number)5978** then the conversion is performed. Otherwise no conversion occurs.5979** The [SQLITE_INTEGER | datatype] after conversion is returned.)^5980**5981** ^Within the [xUpdate] method of a [virtual table], the5982** sqlite3_value_nochange(X) interface returns true if and only if5983** the column corresponding to X is unchanged by the UPDATE operation5984** that the xUpdate method call was invoked to implement and if5985** the prior [xColumn] method call that was invoked to extract5986** the value for that column returned without setting a result (probably5987** because it queried [sqlite3_vtab_nochange()] and found that the column5988** was unchanging). ^Within an [xUpdate] method, any value for which5989** sqlite3_value_nochange(X) is true will in all other respects appear5990** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other5991** than within an [xUpdate] method call for an UPDATE statement, then5992** the return value is arbitrary and meaningless.5993**5994** ^The sqlite3_value_frombind(X) interface returns non-zero if the5995** value X originated from one of the [sqlite3_bind_int|sqlite3_bind()]5996** interfaces. ^If X comes from an SQL literal value, or a table column,5997** or an expression, then sqlite3_value_frombind(X) returns zero.5998**5999** Please pay particular attention to the fact that the pointer returned6000** from [sqlite3_value_blob()], [sqlite3_value_text()], or6001** [sqlite3_value_text16()] can be invalidated by a subsequent call to6002** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],6003** or [sqlite3_value_text16()].6004**6005** These routines must be called from the same thread as6006** the SQL function that supplied the [sqlite3_value*] parameters.6007**6008** As long as the input parameter is correct, these routines can only6009** fail if an out-of-memory error occurs during a format conversion.6010** Only the following subset of interfaces are subject to out-of-memory6011** errors:6012**6013** <ul>6014** <li> sqlite3_value_blob()6015** <li> sqlite3_value_text()6016** <li> sqlite3_value_text16()6017** <li> sqlite3_value_text16le()6018** <li> sqlite3_value_text16be()6019** <li> sqlite3_value_bytes()6020** <li> sqlite3_value_bytes16()6021** </ul>6022**6023** If an out-of-memory error occurs, then the return value from these6024** routines is the same as if the column had contained an SQL NULL value.6025** Valid SQL NULL returns can be distinguished from out-of-memory errors6026** by invoking the [sqlite3_errcode()] immediately after the suspect6027** return value is obtained and before any6028** other SQLite interface is called on the same [database connection].6029*/6030SQLITE_API const void *sqlite3_value_blob(sqlite3_value*);6031SQLITE_API double sqlite3_value_double(sqlite3_value*);6032SQLITE_API int sqlite3_value_int(sqlite3_value*);6033SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*);6034SQLITE_API void *sqlite3_value_pointer(sqlite3_value*, const char*);6035SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*);6036SQLITE_API const void *sqlite3_value_text16(sqlite3_value*);6037SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*);6038SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);6039SQLITE_API int sqlite3_value_bytes(sqlite3_value*);6040SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);6041SQLITE_API int sqlite3_value_type(sqlite3_value*);6042SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);6043SQLITE_API int sqlite3_value_nochange(sqlite3_value*);6044SQLITE_API int sqlite3_value_frombind(sqlite3_value*);60456046/*6047** CAPI3REF: Report the internal text encoding state of an sqlite3_value object6048** METHOD: sqlite3_value6049**6050** ^(The sqlite3_value_encoding(X) interface returns one of [SQLITE_UTF8],6051** [SQLITE_UTF16BE], or [SQLITE_UTF16LE] according to the current text encoding6052** of the value X, assuming that X has type TEXT.)^ If sqlite3_value_type(X)6053** returns something other than SQLITE_TEXT, then the return value from6054** sqlite3_value_encoding(X) is meaningless. ^Calls to6055** [sqlite3_value_text(X)], [sqlite3_value_text16(X)], [sqlite3_value_text16be(X)],6056** [sqlite3_value_text16le(X)], [sqlite3_value_bytes(X)], or6057** [sqlite3_value_bytes16(X)] might change the encoding of the value X and6058** thus change the return from subsequent calls to sqlite3_value_encoding(X).6059**6060** This routine is intended for used by applications that test and validate6061** the SQLite implementation. This routine is inquiring about the opaque6062** internal state of an [sqlite3_value] object. Ordinary applications should6063** not need to know what the internal state of an sqlite3_value object is and6064** hence should not need to use this interface.6065*/6066SQLITE_API int sqlite3_value_encoding(sqlite3_value*);60676068/*6069** CAPI3REF: Finding The Subtype Of SQL Values6070** METHOD: sqlite3_value6071**6072** The sqlite3_value_subtype(V) function returns the subtype for6073** an [application-defined SQL function] argument V. The subtype6074** information can be used to pass a limited amount of context from6075** one SQL function to another. Use the [sqlite3_result_subtype()]6076** routine to set the subtype for the return value of an SQL function.6077**6078** Every [application-defined SQL function] that invokes this interface6079** should include the [SQLITE_SUBTYPE] property in the text6080** encoding argument when the function is [sqlite3_create_function|registered].6081** If the [SQLITE_SUBTYPE] property is omitted, then sqlite3_value_subtype()6082** might return zero instead of the upstream subtype in some corner cases.6083*/6084SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value*);60856086/*6087** CAPI3REF: Copy And Free SQL Values6088** METHOD: sqlite3_value6089**6090** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]6091** object V and returns a pointer to that copy. ^The [sqlite3_value] returned6092** is a [protected sqlite3_value] object even if the input is not.6093** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a6094** memory allocation fails. ^If V is a [pointer value], then the result6095** of sqlite3_value_dup(V) is a NULL value.6096**6097** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object6098** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer6099** then sqlite3_value_free(V) is a harmless no-op.6100*/6101SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value*);6102SQLITE_API void sqlite3_value_free(sqlite3_value*);61036104/*6105** CAPI3REF: Obtain Aggregate Function Context6106** METHOD: sqlite3_context6107**6108** Implementations of aggregate SQL functions use this6109** routine to allocate memory for storing their state.6110**6111** ^The first time the sqlite3_aggregate_context(C,N) routine is called6112** for a particular aggregate function, SQLite allocates6113** N bytes of memory, zeroes out that memory, and returns a pointer6114** to the new memory. ^On second and subsequent calls to6115** sqlite3_aggregate_context() for the same aggregate function instance,6116** the same buffer is returned. Sqlite3_aggregate_context() is normally6117** called once for each invocation of the xStep callback and then one6118** last time when the xFinal callback is invoked. ^(When no rows match6119** an aggregate query, the xStep() callback of the aggregate function6120** implementation is never called and xFinal() is called exactly once.6121** In those cases, sqlite3_aggregate_context() might be called for the6122** first time from within xFinal().)^6123**6124** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer6125** when first called if N is less than or equal to zero or if a memory6126** allocation error occurs.6127**6128** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is6129** determined by the N parameter on the first successful call. Changing the6130** value of N in any subsequent call to sqlite3_aggregate_context() within6131** the same aggregate function instance will not resize the memory6132** allocation.)^ Within the xFinal callback, it is customary to set6133** N=0 in calls to sqlite3_aggregate_context(C,N) so that no6134** pointless memory allocations occur.6135**6136** ^SQLite automatically frees the memory allocated by6137** sqlite3_aggregate_context() when the aggregate query concludes.6138**6139** The first parameter must be a copy of the6140** [sqlite3_context | SQL function context] that is the first parameter6141** to the xStep or xFinal callback routine that implements the aggregate6142** function.6143**6144** This routine must be called from the same thread in which6145** the aggregate SQL function is running.6146*/6147SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);61486149/*6150** CAPI3REF: User Data For Functions6151** METHOD: sqlite3_context6152**6153** ^The sqlite3_user_data() interface returns a copy of6154** the pointer that was the pUserData parameter (the 5th parameter)6155** of the [sqlite3_create_function()]6156** and [sqlite3_create_function16()] routines that originally6157** registered the application defined function.6158**6159** This routine must be called from the same thread in which6160** the application-defined function is running.6161*/6162SQLITE_API void *sqlite3_user_data(sqlite3_context*);61636164/*6165** CAPI3REF: Database Connection For Functions6166** METHOD: sqlite3_context6167**6168** ^The sqlite3_context_db_handle() interface returns a copy of6169** the pointer to the [database connection] (the 1st parameter)6170** of the [sqlite3_create_function()]6171** and [sqlite3_create_function16()] routines that originally6172** registered the application defined function.6173*/6174SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);61756176/*6177** CAPI3REF: Function Auxiliary Data6178** METHOD: sqlite3_context6179**6180** These functions may be used by (non-aggregate) SQL functions to6181** associate auxiliary data with argument values. If the same argument6182** value is passed to multiple invocations of the same SQL function during6183** query execution, under some circumstances the associated auxiliary data6184** might be preserved. An example of where this might be useful is in a6185** regular-expression matching function. The compiled version of the regular6186** expression can be stored as auxiliary data associated with the pattern string.6187** Then as long as the pattern string remains the same,6188** the compiled regular expression can be reused on multiple6189** invocations of the same function.6190**6191** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the auxiliary data6192** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument6193** value to the application-defined function. ^N is zero for the left-most6194** function argument. ^If there is no auxiliary data6195** associated with the function argument, the sqlite3_get_auxdata(C,N) interface6196** returns a NULL pointer.6197**6198** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as auxiliary data for the6199** N-th argument of the application-defined function. ^Subsequent6200** calls to sqlite3_get_auxdata(C,N) return P from the most recent6201** sqlite3_set_auxdata(C,N,P,X) call if the auxiliary data is still valid or6202** NULL if the auxiliary data has been discarded.6203** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL,6204** SQLite will invoke the destructor function X with parameter P exactly6205** once, when the auxiliary data is discarded.6206** SQLite is free to discard the auxiliary data at any time, including: <ul>6207** <li> ^(when the corresponding function parameter changes)^, or6208** <li> ^(when [sqlite3_reset()] or [sqlite3_finalize()] is called for the6209** SQL statement)^, or6210** <li> ^(when sqlite3_set_auxdata() is invoked again on the same6211** parameter)^, or6212** <li> ^(during the original sqlite3_set_auxdata() call when a memory6213** allocation error occurs.)^6214** <li> ^(during the original sqlite3_set_auxdata() call if the function6215** is evaluated during query planning instead of during query execution,6216** as sometimes happens with [SQLITE_ENABLE_STAT4].)^ </ul>6217**6218** Note the last two bullets in particular. The destructor X in6219** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the6220** sqlite3_set_auxdata() interface even returns. Hence sqlite3_set_auxdata()6221** should be called near the end of the function implementation and the6222** function implementation should not make any use of P after6223** sqlite3_set_auxdata() has been called. Furthermore, a call to6224** sqlite3_get_auxdata() that occurs immediately after a corresponding call6225** to sqlite3_set_auxdata() might still return NULL if an out-of-memory6226** condition occurred during the sqlite3_set_auxdata() call or if the6227** function is being evaluated during query planning rather than during6228** query execution.6229**6230** ^(In practice, auxiliary data is preserved between function calls for6231** function parameters that are compile-time constants, including literal6232** values and [parameters] and expressions composed from the same.)^6233**6234** The value of the N parameter to these interfaces should be non-negative.6235** Future enhancements may make use of negative N values to define new6236** kinds of function caching behavior.6237**6238** These routines must be called from the same thread in which6239** the SQL function is running.6240**6241** See also: [sqlite3_get_clientdata()] and [sqlite3_set_clientdata()].6242*/6243SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);6244SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));62456246/*6247** CAPI3REF: Database Connection Client Data6248** METHOD: sqlite36249**6250** These functions are used to associate one or more named pointers6251** with a [database connection].6252** A call to sqlite3_set_clientdata(D,N,P,X) causes the pointer P6253** to be attached to [database connection] D using name N. Subsequent6254** calls to sqlite3_get_clientdata(D,N) will return a copy of pointer P6255** or a NULL pointer if there were no prior calls to6256** sqlite3_set_clientdata() with the same values of D and N.6257** Names are compared using strcmp() and are thus case sensitive.6258** It returns 0 on success and SQLITE_NOMEM on allocation failure.6259**6260** If P and X are both non-NULL, then the destructor X is invoked with6261** argument P on the first of the following occurrences:6262** <ul>6263** <li> An out-of-memory error occurs during the call to6264** sqlite3_set_clientdata() which attempts to register pointer P.6265** <li> A subsequent call to sqlite3_set_clientdata(D,N,P,X) is made6266** with the same D and N parameters.6267** <li> The database connection closes. SQLite does not make any guarantees6268** about the order in which destructors are called, only that all6269** destructors will be called exactly once at some point during the6270** database connection closing process.6271** </ul>6272**6273** SQLite does not do anything with client data other than invoke6274** destructors on the client data at the appropriate time. The intended6275** use for client data is to provide a mechanism for wrapper libraries6276** to store additional information about an SQLite database connection.6277**6278** There is no limit (other than available memory) on the number of different6279** client data pointers (with different names) that can be attached to a6280** single database connection. However, the implementation is optimized6281** for the case of having only one or two different client data names.6282** Applications and wrapper libraries are discouraged from using more than6283** one client data name each.6284**6285** There is no way to enumerate the client data pointers6286** associated with a database connection. The N parameter can be thought6287** of as a secret key such that only code that knows the secret key is able6288** to access the associated data.6289**6290** Security Warning: These interfaces should not be exposed in scripting6291** languages or in other circumstances where it might be possible for an6292** attacker to invoke them. Any agent that can invoke these interfaces6293** can probably also take control of the process.6294**6295** Database connection client data is only available for SQLite6296** version 3.44.0 ([dateof:3.44.0]) and later.6297**6298** See also: [sqlite3_set_auxdata()] and [sqlite3_get_auxdata()].6299*/6300SQLITE_API void *sqlite3_get_clientdata(sqlite3*,const char*);6301SQLITE_API int sqlite3_set_clientdata(sqlite3*, const char*, void*, void(*)(void*));63026303/*6304** CAPI3REF: Constants Defining Special Destructor Behavior6305**6306** These are special values for the destructor that is passed in as the6307** final argument to routines like [sqlite3_result_blob()]. ^If the destructor6308** argument is SQLITE_STATIC, it means that the content pointer is constant6309** and will never change. It does not need to be destroyed. ^The6310** SQLITE_TRANSIENT value means that the content will likely change in6311** the near future and that SQLite should make its own private copy of6312** the content before returning.6313**6314** The typedef is necessary to work around problems in certain6315** C++ compilers.6316*/6317typedef void (*sqlite3_destructor_type)(void*);6318#define SQLITE_STATIC ((sqlite3_destructor_type)0)6319#define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)63206321/*6322** CAPI3REF: Setting The Result Of An SQL Function6323** METHOD: sqlite3_context6324**6325** These routines are used by the xFunc or xFinal callbacks that6326** implement SQL functions and aggregates. See6327** [sqlite3_create_function()] and [sqlite3_create_function16()]6328** for additional information.6329**6330** These functions work very much like the [parameter binding] family of6331** functions used to bind values to host parameters in prepared statements.6332** Refer to the [SQL parameter] documentation for additional information.6333**6334** ^The sqlite3_result_blob() interface sets the result from6335** an application-defined function to be the BLOB whose content is pointed6336** to by the second parameter and which is N bytes long where N is the6337** third parameter.6338**6339** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N)6340** interfaces set the result of the application-defined function to be6341** a BLOB containing all zero bytes and N bytes in size.6342**6343** ^The sqlite3_result_double() interface sets the result from6344** an application-defined function to be a floating point value specified6345** by its 2nd argument.6346**6347** ^The sqlite3_result_error() and sqlite3_result_error16() functions6348** cause the implemented SQL function to throw an exception.6349** ^SQLite uses the string pointed to by the6350** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()6351** as the text of an error message. ^SQLite interprets the error6352** message string from sqlite3_result_error() as UTF-8. ^SQLite6353** interprets the string from sqlite3_result_error16() as UTF-16 using6354** the same [byte-order determination rules] as [sqlite3_bind_text16()].6355** ^If the third parameter to sqlite3_result_error()6356** or sqlite3_result_error16() is negative then SQLite takes as the error6357** message all text up through the first zero character.6358** ^If the third parameter to sqlite3_result_error() or6359** sqlite3_result_error16() is non-negative then SQLite takes that many6360** bytes (not characters) from the 2nd parameter as the error message.6361** ^The sqlite3_result_error() and sqlite3_result_error16()6362** routines make a private copy of the error message text before6363** they return. Hence, the calling function can deallocate or6364** modify the text after they return without harm.6365** ^The sqlite3_result_error_code() function changes the error code6366** returned by SQLite as a result of an error in a function. ^By default,6367** the error code is SQLITE_ERROR. ^A subsequent call to sqlite3_result_error()6368** or sqlite3_result_error16() resets the error code to SQLITE_ERROR.6369**6370** ^The sqlite3_result_error_toobig() interface causes SQLite to throw an6371** error indicating that a string or BLOB is too long to represent.6372**6373** ^The sqlite3_result_error_nomem() interface causes SQLite to throw an6374** error indicating that a memory allocation failed.6375**6376** ^The sqlite3_result_int() interface sets the return value6377** of the application-defined function to be the 32-bit signed integer6378** value given in the 2nd argument.6379** ^The sqlite3_result_int64() interface sets the return value6380** of the application-defined function to be the 64-bit signed integer6381** value given in the 2nd argument.6382**6383** ^The sqlite3_result_null() interface sets the return value6384** of the application-defined function to be NULL.6385**6386** ^The sqlite3_result_text(), sqlite3_result_text16(),6387** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces6388** set the return value of the application-defined function to be6389** a text string which is represented as UTF-8, UTF-16 native byte order,6390** UTF-16 little endian, or UTF-16 big endian, respectively.6391** ^The sqlite3_result_text64() interface sets the return value of an6392** application-defined function to be a text string in an encoding6393** specified by the fifth (and last) parameter, which must be one6394** of [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE].6395** ^SQLite takes the text result from the application from6396** the 2nd parameter of the sqlite3_result_text* interfaces.6397** ^If the 3rd parameter to any of the sqlite3_result_text* interfaces6398** other than sqlite3_result_text64() is negative, then SQLite computes6399** the string length itself by searching the 2nd parameter for the first6400** zero character.6401** ^If the 3rd parameter to the sqlite3_result_text* interfaces6402** is non-negative, then as many bytes (not characters) of the text6403** pointed to by the 2nd parameter are taken as the application-defined6404** function result. If the 3rd parameter is non-negative, then it6405** must be the byte offset into the string where the NUL terminator would6406** appear if the string were NUL terminated. If any NUL characters occur6407** in the string at a byte offset that is less than the value of the 3rd6408** parameter, then the resulting string will contain embedded NULs and the6409** result of expressions operating on strings with embedded NULs is undefined.6410** ^If the 4th parameter to the sqlite3_result_text* interfaces6411** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that6412** function as the destructor on the text or BLOB result when it has6413** finished using that result.6414** ^If the 4th parameter to the sqlite3_result_text* interfaces or to6415** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite6416** assumes that the text or BLOB result is in constant space and does not6417** copy the content of the parameter nor call a destructor on the content6418** when it has finished using that result.6419** ^If the 4th parameter to the sqlite3_result_text* interfaces6420** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT6421** then SQLite makes a copy of the result into space obtained6422** from [sqlite3_malloc()] before it returns.6423**6424** ^For the sqlite3_result_text16(), sqlite3_result_text16le(), and6425** sqlite3_result_text16be() routines, and for sqlite3_result_text64()6426** when the encoding is not UTF8, if the input UTF16 begins with a6427** byte-order mark (BOM, U+FEFF) then the BOM is removed from the6428** string and the rest of the string is interpreted according to the6429** byte-order specified by the BOM. ^The byte-order specified by6430** the BOM at the beginning of the text overrides the byte-order6431** specified by the interface procedure. ^So, for example, if6432** sqlite3_result_text16le() is invoked with text that begins6433** with bytes 0xfe, 0xff (a big-endian byte-order mark) then the6434** first two bytes of input are skipped and the remaining input6435** is interpreted as UTF16BE text.6436**6437** ^For UTF16 input text to the sqlite3_result_text16(),6438** sqlite3_result_text16be(), sqlite3_result_text16le(), and6439** sqlite3_result_text64() routines, if the text contains invalid6440** UTF16 characters, the invalid characters might be converted6441** into the unicode replacement character, U+FFFD.6442**6443** ^The sqlite3_result_value() interface sets the result of6444** the application-defined function to be a copy of the6445** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The6446** sqlite3_result_value() interface makes a copy of the [sqlite3_value]6447** so that the [sqlite3_value] specified in the parameter may change or6448** be deallocated after sqlite3_result_value() returns without harm.6449** ^A [protected sqlite3_value] object may always be used where an6450** [unprotected sqlite3_value] object is required, so either6451** kind of [sqlite3_value] object can be used with this interface.6452**6453** ^The sqlite3_result_pointer(C,P,T,D) interface sets the result to an6454** SQL NULL value, just like [sqlite3_result_null(C)], except that it6455** also associates the host-language pointer P or type T with that6456** NULL value such that the pointer can be retrieved within an6457** [application-defined SQL function] using [sqlite3_value_pointer()].6458** ^If the D parameter is not NULL, then it is a pointer to a destructor6459** for the P parameter. ^SQLite invokes D with P as its only argument6460** when SQLite is finished with P. The T parameter should be a static6461** string and preferably a string literal. The sqlite3_result_pointer()6462** routine is part of the [pointer passing interface] added for SQLite 3.20.0.6463**6464** If these routines are called from within a different thread6465** than the one containing the application-defined function that received6466** the [sqlite3_context] pointer, the results are undefined.6467*/6468SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));6469SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,6470sqlite3_uint64,void(*)(void*));6471SQLITE_API void sqlite3_result_double(sqlite3_context*, double);6472SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);6473SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);6474SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);6475SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);6476SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int);6477SQLITE_API void sqlite3_result_int(sqlite3_context*, int);6478SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);6479SQLITE_API void sqlite3_result_null(sqlite3_context*);6480SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));6481SQLITE_API void sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64,6482void(*)(void*), unsigned char encoding);6483SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));6484SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));6485SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));6486SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);6487SQLITE_API void sqlite3_result_pointer(sqlite3_context*, void*,const char*,void(*)(void*));6488SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);6489SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);649064916492/*6493** CAPI3REF: Setting The Subtype Of An SQL Function6494** METHOD: sqlite3_context6495**6496** The sqlite3_result_subtype(C,T) function causes the subtype of6497** the result from the [application-defined SQL function] with6498** [sqlite3_context] C to be the value T. Only the lower 8 bits6499** of the subtype T are preserved in current versions of SQLite;6500** higher order bits are discarded.6501** The number of subtype bytes preserved by SQLite might increase6502** in future releases of SQLite.6503**6504** Every [application-defined SQL function] that invokes this interface6505** should include the [SQLITE_RESULT_SUBTYPE] property in its6506** text encoding argument when the SQL function is6507** [sqlite3_create_function|registered]. If the [SQLITE_RESULT_SUBTYPE]6508** property is omitted from the function that invokes sqlite3_result_subtype(),6509** then in some cases the sqlite3_result_subtype() might fail to set6510** the result subtype.6511**6512** If SQLite is compiled with -DSQLITE_STRICT_SUBTYPE=1, then any6513** SQL function that invokes the sqlite3_result_subtype() interface6514** and that does not have the SQLITE_RESULT_SUBTYPE property will raise6515** an error. Future versions of SQLite might enable -DSQLITE_STRICT_SUBTYPE=16516** by default.6517*/6518SQLITE_API void sqlite3_result_subtype(sqlite3_context*,unsigned int);65196520/*6521** CAPI3REF: Define New Collating Sequences6522** METHOD: sqlite36523**6524** ^These functions add, remove, or modify a [collation] associated6525** with the [database connection] specified as the first argument.6526**6527** ^The name of the collation is a UTF-8 string6528** for sqlite3_create_collation() and sqlite3_create_collation_v2()6529** and a UTF-16 string in native byte order for sqlite3_create_collation16().6530** ^Collation names that compare equal according to [sqlite3_strnicmp()] are6531** considered to be the same name.6532**6533** ^(The third argument (eTextRep) must be one of the constants:6534** <ul>6535** <li> [SQLITE_UTF8],6536** <li> [SQLITE_UTF16LE],6537** <li> [SQLITE_UTF16BE],6538** <li> [SQLITE_UTF16], or6539** <li> [SQLITE_UTF16_ALIGNED].6540** </ul>)^6541** ^The eTextRep argument determines the encoding of strings passed6542** to the collating function callback, xCompare.6543** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep6544** force strings to be UTF16 with native byte order.6545** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin6546** on an even byte address.6547**6548** ^The fourth argument, pArg, is an application data pointer that is passed6549** through as the first argument to the collating function callback.6550**6551** ^The fifth argument, xCompare, is a pointer to the collating function.6552** ^Multiple collating functions can be registered using the same name but6553** with different eTextRep parameters and SQLite will use whichever6554** function requires the least amount of data transformation.6555** ^If the xCompare argument is NULL then the collating function is6556** deleted. ^When all collating functions having the same name are deleted,6557** that collation is no longer usable.6558**6559** ^The collating function callback is invoked with a copy of the pArg6560** application data pointer and with two strings in the encoding specified6561** by the eTextRep argument. The two integer parameters to the collating6562** function callback are the length of the two strings, in bytes. The collating6563** function must return an integer that is negative, zero, or positive6564** if the first string is less than, equal to, or greater than the second,6565** respectively. A collating function must always return the same answer6566** given the same inputs. If two or more collating functions are registered6567** to the same collation name (using different eTextRep values) then all6568** must give an equivalent answer when invoked with equivalent strings.6569** The collating function must obey the following properties for all6570** strings A, B, and C:6571**6572** <ol>6573** <li> If A==B then B==A.6574** <li> If A==B and B==C then A==C.6575** <li> If A<B THEN B>A.6576** <li> If A<B and B<C then A<C.6577** </ol>6578**6579** If a collating function fails any of the above constraints and that6580** collating function is registered and used, then the behavior of SQLite6581** is undefined.6582**6583** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()6584** with the addition that the xDestroy callback is invoked on pArg when6585** the collating function is deleted.6586** ^Collating functions are deleted when they are overridden by later6587** calls to the collation creation functions or when the6588** [database connection] is closed using [sqlite3_close()].6589**6590** ^The xDestroy callback is <u>not</u> called if the6591** sqlite3_create_collation_v2() function fails. Applications that invoke6592** sqlite3_create_collation_v2() with a non-NULL xDestroy argument should6593** check the return code and dispose of the application data pointer6594** themselves rather than expecting SQLite to deal with it for them.6595** This is different from every other SQLite interface. The inconsistency6596** is unfortunate but cannot be changed without breaking backwards6597** compatibility.6598**6599** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].6600*/6601SQLITE_API int sqlite3_create_collation(6602sqlite3*,6603const char *zName,6604int eTextRep,6605void *pArg,6606int(*xCompare)(void*,int,const void*,int,const void*)6607);6608SQLITE_API int sqlite3_create_collation_v2(6609sqlite3*,6610const char *zName,6611int eTextRep,6612void *pArg,6613int(*xCompare)(void*,int,const void*,int,const void*),6614void(*xDestroy)(void*)6615);6616SQLITE_API int sqlite3_create_collation16(6617sqlite3*,6618const void *zName,6619int eTextRep,6620void *pArg,6621int(*xCompare)(void*,int,const void*,int,const void*)6622);66236624/*6625** CAPI3REF: Collation Needed Callbacks6626** METHOD: sqlite36627**6628** ^To avoid having to register all collation sequences before a database6629** can be used, a single callback function may be registered with the6630** [database connection] to be invoked whenever an undefined collation6631** sequence is required.6632**6633** ^If the function is registered using the sqlite3_collation_needed() API,6634** then it is passed the names of undefined collation sequences as strings6635** encoded in UTF-8. ^If sqlite3_collation_needed16() is used,6636** the names are passed as UTF-16 in machine native byte order.6637** ^A call to either function replaces the existing collation-needed callback.6638**6639** ^(When the callback is invoked, the first argument passed is a copy6640** of the second argument to sqlite3_collation_needed() or6641** sqlite3_collation_needed16(). The second argument is the database6642** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE],6643** or [SQLITE_UTF16LE], indicating the most desirable form of the collation6644** sequence function required. The fourth parameter is the name of the6645** required collation sequence.)^6646**6647** The callback function should register the desired collation using6648** [sqlite3_create_collation()], [sqlite3_create_collation16()], or6649** [sqlite3_create_collation_v2()].6650*/6651SQLITE_API int sqlite3_collation_needed(6652sqlite3*,6653void*,6654void(*)(void*,sqlite3*,int eTextRep,const char*)6655);6656SQLITE_API int sqlite3_collation_needed16(6657sqlite3*,6658void*,6659void(*)(void*,sqlite3*,int eTextRep,const void*)6660);66616662#ifdef SQLITE_ENABLE_CEROD6663/*6664** Specify the activation key for a CEROD database. Unless6665** activated, none of the CEROD routines will work.6666*/6667SQLITE_API void sqlite3_activate_cerod(6668const char *zPassPhrase /* Activation phrase */6669);6670#endif66716672/*6673** CAPI3REF: Suspend Execution For A Short Time6674**6675** The sqlite3_sleep() function causes the current thread to suspend execution6676** for at least a number of milliseconds specified in its parameter.6677**6678** If the operating system does not support sleep requests with6679** millisecond time resolution, then the time will be rounded up to6680** the nearest second. The number of milliseconds of sleep actually6681** requested from the operating system is returned.6682**6683** ^SQLite implements this interface by calling the xSleep()6684** method of the default [sqlite3_vfs] object. If the xSleep() method6685** of the default VFS is not implemented correctly, or not implemented at6686** all, then the behavior of sqlite3_sleep() may deviate from the description6687** in the previous paragraphs.6688**6689** If a negative argument is passed to sqlite3_sleep() the results vary by6690** VFS and operating system. Some system treat a negative argument as an6691** instruction to sleep forever. Others understand it to mean do not sleep6692** at all. ^In SQLite version 3.42.0 and later, a negative6693** argument passed into sqlite3_sleep() is changed to zero before it is relayed6694** down into the xSleep method of the VFS.6695*/6696SQLITE_API int sqlite3_sleep(int);66976698/*6699** CAPI3REF: Name Of The Folder Holding Temporary Files6700**6701** ^(If this global variable is made to point to a string which is6702** the name of a folder (a.k.a. directory), then all temporary files6703** created by SQLite when using a built-in [sqlite3_vfs | VFS]6704** will be placed in that directory.)^ ^If this variable6705** is a NULL pointer, then SQLite performs a search for an appropriate6706** temporary file directory.6707**6708** Applications are strongly discouraged from using this global variable.6709** It is required to set a temporary folder on Windows Runtime (WinRT).6710** But for all other platforms, it is highly recommended that applications6711** neither read nor write this variable. This global variable is a relic6712** that exists for backwards compatibility of legacy applications and should6713** be avoided in new projects.6714**6715** It is not safe to read or modify this variable in more than one6716** thread at a time. It is not safe to read or modify this variable6717** if a [database connection] is being used at the same time in a separate6718** thread.6719** It is intended that this variable be set once6720** as part of process initialization and before any SQLite interface6721** routines have been called and that this variable remain unchanged6722** thereafter.6723**6724** ^The [temp_store_directory pragma] may modify this variable and cause6725** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore,6726** the [temp_store_directory pragma] always assumes that any string6727** that this variable points to is held in memory obtained from6728** [sqlite3_malloc] and the pragma may attempt to free that memory6729** using [sqlite3_free].6730** Hence, if this variable is modified directly, either it should be6731** made NULL or made to point to memory obtained from [sqlite3_malloc]6732** or else the use of the [temp_store_directory pragma] should be avoided.6733** Except when requested by the [temp_store_directory pragma], SQLite6734** does not free the memory that sqlite3_temp_directory points to. If6735** the application wants that memory to be freed, it must do6736** so itself, taking care to only do so after all [database connection]6737** objects have been destroyed.6738**6739** <b>Note to Windows Runtime users:</b> The temporary directory must be set6740** prior to calling [sqlite3_open] or [sqlite3_open_v2]. Otherwise, various6741** features that require the use of temporary files may fail. Here is an6742** example of how to do this using C++ with the Windows Runtime:6743**6744** <blockquote><pre>6745** LPCWSTR zPath = Windows::Storage::ApplicationData::Current->6746** TemporaryFolder->Path->Data();6747** char zPathBuf[MAX_PATH + 1];6748** memset(zPathBuf, 0, sizeof(zPathBuf));6749** WideCharToMultiByte(CP_UTF8, 0, zPath, -1, zPathBuf, sizeof(zPathBuf),6750** NULL, NULL);6751** sqlite3_temp_directory = sqlite3_mprintf("%s", zPathBuf);6752** </pre></blockquote>6753*/6754SQLITE_API SQLITE_EXTERN char *sqlite3_temp_directory;67556756/*6757** CAPI3REF: Name Of The Folder Holding Database Files6758**6759** ^(If this global variable is made to point to a string which is6760** the name of a folder (a.k.a. directory), then all database files6761** specified with a relative pathname and created or accessed by6762** SQLite when using a built-in windows [sqlite3_vfs | VFS] will be assumed6763** to be relative to that directory.)^ ^If this variable is a NULL6764** pointer, then SQLite assumes that all database files specified6765** with a relative pathname are relative to the current directory6766** for the process. Only the windows VFS makes use of this global6767** variable; it is ignored by the unix VFS.6768**6769** Changing the value of this variable while a database connection is6770** open can result in a corrupt database.6771**6772** It is not safe to read or modify this variable in more than one6773** thread at a time. It is not safe to read or modify this variable6774** if a [database connection] is being used at the same time in a separate6775** thread.6776** It is intended that this variable be set once6777** as part of process initialization and before any SQLite interface6778** routines have been called and that this variable remain unchanged6779** thereafter.6780**6781** ^The [data_store_directory pragma] may modify this variable and cause6782** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore,6783** the [data_store_directory pragma] always assumes that any string6784** that this variable points to is held in memory obtained from6785** [sqlite3_malloc] and the pragma may attempt to free that memory6786** using [sqlite3_free].6787** Hence, if this variable is modified directly, either it should be6788** made NULL or made to point to memory obtained from [sqlite3_malloc]6789** or else the use of the [data_store_directory pragma] should be avoided.6790*/6791SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory;67926793/*6794** CAPI3REF: Win32 Specific Interface6795**6796** These interfaces are available only on Windows. The6797** [sqlite3_win32_set_directory] interface is used to set the value associated6798** with the [sqlite3_temp_directory] or [sqlite3_data_directory] variable, to6799** zValue, depending on the value of the type parameter. The zValue parameter6800** should be NULL to cause the previous value to be freed via [sqlite3_free];6801** a non-NULL value will be copied into memory obtained from [sqlite3_malloc]6802** prior to being used. The [sqlite3_win32_set_directory] interface returns6803** [SQLITE_OK] to indicate success, [SQLITE_ERROR] if the type is unsupported,6804** or [SQLITE_NOMEM] if memory could not be allocated. The value of the6805** [sqlite3_data_directory] variable is intended to act as a replacement for6806** the current directory on the sub-platforms of Win32 where that concept is6807** not present, e.g. WinRT and UWP. The [sqlite3_win32_set_directory8] and6808** [sqlite3_win32_set_directory16] interfaces behave exactly the same as the6809** sqlite3_win32_set_directory interface except the string parameter must be6810** UTF-8 or UTF-16, respectively.6811*/6812SQLITE_API int sqlite3_win32_set_directory(6813unsigned long type, /* Identifier for directory being set or reset */6814void *zValue /* New value for directory being set or reset */6815);6816SQLITE_API int sqlite3_win32_set_directory8(unsigned long type, const char *zValue);6817SQLITE_API int sqlite3_win32_set_directory16(unsigned long type, const void *zValue);68186819/*6820** CAPI3REF: Win32 Directory Types6821**6822** These macros are only available on Windows. They define the allowed values6823** for the type argument to the [sqlite3_win32_set_directory] interface.6824*/6825#define SQLITE_WIN32_DATA_DIRECTORY_TYPE 16826#define SQLITE_WIN32_TEMP_DIRECTORY_TYPE 268276828/*6829** CAPI3REF: Test For Auto-Commit Mode6830** KEYWORDS: {autocommit mode}6831** METHOD: sqlite36832**6833** ^The sqlite3_get_autocommit() interface returns non-zero or6834** zero if the given database connection is or is not in autocommit mode,6835** respectively. ^Autocommit mode is on by default.6836** ^Autocommit mode is disabled by a [BEGIN] statement.6837** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK].6838**6839** If certain kinds of errors occur on a statement within a multi-statement6840** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR],6841** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the6842** transaction might be rolled back automatically. The only way to6843** find out whether SQLite automatically rolled back the transaction after6844** an error is to use this function.6845**6846** If another thread changes the autocommit status of the database6847** connection while this routine is running, then the return value6848** is undefined.6849*/6850SQLITE_API int sqlite3_get_autocommit(sqlite3*);68516852/*6853** CAPI3REF: Find The Database Handle Of A Prepared Statement6854** METHOD: sqlite3_stmt6855**6856** ^The sqlite3_db_handle interface returns the [database connection] handle6857** to which a [prepared statement] belongs. ^The [database connection]6858** returned by sqlite3_db_handle is the same [database connection]6859** that was the first argument6860** to the [sqlite3_prepare_v2()] call (or its variants) that was used to6861** create the statement in the first place.6862*/6863SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);68646865/*6866** CAPI3REF: Return The Schema Name For A Database Connection6867** METHOD: sqlite36868**6869** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name6870** for the N-th database on database connection D, or a NULL pointer if N is6871** out of range. An N value of 0 means the main database file. An N of 1 is6872** the "temp" schema. Larger values of N correspond to various ATTACH-ed6873** databases.6874**6875** Space to hold the string that is returned by sqlite3_db_name() is managed6876** by SQLite itself. The string might be deallocated by any operation that6877** changes the schema, including [ATTACH] or [DETACH] or calls to6878** [sqlite3_serialize()] or [sqlite3_deserialize()], even operations that6879** occur on a different thread. Applications that need to6880** remember the string long-term should make their own copy. Applications that6881** are accessing the same database connection simultaneously on multiple6882** threads should mutex-protect calls to this API and should make their own6883** private copy of the result prior to releasing the mutex.6884*/6885SQLITE_API const char *sqlite3_db_name(sqlite3 *db, int N);68866887/*6888** CAPI3REF: Return The Filename For A Database Connection6889** METHOD: sqlite36890**6891** ^The sqlite3_db_filename(D,N) interface returns a pointer to the filename6892** associated with database N of connection D.6893** ^If there is no attached database N on the database6894** connection D, or if database N is a temporary or in-memory database, then6895** this function will return either a NULL pointer or an empty string.6896**6897** ^The string value returned by this routine is owned and managed by6898** the database connection. ^The value will be valid until the database N6899** is [DETACH]-ed or until the database connection closes.6900**6901** ^The filename returned by this function is the output of the6902** xFullPathname method of the [VFS]. ^In other words, the filename6903** will be an absolute pathname, even if the filename used6904** to open the database originally was a URI or relative pathname.6905**6906** If the filename pointer returned by this routine is not NULL, then it6907** can be used as the filename input parameter to these routines:6908** <ul>6909** <li> [sqlite3_uri_parameter()]6910** <li> [sqlite3_uri_boolean()]6911** <li> [sqlite3_uri_int64()]6912** <li> [sqlite3_filename_database()]6913** <li> [sqlite3_filename_journal()]6914** <li> [sqlite3_filename_wal()]6915** </ul>6916*/6917SQLITE_API sqlite3_filename sqlite3_db_filename(sqlite3 *db, const char *zDbName);69186919/*6920** CAPI3REF: Determine if a database is read-only6921** METHOD: sqlite36922**6923** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N6924** of connection D is read-only, 0 if it is read/write, or -1 if N is not6925** the name of a database on connection D.6926*/6927SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);69286929/*6930** CAPI3REF: Determine the transaction state of a database6931** METHOD: sqlite36932**6933** ^The sqlite3_txn_state(D,S) interface returns the current6934** [transaction state] of schema S in database connection D. ^If S is NULL,6935** then the highest transaction state of any schema on database connection D6936** is returned. Transaction states are (in order of lowest to highest):6937** <ol>6938** <li value="0"> SQLITE_TXN_NONE6939** <li value="1"> SQLITE_TXN_READ6940** <li value="2"> SQLITE_TXN_WRITE6941** </ol>6942** ^If the S argument to sqlite3_txn_state(D,S) is not the name of6943** a valid schema, then -1 is returned.6944*/6945SQLITE_API int sqlite3_txn_state(sqlite3*,const char *zSchema);69466947/*6948** CAPI3REF: Allowed return values from sqlite3_txn_state()6949** KEYWORDS: {transaction state}6950**6951** These constants define the current transaction state of a database file.6952** ^The [sqlite3_txn_state(D,S)] interface returns one of these6953** constants in order to describe the transaction state of schema S6954** in [database connection] D.6955**6956** <dl>6957** [[SQLITE_TXN_NONE]] <dt>SQLITE_TXN_NONE</dt>6958** <dd>The SQLITE_TXN_NONE state means that no transaction is currently6959** pending.</dd>6960**6961** [[SQLITE_TXN_READ]] <dt>SQLITE_TXN_READ</dt>6962** <dd>The SQLITE_TXN_READ state means that the database is currently6963** in a read transaction. Content has been read from the database file6964** but nothing in the database file has changed. The transaction state6965** will be advanced to SQLITE_TXN_WRITE if any changes occur and there are6966** no other conflicting concurrent write transactions. The transaction6967** state will revert to SQLITE_TXN_NONE following a [ROLLBACK] or6968** [COMMIT].</dd>6969**6970** [[SQLITE_TXN_WRITE]] <dt>SQLITE_TXN_WRITE</dt>6971** <dd>The SQLITE_TXN_WRITE state means that the database is currently6972** in a write transaction. Content has been written to the database file6973** but has not yet committed. The transaction state will change to6974** SQLITE_TXN_NONE at the next [ROLLBACK] or [COMMIT].</dd>6975*/6976#define SQLITE_TXN_NONE 06977#define SQLITE_TXN_READ 16978#define SQLITE_TXN_WRITE 269796980/*6981** CAPI3REF: Find the next prepared statement6982** METHOD: sqlite36983**6984** ^This interface returns a pointer to the next [prepared statement] after6985** pStmt associated with the [database connection] pDb. ^If pStmt is NULL6986** then this interface returns a pointer to the first prepared statement6987** associated with the database connection pDb. ^If no prepared statement6988** satisfies the conditions of this routine, it returns NULL.6989**6990** The [database connection] pointer D in a call to6991** [sqlite3_next_stmt(D,S)] must refer to an open database6992** connection and in particular must not be a NULL pointer.6993*/6994SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);69956996/*6997** CAPI3REF: Commit And Rollback Notification Callbacks6998** METHOD: sqlite36999**7000** ^The sqlite3_commit_hook() interface registers a callback7001** function to be invoked whenever a transaction is [COMMIT | committed].7002** ^Any callback set by a previous call to sqlite3_commit_hook()7003** for the same database connection is overridden.7004** ^The sqlite3_rollback_hook() interface registers a callback7005** function to be invoked whenever a transaction is [ROLLBACK | rolled back].7006** ^Any callback set by a previous call to sqlite3_rollback_hook()7007** for the same database connection is overridden.7008** ^The pArg argument is passed through to the callback.7009** ^If the callback on a commit hook function returns non-zero,7010** then the commit is converted into a rollback.7011**7012** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions7013** return the P argument from the previous call of the same function7014** on the same [database connection] D, or NULL for7015** the first call for each function on D.7016**7017** The commit and rollback hook callbacks are not reentrant.7018** The callback implementation must not do anything that will modify7019** the database connection that invoked the callback. Any actions7020** to modify the database connection must be deferred until after the7021** completion of the [sqlite3_step()] call that triggered the commit7022** or rollback hook in the first place.7023** Note that running any other SQL statements, including SELECT statements,7024** or merely calling [sqlite3_prepare_v2()] and [sqlite3_step()] will modify7025** the database connections for the meaning of "modify" in this paragraph.7026**7027** ^Registering a NULL function disables the callback.7028**7029** ^When the commit hook callback routine returns zero, the [COMMIT]7030** operation is allowed to continue normally. ^If the commit hook7031** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK].7032** ^The rollback hook is invoked on a rollback that results from a commit7033** hook returning non-zero, just as it would be with any other rollback.7034**7035** ^For the purposes of this API, a transaction is said to have been7036** rolled back if an explicit "ROLLBACK" statement is executed, or7037** an error or constraint causes an implicit rollback to occur.7038** ^The rollback callback is not invoked if a transaction is7039** automatically rolled back because the database connection is closed.7040**7041** See also the [sqlite3_update_hook()] interface.7042*/7043SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);7044SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);70457046/*7047** CAPI3REF: Autovacuum Compaction Amount Callback7048** METHOD: sqlite37049**7050** ^The sqlite3_autovacuum_pages(D,C,P,X) interface registers a callback7051** function C that is invoked prior to each autovacuum of the database7052** file. ^The callback is passed a copy of the generic data pointer (P),7053** the schema-name of the attached database that is being autovacuumed,7054** the size of the database file in pages, the number of free pages,7055** and the number of bytes per page, respectively. The callback should7056** return the number of free pages that should be removed by the7057** autovacuum. ^If the callback returns zero, then no autovacuum happens.7058** ^If the value returned is greater than or equal to the number of7059** free pages, then a complete autovacuum happens.7060**7061** <p>^If there are multiple ATTACH-ed database files that are being7062** modified as part of a transaction commit, then the autovacuum pages7063** callback is invoked separately for each file.7064**7065** <p><b>The callback is not reentrant.</b> The callback function should7066** not attempt to invoke any other SQLite interface. If it does, bad7067** things may happen, including segmentation faults and corrupt database7068** files. The callback function should be a simple function that7069** does some arithmetic on its input parameters and returns a result.7070**7071** ^The X parameter to sqlite3_autovacuum_pages(D,C,P,X) is an optional7072** destructor for the P parameter. ^If X is not NULL, then X(P) is7073** invoked whenever the database connection closes or when the callback7074** is overwritten by another invocation of sqlite3_autovacuum_pages().7075**7076** <p>^There is only one autovacuum pages callback per database connection.7077** ^Each call to the sqlite3_autovacuum_pages() interface overrides all7078** previous invocations for that database connection. ^If the callback7079** argument (C) to sqlite3_autovacuum_pages(D,C,P,X) is a NULL pointer,7080** then the autovacuum steps callback is canceled. The return value7081** from sqlite3_autovacuum_pages() is normally SQLITE_OK, but might7082** be some other error code if something goes wrong. The current7083** implementation will only return SQLITE_OK or SQLITE_MISUSE, but other7084** return codes might be added in future releases.7085**7086** <p>If no autovacuum pages callback is specified (the usual case) or7087** a NULL pointer is provided for the callback,7088** then the default behavior is to vacuum all free pages. So, in other7089** words, the default behavior is the same as if the callback function7090** were something like this:7091**7092** <blockquote><pre>7093** unsigned int demonstration_autovac_pages_callback(7094** void *pClientData,7095** const char *zSchema,7096** unsigned int nDbPage,7097** unsigned int nFreePage,7098** unsigned int nBytePerPage7099** ){7100** return nFreePage;7101** }7102** </pre></blockquote>7103*/7104SQLITE_API int sqlite3_autovacuum_pages(7105sqlite3 *db,7106unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int),7107void*,7108void(*)(void*)7109);711071117112/*7113** CAPI3REF: Data Change Notification Callbacks7114** METHOD: sqlite37115**7116** ^The sqlite3_update_hook() interface registers a callback function7117** with the [database connection] identified by the first argument7118** to be invoked whenever a row is updated, inserted or deleted in7119** a [rowid table].7120** ^Any callback set by a previous call to this function7121** for the same database connection is overridden.7122**7123** ^The second argument is a pointer to the function to invoke when a7124** row is updated, inserted or deleted in a rowid table.7125** ^The update hook is disabled by invoking sqlite3_update_hook()7126** with a NULL pointer as the second parameter.7127** ^The first argument to the callback is a copy of the third argument7128** to sqlite3_update_hook().7129** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],7130** or [SQLITE_UPDATE], depending on the operation that caused the callback7131** to be invoked.7132** ^The third and fourth arguments to the callback contain pointers to the7133** database and table name containing the affected row.7134** ^The final callback parameter is the [rowid] of the row.7135** ^In the case of an update, this is the [rowid] after the update takes place.7136**7137** ^(The update hook is not invoked when internal system tables are7138** modified (i.e. sqlite_sequence).)^7139** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.7140**7141** ^In the current implementation, the update hook7142** is not invoked when conflicting rows are deleted because of an7143** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook7144** invoked when rows are deleted using the [truncate optimization].7145** The exceptions defined in this paragraph might change in a future7146** release of SQLite.7147**7148** Whether the update hook is invoked before or after the7149** corresponding change is currently unspecified and may differ7150** depending on the type of change. Do not rely on the order of the7151** hook call with regards to the final result of the operation which7152** triggers the hook.7153**7154** The update hook implementation must not do anything that will modify7155** the database connection that invoked the update hook. Any actions7156** to modify the database connection must be deferred until after the7157** completion of the [sqlite3_step()] call that triggered the update hook.7158** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their7159** database connections for the meaning of "modify" in this paragraph.7160**7161** ^The sqlite3_update_hook(D,C,P) function7162** returns the P argument from the previous call7163** on the same [database connection] D, or NULL for7164** the first call on D.7165**7166** See also the [sqlite3_commit_hook()], [sqlite3_rollback_hook()],7167** and [sqlite3_preupdate_hook()] interfaces.7168*/7169SQLITE_API void *sqlite3_update_hook(7170sqlite3*,7171void(*)(void *,int ,char const *,char const *,sqlite3_int64),7172void*7173);71747175/*7176** CAPI3REF: Enable Or Disable Shared Pager Cache7177**7178** ^(This routine enables or disables the sharing of the database cache7179** and schema data structures between [database connection | connections]7180** to the same database. Sharing is enabled if the argument is true7181** and disabled if the argument is false.)^7182**7183** This interface is omitted if SQLite is compiled with7184** [-DSQLITE_OMIT_SHARED_CACHE]. The [-DSQLITE_OMIT_SHARED_CACHE]7185** compile-time option is recommended because the7186** [use of shared cache mode is discouraged].7187**7188** ^Cache sharing is enabled and disabled for an entire process.7189** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]).7190** In prior versions of SQLite,7191** sharing was enabled or disabled for each thread separately.7192**7193** ^(The cache sharing mode set by this interface effects all subsequent7194** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].7195** Existing database connections continue to use the sharing mode7196** that was in effect at the time they were opened.)^7197**7198** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled7199** successfully. An [error code] is returned otherwise.)^7200**7201** ^Shared cache is disabled by default. It is recommended that it stay7202** that way. In other words, do not use this routine. This interface7203** continues to be provided for historical compatibility, but its use is7204** discouraged. Any use of shared cache is discouraged. If shared cache7205** must be used, it is recommended that shared cache only be enabled for7206** individual database connections using the [sqlite3_open_v2()] interface7207** with the [SQLITE_OPEN_SHAREDCACHE] flag.7208**7209** Note: This method is disabled on MacOS X 10.7 and iOS version 5.07210** and will always return SQLITE_MISUSE. On those systems,7211** shared cache mode should be enabled per-database connection via7212** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE].7213**7214** This interface is threadsafe on processors where writing a7215** 32-bit integer is atomic.7216**7217** See Also: [SQLite Shared-Cache Mode]7218*/7219SQLITE_API int sqlite3_enable_shared_cache(int);72207221/*7222** CAPI3REF: Attempt To Free Heap Memory7223**7224** ^The sqlite3_release_memory() interface attempts to free N bytes7225** of heap memory by deallocating non-essential memory allocations7226** held by the database library. Memory used to cache database7227** pages to improve performance is an example of non-essential memory.7228** ^sqlite3_release_memory() returns the number of bytes actually freed,7229** which might be more or less than the amount requested.7230** ^The sqlite3_release_memory() routine is a no-op returning zero7231** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT].7232**7233** See also: [sqlite3_db_release_memory()]7234*/7235SQLITE_API int sqlite3_release_memory(int);72367237/*7238** CAPI3REF: Free Memory Used By A Database Connection7239** METHOD: sqlite37240**7241** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap7242** memory as possible from database connection D. Unlike the7243** [sqlite3_release_memory()] interface, this interface is in effect even7244** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is7245** omitted.7246**7247** See also: [sqlite3_release_memory()]7248*/7249SQLITE_API int sqlite3_db_release_memory(sqlite3*);72507251/*7252** CAPI3REF: Impose A Limit On Heap Size7253**7254** These interfaces impose limits on the amount of heap memory that will be7255** used by all database connections within a single process.7256**7257** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the7258** soft limit on the amount of heap memory that may be allocated by SQLite.7259** ^SQLite strives to keep heap memory utilization below the soft heap7260** limit by reducing the number of pages held in the page cache7261** as heap memory usages approaches the limit.7262** ^The soft heap limit is "soft" because even though SQLite strives to stay7263** below the limit, it will exceed the limit rather than generate7264** an [SQLITE_NOMEM] error. In other words, the soft heap limit7265** is advisory only.7266**7267** ^The sqlite3_hard_heap_limit64(N) interface sets a hard upper bound of7268** N bytes on the amount of memory that will be allocated. ^The7269** sqlite3_hard_heap_limit64(N) interface is similar to7270** sqlite3_soft_heap_limit64(N) except that memory allocations will fail7271** when the hard heap limit is reached.7272**7273** ^The return value from both sqlite3_soft_heap_limit64() and7274** sqlite3_hard_heap_limit64() is the size of7275** the heap limit prior to the call, or negative in the case of an7276** error. ^If the argument N is negative7277** then no change is made to the heap limit. Hence, the current7278** size of heap limits can be determined by invoking7279** sqlite3_soft_heap_limit64(-1) or sqlite3_hard_heap_limit(-1).7280**7281** ^Setting the heap limits to zero disables the heap limiter mechanism.7282**7283** ^The soft heap limit may not be greater than the hard heap limit.7284** ^If the hard heap limit is enabled and if sqlite3_soft_heap_limit(N)7285** is invoked with a value of N that is greater than the hard heap limit,7286** the soft heap limit is set to the value of the hard heap limit.7287** ^The soft heap limit is automatically enabled whenever the hard heap7288** limit is enabled. ^When sqlite3_hard_heap_limit64(N) is invoked and7289** the soft heap limit is outside the range of 1..N, then the soft heap7290** limit is set to N. ^Invoking sqlite3_soft_heap_limit64(0) when the7291** hard heap limit is enabled makes the soft heap limit equal to the7292** hard heap limit.7293**7294** The memory allocation limits can also be adjusted using7295** [PRAGMA soft_heap_limit] and [PRAGMA hard_heap_limit].7296**7297** ^(The heap limits are not enforced in the current implementation7298** if one or more of following conditions are true:7299**7300** <ul>7301** <li> The limit value is set to zero.7302** <li> Memory accounting is disabled using a combination of the7303** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and7304** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option.7305** <li> An alternative page cache implementation is specified using7306** [sqlite3_config]([SQLITE_CONFIG_PCACHE2],...).7307** <li> The page cache allocates from its own memory pool supplied7308** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than7309** from the heap.7310** </ul>)^7311**7312** The circumstances under which SQLite will enforce the heap limits may7313** change in future releases of SQLite.7314*/7315SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);7316SQLITE_API sqlite3_int64 sqlite3_hard_heap_limit64(sqlite3_int64 N);73177318/*7319** CAPI3REF: Deprecated Soft Heap Limit Interface7320** DEPRECATED7321**7322** This is a deprecated version of the [sqlite3_soft_heap_limit64()]7323** interface. This routine is provided for historical compatibility7324** only. All new applications should use the7325** [sqlite3_soft_heap_limit64()] interface rather than this one.7326*/7327SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N);732873297330/*7331** CAPI3REF: Extract Metadata About A Column Of A Table7332** METHOD: sqlite37333**7334** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns7335** information about column C of table T in database D7336** on [database connection] X.)^ ^The sqlite3_table_column_metadata()7337** interface returns SQLITE_OK and fills in the non-NULL pointers in7338** the final five arguments with appropriate values if the specified7339** column exists. ^The sqlite3_table_column_metadata() interface returns7340** SQLITE_ERROR if the specified column does not exist.7341** ^If the column-name parameter to sqlite3_table_column_metadata() is a7342** NULL pointer, then this routine simply checks for the existence of the7343** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it7344** does not. If the table name parameter T in a call to7345** sqlite3_table_column_metadata(X,D,T,C,...) is NULL then the result is7346** undefined behavior.7347**7348** ^The column is identified by the second, third and fourth parameters to7349** this function. ^(The second parameter is either the name of the database7350** (i.e. "main", "temp", or an attached database) containing the specified7351** table or NULL.)^ ^If it is NULL, then all attached databases are searched7352** for the table using the same algorithm used by the database engine to7353** resolve unqualified table references.7354**7355** ^The third and fourth parameters to this function are the table and column7356** name of the desired column, respectively.7357**7358** ^Metadata is returned by writing to the memory locations passed as the 5th7359** and subsequent parameters to this function. ^Any of these arguments may be7360** NULL, in which case the corresponding element of metadata is omitted.7361**7362** ^(<blockquote>7363** <table border="1">7364** <tr><th> Parameter <th> Output<br>Type <th> Description7365**7366** <tr><td> 5th <td> const char* <td> Data type7367** <tr><td> 6th <td> const char* <td> Name of default collation sequence7368** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint7369** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY7370** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT]7371** </table>7372** </blockquote>)^7373**7374** ^The memory pointed to by the character pointers returned for the7375** declaration type and collation sequence is valid until the next7376** call to any SQLite API function.7377**7378** ^If the specified table is actually a view, an [error code] is returned.7379**7380** ^If the specified column is "rowid", "oid" or "_rowid_" and the table7381** is not a [WITHOUT ROWID] table and an7382** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output7383** parameters are set for the explicitly declared column. ^(If there is no7384** [INTEGER PRIMARY KEY] column, then the outputs7385** for the [rowid] are set as follows:7386**7387** <pre>7388** data type: "INTEGER"7389** collation sequence: "BINARY"7390** not null: 07391** primary key: 17392** auto increment: 07393** </pre>)^7394**7395** ^This function causes all database schemas to be read from disk and7396** parsed, if that has not already been done, and returns an error if7397** any errors are encountered while loading the schema.7398*/7399SQLITE_API int sqlite3_table_column_metadata(7400sqlite3 *db, /* Connection handle */7401const char *zDbName, /* Database name or NULL */7402const char *zTableName, /* Table name */7403const char *zColumnName, /* Column name */7404char const **pzDataType, /* OUTPUT: Declared data type */7405char const **pzCollSeq, /* OUTPUT: Collation sequence name */7406int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */7407int *pPrimaryKey, /* OUTPUT: True if column part of PK */7408int *pAutoinc /* OUTPUT: True if column is auto-increment */7409);74107411/*7412** CAPI3REF: Load An Extension7413** METHOD: sqlite37414**7415** ^This interface loads an SQLite extension library from the named file.7416**7417** ^The sqlite3_load_extension() interface attempts to load an7418** [SQLite extension] library contained in the file zFile. If7419** the file cannot be loaded directly, attempts are made to load7420** with various operating-system specific extensions added.7421** So for example, if "samplelib" cannot be loaded, then names like7422** "samplelib.so" or "samplelib.dylib" or "samplelib.dll" might7423** be tried also.7424**7425** ^The entry point is zProc.7426** ^(zProc may be 0, in which case SQLite will try to come up with an7427** entry point name on its own. It first tries "sqlite3_extension_init".7428** If that does not work, it constructs a name "sqlite3_X_init" where7429** X consists of the lower-case equivalent of all ASCII alphabetic7430** characters in the filename from the last "/" to the first following7431** "." and omitting any initial "lib".)^7432** ^The sqlite3_load_extension() interface returns7433** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.7434** ^If an error occurs and pzErrMsg is not 0, then the7435** [sqlite3_load_extension()] interface shall attempt to7436** fill *pzErrMsg with error message text stored in memory7437** obtained from [sqlite3_malloc()]. The calling function7438** should free this memory by calling [sqlite3_free()].7439**7440** ^Extension loading must be enabled using7441** [sqlite3_enable_load_extension()] or7442** [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],1,NULL)7443** prior to calling this API,7444** otherwise an error will be returned.7445**7446** <b>Security warning:</b> It is recommended that the7447** [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method be used to enable only this7448** interface. The use of the [sqlite3_enable_load_extension()] interface7449** should be avoided. This will keep the SQL function [load_extension()]7450** disabled and prevent SQL injections from giving attackers7451** access to extension loading capabilities.7452**7453** See also the [load_extension() SQL function].7454*/7455SQLITE_API int sqlite3_load_extension(7456sqlite3 *db, /* Load the extension into this database connection */7457const char *zFile, /* Name of the shared library containing extension */7458const char *zProc, /* Entry point. Derived from zFile if 0 */7459char **pzErrMsg /* Put error message here if not 0 */7460);74617462/*7463** CAPI3REF: Enable Or Disable Extension Loading7464** METHOD: sqlite37465**7466** ^So as not to open security holes in older applications that are7467** unprepared to deal with [extension loading], and as a means of disabling7468** [extension loading] while evaluating user-entered SQL, the following API7469** is provided to turn the [sqlite3_load_extension()] mechanism on and off.7470**7471** ^Extension loading is off by default.7472** ^Call the sqlite3_enable_load_extension() routine with onoff==17473** to turn extension loading on and call it with onoff==0 to turn7474** it back off again.7475**7476** ^This interface enables or disables both the C-API7477** [sqlite3_load_extension()] and the SQL function [load_extension()].7478** ^(Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)7479** to enable or disable only the C-API.)^7480**7481** <b>Security warning:</b> It is recommended that extension loading7482** be enabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method7483** rather than this interface, so the [load_extension()] SQL function7484** remains disabled. This will prevent SQL injections from giving attackers7485** access to extension loading capabilities.7486*/7487SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);74887489/*7490** CAPI3REF: Automatically Load Statically Linked Extensions7491**7492** ^This interface causes the xEntryPoint() function to be invoked for7493** each new [database connection] that is created. The idea here is that7494** xEntryPoint() is the entry point for a statically linked [SQLite extension]7495** that is to be automatically loaded into all new database connections.7496**7497** ^(Even though the function prototype shows that xEntryPoint() takes7498** no arguments and returns void, SQLite invokes xEntryPoint() with three7499** arguments and expects an integer result as if the signature of the7500** entry point were as follows:7501**7502** <blockquote><pre>7503** int xEntryPoint(7504** sqlite3 *db,7505** const char **pzErrMsg,7506** const struct sqlite3_api_routines *pThunk7507** );7508** </pre></blockquote>)^7509**7510** If the xEntryPoint routine encounters an error, it should make *pzErrMsg7511** point to an appropriate error message (obtained from [sqlite3_mprintf()])7512** and return an appropriate [error code]. ^SQLite ensures that *pzErrMsg7513** is NULL before calling the xEntryPoint(). ^SQLite will invoke7514** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns. ^If any7515** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()],7516** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail.7517**7518** ^Calling sqlite3_auto_extension(X) with an entry point X that is already7519** on the list of automatic extensions is a harmless no-op. ^No entry point7520** will be called more than once for each database connection that is opened.7521**7522** See also: [sqlite3_reset_auto_extension()]7523** and [sqlite3_cancel_auto_extension()]7524*/7525SQLITE_API int sqlite3_auto_extension(void(*xEntryPoint)(void));75267527/*7528** CAPI3REF: Cancel Automatic Extension Loading7529**7530** ^The [sqlite3_cancel_auto_extension(X)] interface unregisters the7531** initialization routine X that was registered using a prior call to7532** [sqlite3_auto_extension(X)]. ^The [sqlite3_cancel_auto_extension(X)]7533** routine returns 1 if initialization routine X was successfully7534** unregistered and it returns 0 if X was not on the list of initialization7535** routines.7536*/7537SQLITE_API int sqlite3_cancel_auto_extension(void(*xEntryPoint)(void));75387539/*7540** CAPI3REF: Reset Automatic Extension Loading7541**7542** ^This interface disables all automatic extensions previously7543** registered using [sqlite3_auto_extension()].7544*/7545SQLITE_API void sqlite3_reset_auto_extension(void);75467547/*7548** Structures used by the virtual table interface7549*/7550typedef struct sqlite3_vtab sqlite3_vtab;7551typedef struct sqlite3_index_info sqlite3_index_info;7552typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor;7553typedef struct sqlite3_module sqlite3_module;75547555/*7556** CAPI3REF: Virtual Table Object7557** KEYWORDS: sqlite3_module {virtual table module}7558**7559** This structure, sometimes called a "virtual table module",7560** defines the implementation of a [virtual table].7561** This structure consists mostly of methods for the module.7562**7563** ^A virtual table module is created by filling in a persistent7564** instance of this structure and passing a pointer to that instance7565** to [sqlite3_create_module()] or [sqlite3_create_module_v2()].7566** ^The registration remains valid until it is replaced by a different7567** module or until the [database connection] closes. The content7568** of this structure must not change while it is registered with7569** any database connection.7570*/7571struct sqlite3_module {7572int iVersion;7573int (*xCreate)(sqlite3*, void *pAux,7574int argc, const char *const*argv,7575sqlite3_vtab **ppVTab, char**);7576int (*xConnect)(sqlite3*, void *pAux,7577int argc, const char *const*argv,7578sqlite3_vtab **ppVTab, char**);7579int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);7580int (*xDisconnect)(sqlite3_vtab *pVTab);7581int (*xDestroy)(sqlite3_vtab *pVTab);7582int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor);7583int (*xClose)(sqlite3_vtab_cursor*);7584int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr,7585int argc, sqlite3_value **argv);7586int (*xNext)(sqlite3_vtab_cursor*);7587int (*xEof)(sqlite3_vtab_cursor*);7588int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int);7589int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid);7590int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *);7591int (*xBegin)(sqlite3_vtab *pVTab);7592int (*xSync)(sqlite3_vtab *pVTab);7593int (*xCommit)(sqlite3_vtab *pVTab);7594int (*xRollback)(sqlite3_vtab *pVTab);7595int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,7596void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),7597void **ppArg);7598int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);7599/* The methods above are in version 1 of the sqlite_module object. Those7600** below are for version 2 and greater. */7601int (*xSavepoint)(sqlite3_vtab *pVTab, int);7602int (*xRelease)(sqlite3_vtab *pVTab, int);7603int (*xRollbackTo)(sqlite3_vtab *pVTab, int);7604/* The methods above are in versions 1 and 2 of the sqlite_module object.7605** Those below are for version 3 and greater. */7606int (*xShadowName)(const char*);7607/* The methods above are in versions 1 through 3 of the sqlite_module object.7608** Those below are for version 4 and greater. */7609int (*xIntegrity)(sqlite3_vtab *pVTab, const char *zSchema,7610const char *zTabName, int mFlags, char **pzErr);7611};76127613/*7614** CAPI3REF: Virtual Table Indexing Information7615** KEYWORDS: sqlite3_index_info7616**7617** The sqlite3_index_info structure and its substructures is used as part7618** of the [virtual table] interface to7619** pass information into and receive the reply from the [xBestIndex]7620** method of a [virtual table module]. The fields under **Inputs** are the7621** inputs to xBestIndex and are read-only. xBestIndex inserts its7622** results into the **Outputs** fields.7623**7624** ^(The aConstraint[] array records WHERE clause constraints of the form:7625**7626** <blockquote>column OP expr</blockquote>7627**7628** where OP is =, <, <=, >, or >=.)^ ^(The particular operator is7629** stored in aConstraint[].op using one of the7630** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^7631** ^(The index of the column is stored in7632** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the7633** expr on the right-hand side can be evaluated (and thus the constraint7634** is usable) and false if it cannot.)^7635**7636** ^The optimizer automatically inverts terms of the form "expr OP column"7637** and makes other simplifications to the WHERE clause in an attempt to7638** get as many WHERE clause terms into the form shown above as possible.7639** ^The aConstraint[] array only reports WHERE clause terms that are7640** relevant to the particular virtual table being queried.7641**7642** ^Information about the ORDER BY clause is stored in aOrderBy[].7643** ^Each term of aOrderBy records a column of the ORDER BY clause.7644**7645** The colUsed field indicates which columns of the virtual table may be7646** required by the current scan. Virtual table columns are numbered from7647** zero in the order in which they appear within the CREATE TABLE statement7648** passed to sqlite3_declare_vtab(). For the first 63 columns (columns 0-62),7649** the corresponding bit is set within the colUsed mask if the column may be7650** required by SQLite. If the table has at least 64 columns and any column7651** to the right of the first 63 is required, then bit 63 of colUsed is also7652** set. In other words, column iCol may be required if the expression7653** (colUsed & ((sqlite3_uint64)1 << (iCol>=63 ? 63 : iCol))) evaluates to7654** non-zero.7655**7656** The [xBestIndex] method must fill aConstraintUsage[] with information7657** about what parameters to pass to xFilter. ^If argvIndex>0 then7658** the right-hand side of the corresponding aConstraint[] is evaluated7659** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit7660** is true, then the constraint is assumed to be fully handled by the7661** virtual table and might not be checked again by the byte code.)^ ^(The7662** aConstraintUsage[].omit flag is an optimization hint. When the omit flag7663** is left in its default setting of false, the constraint will always be7664** checked separately in byte code. If the omit flag is changed to true, then7665** the constraint may or may not be checked in byte code. In other words,7666** when the omit flag is true there is no guarantee that the constraint will7667** not be checked again using byte code.)^7668**7669** ^The idxNum and idxStr values are recorded and passed into the7670** [xFilter] method.7671** ^[sqlite3_free()] is used to free idxStr if and only if7672** needToFreeIdxStr is true.7673**7674** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in7675** the correct order to satisfy the ORDER BY clause so that no separate7676** sorting step is required.7677**7678** ^The estimatedCost value is an estimate of the cost of a particular7679** strategy. A cost of N indicates that the cost of the strategy is similar7680** to a linear scan of an SQLite table with N rows. A cost of log(N)7681** indicates that the expense of the operation is similar to that of a7682** binary search on a unique indexed field of an SQLite table with N rows.7683**7684** ^The estimatedRows value is an estimate of the number of rows that7685** will be returned by the strategy.7686**7687** The xBestIndex method may optionally populate the idxFlags field with a7688** mask of SQLITE_INDEX_SCAN_* flags. One such flag is7689** [SQLITE_INDEX_SCAN_HEX], which if set causes the [EXPLAIN QUERY PLAN]7690** output to show the idxNum as hex instead of as decimal. Another flag is7691** SQLITE_INDEX_SCAN_UNIQUE, which if set indicates that the query plan will7692** return at most one row.7693**7694** Additionally, if xBestIndex sets the SQLITE_INDEX_SCAN_UNIQUE flag, then7695** SQLite also assumes that if a call to the xUpdate() method is made as7696** part of the same statement to delete or update a virtual table row and the7697** implementation returns SQLITE_CONSTRAINT, then there is no need to rollback7698** any database changes. In other words, if the xUpdate() returns7699** SQLITE_CONSTRAINT, the database contents must be exactly as they were7700** before xUpdate was called. By contrast, if SQLITE_INDEX_SCAN_UNIQUE is not7701** set and xUpdate returns SQLITE_CONSTRAINT, any database changes made by7702** the xUpdate method are automatically rolled back by SQLite.7703**7704** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info7705** structure for SQLite [version 3.8.2] ([dateof:3.8.2]).7706** If a virtual table extension is7707** used with an SQLite version earlier than 3.8.2, the results of attempting7708** to read or write the estimatedRows field are undefined (but are likely7709** to include crashing the application). The estimatedRows field should7710** therefore only be used if [sqlite3_libversion_number()] returns a7711** value greater than or equal to 3008002. Similarly, the idxFlags field7712** was added for [version 3.9.0] ([dateof:3.9.0]).7713** It may therefore only be used if7714** sqlite3_libversion_number() returns a value greater than or equal to7715** 3009000.7716*/7717struct sqlite3_index_info {7718/* Inputs */7719int nConstraint; /* Number of entries in aConstraint */7720struct sqlite3_index_constraint {7721int iColumn; /* Column constrained. -1 for ROWID */7722unsigned char op; /* Constraint operator */7723unsigned char usable; /* True if this constraint is usable */7724int iTermOffset; /* Used internally - xBestIndex should ignore */7725} *aConstraint; /* Table of WHERE clause constraints */7726int nOrderBy; /* Number of terms in the ORDER BY clause */7727struct sqlite3_index_orderby {7728int iColumn; /* Column number */7729unsigned char desc; /* True for DESC. False for ASC. */7730} *aOrderBy; /* The ORDER BY clause */7731/* Outputs */7732struct sqlite3_index_constraint_usage {7733int argvIndex; /* if >0, constraint is part of argv to xFilter */7734unsigned char omit; /* Do not code a test for this constraint */7735} *aConstraintUsage;7736int idxNum; /* Number used to identify the index */7737char *idxStr; /* String, possibly obtained from sqlite3_malloc */7738int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */7739int orderByConsumed; /* True if output is already ordered */7740double estimatedCost; /* Estimated cost of using this index */7741/* Fields below are only available in SQLite 3.8.2 and later */7742sqlite3_int64 estimatedRows; /* Estimated number of rows returned */7743/* Fields below are only available in SQLite 3.9.0 and later */7744int idxFlags; /* Mask of SQLITE_INDEX_SCAN_* flags */7745/* Fields below are only available in SQLite 3.10.0 and later */7746sqlite3_uint64 colUsed; /* Input: Mask of columns used by statement */7747};77487749/*7750** CAPI3REF: Virtual Table Scan Flags7751**7752** Virtual table implementations are allowed to set the7753** [sqlite3_index_info].idxFlags field to some combination of7754** these bits.7755*/7756#define SQLITE_INDEX_SCAN_UNIQUE 0x00000001 /* Scan visits at most 1 row */7757#define SQLITE_INDEX_SCAN_HEX 0x00000002 /* Display idxNum as hex */7758/* in EXPLAIN QUERY PLAN */77597760/*7761** CAPI3REF: Virtual Table Constraint Operator Codes7762**7763** These macros define the allowed values for the7764** [sqlite3_index_info].aConstraint[].op field. Each value represents7765** an operator that is part of a constraint term in the WHERE clause of7766** a query that uses a [virtual table].7767**7768** ^The left-hand operand of the operator is given by the corresponding7769** aConstraint[].iColumn field. ^An iColumn of -1 indicates the left-hand7770** operand is the rowid.7771** The SQLITE_INDEX_CONSTRAINT_LIMIT and SQLITE_INDEX_CONSTRAINT_OFFSET7772** operators have no left-hand operand, and so for those operators the7773** corresponding aConstraint[].iColumn is meaningless and should not be7774** used.7775**7776** All operator values from SQLITE_INDEX_CONSTRAINT_FUNCTION through7777** value 255 are reserved to represent functions that are overloaded7778** by the [xFindFunction|xFindFunction method] of the virtual table7779** implementation.7780**7781** The right-hand operands for each constraint might be accessible using7782** the [sqlite3_vtab_rhs_value()] interface. Usually the right-hand7783** operand is only available if it appears as a single constant literal7784** in the input SQL. If the right-hand operand is another column or an7785** expression (even a constant expression) or a parameter, then the7786** sqlite3_vtab_rhs_value() probably will not be able to extract it.7787** ^The SQLITE_INDEX_CONSTRAINT_ISNULL and7788** SQLITE_INDEX_CONSTRAINT_ISNOTNULL operators have no right-hand operand7789** and hence calls to sqlite3_vtab_rhs_value() for those operators will7790** always return SQLITE_NOTFOUND.7791**7792** The collating sequence to be used for comparison can be found using7793** the [sqlite3_vtab_collation()] interface. For most real-world virtual7794** tables, the collating sequence of constraints does not matter (for example7795** because the constraints are numeric) and so the sqlite3_vtab_collation()7796** interface is not commonly needed.7797*/7798#define SQLITE_INDEX_CONSTRAINT_EQ 27799#define SQLITE_INDEX_CONSTRAINT_GT 47800#define SQLITE_INDEX_CONSTRAINT_LE 87801#define SQLITE_INDEX_CONSTRAINT_LT 167802#define SQLITE_INDEX_CONSTRAINT_GE 327803#define SQLITE_INDEX_CONSTRAINT_MATCH 647804#define SQLITE_INDEX_CONSTRAINT_LIKE 657805#define SQLITE_INDEX_CONSTRAINT_GLOB 667806#define SQLITE_INDEX_CONSTRAINT_REGEXP 677807#define SQLITE_INDEX_CONSTRAINT_NE 687808#define SQLITE_INDEX_CONSTRAINT_ISNOT 697809#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 707810#define SQLITE_INDEX_CONSTRAINT_ISNULL 717811#define SQLITE_INDEX_CONSTRAINT_IS 727812#define SQLITE_INDEX_CONSTRAINT_LIMIT 737813#define SQLITE_INDEX_CONSTRAINT_OFFSET 747814#define SQLITE_INDEX_CONSTRAINT_FUNCTION 15078157816/*7817** CAPI3REF: Register A Virtual Table Implementation7818** METHOD: sqlite37819**7820** ^These routines are used to register a new [virtual table module] name.7821** ^Module names must be registered before7822** creating a new [virtual table] using the module and before using a7823** preexisting [virtual table] for the module.7824**7825** ^The module name is registered on the [database connection] specified7826** by the first parameter. ^The name of the module is given by the7827** second parameter. ^The third parameter is a pointer to7828** the implementation of the [virtual table module]. ^The fourth7829** parameter is an arbitrary client data pointer that is passed through7830** into the [xCreate] and [xConnect] methods of the virtual table module7831** when a new virtual table is being created or reinitialized.7832**7833** ^The sqlite3_create_module_v2() interface has a fifth parameter which7834** is a pointer to a destructor for the pClientData. ^SQLite will7835** invoke the destructor function (if it is not NULL) when SQLite7836** no longer needs the pClientData pointer. ^The destructor will also7837** be invoked if the call to sqlite3_create_module_v2() fails.7838** ^The sqlite3_create_module()7839** interface is equivalent to sqlite3_create_module_v2() with a NULL7840** destructor.7841**7842** ^If the third parameter (the pointer to the sqlite3_module object) is7843** NULL then no new module is created and any existing modules with the7844** same name are dropped.7845**7846** See also: [sqlite3_drop_modules()]7847*/7848SQLITE_API int sqlite3_create_module(7849sqlite3 *db, /* SQLite connection to register module with */7850const char *zName, /* Name of the module */7851const sqlite3_module *p, /* Methods for the module */7852void *pClientData /* Client data for xCreate/xConnect */7853);7854SQLITE_API int sqlite3_create_module_v2(7855sqlite3 *db, /* SQLite connection to register module with */7856const char *zName, /* Name of the module */7857const sqlite3_module *p, /* Methods for the module */7858void *pClientData, /* Client data for xCreate/xConnect */7859void(*xDestroy)(void*) /* Module destructor function */7860);78617862/*7863** CAPI3REF: Remove Unnecessary Virtual Table Implementations7864** METHOD: sqlite37865**7866** ^The sqlite3_drop_modules(D,L) interface removes all virtual7867** table modules from database connection D except those named on list L.7868** The L parameter must be either NULL or a pointer to an array of pointers7869** to strings where the array is terminated by a single NULL pointer.7870** ^If the L parameter is NULL, then all virtual table modules are removed.7871**7872** See also: [sqlite3_create_module()]7873*/7874SQLITE_API int sqlite3_drop_modules(7875sqlite3 *db, /* Remove modules from this connection */7876const char **azKeep /* Except, do not remove the ones named here */7877);78787879/*7880** CAPI3REF: Virtual Table Instance Object7881** KEYWORDS: sqlite3_vtab7882**7883** Every [virtual table module] implementation uses a subclass7884** of this object to describe a particular instance7885** of the [virtual table]. Each subclass will7886** be tailored to the specific needs of the module implementation.7887** The purpose of this superclass is to define certain fields that are7888** common to all module implementations.7889**7890** ^Virtual tables methods can set an error message by assigning a7891** string obtained from [sqlite3_mprintf()] to zErrMsg. The method should7892** take care that any prior string is freed by a call to [sqlite3_free()]7893** prior to assigning a new string to zErrMsg. ^After the error message7894** is delivered up to the client application, the string will be automatically7895** freed by sqlite3_free() and the zErrMsg field will be zeroed.7896*/7897struct sqlite3_vtab {7898const sqlite3_module *pModule; /* The module for this virtual table */7899int nRef; /* Number of open cursors */7900char *zErrMsg; /* Error message from sqlite3_mprintf() */7901/* Virtual table implementations will typically add additional fields */7902};79037904/*7905** CAPI3REF: Virtual Table Cursor Object7906** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}7907**7908** Every [virtual table module] implementation uses a subclass of the7909** following structure to describe cursors that point into the7910** [virtual table] and are used7911** to loop through the virtual table. Cursors are created using the7912** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed7913** by the [sqlite3_module.xClose | xClose] method. Cursors are used7914** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods7915** of the module. Each module implementation will define7916** the content of a cursor structure to suit its own needs.7917**7918** This superclass exists in order to define fields of the cursor that7919** are common to all implementations.7920*/7921struct sqlite3_vtab_cursor {7922sqlite3_vtab *pVtab; /* Virtual table of this cursor */7923/* Virtual table implementations will typically add additional fields */7924};79257926/*7927** CAPI3REF: Declare The Schema Of A Virtual Table7928**7929** ^The [xCreate] and [xConnect] methods of a7930** [virtual table module] call this interface7931** to declare the format (the names and datatypes of the columns) of7932** the virtual tables they implement.7933*/7934SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL);79357936/*7937** CAPI3REF: Overload A Function For A Virtual Table7938** METHOD: sqlite37939**7940** ^(Virtual tables can provide alternative implementations of functions7941** using the [xFindFunction] method of the [virtual table module].7942** But global versions of those functions7943** must exist in order to be overloaded.)^7944**7945** ^(This API makes sure a global version of a function with a particular7946** name and number of parameters exists. If no such function exists7947** before this API is called, a new function is created.)^ ^The implementation7948** of the new function always causes an exception to be thrown. So7949** the new function is not good for anything by itself. Its only7950** purpose is to be a placeholder function that can be overloaded7951** by a [virtual table].7952*/7953SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);79547955/*7956** CAPI3REF: A Handle To An Open BLOB7957** KEYWORDS: {BLOB handle} {BLOB handles}7958**7959** An instance of this object represents an open BLOB on which7960** [sqlite3_blob_open | incremental BLOB I/O] can be performed.7961** ^Objects of this type are created by [sqlite3_blob_open()]7962** and destroyed by [sqlite3_blob_close()].7963** ^The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces7964** can be used to read or write small subsections of the BLOB.7965** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes.7966*/7967typedef struct sqlite3_blob sqlite3_blob;79687969/*7970** CAPI3REF: Open A BLOB For Incremental I/O7971** METHOD: sqlite37972** CONSTRUCTOR: sqlite3_blob7973**7974** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located7975** in row iRow, column zColumn, table zTable in database zDb;7976** in other words, the same BLOB that would be selected by:7977**7978** <pre>7979** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;7980** </pre>)^7981**7982** ^(Parameter zDb is not the filename that contains the database, but7983** rather the symbolic name of the database. For attached databases, this is7984** the name that appears after the AS keyword in the [ATTACH] statement.7985** For the main database file, the database name is "main". For TEMP7986** tables, the database name is "temp".)^7987**7988** ^If the flags parameter is non-zero, then the BLOB is opened for read7989** and write access. ^If the flags parameter is zero, the BLOB is opened for7990** read-only access.7991**7992** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored7993** in *ppBlob. Otherwise an [error code] is returned and, unless the error7994** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided7995** the API is not misused, it is always safe to call [sqlite3_blob_close()]7996** on *ppBlob after this function returns.7997**7998** This function fails with SQLITE_ERROR if any of the following are true:7999** <ul>8000** <li> ^(Database zDb does not exist)^,8001** <li> ^(Table zTable does not exist within database zDb)^,8002** <li> ^(Table zTable is a WITHOUT ROWID table)^,8003** <li> ^(Column zColumn does not exist)^,8004** <li> ^(Row iRow is not present in the table)^,8005** <li> ^(The specified column of row iRow contains a value that is not8006** a TEXT or BLOB value)^,8007** <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE8008** constraint and the blob is being opened for read/write access)^,8009** <li> ^([foreign key constraints | Foreign key constraints] are enabled,8010** column zColumn is part of a [child key] definition and the blob is8011** being opened for read/write access)^.8012** </ul>8013**8014** ^Unless it returns SQLITE_MISUSE, this function sets the8015** [database connection] error code and message accessible via8016** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.8017**8018** A BLOB referenced by sqlite3_blob_open() may be read using the8019** [sqlite3_blob_read()] interface and modified by using8020** [sqlite3_blob_write()]. The [BLOB handle] can be moved to a8021** different row of the same table using the [sqlite3_blob_reopen()]8022** interface. However, the column, table, or database of a [BLOB handle]8023** cannot be changed after the [BLOB handle] is opened.8024**8025** ^(If the row that a BLOB handle points to is modified by an8026** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects8027** then the BLOB handle is marked as "expired".8028** This is true if any column of the row is changed, even a column8029** other than the one the BLOB handle is open on.)^8030** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for8031** an expired BLOB handle fail with a return code of [SQLITE_ABORT].8032** ^(Changes written into a BLOB prior to the BLOB expiring are not8033** rolled back by the expiration of the BLOB. Such changes will eventually8034** commit if the transaction continues to completion.)^8035**8036** ^Use the [sqlite3_blob_bytes()] interface to determine the size of8037** the opened blob. ^The size of a blob may not be changed by this8038** interface. Use the [UPDATE] SQL command to change the size of a8039** blob.8040**8041** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces8042** and the built-in [zeroblob] SQL function may be used to create a8043** zero-filled blob to read or write using the incremental-blob interface.8044**8045** To avoid a resource leak, every open [BLOB handle] should eventually8046** be released by a call to [sqlite3_blob_close()].8047**8048** See also: [sqlite3_blob_close()],8049** [sqlite3_blob_reopen()], [sqlite3_blob_read()],8050** [sqlite3_blob_bytes()], [sqlite3_blob_write()].8051*/8052SQLITE_API int sqlite3_blob_open(8053sqlite3*,8054const char *zDb,8055const char *zTable,8056const char *zColumn,8057sqlite3_int64 iRow,8058int flags,8059sqlite3_blob **ppBlob8060);80618062/*8063** CAPI3REF: Move a BLOB Handle to a New Row8064** METHOD: sqlite3_blob8065**8066** ^This function is used to move an existing [BLOB handle] so that it points8067** to a different row of the same database table. ^The new row is identified8068** by the rowid value passed as the second argument. Only the row can be8069** changed. ^The database, table and column on which the blob handle is open8070** remain the same. Moving an existing [BLOB handle] to a new row is8071** faster than closing the existing handle and opening a new one.8072**8073** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] -8074** it must exist and there must be either a blob or text value stored in8075** the nominated column.)^ ^If the new row is not present in the table, or if8076** it does not contain a blob or text value, or if another error occurs, an8077** SQLite error code is returned and the blob handle is considered aborted.8078** ^All subsequent calls to [sqlite3_blob_read()], [sqlite3_blob_write()] or8079** [sqlite3_blob_reopen()] on an aborted blob handle immediately return8080** SQLITE_ABORT. ^Calling [sqlite3_blob_bytes()] on an aborted blob handle8081** always returns zero.8082**8083** ^This function sets the database handle error code and message.8084*/8085SQLITE_API int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);80868087/*8088** CAPI3REF: Close A BLOB Handle8089** DESTRUCTOR: sqlite3_blob8090**8091** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed8092** unconditionally. Even if this routine returns an error code, the8093** handle is still closed.)^8094**8095** ^If the blob handle being closed was opened for read-write access, and if8096** the database is in auto-commit mode and there are no other open read-write8097** blob handles or active write statements, the current transaction is8098** committed. ^If an error occurs while committing the transaction, an error8099** code is returned and the transaction rolled back.8100**8101** Calling this function with an argument that is not a NULL pointer or an8102** open blob handle results in undefined behavior. ^Calling this routine8103** with a null pointer (such as would be returned by a failed call to8104** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function8105** is passed a valid open blob handle, the values returned by the8106** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.8107*/8108SQLITE_API int sqlite3_blob_close(sqlite3_blob *);81098110/*8111** CAPI3REF: Return The Size Of An Open BLOB8112** METHOD: sqlite3_blob8113**8114** ^Returns the size in bytes of the BLOB accessible via the8115** successfully opened [BLOB handle] in its only argument. ^The8116** incremental blob I/O routines can only read or overwrite existing8117** blob content; they cannot change the size of a blob.8118**8119** This routine only works on a [BLOB handle] which has been created8120** by a prior successful call to [sqlite3_blob_open()] and which has not8121** been closed by [sqlite3_blob_close()]. Passing any other pointer in8122** to this routine results in undefined and probably undesirable behavior.8123*/8124SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *);81258126/*8127** CAPI3REF: Read Data From A BLOB Incrementally8128** METHOD: sqlite3_blob8129**8130** ^(This function is used to read data from an open [BLOB handle] into a8131** caller-supplied buffer. N bytes of data are copied into buffer Z8132** from the open BLOB, starting at offset iOffset.)^8133**8134** ^If offset iOffset is less than N bytes from the end of the BLOB,8135** [SQLITE_ERROR] is returned and no data is read. ^If N or iOffset is8136** less than zero, [SQLITE_ERROR] is returned and no data is read.8137** ^The size of the blob (and hence the maximum value of N+iOffset)8138** can be determined using the [sqlite3_blob_bytes()] interface.8139**8140** ^An attempt to read from an expired [BLOB handle] fails with an8141** error code of [SQLITE_ABORT].8142**8143** ^(On success, sqlite3_blob_read() returns SQLITE_OK.8144** Otherwise, an [error code] or an [extended error code] is returned.)^8145**8146** This routine only works on a [BLOB handle] which has been created8147** by a prior successful call to [sqlite3_blob_open()] and which has not8148** been closed by [sqlite3_blob_close()]. Passing any other pointer in8149** to this routine results in undefined and probably undesirable behavior.8150**8151** See also: [sqlite3_blob_write()].8152*/8153SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);81548155/*8156** CAPI3REF: Write Data Into A BLOB Incrementally8157** METHOD: sqlite3_blob8158**8159** ^(This function is used to write data into an open [BLOB handle] from a8160** caller-supplied buffer. N bytes of data are copied from the buffer Z8161** into the open BLOB, starting at offset iOffset.)^8162**8163** ^(On success, sqlite3_blob_write() returns SQLITE_OK.8164** Otherwise, an [error code] or an [extended error code] is returned.)^8165** ^Unless SQLITE_MISUSE is returned, this function sets the8166** [database connection] error code and message accessible via8167** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.8168**8169** ^If the [BLOB handle] passed as the first argument was not opened for8170** writing (the flags parameter to [sqlite3_blob_open()] was zero),8171** this function returns [SQLITE_READONLY].8172**8173** This function may only modify the contents of the BLOB; it is8174** not possible to increase the size of a BLOB using this API.8175** ^If offset iOffset is less than N bytes from the end of the BLOB,8176** [SQLITE_ERROR] is returned and no data is written. The size of the8177** BLOB (and hence the maximum value of N+iOffset) can be determined8178** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less8179** than zero [SQLITE_ERROR] is returned and no data is written.8180**8181** ^An attempt to write to an expired [BLOB handle] fails with an8182** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred8183** before the [BLOB handle] expired are not rolled back by the8184** expiration of the handle, though of course those changes might8185** have been overwritten by the statement that expired the BLOB handle8186** or by other independent statements.8187**8188** This routine only works on a [BLOB handle] which has been created8189** by a prior successful call to [sqlite3_blob_open()] and which has not8190** been closed by [sqlite3_blob_close()]. Passing any other pointer in8191** to this routine results in undefined and probably undesirable behavior.8192**8193** See also: [sqlite3_blob_read()].8194*/8195SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);81968197/*8198** CAPI3REF: Virtual File System Objects8199**8200** A virtual filesystem (VFS) is an [sqlite3_vfs] object8201** that SQLite uses to interact8202** with the underlying operating system. Most SQLite builds come with a8203** single default VFS that is appropriate for the host computer.8204** New VFSes can be registered and existing VFSes can be unregistered.8205** The following interfaces are provided.8206**8207** ^The sqlite3_vfs_find() interface returns a pointer to a VFS given its name.8208** ^Names are case sensitive.8209** ^Names are zero-terminated UTF-8 strings.8210** ^If there is no match, a NULL pointer is returned.8211** ^If zVfsName is NULL then the default VFS is returned.8212**8213** ^New VFSes are registered with sqlite3_vfs_register().8214** ^Each new VFS becomes the default VFS if the makeDflt flag is set.8215** ^The same VFS can be registered multiple times without injury.8216** ^To make an existing VFS into the default VFS, register it again8217** with the makeDflt flag set. If two different VFSes with the8218** same name are registered, the behavior is undefined. If a8219** VFS is registered with a name that is NULL or an empty string,8220** then the behavior is undefined.8221**8222** ^Unregister a VFS with the sqlite3_vfs_unregister() interface.8223** ^(If the default VFS is unregistered, another VFS is chosen as8224** the default. The choice for the new VFS is arbitrary.)^8225*/8226SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName);8227SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);8228SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*);82298230/*8231** CAPI3REF: Mutexes8232**8233** The SQLite core uses these routines for thread8234** synchronization. Though they are intended for internal8235** use by SQLite, code that links against SQLite is8236** permitted to use any of these routines.8237**8238** The SQLite source code contains multiple implementations8239** of these mutex routines. An appropriate implementation8240** is selected automatically at compile-time. The following8241** implementations are available in the SQLite core:8242**8243** <ul>8244** <li> SQLITE_MUTEX_PTHREADS8245** <li> SQLITE_MUTEX_W328246** <li> SQLITE_MUTEX_NOOP8247** </ul>8248**8249** The SQLITE_MUTEX_NOOP implementation is a set of routines8250** that does no real locking and is appropriate for use in8251** a single-threaded application. The SQLITE_MUTEX_PTHREADS and8252** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix8253** and Windows.8254**8255** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor8256** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex8257** implementation is included with the library. In this case the8258** application must supply a custom mutex implementation using the8259** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function8260** before calling sqlite3_initialize() or any other public sqlite3_8261** function that calls sqlite3_initialize().8262**8263** ^The sqlite3_mutex_alloc() routine allocates a new8264** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()8265** routine returns NULL if it is unable to allocate the requested8266** mutex. The argument to sqlite3_mutex_alloc() must be one of these8267** integer constants:8268**8269** <ul>8270** <li> SQLITE_MUTEX_FAST8271** <li> SQLITE_MUTEX_RECURSIVE8272** <li> SQLITE_MUTEX_STATIC_MAIN8273** <li> SQLITE_MUTEX_STATIC_MEM8274** <li> SQLITE_MUTEX_STATIC_OPEN8275** <li> SQLITE_MUTEX_STATIC_PRNG8276** <li> SQLITE_MUTEX_STATIC_LRU8277** <li> SQLITE_MUTEX_STATIC_PMEM8278** <li> SQLITE_MUTEX_STATIC_APP18279** <li> SQLITE_MUTEX_STATIC_APP28280** <li> SQLITE_MUTEX_STATIC_APP38281** <li> SQLITE_MUTEX_STATIC_VFS18282** <li> SQLITE_MUTEX_STATIC_VFS28283** <li> SQLITE_MUTEX_STATIC_VFS38284** </ul>8285**8286** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)8287** cause sqlite3_mutex_alloc() to create8288** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE8289** is used but not necessarily so when SQLITE_MUTEX_FAST is used.8290** The mutex implementation does not need to make a distinction8291** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does8292** not want to. SQLite will only request a recursive mutex in8293** cases where it really needs one. If a faster non-recursive mutex8294** implementation is available on the host platform, the mutex subsystem8295** might return such a mutex in response to SQLITE_MUTEX_FAST.8296**8297** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other8298** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return8299** a pointer to a static preexisting mutex. ^Nine static mutexes are8300** used by the current version of SQLite. Future versions of SQLite8301** may add additional static mutexes. Static mutexes are for internal8302** use by SQLite only. Applications that use SQLite mutexes should8303** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or8304** SQLITE_MUTEX_RECURSIVE.8305**8306** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST8307** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()8308** returns a different mutex on every call. ^For the static8309** mutex types, the same mutex is returned on every call that has8310** the same type number.8311**8312** ^The sqlite3_mutex_free() routine deallocates a previously8313** allocated dynamic mutex. Attempting to deallocate a static8314** mutex results in undefined behavior.8315**8316** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt8317** to enter a mutex. ^If another thread is already within the mutex,8318** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return8319** SQLITE_BUSY. ^The sqlite3_mutex_try() interface returns [SQLITE_OK]8320** upon successful entry. ^(Mutexes created using8321** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.8322** In such cases, the8323** mutex must be exited an equal number of times before another thread8324** can enter.)^ If the same thread tries to enter any mutex other8325** than an SQLITE_MUTEX_RECURSIVE more than once, the behavior is undefined.8326**8327** ^(Some systems (for example, Windows 95) do not support the operation8328** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try()8329** will always return SQLITE_BUSY. In most cases the SQLite core only uses8330** sqlite3_mutex_try() as an optimization, so this is acceptable8331** behavior. The exceptions are unix builds that set the8332** SQLITE_ENABLE_SETLK_TIMEOUT build option. In that case a working8333** sqlite3_mutex_try() is required.)^8334**8335** ^The sqlite3_mutex_leave() routine exits a mutex that was8336** previously entered by the same thread. The behavior8337** is undefined if the mutex is not currently entered by the8338** calling thread or is not currently allocated.8339**8340** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(),8341** sqlite3_mutex_leave(), or sqlite3_mutex_free() is a NULL pointer,8342** then any of the four routines behaves as a no-op.8343**8344** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()].8345*/8346SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int);8347SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*);8348SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*);8349SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);8350SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);83518352/*8353** CAPI3REF: Mutex Methods Object8354**8355** An instance of this structure defines the low-level routines8356** used to allocate and use mutexes.8357**8358** Usually, the default mutex implementations provided by SQLite are8359** sufficient, however the application has the option of substituting a custom8360** implementation for specialized deployments or systems for which SQLite8361** does not provide a suitable implementation. In this case, the application8362** creates and populates an instance of this structure to pass8363** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option.8364** Additionally, an instance of this structure can be used as an8365** output variable when querying the system for the current mutex8366** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.8367**8368** ^The xMutexInit method defined by this structure is invoked as8369** part of system initialization by the sqlite3_initialize() function.8370** ^The xMutexInit routine is called by SQLite exactly once for each8371** effective call to [sqlite3_initialize()].8372**8373** ^The xMutexEnd method defined by this structure is invoked as8374** part of system shutdown by the sqlite3_shutdown() function. The8375** implementation of this method is expected to release all outstanding8376** resources obtained by the mutex methods implementation, especially8377** those obtained by the xMutexInit method. ^The xMutexEnd()8378** interface is invoked exactly once for each call to [sqlite3_shutdown()].8379**8380** ^(The remaining seven methods defined by this structure (xMutexAlloc,8381** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and8382** xMutexNotheld) implement the following interfaces (respectively):8383**8384** <ul>8385** <li> [sqlite3_mutex_alloc()] </li>8386** <li> [sqlite3_mutex_free()] </li>8387** <li> [sqlite3_mutex_enter()] </li>8388** <li> [sqlite3_mutex_try()] </li>8389** <li> [sqlite3_mutex_leave()] </li>8390** <li> [sqlite3_mutex_held()] </li>8391** <li> [sqlite3_mutex_notheld()] </li>8392** </ul>)^8393**8394** The only difference is that the public sqlite3_XXX functions enumerated8395** above silently ignore any invocations that pass a NULL pointer instead8396** of a valid mutex handle. The implementations of the methods defined8397** by this structure are not required to handle this case. The results8398** of passing a NULL pointer instead of a valid mutex handle are undefined8399** (i.e. it is acceptable to provide an implementation that segfaults if8400** it is passed a NULL pointer).8401**8402** The xMutexInit() method must be threadsafe. It must be harmless to8403** invoke xMutexInit() multiple times within the same process and without8404** intervening calls to xMutexEnd(). Second and subsequent calls to8405** xMutexInit() must be no-ops.8406**8407** xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()]8408** and its associates). Similarly, xMutexAlloc() must not use SQLite memory8409** allocation for a static mutex. ^However xMutexAlloc() may use SQLite8410** memory allocation for a fast or recursive mutex.8411**8412** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is8413** called, but only if the prior call to xMutexInit returned SQLITE_OK.8414** If xMutexInit fails in any way, it is expected to clean up after itself8415** prior to returning.8416*/8417typedef struct sqlite3_mutex_methods sqlite3_mutex_methods;8418struct sqlite3_mutex_methods {8419int (*xMutexInit)(void);8420int (*xMutexEnd)(void);8421sqlite3_mutex *(*xMutexAlloc)(int);8422void (*xMutexFree)(sqlite3_mutex *);8423void (*xMutexEnter)(sqlite3_mutex *);8424int (*xMutexTry)(sqlite3_mutex *);8425void (*xMutexLeave)(sqlite3_mutex *);8426int (*xMutexHeld)(sqlite3_mutex *);8427int (*xMutexNotheld)(sqlite3_mutex *);8428};84298430/*8431** CAPI3REF: Mutex Verification Routines8432**8433** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines8434** are intended for use inside assert() statements. The SQLite core8435** never uses these routines except inside an assert() and applications8436** are advised to follow the lead of the core. The SQLite core only8437** provides implementations for these routines when it is compiled8438** with the SQLITE_DEBUG flag. External mutex implementations8439** are only required to provide these routines if SQLITE_DEBUG is8440** defined and if NDEBUG is not defined.8441**8442** These routines should return true if the mutex in their argument8443** is held or not held, respectively, by the calling thread.8444**8445** The implementation is not required to provide versions of these8446** routines that actually work. If the implementation does not provide working8447** versions of these routines, it should at least provide stubs that always8448** return true so that one does not get spurious assertion failures.8449**8450** If the argument to sqlite3_mutex_held() is a NULL pointer then8451** the routine should return 1. This seems counter-intuitive since8452** clearly the mutex cannot be held if it does not exist. But8453** the reason the mutex does not exist is because the build is not8454** using mutexes. And we do not want the assert() containing the8455** call to sqlite3_mutex_held() to fail, so a non-zero return is8456** the appropriate thing to do. The sqlite3_mutex_notheld()8457** interface should also return 1 when given a NULL pointer.8458*/8459#ifndef NDEBUG8460SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*);8461SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*);8462#endif84638464/*8465** CAPI3REF: Mutex Types8466**8467** The [sqlite3_mutex_alloc()] interface takes a single argument8468** which is one of these integer constants.8469**8470** The set of static mutexes may change from one SQLite release to the8471** next. Applications that override the built-in mutex logic must be8472** prepared to accommodate additional static mutexes.8473*/8474#define SQLITE_MUTEX_FAST 08475#define SQLITE_MUTEX_RECURSIVE 18476#define SQLITE_MUTEX_STATIC_MAIN 28477#define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */8478#define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */8479#define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */8480#define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_randomness() */8481#define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */8482#define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */8483#define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */8484#define SQLITE_MUTEX_STATIC_APP1 8 /* For use by application */8485#define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */8486#define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */8487#define SQLITE_MUTEX_STATIC_VFS1 11 /* For use by built-in VFS */8488#define SQLITE_MUTEX_STATIC_VFS2 12 /* For use by extension VFS */8489#define SQLITE_MUTEX_STATIC_VFS3 13 /* For use by application VFS */84908491/* Legacy compatibility: */8492#define SQLITE_MUTEX_STATIC_MASTER 2849384948495/*8496** CAPI3REF: Retrieve the mutex for a database connection8497** METHOD: sqlite38498**8499** ^This interface returns a pointer to the [sqlite3_mutex] object that8500** serializes access to the [database connection] given in the argument8501** when the [threading mode] is Serialized.8502** ^If the [threading mode] is Single-thread or Multi-thread then this8503** routine returns a NULL pointer.8504*/8505SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*);85068507/*8508** CAPI3REF: Low-Level Control Of Database Files8509** METHOD: sqlite38510** KEYWORDS: {file control}8511**8512** ^The [sqlite3_file_control()] interface makes a direct call to the8513** xFileControl method for the [sqlite3_io_methods] object associated8514** with a particular database identified by the second argument. ^The8515** name of the database is "main" for the main database or "temp" for the8516** TEMP database, or the name that appears after the AS keyword for8517** databases that are added using the [ATTACH] SQL command.8518** ^A NULL pointer can be used in place of "main" to refer to the8519** main database file.8520** ^The third and fourth parameters to this routine8521** are passed directly through to the second and third parameters of8522** the xFileControl method. ^The return value of the xFileControl8523** method becomes the return value of this routine.8524**8525** A few opcodes for [sqlite3_file_control()] are handled directly8526** by the SQLite core and never invoke the8527** sqlite3_io_methods.xFileControl method.8528** ^The [SQLITE_FCNTL_FILE_POINTER] value for the op parameter causes8529** a pointer to the underlying [sqlite3_file] object to be written into8530** the space pointed to by the 4th parameter. The8531** [SQLITE_FCNTL_JOURNAL_POINTER] works similarly except that it returns8532** the [sqlite3_file] object associated with the journal file instead of8533** the main database. The [SQLITE_FCNTL_VFS_POINTER] opcode returns8534** a pointer to the underlying [sqlite3_vfs] object for the file.8535** The [SQLITE_FCNTL_DATA_VERSION] returns the data version counter8536** from the pager.8537**8538** ^If the second parameter (zDbName) does not match the name of any8539** open database file, then SQLITE_ERROR is returned. ^This error8540** code is not remembered and will not be recalled by [sqlite3_errcode()]8541** or [sqlite3_errmsg()]. The underlying xFileControl method might8542** also return SQLITE_ERROR. There is no way to distinguish between8543** an incorrect zDbName and an SQLITE_ERROR return from the underlying8544** xFileControl method.8545**8546** See also: [file control opcodes]8547*/8548SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);85498550/*8551** CAPI3REF: Testing Interface8552**8553** ^The sqlite3_test_control() interface is used to read out internal8554** state of SQLite and to inject faults into SQLite for testing8555** purposes. ^The first parameter is an operation code that determines8556** the number, meaning, and operation of all subsequent parameters.8557**8558** This interface is not for use by applications. It exists solely8559** for verifying the correct operation of the SQLite library. Depending8560** on how the SQLite library is compiled, this interface might not exist.8561**8562** The details of the operation codes, their meanings, the parameters8563** they take, and what they do are all subject to change without notice.8564** Unlike most of the SQLite API, this function is not guaranteed to8565** operate consistently from one release to the next.8566*/8567SQLITE_API int sqlite3_test_control(int op, ...);85688569/*8570** CAPI3REF: Testing Interface Operation Codes8571**8572** These constants are the valid operation code parameters used8573** as the first argument to [sqlite3_test_control()].8574**8575** These parameters and their meanings are subject to change8576** without notice. These values are for testing purposes only.8577** Applications should not use any of these parameters or the8578** [sqlite3_test_control()] interface.8579*/8580#define SQLITE_TESTCTRL_FIRST 58581#define SQLITE_TESTCTRL_PRNG_SAVE 58582#define SQLITE_TESTCTRL_PRNG_RESTORE 68583#define SQLITE_TESTCTRL_PRNG_RESET 7 /* NOT USED */8584#define SQLITE_TESTCTRL_FK_NO_ACTION 78585#define SQLITE_TESTCTRL_BITVEC_TEST 88586#define SQLITE_TESTCTRL_FAULT_INSTALL 98587#define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 108588#define SQLITE_TESTCTRL_PENDING_BYTE 118589#define SQLITE_TESTCTRL_ASSERT 128590#define SQLITE_TESTCTRL_ALWAYS 138591#define SQLITE_TESTCTRL_RESERVE 14 /* NOT USED */8592#define SQLITE_TESTCTRL_JSON_SELFCHECK 148593#define SQLITE_TESTCTRL_OPTIMIZATIONS 158594#define SQLITE_TESTCTRL_ISKEYWORD 16 /* NOT USED */8595#define SQLITE_TESTCTRL_GETOPT 168596#define SQLITE_TESTCTRL_SCRATCHMALLOC 17 /* NOT USED */8597#define SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 178598#define SQLITE_TESTCTRL_LOCALTIME_FAULT 188599#define SQLITE_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */8600#define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD 198601#define SQLITE_TESTCTRL_NEVER_CORRUPT 208602#define SQLITE_TESTCTRL_VDBE_COVERAGE 218603#define SQLITE_TESTCTRL_BYTEORDER 228604#define SQLITE_TESTCTRL_ISINIT 238605#define SQLITE_TESTCTRL_SORTER_MMAP 248606#define SQLITE_TESTCTRL_IMPOSTER 258607#define SQLITE_TESTCTRL_PARSER_COVERAGE 268608#define SQLITE_TESTCTRL_RESULT_INTREAL 278609#define SQLITE_TESTCTRL_PRNG_SEED 288610#define SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS 298611#define SQLITE_TESTCTRL_SEEK_COUNT 308612#define SQLITE_TESTCTRL_TRACEFLAGS 318613#define SQLITE_TESTCTRL_TUNE 328614#define SQLITE_TESTCTRL_LOGEST 338615#define SQLITE_TESTCTRL_USELONGDOUBLE 34 /* NOT USED */8616#define SQLITE_TESTCTRL_LAST 34 /* Largest TESTCTRL */86178618/*8619** CAPI3REF: SQL Keyword Checking8620**8621** These routines provide access to the set of SQL language keywords8622** recognized by SQLite. Applications can use these routines to determine8623** whether or not a specific identifier needs to be escaped (for example,8624** by enclosing in double-quotes) so as not to confuse the parser.8625**8626** The sqlite3_keyword_count() interface returns the number of distinct8627** keywords understood by SQLite.8628**8629** The sqlite3_keyword_name(N,Z,L) interface finds the 0-based N-th keyword and8630** makes *Z point to that keyword expressed as UTF8 and writes the number8631** of bytes in the keyword into *L. The string that *Z points to is not8632** zero-terminated. The sqlite3_keyword_name(N,Z,L) routine returns8633** SQLITE_OK if N is within bounds and SQLITE_ERROR if not. If either Z8634** or L are NULL or invalid pointers then calls to8635** sqlite3_keyword_name(N,Z,L) result in undefined behavior.8636**8637** The sqlite3_keyword_check(Z,L) interface checks to see whether or not8638** the L-byte UTF8 identifier that Z points to is a keyword, returning non-zero8639** if it is and zero if not.8640**8641** The parser used by SQLite is forgiving. It is often possible to use8642** a keyword as an identifier as long as such use does not result in a8643** parsing ambiguity. For example, the statement8644** "CREATE TABLE BEGIN(REPLACE,PRAGMA,END);" is accepted by SQLite, and8645** creates a new table named "BEGIN" with three columns named8646** "REPLACE", "PRAGMA", and "END". Nevertheless, best practice is to avoid8647** using keywords as identifiers. Common techniques used to avoid keyword8648** name collisions include:8649** <ul>8650** <li> Put all identifier names inside double-quotes. This is the official8651** SQL way to escape identifier names.8652** <li> Put identifier names inside [...]. This is not standard SQL,8653** but it is what SQL Server does and so lots of programmers use this8654** technique.8655** <li> Begin every identifier with the letter "Z" as no SQL keywords start8656** with "Z".8657** <li> Include a digit somewhere in every identifier name.8658** </ul>8659**8660** Note that the number of keywords understood by SQLite can depend on8661** compile-time options. For example, "VACUUM" is not a keyword if8662** SQLite is compiled with the [-DSQLITE_OMIT_VACUUM] option. Also,8663** new keywords may be added to future releases of SQLite.8664*/8665SQLITE_API int sqlite3_keyword_count(void);8666SQLITE_API int sqlite3_keyword_name(int,const char**,int*);8667SQLITE_API int sqlite3_keyword_check(const char*,int);86688669/*8670** CAPI3REF: Dynamic String Object8671** KEYWORDS: {dynamic string}8672**8673** An instance of the sqlite3_str object contains a dynamically-sized8674** string under construction.8675**8676** The lifecycle of an sqlite3_str object is as follows:8677** <ol>8678** <li> ^The sqlite3_str object is created using [sqlite3_str_new()].8679** <li> ^Text is appended to the sqlite3_str object using various8680** methods, such as [sqlite3_str_appendf()].8681** <li> ^The sqlite3_str object is destroyed and the string it created8682** is returned using the [sqlite3_str_finish()] interface.8683** </ol>8684*/8685typedef struct sqlite3_str sqlite3_str;86868687/*8688** CAPI3REF: Create A New Dynamic String Object8689** CONSTRUCTOR: sqlite3_str8690**8691** ^The [sqlite3_str_new(D)] interface allocates and initializes8692** a new [sqlite3_str] object. To avoid memory leaks, the object returned by8693** [sqlite3_str_new()] must be freed by a subsequent call to8694** [sqlite3_str_finish(X)].8695**8696** ^The [sqlite3_str_new(D)] interface always returns a pointer to a8697** valid [sqlite3_str] object, though in the event of an out-of-memory8698** error the returned object might be a special singleton that will8699** silently reject new text, always return SQLITE_NOMEM from8700** [sqlite3_str_errcode()], always return 0 for8701** [sqlite3_str_length()], and always return NULL from8702** [sqlite3_str_finish(X)]. It is always safe to use the value8703** returned by [sqlite3_str_new(D)] as the sqlite3_str parameter8704** to any of the other [sqlite3_str] methods.8705**8706** The D parameter to [sqlite3_str_new(D)] may be NULL. If the8707** D parameter in [sqlite3_str_new(D)] is not NULL, then the maximum8708** length of the string contained in the [sqlite3_str] object will be8709** the value set for [sqlite3_limit](D,[SQLITE_LIMIT_LENGTH]) instead8710** of [SQLITE_MAX_LENGTH].8711*/8712SQLITE_API sqlite3_str *sqlite3_str_new(sqlite3*);87138714/*8715** CAPI3REF: Finalize A Dynamic String8716** DESTRUCTOR: sqlite3_str8717**8718** ^The [sqlite3_str_finish(X)] interface destroys the sqlite3_str object X8719** and returns a pointer to a memory buffer obtained from [sqlite3_malloc64()]8720** that contains the constructed string. The calling application should8721** pass the returned value to [sqlite3_free()] to avoid a memory leak.8722** ^The [sqlite3_str_finish(X)] interface may return a NULL pointer if any8723** errors were encountered during construction of the string. ^The8724** [sqlite3_str_finish(X)] interface will also return a NULL pointer if the8725** string in [sqlite3_str] object X is zero bytes long.8726*/8727SQLITE_API char *sqlite3_str_finish(sqlite3_str*);87288729/*8730** CAPI3REF: Add Content To A Dynamic String8731** METHOD: sqlite3_str8732**8733** These interfaces add content to an sqlite3_str object previously obtained8734** from [sqlite3_str_new()].8735**8736** ^The [sqlite3_str_appendf(X,F,...)] and8737** [sqlite3_str_vappendf(X,F,V)] interfaces uses the [built-in printf]8738** functionality of SQLite to append formatted text onto the end of8739** [sqlite3_str] object X.8740**8741** ^The [sqlite3_str_append(X,S,N)] method appends exactly N bytes from string S8742** onto the end of the [sqlite3_str] object X. N must be non-negative.8743** S must contain at least N non-zero bytes of content. To append a8744** zero-terminated string in its entirety, use the [sqlite3_str_appendall()]8745** method instead.8746**8747** ^The [sqlite3_str_appendall(X,S)] method appends the complete content of8748** zero-terminated string S onto the end of [sqlite3_str] object X.8749**8750** ^The [sqlite3_str_appendchar(X,N,C)] method appends N copies of the8751** single-byte character C onto the end of [sqlite3_str] object X.8752** ^This method can be used, for example, to add whitespace indentation.8753**8754** ^The [sqlite3_str_reset(X)] method resets the string under construction8755** inside [sqlite3_str] object X back to zero bytes in length.8756**8757** These methods do not return a result code. ^If an error occurs, that fact8758** is recorded in the [sqlite3_str] object and can be recovered by a8759** subsequent call to [sqlite3_str_errcode(X)].8760*/8761SQLITE_API void sqlite3_str_appendf(sqlite3_str*, const char *zFormat, ...);8762SQLITE_API void sqlite3_str_vappendf(sqlite3_str*, const char *zFormat, va_list);8763SQLITE_API void sqlite3_str_append(sqlite3_str*, const char *zIn, int N);8764SQLITE_API void sqlite3_str_appendall(sqlite3_str*, const char *zIn);8765SQLITE_API void sqlite3_str_appendchar(sqlite3_str*, int N, char C);8766SQLITE_API void sqlite3_str_reset(sqlite3_str*);87678768/*8769** CAPI3REF: Status Of A Dynamic String8770** METHOD: sqlite3_str8771**8772** These interfaces return the current status of an [sqlite3_str] object.8773**8774** ^If any prior errors have occurred while constructing the dynamic string8775** in sqlite3_str X, then the [sqlite3_str_errcode(X)] method will return8776** an appropriate error code. ^The [sqlite3_str_errcode(X)] method returns8777** [SQLITE_NOMEM] following any out-of-memory error, or8778** [SQLITE_TOOBIG] if the size of the dynamic string exceeds8779** [SQLITE_MAX_LENGTH], or [SQLITE_OK] if there have been no errors.8780**8781** ^The [sqlite3_str_length(X)] method returns the current length, in bytes,8782** of the dynamic string under construction in [sqlite3_str] object X.8783** ^The length returned by [sqlite3_str_length(X)] does not include the8784** zero-termination byte.8785**8786** ^The [sqlite3_str_value(X)] method returns a pointer to the current8787** content of the dynamic string under construction in X. The value8788** returned by [sqlite3_str_value(X)] is managed by the sqlite3_str object X8789** and might be freed or altered by any subsequent method on the same8790** [sqlite3_str] object. Applications must not use the pointer returned by8791** [sqlite3_str_value(X)] after any subsequent method call on the same8792** object. ^Applications may change the content of the string returned8793** by [sqlite3_str_value(X)] as long as they do not write into any bytes8794** outside the range of 0 to [sqlite3_str_length(X)] and do not read or8795** write any byte after any subsequent sqlite3_str method call.8796*/8797SQLITE_API int sqlite3_str_errcode(sqlite3_str*);8798SQLITE_API int sqlite3_str_length(sqlite3_str*);8799SQLITE_API char *sqlite3_str_value(sqlite3_str*);88008801/*8802** CAPI3REF: SQLite Runtime Status8803**8804** ^These interfaces are used to retrieve runtime status information8805** about the performance of SQLite, and optionally to reset various8806** highwater marks. ^The first argument is an integer code for8807** the specific parameter to measure. ^(Recognized integer codes8808** are of the form [status parameters | SQLITE_STATUS_...].)^8809** ^The current value of the parameter is returned into *pCurrent.8810** ^The highest recorded value is returned in *pHighwater. ^If the8811** resetFlag is true, then the highest record value is reset after8812** *pHighwater is written. ^(Some parameters do not record the highest8813** value. For those parameters8814** nothing is written into *pHighwater and the resetFlag is ignored.)^8815** ^(Other parameters record only the highwater mark and not the current8816** value. For these latter parameters nothing is written into *pCurrent.)^8817**8818** ^The sqlite3_status() and sqlite3_status64() routines return8819** SQLITE_OK on success and a non-zero [error code] on failure.8820**8821** If either the current value or the highwater mark is too large to8822** be represented by a 32-bit integer, then the values returned by8823** sqlite3_status() are undefined.8824**8825** See also: [sqlite3_db_status()]8826*/8827SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);8828SQLITE_API int sqlite3_status64(8829int op,8830sqlite3_int64 *pCurrent,8831sqlite3_int64 *pHighwater,8832int resetFlag8833);883488358836/*8837** CAPI3REF: Status Parameters8838** KEYWORDS: {status parameters}8839**8840** These integer constants designate various run-time status parameters8841** that can be returned by [sqlite3_status()].8842**8843** <dl>8844** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>8845** <dd>This parameter is the current amount of memory checked out8846** using [sqlite3_malloc()], either directly or indirectly. The8847** figure includes calls made to [sqlite3_malloc()] by the application8848** and internal memory usage by the SQLite library. Auxiliary page-cache8849** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in8850** this parameter. The amount returned is the sum of the allocation8851** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^8852**8853** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>8854** <dd>This parameter records the largest memory allocation request8855** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their8856** internal equivalents). Only the value returned in the8857** *pHighwater parameter to [sqlite3_status()] is of interest.8858** The value written into the *pCurrent parameter is undefined.</dd>)^8859**8860** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>8861** <dd>This parameter records the number of separate memory allocations8862** currently checked out.</dd>)^8863**8864** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>8865** <dd>This parameter returns the number of pages used out of the8866** [pagecache memory allocator] that was configured using8867** [SQLITE_CONFIG_PAGECACHE]. The8868** value returned is in pages, not in bytes.</dd>)^8869**8870** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]]8871** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>8872** <dd>This parameter returns the number of bytes of page cache8873** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]8874** buffer and where forced to overflow to [sqlite3_malloc()]. The8875** returned value includes allocations that overflowed because they8876** were too large (they were larger than the "sz" parameter to8877** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because8878** no space was left in the page cache.</dd>)^8879**8880** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>8881** <dd>This parameter records the largest memory allocation request8882** handed to the [pagecache memory allocator]. Only the value returned in the8883** *pHighwater parameter to [sqlite3_status()] is of interest.8884** The value written into the *pCurrent parameter is undefined.</dd>)^8885**8886** [[SQLITE_STATUS_SCRATCH_USED]] <dt>SQLITE_STATUS_SCRATCH_USED</dt>8887** <dd>No longer used.</dd>8888**8889** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>8890** <dd>No longer used.</dd>8891**8892** [[SQLITE_STATUS_SCRATCH_SIZE]] <dt>SQLITE_STATUS_SCRATCH_SIZE</dt>8893** <dd>No longer used.</dd>8894**8895** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>8896** <dd>The *pHighwater parameter records the deepest parser stack.8897** The *pCurrent value is undefined. The *pHighwater value is only8898** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^8899** </dl>8900**8901** New status parameters may be added from time to time.8902*/8903#define SQLITE_STATUS_MEMORY_USED 08904#define SQLITE_STATUS_PAGECACHE_USED 18905#define SQLITE_STATUS_PAGECACHE_OVERFLOW 28906#define SQLITE_STATUS_SCRATCH_USED 3 /* NOT USED */8907#define SQLITE_STATUS_SCRATCH_OVERFLOW 4 /* NOT USED */8908#define SQLITE_STATUS_MALLOC_SIZE 58909#define SQLITE_STATUS_PARSER_STACK 68910#define SQLITE_STATUS_PAGECACHE_SIZE 78911#define SQLITE_STATUS_SCRATCH_SIZE 8 /* NOT USED */8912#define SQLITE_STATUS_MALLOC_COUNT 989138914/*8915** CAPI3REF: Database Connection Status8916** METHOD: sqlite38917**8918** ^This interface is used to retrieve runtime status information8919** about a single [database connection]. ^The first argument is the8920** database connection object to be interrogated. ^The second argument8921** is an integer constant, taken from the set of8922** [SQLITE_DBSTATUS options], that8923** determines the parameter to interrogate. The set of8924** [SQLITE_DBSTATUS options] is likely8925** to grow in future releases of SQLite.8926**8927** ^The current value of the requested parameter is written into *pCur8928** and the highest instantaneous value is written into *pHiwtr. ^If8929** the resetFlg is true, then the highest instantaneous value is8930** reset back down to the current value.8931**8932** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a8933** non-zero [error code] on failure.8934**8935** ^The sqlite3_db_status64(D,O,C,H,R) routine works exactly the same8936** way as sqlite3_db_status(D,O,C,H,R) routine except that the C and H8937** parameters are pointer to 64-bit integers (type: sqlite3_int64) instead8938** of pointers to 32-bit integers, which allows larger status values8939** to be returned. If a status value exceeds 2,147,483,647 then8940** sqlite3_db_status() will truncate the value whereas sqlite3_db_status64()8941** will return the full value.8942**8943** See also: [sqlite3_status()] and [sqlite3_stmt_status()].8944*/8945SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);8946SQLITE_API int sqlite3_db_status64(sqlite3*,int,sqlite3_int64*,sqlite3_int64*,int);89478948/*8949** CAPI3REF: Status Parameters for database connections8950** KEYWORDS: {SQLITE_DBSTATUS options}8951**8952** These constants are the available integer "verbs" that can be passed as8953** the second argument to the [sqlite3_db_status()] interface.8954**8955** New verbs may be added in future releases of SQLite. Existing verbs8956** might be discontinued. Applications should check the return code from8957** [sqlite3_db_status()] to make sure that the call worked.8958** The [sqlite3_db_status()] interface will return a non-zero error code8959** if a discontinued or unsupported verb is invoked.8960**8961** <dl>8962** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>8963** <dd>This parameter returns the number of lookaside memory slots currently8964** checked out.</dd>)^8965**8966** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>8967** <dd>This parameter returns the number of malloc attempts that were8968** satisfied using lookaside memory. Only the high-water value is meaningful;8969** the current value is always zero.</dd>)^8970**8971** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]8972** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>8973** <dd>This parameter returns the number of malloc attempts that might have8974** been satisfied using lookaside memory but failed due to the amount of8975** memory requested being larger than the lookaside slot size.8976** Only the high-water value is meaningful;8977** the current value is always zero.</dd>)^8978**8979** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]]8980** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>8981** <dd>This parameter returns the number of malloc attempts that might have8982** been satisfied using lookaside memory but failed due to all lookaside8983** memory already being in use.8984** Only the high-water value is meaningful;8985** the current value is always zero.</dd>)^8986**8987** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>8988** <dd>This parameter returns the approximate number of bytes of heap8989** memory used by all pager caches associated with the database connection.)^8990** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.8991** </dd>8992**8993** [[SQLITE_DBSTATUS_CACHE_USED_SHARED]]8994** ^(<dt>SQLITE_DBSTATUS_CACHE_USED_SHARED</dt>8995** <dd>This parameter is similar to DBSTATUS_CACHE_USED, except that if a8996** pager cache is shared between two or more connections the bytes of heap8997** memory used by that pager cache is divided evenly between the attached8998** connections.)^ In other words, if none of the pager caches associated8999** with the database connection are shared, this request returns the same9000** value as DBSTATUS_CACHE_USED. Or, if one or more of the pager caches are9001** shared, the value returned by this call will be smaller than that returned9002** by DBSTATUS_CACHE_USED. ^The highwater mark associated with9003** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0.</dd>9004**9005** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>9006** <dd>This parameter returns the approximate number of bytes of heap9007** memory used to store the schema for all databases associated9008** with the connection - main, temp, and any [ATTACH]-ed databases.)^9009** ^The full amount of memory used by the schemas is reported, even if the9010** schema memory is shared with other database connections due to9011** [shared cache mode] being enabled.9012** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.9013** </dd>9014**9015** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>9016** <dd>This parameter returns the approximate number of bytes of heap9017** and lookaside memory used by all prepared statements associated with9018** the database connection.)^9019** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.9020** </dd>9021**9022** [[SQLITE_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE_DBSTATUS_CACHE_HIT</dt>9023** <dd>This parameter returns the number of pager cache hits that have9024** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_HIT9025** is always 0.9026** </dd>9027**9028** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt>9029** <dd>This parameter returns the number of pager cache misses that have9030** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS9031** is always 0.9032** </dd>9033**9034** [[SQLITE_DBSTATUS_CACHE_WRITE]] ^(<dt>SQLITE_DBSTATUS_CACHE_WRITE</dt>9035** <dd>This parameter returns the number of dirty cache entries that have9036** been written to disk. Specifically, the number of pages written to the9037** wal file in wal mode databases, or the number of pages written to the9038** database file in rollback mode databases. Any pages written as part of9039** transaction rollback or database recovery operations are not included.9040** If an IO or other error occurs while writing a page to disk, the effect9041** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The9042** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0.9043** <p>9044** ^(There is overlap between the quantities measured by this parameter9045** (SQLITE_DBSTATUS_CACHE_WRITE) and SQLITE_DBSTATUS_TEMPBUF_SPILL.9046** Resetting one will reduce the other.)^9047** </dd>9048**9049** [[SQLITE_DBSTATUS_CACHE_SPILL]] ^(<dt>SQLITE_DBSTATUS_CACHE_SPILL</dt>9050** <dd>This parameter returns the number of dirty cache entries that have9051** been written to disk in the middle of a transaction due to the page9052** cache overflowing. Transactions are more efficient if they are written9053** to disk all at once. When pages spill mid-transaction, that introduces9054** additional overhead. This parameter can be used to help identify9055** inefficiencies that can be resolved by increasing the cache size.9056** </dd>9057**9058** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>9059** <dd>This parameter returns zero for the current value if and only if9060** all foreign key constraints (deferred or immediate) have been9061** resolved.)^ ^The highwater mark is always 0.9062**9063** [[SQLITE_DBSTATUS_TEMPBUF_SPILL] ^(<dt>SQLITE_DBSTATUS_TEMPBUF_SPILL</dt>9064** <dd>^(This parameter returns the number of bytes written to temporary9065** files on disk that could have been kept in memory had sufficient memory9066** been available. This value includes writes to intermediate tables that9067** are part of complex queries, external sorts that spill to disk, and9068** writes to TEMP tables.)^9069** ^The highwater mark is always 0.9070** <p>9071** ^(There is overlap between the quantities measured by this parameter9072** (SQLITE_DBSTATUS_TEMPBUF_SPILL) and SQLITE_DBSTATUS_CACHE_WRITE.9073** Resetting one will reduce the other.)^9074** </dd>9075** </dl>9076*/9077#define SQLITE_DBSTATUS_LOOKASIDE_USED 09078#define SQLITE_DBSTATUS_CACHE_USED 19079#define SQLITE_DBSTATUS_SCHEMA_USED 29080#define SQLITE_DBSTATUS_STMT_USED 39081#define SQLITE_DBSTATUS_LOOKASIDE_HIT 49082#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 59083#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 69084#define SQLITE_DBSTATUS_CACHE_HIT 79085#define SQLITE_DBSTATUS_CACHE_MISS 89086#define SQLITE_DBSTATUS_CACHE_WRITE 99087#define SQLITE_DBSTATUS_DEFERRED_FKS 109088#define SQLITE_DBSTATUS_CACHE_USED_SHARED 119089#define SQLITE_DBSTATUS_CACHE_SPILL 129090#define SQLITE_DBSTATUS_TEMPBUF_SPILL 139091#define SQLITE_DBSTATUS_MAX 13 /* Largest defined DBSTATUS */909290939094/*9095** CAPI3REF: Prepared Statement Status9096** METHOD: sqlite3_stmt9097**9098** ^(Each prepared statement maintains various9099** [SQLITE_STMTSTATUS counters] that measure the number9100** of times it has performed specific operations.)^ These counters can9101** be used to monitor the performance characteristics of the prepared9102** statements. For example, if the number of table steps greatly exceeds9103** the number of table searches or result rows, that would tend to indicate9104** that the prepared statement is using a full table scan rather than9105** an index.9106**9107** ^(This interface is used to retrieve and reset counter values from9108** a [prepared statement]. The first argument is the prepared statement9109** object to be interrogated. The second argument9110** is an integer code for a specific [SQLITE_STMTSTATUS counter]9111** to be interrogated.)^9112** ^The current value of the requested counter is returned.9113** ^If the resetFlg is true, then the counter is reset to zero after this9114** interface call returns.9115**9116** See also: [sqlite3_status()] and [sqlite3_db_status()].9117*/9118SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);91199120/*9121** CAPI3REF: Status Parameters for prepared statements9122** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters}9123**9124** These preprocessor macros define integer codes that name counter9125** values associated with the [sqlite3_stmt_status()] interface.9126** The meanings of the various counters are as follows:9127**9128** <dl>9129** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>9130** <dd>^This is the number of times that SQLite has stepped forward in9131** a table as part of a full table scan. Large numbers for this counter9132** may indicate opportunities for performance improvement through9133** careful use of indices.</dd>9134**9135** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt>9136** <dd>^This is the number of sort operations that have occurred.9137** A non-zero value in this counter may indicate an opportunity to9138** improve performance through careful use of indices.</dd>9139**9140** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>9141** <dd>^This is the number of rows inserted into transient indices that9142** were created automatically in order to help joins run faster.9143** A non-zero value in this counter may indicate an opportunity to9144** improve performance by adding permanent indices that do not9145** need to be reinitialized each time the statement is run.</dd>9146**9147** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>9148** <dd>^This is the number of virtual machine operations executed9149** by the prepared statement if that number is less than or equal9150** to 2147483647. The number of virtual machine operations can be9151** used as a proxy for the total work done by the prepared statement.9152** If the number of virtual machine operations exceeds 21474836479153** then the value returned by this statement status code is undefined.</dd>9154**9155** [[SQLITE_STMTSTATUS_REPREPARE]] <dt>SQLITE_STMTSTATUS_REPREPARE</dt>9156** <dd>^This is the number of times that the prepare statement has been9157** automatically regenerated due to schema changes or changes to9158** [bound parameters] that might affect the query plan.</dd>9159**9160** [[SQLITE_STMTSTATUS_RUN]] <dt>SQLITE_STMTSTATUS_RUN</dt>9161** <dd>^This is the number of times that the prepared statement has9162** been run. A single "run" for the purposes of this counter is one9163** or more calls to [sqlite3_step()] followed by a call to [sqlite3_reset()].9164** The counter is incremented on the first [sqlite3_step()] call of each9165** cycle.</dd>9166**9167** [[SQLITE_STMTSTATUS_FILTER_MISS]]9168** [[SQLITE_STMTSTATUS_FILTER HIT]]9169** <dt>SQLITE_STMTSTATUS_FILTER_HIT<br>9170** SQLITE_STMTSTATUS_FILTER_MISS</dt>9171** <dd>^SQLITE_STMTSTATUS_FILTER_HIT is the number of times that a join9172** step was bypassed because a Bloom filter returned not-found. The9173** corresponding SQLITE_STMTSTATUS_FILTER_MISS value is the number of9174** times that the Bloom filter returned a find, and thus the join step9175** had to be processed as normal.</dd>9176**9177** [[SQLITE_STMTSTATUS_MEMUSED]] <dt>SQLITE_STMTSTATUS_MEMUSED</dt>9178** <dd>^This is the approximate number of bytes of heap memory9179** used to store the prepared statement. ^This value is not actually9180** a counter, and so the resetFlg parameter to sqlite3_stmt_status()9181** is ignored when the opcode is SQLITE_STMTSTATUS_MEMUSED.9182** </dd>9183** </dl>9184*/9185#define SQLITE_STMTSTATUS_FULLSCAN_STEP 19186#define SQLITE_STMTSTATUS_SORT 29187#define SQLITE_STMTSTATUS_AUTOINDEX 39188#define SQLITE_STMTSTATUS_VM_STEP 49189#define SQLITE_STMTSTATUS_REPREPARE 59190#define SQLITE_STMTSTATUS_RUN 69191#define SQLITE_STMTSTATUS_FILTER_MISS 79192#define SQLITE_STMTSTATUS_FILTER_HIT 89193#define SQLITE_STMTSTATUS_MEMUSED 9991949195/*9196** CAPI3REF: Custom Page Cache Object9197**9198** The sqlite3_pcache type is opaque. It is implemented by9199** the pluggable module. The SQLite core has no knowledge of9200** its size or internal structure and never deals with the9201** sqlite3_pcache object except by holding and passing pointers9202** to the object.9203**9204** See [sqlite3_pcache_methods2] for additional information.9205*/9206typedef struct sqlite3_pcache sqlite3_pcache;92079208/*9209** CAPI3REF: Custom Page Cache Object9210**9211** The sqlite3_pcache_page object represents a single page in the9212** page cache. The page cache will allocate instances of this9213** object. Various methods of the page cache use pointers to instances9214** of this object as parameters or as their return value.9215**9216** See [sqlite3_pcache_methods2] for additional information.9217*/9218typedef struct sqlite3_pcache_page sqlite3_pcache_page;9219struct sqlite3_pcache_page {9220void *pBuf; /* The content of the page */9221void *pExtra; /* Extra information associated with the page */9222};92239224/*9225** CAPI3REF: Application Defined Page Cache.9226** KEYWORDS: {page cache}9227**9228** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE2], ...) interface can9229** register an alternative page cache implementation by passing in an9230** instance of the sqlite3_pcache_methods2 structure.)^9231** In many applications, most of the heap memory allocated by9232** SQLite is used for the page cache.9233** By implementing a9234** custom page cache using this API, an application can better control9235** the amount of memory consumed by SQLite, the way in which9236** that memory is allocated and released, and the policies used to9237** determine exactly which parts of a database file are cached and for9238** how long.9239**9240** The alternative page cache mechanism is an9241** extreme measure that is only needed by the most demanding applications.9242** The built-in page cache is recommended for most uses.9243**9244** ^(The contents of the sqlite3_pcache_methods2 structure are copied to an9245** internal buffer by SQLite within the call to [sqlite3_config]. Hence9246** the application may discard the parameter after the call to9247** [sqlite3_config()] returns.)^9248**9249** [[the xInit() page cache method]]9250** ^(The xInit() method is called once for each effective9251** call to [sqlite3_initialize()])^9252** (usually only once during the lifetime of the process). ^(The xInit()9253** method is passed a copy of the sqlite3_pcache_methods2.pArg value.)^9254** The intent of the xInit() method is to set up global data structures9255** required by the custom page cache implementation.9256** ^(If the xInit() method is NULL, then the9257** built-in default page cache is used instead of the application defined9258** page cache.)^9259**9260** [[the xShutdown() page cache method]]9261** ^The xShutdown() method is called by [sqlite3_shutdown()].9262** It can be used to clean up9263** any outstanding resources before process shutdown, if required.9264** ^The xShutdown() method may be NULL.9265**9266** ^SQLite automatically serializes calls to the xInit method,9267** so the xInit method need not be threadsafe. ^The9268** xShutdown method is only called from [sqlite3_shutdown()] so it does9269** not need to be threadsafe either. All other methods must be threadsafe9270** in multithreaded applications.9271**9272** ^SQLite will never invoke xInit() more than once without an intervening9273** call to xShutdown().9274**9275** [[the xCreate() page cache methods]]9276** ^SQLite invokes the xCreate() method to construct a new cache instance.9277** SQLite will typically create one cache instance for each open database file,9278** though this is not guaranteed. ^The9279** first parameter, szPage, is the size in bytes of the pages that must9280** be allocated by the cache. ^szPage will always be a power of two. ^The9281** second parameter szExtra is a number of bytes of extra storage9282** associated with each page cache entry. ^The szExtra parameter will be9283** a number less than 250. SQLite will use the9284** extra szExtra bytes on each page to store metadata about the underlying9285** database page on disk. The value passed into szExtra depends9286** on the SQLite version, the target platform, and how SQLite was compiled.9287** ^The third argument to xCreate(), bPurgeable, is true if the cache being9288** created will be used to cache database pages of a file stored on disk, or9289** false if it is used for an in-memory database. The cache implementation9290** does not have to do anything special based upon the value of bPurgeable;9291** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will9292** never invoke xUnpin() except to deliberately delete a page.9293** ^In other words, calls to xUnpin() on a cache with bPurgeable set to9294** false will always have the "discard" flag set to true.9295** ^Hence, a cache created with bPurgeable set to false will9296** never contain any unpinned pages.9297**9298** [[the xCachesize() page cache method]]9299** ^(The xCachesize() method may be called at any time by SQLite to set the9300** suggested maximum cache-size (number of pages stored) for the cache9301** instance passed as the first argument. This is the value configured using9302** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable9303** parameter, the implementation is not required to do anything with this9304** value; it is advisory only.9305**9306** [[the xPagecount() page cache methods]]9307** The xPagecount() method must return the number of pages currently9308** stored in the cache, both pinned and unpinned.9309**9310** [[the xFetch() page cache methods]]9311** The xFetch() method locates a page in the cache and returns a pointer to9312** an sqlite3_pcache_page object associated with that page, or a NULL pointer.9313** The pBuf element of the returned sqlite3_pcache_page object will be a9314** pointer to a buffer of szPage bytes used to store the content of a9315** single database page. The pExtra element of sqlite3_pcache_page will be9316** a pointer to the szExtra bytes of extra storage that SQLite has requested9317** for each entry in the page cache.9318**9319** The page to be fetched is determined by the key. ^The minimum key value9320** is 1. After it has been retrieved using xFetch, the page is considered9321** to be "pinned".9322**9323** If the requested page is already in the page cache, then the page cache9324** implementation must return a pointer to the page buffer with its content9325** intact. If the requested page is not already in the cache, then the9326** cache implementation should use the value of the createFlag9327** parameter to help it determine what action to take:9328**9329** <table border=1 width=85% align=center>9330** <tr><th> createFlag <th> Behavior when page is not already in cache9331** <tr><td> 0 <td> Do not allocate a new page. Return NULL.9332** <tr><td> 1 <td> Allocate a new page if it is easy and convenient to do so.9333** Otherwise return NULL.9334** <tr><td> 2 <td> Make every effort to allocate a new page. Only return9335** NULL if allocating a new page is effectively impossible.9336** </table>9337**9338** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite9339** will only use a createFlag of 2 after a prior call with a createFlag of 19340** failed.)^ In between the xFetch() calls, SQLite may9341** attempt to unpin one or more cache pages by spilling the content of9342** pinned pages to disk and synching the operating system disk cache.9343**9344** [[the xUnpin() page cache method]]9345** ^xUnpin() is called by SQLite with a pointer to a currently pinned page9346** as its second argument. If the third parameter, discard, is non-zero,9347** then the page must be evicted from the cache.9348** ^If the discard parameter is9349** zero, then the page may be discarded or retained at the discretion of the9350** page cache implementation. ^The page cache implementation9351** may choose to evict unpinned pages at any time.9352**9353** The cache must not perform any reference counting. A single9354** call to xUnpin() unpins the page regardless of the number of prior calls9355** to xFetch().9356**9357** [[the xRekey() page cache methods]]9358** The xRekey() method is used to change the key value associated with the9359** page passed as the second argument. If the cache9360** previously contains an entry associated with newKey, it must be9361** discarded. ^Any prior cache entry associated with newKey is guaranteed not9362** to be pinned.9363**9364** When SQLite calls the xTruncate() method, the cache must discard all9365** existing cache entries with page numbers (keys) greater than or equal9366** to the value of the iLimit parameter passed to xTruncate(). If any9367** of these pages are pinned, they become implicitly unpinned, meaning that9368** they can be safely discarded.9369**9370** [[the xDestroy() page cache method]]9371** ^The xDestroy() method is used to delete a cache allocated by xCreate().9372** All resources associated with the specified cache should be freed. ^After9373** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]9374** handle invalid, and will not use it with any other sqlite3_pcache_methods29375** functions.9376**9377** [[the xShrink() page cache method]]9378** ^SQLite invokes the xShrink() method when it wants the page cache to9379** free up as much of heap memory as possible. The page cache implementation9380** is not obligated to free any memory, but well-behaved implementations should9381** do their best.9382*/9383typedef struct sqlite3_pcache_methods2 sqlite3_pcache_methods2;9384struct sqlite3_pcache_methods2 {9385int iVersion;9386void *pArg;9387int (*xInit)(void*);9388void (*xShutdown)(void*);9389sqlite3_pcache *(*xCreate)(int szPage, int szExtra, int bPurgeable);9390void (*xCachesize)(sqlite3_pcache*, int nCachesize);9391int (*xPagecount)(sqlite3_pcache*);9392sqlite3_pcache_page *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);9393void (*xUnpin)(sqlite3_pcache*, sqlite3_pcache_page*, int discard);9394void (*xRekey)(sqlite3_pcache*, sqlite3_pcache_page*,9395unsigned oldKey, unsigned newKey);9396void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);9397void (*xDestroy)(sqlite3_pcache*);9398void (*xShrink)(sqlite3_pcache*);9399};94009401/*9402** This is the obsolete pcache_methods object that has now been replaced9403** by sqlite3_pcache_methods2. This object is not used by SQLite. It is9404** retained in the header file for backwards compatibility only.9405*/9406typedef struct sqlite3_pcache_methods sqlite3_pcache_methods;9407struct sqlite3_pcache_methods {9408void *pArg;9409int (*xInit)(void*);9410void (*xShutdown)(void*);9411sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable);9412void (*xCachesize)(sqlite3_pcache*, int nCachesize);9413int (*xPagecount)(sqlite3_pcache*);9414void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);9415void (*xUnpin)(sqlite3_pcache*, void*, int discard);9416void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey);9417void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);9418void (*xDestroy)(sqlite3_pcache*);9419};942094219422/*9423** CAPI3REF: Online Backup Object9424**9425** The sqlite3_backup object records state information about an ongoing9426** online backup operation. ^The sqlite3_backup object is created by9427** a call to [sqlite3_backup_init()] and is destroyed by a call to9428** [sqlite3_backup_finish()].9429**9430** See Also: [Using the SQLite Online Backup API]9431*/9432typedef struct sqlite3_backup sqlite3_backup;94339434/*9435** CAPI3REF: Online Backup API.9436**9437** The backup API copies the content of one database into another.9438** It is useful either for creating backups of databases or9439** for copying in-memory databases to or from persistent files.9440**9441** See Also: [Using the SQLite Online Backup API]9442**9443** ^SQLite holds a write transaction open on the destination database file9444** for the duration of the backup operation.9445** ^The source database is read-locked only while it is being read;9446** it is not locked continuously for the entire backup operation.9447** ^Thus, the backup may be performed on a live source database without9448** preventing other database connections from9449** reading or writing to the source database while the backup is underway.9450**9451** ^(To perform a backup operation:9452** <ol>9453** <li><b>sqlite3_backup_init()</b> is called once to initialize the9454** backup,9455** <li><b>sqlite3_backup_step()</b> is called one or more times to transfer9456** the data between the two databases, and finally9457** <li><b>sqlite3_backup_finish()</b> is called to release all resources9458** associated with the backup operation.9459** </ol>)^9460** There should be exactly one call to sqlite3_backup_finish() for each9461** successful call to sqlite3_backup_init().9462**9463** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b>9464**9465** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the9466** [database connection] associated with the destination database9467** and the database name, respectively.9468** ^The database name is "main" for the main database, "temp" for the9469** temporary database, or the name specified after the AS keyword in9470** an [ATTACH] statement for an attached database.9471** ^The S and M arguments passed to9472** sqlite3_backup_init(D,N,S,M) identify the [database connection]9473** and database name of the source database, respectively.9474** ^The source and destination [database connections] (parameters S and D)9475** must be different or else sqlite3_backup_init(D,N,S,M) will fail with9476** an error.9477**9478** ^A call to sqlite3_backup_init() will fail, returning NULL, if9479** there is already a read or read-write transaction open on the9480** destination database.9481**9482** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is9483** returned and an error code and error message are stored in the9484** destination [database connection] D.9485** ^The error code and message for the failed call to sqlite3_backup_init()9486** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or9487** [sqlite3_errmsg16()] functions.9488** ^A successful call to sqlite3_backup_init() returns a pointer to an9489** [sqlite3_backup] object.9490** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and9491** sqlite3_backup_finish() functions to perform the specified backup9492** operation.9493**9494** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b>9495**9496** ^Function sqlite3_backup_step(B,N) will copy up to N pages between9497** the source and destination databases specified by [sqlite3_backup] object B.9498** ^If N is negative, all remaining source pages are copied.9499** ^If sqlite3_backup_step(B,N) successfully copies N pages and there9500** are still more pages to be copied, then the function returns [SQLITE_OK].9501** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages9502** from source to destination, then it returns [SQLITE_DONE].9503** ^If an error occurs while running sqlite3_backup_step(B,N),9504** then an [error code] is returned. ^As well as [SQLITE_OK] and9505** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],9506** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an9507** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code.9508**9509** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if9510** <ol>9511** <li> the destination database was opened read-only, or9512** <li> the destination database is using write-ahead-log journaling9513** and the destination and source page sizes differ, or9514** <li> the destination database is an in-memory database and the9515** destination and source page sizes differ.9516** </ol>)^9517**9518** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then9519** the [sqlite3_busy_handler | busy-handler function]9520** is invoked (if one is specified). ^If the9521** busy-handler returns non-zero before the lock is available, then9522** [SQLITE_BUSY] is returned to the caller. ^In this case the call to9523** sqlite3_backup_step() can be retried later. ^If the source9524** [database connection]9525** is being used to write to the source database when sqlite3_backup_step()9526** is called, then [SQLITE_LOCKED] is returned immediately. ^Again, in this9527** case the call to sqlite3_backup_step() can be retried later on. ^(If9528** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or9529** [SQLITE_READONLY] is returned, then9530** there is no point in retrying the call to sqlite3_backup_step(). These9531** errors are considered fatal.)^ The application must accept9532** that the backup operation has failed and pass the backup operation handle9533** to the sqlite3_backup_finish() to release associated resources.9534**9535** ^The first call to sqlite3_backup_step() obtains an exclusive lock9536** on the destination file. ^The exclusive lock is not released until either9537** sqlite3_backup_finish() is called or the backup operation is complete9538** and sqlite3_backup_step() returns [SQLITE_DONE]. ^Every call to9539** sqlite3_backup_step() obtains a [shared lock] on the source database that9540** lasts for the duration of the sqlite3_backup_step() call.9541** ^Because the source database is not locked between calls to9542** sqlite3_backup_step(), the source database may be modified mid-way9543** through the backup process. ^If the source database is modified by an9544** external process or via a database connection other than the one being9545** used by the backup operation, then the backup will be automatically9546** restarted by the next call to sqlite3_backup_step(). ^If the source9547** database is modified by using the same database connection as is used9548** by the backup operation, then the backup database is automatically9549** updated at the same time.9550**9551** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>9552**9553** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the9554** application wishes to abandon the backup operation, the application9555** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish().9556** ^The sqlite3_backup_finish() interfaces releases all9557** resources associated with the [sqlite3_backup] object.9558** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any9559** active write-transaction on the destination database is rolled back.9560** The [sqlite3_backup] object is invalid9561** and may not be used following a call to sqlite3_backup_finish().9562**9563** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no9564** sqlite3_backup_step() errors occurred, regardless of whether or not9565** sqlite3_backup_step() completed.9566** ^If an out-of-memory condition or IO error occurred during any prior9567** sqlite3_backup_step() call on the same [sqlite3_backup] object, then9568** sqlite3_backup_finish() returns the corresponding [error code].9569**9570** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()9571** is not a permanent error and does not affect the return value of9572** sqlite3_backup_finish().9573**9574** [[sqlite3_backup_remaining()]] [[sqlite3_backup_pagecount()]]9575** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b>9576**9577** ^The sqlite3_backup_remaining() routine returns the number of pages still9578** to be backed up at the conclusion of the most recent sqlite3_backup_step().9579** ^The sqlite3_backup_pagecount() routine returns the total number of pages9580** in the source database at the conclusion of the most recent9581** sqlite3_backup_step().9582** ^(The values returned by these functions are only updated by9583** sqlite3_backup_step(). If the source database is modified in a way that9584** changes the size of the source database or the number of pages remaining,9585** those changes are not reflected in the output of sqlite3_backup_pagecount()9586** and sqlite3_backup_remaining() until after the next9587** sqlite3_backup_step().)^9588**9589** <b>Concurrent Usage of Database Handles</b>9590**9591** ^The source [database connection] may be used by the application for other9592** purposes while a backup operation is underway or being initialized.9593** ^If SQLite is compiled and configured to support threadsafe database9594** connections, then the source database connection may be used concurrently9595** from within other threads.9596**9597** However, the application must guarantee that the destination9598** [database connection] is not passed to any other API (by any thread) after9599** sqlite3_backup_init() is called and before the corresponding call to9600** sqlite3_backup_finish(). SQLite does not currently check to see9601** if the application incorrectly accesses the destination [database connection]9602** and so no error code is reported, but the operations may malfunction9603** nevertheless. Use of the destination database connection while a9604** backup is in progress might also cause a mutex deadlock.9605**9606** If running in [shared cache mode], the application must9607** guarantee that the shared cache used by the destination database9608** is not accessed while the backup is running. In practice this means9609** that the application must guarantee that the disk file being9610** backed up to is not accessed by any connection within the process,9611** not just the specific connection that was passed to sqlite3_backup_init().9612**9613** The [sqlite3_backup] object itself is partially threadsafe. Multiple9614** threads may safely make multiple concurrent calls to sqlite3_backup_step().9615** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount()9616** APIs are not strictly speaking threadsafe. If they are invoked at the9617** same time as another thread is invoking sqlite3_backup_step() it is9618** possible that they return invalid values.9619**9620** <b>Alternatives To Using The Backup API</b>9621**9622** Other techniques for safely creating a consistent backup of an SQLite9623** database include:9624**9625** <ul>9626** <li> The [VACUUM INTO] command.9627** <li> The [sqlite3_rsync] utility program.9628** </ul>9629*/9630SQLITE_API sqlite3_backup *sqlite3_backup_init(9631sqlite3 *pDest, /* Destination database handle */9632const char *zDestName, /* Destination database name */9633sqlite3 *pSource, /* Source database handle */9634const char *zSourceName /* Source database name */9635);9636SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage);9637SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p);9638SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);9639SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);96409641/*9642** CAPI3REF: Unlock Notification9643** METHOD: sqlite39644**9645** ^When running in shared-cache mode, a database operation may fail with9646** an [SQLITE_LOCKED] error if the required locks on the shared-cache or9647** individual tables within the shared-cache cannot be obtained. See9648** [SQLite Shared-Cache Mode] for a description of shared-cache locking.9649** ^This API may be used to register a callback that SQLite will invoke9650** when the connection currently holding the required lock relinquishes it.9651** ^This API is only available if the library was compiled with the9652** [SQLITE_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined.9653**9654** See Also: [Using the SQLite Unlock Notification Feature].9655**9656** ^Shared-cache locks are released when a database connection concludes9657** its current transaction, either by committing it or rolling it back.9658**9659** ^When a connection (known as the blocked connection) fails to obtain a9660** shared-cache lock and SQLITE_LOCKED is returned to the caller, the9661** identity of the database connection (the blocking connection) that9662** has locked the required resource is stored internally. ^After an9663** application receives an SQLITE_LOCKED error, it may call the9664** sqlite3_unlock_notify() method with the blocked connection handle as9665** the first argument to register for a callback that will be invoked9666** when the blocking connection's current transaction is concluded. ^The9667** callback is invoked from within the [sqlite3_step] or [sqlite3_close]9668** call that concludes the blocking connection's transaction.9669**9670** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,9671** there is a chance that the blocking connection will have already9672** concluded its transaction by the time sqlite3_unlock_notify() is invoked.9673** If this happens, then the specified callback is invoked immediately,9674** from within the call to sqlite3_unlock_notify().)^9675**9676** ^If the blocked connection is attempting to obtain a write-lock on a9677** shared-cache table, and more than one other connection currently holds9678** a read-lock on the same table, then SQLite arbitrarily selects one of9679** the other connections to use as the blocking connection.9680**9681** ^(There may be at most one unlock-notify callback registered by a9682** blocked connection. If sqlite3_unlock_notify() is called when the9683** blocked connection already has a registered unlock-notify callback,9684** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is9685** called with a NULL pointer as its second argument, then any existing9686** unlock-notify callback is canceled. ^The blocked connection's9687** unlock-notify callback may also be canceled by closing the blocked9688** connection using [sqlite3_close()].9689**9690** The unlock-notify callback is not reentrant. If an application invokes9691** any sqlite3_xxx API functions from within an unlock-notify callback, a9692** crash or deadlock may be the result.9693**9694** ^Unless deadlock is detected (see below), sqlite3_unlock_notify() always9695** returns SQLITE_OK.9696**9697** <b>Callback Invocation Details</b>9698**9699** When an unlock-notify callback is registered, the application provides a9700** single void* pointer that is passed to the callback when it is invoked.9701** However, the signature of the callback function allows SQLite to pass9702** it an array of void* context pointers. The first argument passed to9703** an unlock-notify callback is a pointer to an array of void* pointers,9704** and the second is the number of entries in the array.9705**9706** When a blocking connection's transaction is concluded, there may be9707** more than one blocked connection that has registered for an unlock-notify9708** callback. ^If two or more such blocked connections have specified the9709** same callback function, then instead of invoking the callback function9710** multiple times, it is invoked once with the set of void* context pointers9711** specified by the blocked connections bundled together into an array.9712** This gives the application an opportunity to prioritize any actions9713** related to the set of unblocked database connections.9714**9715** <b>Deadlock Detection</b>9716**9717** Assuming that after registering for an unlock-notify callback a9718** database waits for the callback to be issued before taking any further9719** action (a reasonable assumption), then using this API may cause the9720** application to deadlock. For example, if connection X is waiting for9721** connection Y's transaction to be concluded, and similarly connection9722** Y is waiting on connection X's transaction, then neither connection9723** will proceed and the system may remain deadlocked indefinitely.9724**9725** To avoid this scenario, the sqlite3_unlock_notify() performs deadlock9726** detection. ^If a given call to sqlite3_unlock_notify() would put the9727** system in a deadlocked state, then SQLITE_LOCKED is returned and no9728** unlock-notify callback is registered. The system is said to be in9729** a deadlocked state if connection A has registered for an unlock-notify9730** callback on the conclusion of connection B's transaction, and connection9731** B has itself registered for an unlock-notify callback when connection9732** A's transaction is concluded. ^Indirect deadlock is also detected, so9733** the system is also considered to be deadlocked if connection B has9734** registered for an unlock-notify callback on the conclusion of connection9735** C's transaction, where connection C is waiting on connection A. ^Any9736** number of levels of indirection are allowed.9737**9738** <b>The "DROP TABLE" Exception</b>9739**9740** When a call to [sqlite3_step()] returns SQLITE_LOCKED, it is almost9741** always appropriate to call sqlite3_unlock_notify(). There is however,9742** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement,9743** SQLite checks if there are any currently executing SELECT statements9744** that belong to the same connection. If there are, SQLITE_LOCKED is9745** returned. In this case there is no "blocking connection", so invoking9746** sqlite3_unlock_notify() results in the unlock-notify callback being9747** invoked immediately. If the application then re-attempts the "DROP TABLE"9748** or "DROP INDEX" query, an infinite loop might be the result.9749**9750** One way around this problem is to check the extended error code returned9751** by an sqlite3_step() call. ^(If there is a blocking connection, then the9752** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in9753** the special "DROP TABLE/INDEX" case, the extended error code is just9754** SQLITE_LOCKED.)^9755*/9756SQLITE_API int sqlite3_unlock_notify(9757sqlite3 *pBlocked, /* Waiting connection */9758void (*xNotify)(void **apArg, int nArg), /* Callback function to invoke */9759void *pNotifyArg /* Argument to pass to xNotify */9760);976197629763/*9764** CAPI3REF: String Comparison9765**9766** ^The [sqlite3_stricmp()] and [sqlite3_strnicmp()] APIs allow applications9767** and extensions to compare the contents of two buffers containing UTF-89768** strings in a case-independent fashion, using the same definition of "case9769** independence" that SQLite uses internally when comparing identifiers.9770*/9771SQLITE_API int sqlite3_stricmp(const char *, const char *);9772SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);97739774/*9775** CAPI3REF: String Globbing9776*9777** ^The [sqlite3_strglob(P,X)] interface returns zero if and only if9778** string X matches the [GLOB] pattern P.9779** ^The definition of [GLOB] pattern matching used in9780** [sqlite3_strglob(P,X)] is the same as for the "X GLOB P" operator in the9781** SQL dialect understood by SQLite. ^The [sqlite3_strglob(P,X)] function9782** is case sensitive.9783**9784** Note that this routine returns zero on a match and non-zero if the strings9785** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()].9786**9787** See also: [sqlite3_strlike()].9788*/9789SQLITE_API int sqlite3_strglob(const char *zGlob, const char *zStr);97909791/*9792** CAPI3REF: String LIKE Matching9793*9794** ^The [sqlite3_strlike(P,X,E)] interface returns zero if and only if9795** string X matches the [LIKE] pattern P with escape character E.9796** ^The definition of [LIKE] pattern matching used in9797** [sqlite3_strlike(P,X,E)] is the same as for the "X LIKE P ESCAPE E"9798** operator in the SQL dialect understood by SQLite. ^For "X LIKE P" without9799** the ESCAPE clause, set the E parameter of [sqlite3_strlike(P,X,E)] to 0.9800** ^As with the LIKE operator, the [sqlite3_strlike(P,X,E)] function is case9801** insensitive - equivalent upper and lower case ASCII characters match9802** one another.9803**9804** ^The [sqlite3_strlike(P,X,E)] function matches Unicode characters, though9805** only ASCII characters are case folded.9806**9807** Note that this routine returns zero on a match and non-zero if the strings9808** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()].9809**9810** See also: [sqlite3_strglob()].9811*/9812SQLITE_API int sqlite3_strlike(const char *zGlob, const char *zStr, unsigned int cEsc);98139814/*9815** CAPI3REF: Error Logging Interface9816**9817** ^The [sqlite3_log()] interface writes a message into the [error log]9818** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].9819** ^If logging is enabled, the zFormat string and subsequent arguments are9820** used with [sqlite3_snprintf()] to generate the final output string.9821**9822** The sqlite3_log() interface is intended for use by extensions such as9823** virtual tables, collating functions, and SQL functions. While there is9824** nothing to prevent an application from calling sqlite3_log(), doing so9825** is considered bad form.9826**9827** The zFormat string must not be NULL.9828**9829** To avoid deadlocks and other threading problems, the sqlite3_log() routine9830** will not use dynamically allocated memory. The log message is stored in9831** a fixed-length buffer on the stack. If the log message is longer than9832** a few hundred characters, it will be truncated to the length of the9833** buffer.9834*/9835SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...);98369837/*9838** CAPI3REF: Write-Ahead Log Commit Hook9839** METHOD: sqlite39840**9841** ^The [sqlite3_wal_hook()] function is used to register a callback that9842** is invoked each time data is committed to a database in wal mode.9843**9844** ^(The callback is invoked by SQLite after the commit has taken place and9845** the associated write-lock on the database released)^, so the implementation9846** may read, write or [checkpoint] the database as required.9847**9848** ^The first parameter passed to the callback function when it is invoked9849** is a copy of the third parameter passed to sqlite3_wal_hook() when9850** registering the callback. ^The second is a copy of the database handle.9851** ^The third parameter is the name of the database that was written to -9852** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter9853** is the number of pages currently in the write-ahead log file,9854** including those that were just committed.9855**9856** ^The callback function should normally return [SQLITE_OK]. ^If an error9857** code is returned, that error will propagate back up through the9858** SQLite code base to cause the statement that provoked the callback9859** to report an error, though the commit will have still occurred. If the9860** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value9861** that does not correspond to any valid SQLite error code, the results9862** are undefined.9863**9864** ^A single database handle may have at most a single write-ahead log9865** callback registered at one time. ^Calling [sqlite3_wal_hook()]9866** replaces the default behavior or previously registered write-ahead9867** log callback.9868**9869** ^The return value is a copy of the third parameter from the9870** previous call, if any, or 0.9871**9872** ^The [sqlite3_wal_autocheckpoint()] interface and the9873** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and9874** will overwrite any prior [sqlite3_wal_hook()] settings.9875**9876** ^If a write-ahead log callback is set using this function then9877** [sqlite3_wal_checkpoint_v2()] or [PRAGMA wal_checkpoint]9878** should be invoked periodically to keep the write-ahead log file9879** from growing without bound.9880**9881** ^Passing a NULL pointer for the callback disables automatic9882** checkpointing entirely. To re-enable the default behavior, call9883** sqlite3_wal_autocheckpoint(db,1000) or use [PRAGMA wal_checkpoint].9884*/9885SQLITE_API void *sqlite3_wal_hook(9886sqlite3*,9887int(*)(void *,sqlite3*,const char*,int),9888void*9889);98909891/*9892** CAPI3REF: Configure an auto-checkpoint9893** METHOD: sqlite39894**9895** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around9896** [sqlite3_wal_hook()] that causes any database on [database connection] D9897** to automatically [checkpoint]9898** after committing a transaction if there are N or9899** more frames in the [write-ahead log] file. ^Passing zero or9900** a negative value as the N parameter disables automatic9901** checkpoints entirely.9902**9903** ^The callback registered by this function replaces any existing callback9904** registered using [sqlite3_wal_hook()]. ^Likewise, registering a callback9905** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism9906** configured by this function.9907**9908** ^The [wal_autocheckpoint pragma] can be used to invoke this interface9909** from SQL.9910**9911** ^Checkpoints initiated by this mechanism are9912** [sqlite3_wal_checkpoint_v2|PASSIVE].9913**9914** ^Every new [database connection] defaults to having the auto-checkpoint9915** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]9916** pages.9917**9918** ^The use of this interface is only necessary if the default setting9919** is found to be suboptimal for a particular application.9920*/9921SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);99229923/*9924** CAPI3REF: Checkpoint a database9925** METHOD: sqlite39926**9927** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to9928** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^9929**9930** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the9931** [write-ahead log] for database X on [database connection] D to be9932** transferred into the database file and for the write-ahead log to9933** be reset. See the [checkpointing] documentation for addition9934** information.9935**9936** This interface used to be the only way to cause a checkpoint to9937** occur. But then the newer and more powerful [sqlite3_wal_checkpoint_v2()]9938** interface was added. This interface is retained for backwards9939** compatibility and as a convenience for applications that need to manually9940** start a callback but which do not need the full power (and corresponding9941** complication) of [sqlite3_wal_checkpoint_v2()].9942*/9943SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);99449945/*9946** CAPI3REF: Checkpoint a database9947** METHOD: sqlite39948**9949** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint9950** operation on database X of [database connection] D in mode M. Status9951** information is written back into integers pointed to by L and C.)^9952** ^(The M parameter must be a valid [checkpoint mode]:)^9953**9954** <dl>9955** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>9956** ^Checkpoint as many frames as possible without waiting for any database9957** readers or writers to finish, then sync the database file if all frames9958** in the log were checkpointed. ^The [busy-handler callback]9959** is never invoked in the SQLITE_CHECKPOINT_PASSIVE mode.9960** ^On the other hand, passive mode might leave the checkpoint unfinished9961** if there are concurrent readers or writers.9962**9963** <dt>SQLITE_CHECKPOINT_FULL<dd>9964** ^This mode blocks (it invokes the9965** [sqlite3_busy_handler|busy-handler callback]) until there is no9966** database writer and all readers are reading from the most recent database9967** snapshot. ^It then checkpoints all frames in the log file and syncs the9968** database file. ^This mode blocks new database writers while it is pending,9969** but new database readers are allowed to continue unimpeded.9970**9971** <dt>SQLITE_CHECKPOINT_RESTART<dd>9972** ^This mode works the same way as SQLITE_CHECKPOINT_FULL with the addition9973** that after checkpointing the log file it blocks (calls the9974** [busy-handler callback])9975** until all readers are reading from the database file only. ^This ensures9976** that the next writer will restart the log file from the beginning.9977** ^Like SQLITE_CHECKPOINT_FULL, this mode blocks new9978** database writer attempts while it is pending, but does not impede readers.9979**9980** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd>9981** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the9982** addition that it also truncates the log file to zero bytes just prior9983** to a successful return.9984**9985** <dt>SQLITE_CHECKPOINT_NOOP<dd>9986** ^This mode always checkpoints zero frames. The only reason to invoke9987** a NOOP checkpoint is to access the values returned by9988** sqlite3_wal_checkpoint_v2() via output parameters *pnLog and *pnCkpt.9989** </dl>9990**9991** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in9992** the log file or to -1 if the checkpoint could not run because9993** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not9994** NULL,then *pnCkpt is set to the total number of checkpointed frames in the9995** log file (including any that were already checkpointed before the function9996** was called) or to -1 if the checkpoint could not run due to an error or9997** because the database is not in WAL mode. ^Note that upon successful9998** completion of an SQLITE_CHECKPOINT_TRUNCATE, the log file will have been9999** truncated to zero bytes and so both *pnLog and *pnCkpt will be set to zero.10000**10001** ^All calls obtain an exclusive "checkpoint" lock on the database file. ^If10002** any other process is running a checkpoint operation at the same time, the10003** lock cannot be obtained and SQLITE_BUSY is returned. ^Even if there is a10004** busy-handler configured, it will not be invoked in this case.10005**10006** ^The SQLITE_CHECKPOINT_FULL, RESTART and TRUNCATE modes also obtain the10007** exclusive "writer" lock on the database file. ^If the writer lock cannot be10008** obtained immediately, and a busy-handler is configured, it is invoked and10009** the writer lock retried until either the busy-handler returns 0 or the lock10010** is successfully obtained. ^The busy-handler is also invoked while waiting for10011** database readers as described above. ^If the busy-handler returns 0 before10012** the writer lock is obtained or while waiting for database readers, the10013** checkpoint operation proceeds from that point in the same way as10014** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible10015** without blocking any further. ^SQLITE_BUSY is returned in this case.10016**10017** ^If parameter zDb is NULL or points to a zero length string, then the10018** specified operation is attempted on all WAL databases [attached] to10019** [database connection] db. In this case the10020** values written to output parameters *pnLog and *pnCkpt are undefined. ^If10021** an SQLITE_BUSY error is encountered when processing one or more of the10022** attached WAL databases, the operation is still attempted on any remaining10023** attached databases and SQLITE_BUSY is returned at the end. ^If any other10024** error occurs while processing an attached database, processing is abandoned10025** and the error code is returned to the caller immediately. ^If no error10026** (SQLITE_BUSY or otherwise) is encountered while processing the attached10027** databases, SQLITE_OK is returned.10028**10029** ^If database zDb is the name of an attached database that is not in WAL10030** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. ^If10031** zDb is not NULL (or a zero length string) and is not the name of any10032** attached database, SQLITE_ERROR is returned to the caller.10033**10034** ^Unless it returns SQLITE_MISUSE,10035** the sqlite3_wal_checkpoint_v2() interface10036** sets the error information that is queried by10037** [sqlite3_errcode()] and [sqlite3_errmsg()].10038**10039** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface10040** from SQL.10041*/10042SQLITE_API int sqlite3_wal_checkpoint_v2(10043sqlite3 *db, /* Database handle */10044const char *zDb, /* Name of attached database (or NULL) */10045int eMode, /* SQLITE_CHECKPOINT_* value */10046int *pnLog, /* OUT: Size of WAL log in frames */10047int *pnCkpt /* OUT: Total number of frames checkpointed */10048);1004910050/*10051** CAPI3REF: Checkpoint Mode Values10052** KEYWORDS: {checkpoint mode}10053**10054** These constants define all valid values for the "checkpoint mode" passed10055** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface.10056** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the10057** meaning of each of these checkpoint modes.10058*/10059#define SQLITE_CHECKPOINT_NOOP -1 /* Do no work at all */10060#define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */10061#define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */10062#define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for readers */10063#define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */1006410065/*10066** CAPI3REF: Virtual Table Interface Configuration10067**10068** This function may be called by either the [xConnect] or [xCreate] method10069** of a [virtual table] implementation to configure10070** various facets of the virtual table interface.10071**10072** If this interface is invoked outside the context of an xConnect or10073** xCreate virtual table method then the behavior is undefined.10074**10075** In the call sqlite3_vtab_config(D,C,...) the D parameter is the10076** [database connection] in which the virtual table is being created and10077** which is passed in as the first argument to the [xConnect] or [xCreate]10078** method that is invoking sqlite3_vtab_config(). The C parameter is one10079** of the [virtual table configuration options]. The presence and meaning10080** of parameters after C depend on which [virtual table configuration option]10081** is used.10082*/10083SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...);1008410085/*10086** CAPI3REF: Virtual Table Configuration Options10087** KEYWORDS: {virtual table configuration options}10088** KEYWORDS: {virtual table configuration option}10089**10090** These macros define the various options to the10091** [sqlite3_vtab_config()] interface that [virtual table] implementations10092** can use to customize and optimize their behavior.10093**10094** <dl>10095** [[SQLITE_VTAB_CONSTRAINT_SUPPORT]]10096** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT</dt>10097** <dd>Calls of the form10098** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,10099** where X is an integer. If X is zero, then the [virtual table] whose10100** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not10101** support constraints. In this configuration (which is the default) if10102** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire10103** statement is rolled back as if [ON CONFLICT | OR ABORT] had been10104** specified as part of the user's SQL statement, regardless of the actual10105** ON CONFLICT mode specified.10106**10107** If X is non-zero, then the virtual table implementation guarantees10108** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before10109** any modifications to internal or persistent data structures have been made.10110** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite10111** is able to roll back a statement or database transaction, and abandon10112** or continue processing the current SQL statement as appropriate.10113** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns10114** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode10115** had been ABORT.10116**10117** Virtual table implementations that are required to handle OR REPLACE10118** must do so within the [xUpdate] method. If a call to the10119** [sqlite3_vtab_on_conflict()] function indicates that the current ON10120** CONFLICT policy is REPLACE, the virtual table implementation should10121** silently replace the appropriate rows within the xUpdate callback and10122** return SQLITE_OK. Or, if this is not possible, it may return10123** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT10124** constraint handling.10125** </dd>10126**10127** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt>10128** <dd>Calls of the form10129** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the10130** the [xConnect] or [xCreate] methods of a [virtual table] implementation10131** prohibits that virtual table from being used from within triggers and10132** views.10133** </dd>10134**10135** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>10136** <dd>Calls of the form10137** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the10138** [xConnect] or [xCreate] methods of a [virtual table] implementation10139** identify that virtual table as being safe to use from within triggers10140** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the10141** virtual table can do no serious harm even if it is controlled by a10142** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS10143** flag unless absolutely necessary.10144** </dd>10145**10146** [[SQLITE_VTAB_USES_ALL_SCHEMAS]]<dt>SQLITE_VTAB_USES_ALL_SCHEMAS</dt>10147** <dd>Calls of the form10148** [sqlite3_vtab_config](db,SQLITE_VTAB_USES_ALL_SCHEMA) from within the10149** the [xConnect] or [xCreate] methods of a [virtual table] implementation10150** instruct the query planner to begin at least a read transaction on10151** all schemas ("main", "temp", and any ATTACH-ed databases) whenever the10152** virtual table is used.10153** </dd>10154** </dl>10155*/10156#define SQLITE_VTAB_CONSTRAINT_SUPPORT 110157#define SQLITE_VTAB_INNOCUOUS 210158#define SQLITE_VTAB_DIRECTONLY 310159#define SQLITE_VTAB_USES_ALL_SCHEMAS 41016010161/*10162** CAPI3REF: Determine The Virtual Table Conflict Policy10163**10164** This function may only be called from within a call to the [xUpdate] method10165** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The10166** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL],10167** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode10168** of the SQL statement that triggered the call to the [xUpdate] method of the10169** [virtual table].10170*/10171SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);1017210173/*10174** CAPI3REF: Determine If Virtual Table Column Access Is For UPDATE10175**10176** If the sqlite3_vtab_nochange(X) routine is called within the [xColumn]10177** method of a [virtual table], then it might return true if the10178** column is being fetched as part of an UPDATE operation during which the10179** column value will not change. The virtual table implementation can use10180** this hint as permission to substitute a return value that is less10181** expensive to compute and that the corresponding10182** [xUpdate] method understands as a "no-change" value.10183**10184** If the [xColumn] method calls sqlite3_vtab_nochange() and finds that10185** the column is not changed by the UPDATE statement, then the xColumn10186** method can optionally return without setting a result, without calling10187** any of the [sqlite3_result_int|sqlite3_result_xxxxx() interfaces].10188** In that case, [sqlite3_value_nochange(X)] will return true for the10189** same column in the [xUpdate] method.10190**10191** The sqlite3_vtab_nochange() routine is an optimization. Virtual table10192** implementations should continue to give a correct answer even if the10193** sqlite3_vtab_nochange() interface were to always return false. In the10194** current implementation, the sqlite3_vtab_nochange() interface does always10195** returns false for the enhanced [UPDATE FROM] statement.10196*/10197SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);1019810199/*10200** CAPI3REF: Determine The Collation For a Virtual Table Constraint10201** METHOD: sqlite3_index_info10202**10203** This function may only be called from within a call to the [xBestIndex]10204** method of a [virtual table]. This function returns a pointer to a string10205** that is the name of the appropriate collation sequence to use for text10206** comparisons on the constraint identified by its arguments.10207**10208** The first argument must be the pointer to the [sqlite3_index_info] object10209** that is the first parameter to the xBestIndex() method. The second argument10210** must be an index into the aConstraint[] array belonging to the10211** sqlite3_index_info structure passed to xBestIndex.10212**10213** Important:10214** The first parameter must be the same pointer that is passed into the10215** xBestMethod() method. The first parameter may not be a pointer to a10216** different [sqlite3_index_info] object, even an exact copy.10217**10218** The return value is computed as follows:10219**10220** <ol>10221** <li><p> If the constraint comes from a WHERE clause expression that contains10222** a [COLLATE operator], then the name of the collation specified by10223** that COLLATE operator is returned.10224** <li><p> If there is no COLLATE operator, but the column that is the subject10225** of the constraint specifies an alternative collating sequence via10226** a [COLLATE clause] on the column definition within the CREATE TABLE10227** statement that was passed into [sqlite3_declare_vtab()], then the10228** name of that alternative collating sequence is returned.10229** <li><p> Otherwise, "BINARY" is returned.10230** </ol>10231*/10232SQLITE_API const char *sqlite3_vtab_collation(sqlite3_index_info*,int);1023310234/*10235** CAPI3REF: Determine if a virtual table query is DISTINCT10236** METHOD: sqlite3_index_info10237**10238** This API may only be used from within an [xBestIndex|xBestIndex method]10239** of a [virtual table] implementation. The result of calling this10240** interface from outside of xBestIndex() is undefined and probably harmful.10241**10242** ^The sqlite3_vtab_distinct() interface returns an integer between 0 and10243** 3. The integer returned by sqlite3_vtab_distinct()10244** gives the virtual table additional information about how the query10245** planner wants the output to be ordered. As long as the virtual table10246** can meet the ordering requirements of the query planner, it may set10247** the "orderByConsumed" flag.10248**10249** <ol><li value="0"><p>10250** ^If the sqlite3_vtab_distinct() interface returns 0, that means10251** that the query planner needs the virtual table to return all rows in the10252** sort order defined by the "nOrderBy" and "aOrderBy" fields of the10253** [sqlite3_index_info] object. This is the default expectation. If the10254** virtual table outputs all rows in sorted order, then it is always safe for10255** the xBestIndex method to set the "orderByConsumed" flag, regardless of10256** the return value from sqlite3_vtab_distinct().10257** <li value="1"><p>10258** ^(If the sqlite3_vtab_distinct() interface returns 1, that means10259** that the query planner does not need the rows to be returned in sorted order10260** as long as all rows with the same values in all columns identified by the10261** "aOrderBy" field are adjacent.)^ This mode is used when the query planner10262** is doing a GROUP BY.10263** <li value="2"><p>10264** ^(If the sqlite3_vtab_distinct() interface returns 2, that means10265** that the query planner does not need the rows returned in any particular10266** order, as long as rows with the same values in all columns identified10267** by "aOrderBy" are adjacent.)^ ^(Furthermore, when two or more rows10268** contain the same values for all columns identified by "colUsed", all but10269** one such row may optionally be omitted from the result.)^10270** The virtual table is not required to omit rows that are duplicates10271** over the "colUsed" columns, but if the virtual table can do that without10272** too much extra effort, it could potentially help the query to run faster.10273** This mode is used for a DISTINCT query.10274** <li value="3"><p>10275** ^(If the sqlite3_vtab_distinct() interface returns 3, that means the10276** virtual table must return rows in the order defined by "aOrderBy" as10277** if the sqlite3_vtab_distinct() interface had returned 0. However if10278** two or more rows in the result have the same values for all columns10279** identified by "colUsed", then all but one such row may optionally be10280** omitted.)^ Like when the return value is 2, the virtual table10281** is not required to omit rows that are duplicates over the "colUsed"10282** columns, but if the virtual table can do that without10283** too much extra effort, it could potentially help the query to run faster.10284** This mode is used for queries10285** that have both DISTINCT and ORDER BY clauses.10286** </ol>10287**10288** <p>The following table summarizes the conditions under which the10289** virtual table is allowed to set the "orderByConsumed" flag based on10290** the value returned by sqlite3_vtab_distinct(). This table is a10291** restatement of the previous four paragraphs:10292**10293** <table border=1 cellspacing=0 cellpadding=10 width="90%">10294** <tr>10295** <td valign="top">sqlite3_vtab_distinct() return value10296** <td valign="top">Rows are returned in aOrderBy order10297** <td valign="top">Rows with the same value in all aOrderBy columns are adjacent10298** <td valign="top">Duplicates over all colUsed columns may be omitted10299** <tr><td>0<td>yes<td>yes<td>no10300** <tr><td>1<td>no<td>yes<td>no10301** <tr><td>2<td>no<td>yes<td>yes10302** <tr><td>3<td>yes<td>yes<td>yes10303** </table>10304**10305** ^For the purposes of comparing virtual table output values to see if the10306** values are the same value for sorting purposes, two NULL values are considered10307** to be the same. In other words, the comparison operator is "IS"10308** (or "IS NOT DISTINCT FROM") and not "==".10309**10310** If a virtual table implementation is unable to meet the requirements10311** specified above, then it must not set the "orderByConsumed" flag in the10312** [sqlite3_index_info] object or an incorrect answer may result.10313**10314** ^A virtual table implementation is always free to return rows in any order10315** it wants, as long as the "orderByConsumed" flag is not set. ^When the10316** "orderByConsumed" flag is unset, the query planner will add extra10317** [bytecode] to ensure that the final results returned by the SQL query are10318** ordered correctly. The use of the "orderByConsumed" flag and the10319** sqlite3_vtab_distinct() interface is merely an optimization. ^Careful10320** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed"10321** flag might help queries against a virtual table to run faster. Being10322** overly aggressive and setting the "orderByConsumed" flag when it is not10323** valid to do so, on the other hand, might cause SQLite to return incorrect10324** results.10325*/10326SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*);1032710328/*10329** CAPI3REF: Identify and handle IN constraints in xBestIndex10330**10331** This interface may only be used from within an10332** [xBestIndex|xBestIndex() method] of a [virtual table] implementation.10333** The result of invoking this interface from any other context is10334** undefined and probably harmful.10335**10336** ^(A constraint on a virtual table of the form10337** "[IN operator|column IN (...)]" is10338** communicated to the xBestIndex method as a10339** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use10340** this constraint, it must set the corresponding10341** aConstraintUsage[].argvIndex to a positive integer. ^(Then, under10342** the usual mode of handling IN operators, SQLite generates [bytecode]10343** that invokes the [xFilter|xFilter() method] once for each value10344** on the right-hand side of the IN operator.)^ Thus the virtual table10345** only sees a single value from the right-hand side of the IN operator10346** at a time.10347**10348** In some cases, however, it would be advantageous for the virtual10349** table to see all values on the right-hand of the IN operator all at10350** once. The sqlite3_vtab_in() interfaces facilitates this in two ways:10351**10352** <ol>10353** <li><p>10354** ^A call to sqlite3_vtab_in(P,N,-1) will return true (non-zero)10355** if and only if the [sqlite3_index_info|P->aConstraint][N] constraint10356** is an [IN operator] that can be processed all at once. ^In other words,10357** sqlite3_vtab_in() with -1 in the third argument is a mechanism10358** by which the virtual table can ask SQLite if all-at-once processing10359** of the IN operator is even possible.10360**10361** <li><p>10362** ^A call to sqlite3_vtab_in(P,N,F) with F==1 or F==0 indicates10363** to SQLite that the virtual table does or does not want to process10364** the IN operator all-at-once, respectively. ^Thus when the third10365** parameter (F) is non-negative, this interface is the mechanism by10366** which the virtual table tells SQLite how it wants to process the10367** IN operator.10368** </ol>10369**10370** ^The sqlite3_vtab_in(P,N,F) interface can be invoked multiple times10371** within the same xBestIndex method call. ^For any given P,N pair,10372** the return value from sqlite3_vtab_in(P,N,F) will always be the same10373** within the same xBestIndex call. ^If the interface returns true10374** (non-zero), that means that the constraint is an IN operator10375** that can be processed all-at-once. ^If the constraint is not an IN10376** operator or cannot be processed all-at-once, then the interface returns10377** false.10378**10379** ^(All-at-once processing of the IN operator is selected if both of the10380** following conditions are met:10381**10382** <ol>10383** <li><p> The P->aConstraintUsage[N].argvIndex value is set to a positive10384** integer. This is how the virtual table tells SQLite that it wants to10385** use the N-th constraint.10386**10387** <li><p> The last call to sqlite3_vtab_in(P,N,F) for which F was10388** non-negative had F>=1.10389** </ol>)^10390**10391** ^If either or both of the conditions above are false, then SQLite uses10392** the traditional one-at-a-time processing strategy for the IN constraint.10393** ^If both conditions are true, then the argvIndex-th parameter to the10394** xFilter method will be an [sqlite3_value] that appears to be NULL,10395** but which can be passed to [sqlite3_vtab_in_first()] and10396** [sqlite3_vtab_in_next()] to find all values on the right-hand side10397** of the IN constraint.10398*/10399SQLITE_API int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle);1040010401/*10402** CAPI3REF: Find all elements on the right-hand side of an IN constraint.10403**10404** These interfaces are only useful from within the10405** [xFilter|xFilter() method] of a [virtual table] implementation.10406** The result of invoking these interfaces from any other context10407** is undefined and probably harmful.10408**10409** The X parameter in a call to sqlite3_vtab_in_first(X,P) or10410** sqlite3_vtab_in_next(X,P) should be one of the parameters to the10411** xFilter method which invokes these routines, and specifically10412** a parameter that was previously selected for all-at-once IN constraint10413** processing using the [sqlite3_vtab_in()] interface in the10414** [xBestIndex|xBestIndex method]. ^(If the X parameter is not10415** an xFilter argument that was selected for all-at-once IN constraint10416** processing, then these routines return [SQLITE_ERROR].)^10417**10418** ^(Use these routines to access all values on the right-hand side10419** of the IN constraint using code like the following:10420**10421** <blockquote><pre>10422** for(rc=sqlite3_vtab_in_first(pList, &pVal);10423** rc==SQLITE_OK && pVal;10424** rc=sqlite3_vtab_in_next(pList, &pVal)10425** ){10426** // do something with pVal10427** }10428** if( rc!=SQLITE_DONE ){10429** // an error has occurred10430** }10431** </pre></blockquote>)^10432**10433** ^On success, the sqlite3_vtab_in_first(X,P) and sqlite3_vtab_in_next(X,P)10434** routines return SQLITE_OK and set *P to point to the first or next value10435** on the RHS of the IN constraint. ^If there are no more values on the10436** right hand side of the IN constraint, then *P is set to NULL and these10437** routines return [SQLITE_DONE]. ^The return value might be10438** some other value, such as SQLITE_NOMEM, in the event of a malfunction.10439**10440** The *ppOut values returned by these routines are only valid until the10441** next call to either of these routines or until the end of the xFilter10442** method from which these routines were called. If the virtual table10443** implementation needs to retain the *ppOut values for longer, it must make10444** copies. The *ppOut values are [protected sqlite3_value|protected].10445*/10446SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut);10447SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut);1044810449/*10450** CAPI3REF: Constraint values in xBestIndex()10451** METHOD: sqlite3_index_info10452**10453** This API may only be used from within the [xBestIndex|xBestIndex method]10454** of a [virtual table] implementation. The result of calling this interface10455** from outside of an xBestIndex method are undefined and probably harmful.10456**10457** ^When the sqlite3_vtab_rhs_value(P,J,V) interface is invoked from within10458** the [xBestIndex] method of a [virtual table] implementation, with P being10459** a copy of the [sqlite3_index_info] object pointer passed into xBestIndex and10460** J being a 0-based index into P->aConstraint[], then this routine10461** attempts to set *V to the value of the right-hand operand of10462** that constraint if the right-hand operand is known. ^If the10463** right-hand operand is not known, then *V is set to a NULL pointer.10464** ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if10465** and only if *V is set to a value. ^The sqlite3_vtab_rhs_value(P,J,V)10466** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th10467** constraint is not available. ^The sqlite3_vtab_rhs_value() interface10468** can return a result code other than SQLITE_OK or SQLITE_NOTFOUND if10469** something goes wrong.10470**10471** The sqlite3_vtab_rhs_value() interface is usually only successful if10472** the right-hand operand of a constraint is a literal value in the original10473** SQL statement. If the right-hand operand is an expression or a reference10474** to some other column or a [host parameter], then sqlite3_vtab_rhs_value()10475** will probably return [SQLITE_NOTFOUND].10476**10477** ^(Some constraints, such as [SQLITE_INDEX_CONSTRAINT_ISNULL] and10478** [SQLITE_INDEX_CONSTRAINT_ISNOTNULL], have no right-hand operand. For such10479** constraints, sqlite3_vtab_rhs_value() always returns SQLITE_NOTFOUND.)^10480**10481** ^The [sqlite3_value] object returned in *V is a protected sqlite3_value10482** and remains valid for the duration of the xBestIndex method call.10483** ^When xBestIndex returns, the sqlite3_value object returned by10484** sqlite3_vtab_rhs_value() is automatically deallocated.10485**10486** The "_rhs_" in the name of this routine is an abbreviation for10487** "Right-Hand Side".10488*/10489SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal);1049010491/*10492** CAPI3REF: Conflict resolution modes10493** KEYWORDS: {conflict resolution mode}10494**10495** These constants are returned by [sqlite3_vtab_on_conflict()] to10496** inform a [virtual table] implementation of the [ON CONFLICT] mode10497** for the SQL statement being evaluated.10498**10499** Note that the [SQLITE_IGNORE] constant is also used as a potential10500** return value from the [sqlite3_set_authorizer()] callback and that10501** [SQLITE_ABORT] is also a [result code].10502*/10503#define SQLITE_ROLLBACK 110504/* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */10505#define SQLITE_FAIL 310506/* #define SQLITE_ABORT 4 // Also an error code */10507#define SQLITE_REPLACE 51050810509/*10510** CAPI3REF: Prepared Statement Scan Status Opcodes10511** KEYWORDS: {scanstatus options}10512**10513** The following constants can be used for the T parameter to the10514** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a10515** different metric for sqlite3_stmt_scanstatus() to return.10516**10517** When the value returned to V is a string, space to hold that string is10518** managed by the prepared statement S and will be automatically freed when10519** S is finalized.10520**10521** Not all values are available for all query elements. When a value is10522** not available, the output variable is set to -1 if the value is numeric,10523** or to NULL if it is a string (SQLITE_SCANSTAT_NAME).10524**10525** <dl>10526** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>10527** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be10528** set to the total number of times that the X-th loop has run.</dd>10529**10530** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>10531** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be set10532** to the total number of rows examined by all iterations of the X-th loop.</dd>10533**10534** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>10535** <dd>^The "double" variable pointed to by the V parameter will be set to the10536** query planner's estimate for the average number of rows output from each10537** iteration of the X-th loop. If the query planner's estimate was accurate,10538** then this value will approximate the quotient NVISIT/NLOOP and the10539** product of this value for all prior loops with the same SELECTID will10540** be the NLOOP value for the current loop.</dd>10541**10542** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>10543** <dd>^The "const char *" variable pointed to by the V parameter will be set10544** to a zero-terminated UTF-8 string containing the name of the index or table10545** used for the X-th loop.</dd>10546**10547** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>10548** <dd>^The "const char *" variable pointed to by the V parameter will be set10549** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]10550** description for the X-th loop.</dd>10551**10552** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECTID</dt>10553** <dd>^The "int" variable pointed to by the V parameter will be set to the10554** id for the X-th query plan element. The id value is unique within the10555** statement. The select-id is the same value as is output in the first10556** column of an [EXPLAIN QUERY PLAN] query.</dd>10557**10558** [[SQLITE_SCANSTAT_PARENTID]] <dt>SQLITE_SCANSTAT_PARENTID</dt>10559** <dd>The "int" variable pointed to by the V parameter will be set to the10560** id of the parent of the current query element, if applicable, or10561** to zero if the query element has no parent. This is the same value as10562** returned in the second column of an [EXPLAIN QUERY PLAN] query.</dd>10563**10564** [[SQLITE_SCANSTAT_NCYCLE]] <dt>SQLITE_SCANSTAT_NCYCLE</dt>10565** <dd>The sqlite3_int64 output value is set to the number of cycles,10566** according to the processor time-stamp counter, that elapsed while the10567** query element was being processed. This value is not available for10568** all query elements - if it is unavailable the output variable is10569** set to -1.</dd>10570** </dl>10571*/10572#define SQLITE_SCANSTAT_NLOOP 010573#define SQLITE_SCANSTAT_NVISIT 110574#define SQLITE_SCANSTAT_EST 210575#define SQLITE_SCANSTAT_NAME 310576#define SQLITE_SCANSTAT_EXPLAIN 410577#define SQLITE_SCANSTAT_SELECTID 510578#define SQLITE_SCANSTAT_PARENTID 610579#define SQLITE_SCANSTAT_NCYCLE 71058010581/*10582** CAPI3REF: Prepared Statement Scan Status10583** METHOD: sqlite3_stmt10584**10585** These interfaces return information about the predicted and measured10586** performance for pStmt. Advanced applications can use this10587** interface to compare the predicted and the measured performance and10588** issue warnings and/or rerun [ANALYZE] if discrepancies are found.10589**10590** Since this interface is expected to be rarely used, it is only10591** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS]10592** compile-time option.10593**10594** The "iScanStatusOp" parameter determines which status information to return.10595** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior10596** of this interface is undefined. ^The requested measurement is written into10597** a variable pointed to by the "pOut" parameter.10598**10599** The "flags" parameter must be passed a mask of flags. At present only10600** one flag is defined - SQLITE_SCANSTAT_COMPLEX. If SQLITE_SCANSTAT_COMPLEX10601** is specified, then status information is available for all elements10602** of a query plan that are reported by "EXPLAIN QUERY PLAN" output. If10603** SQLITE_SCANSTAT_COMPLEX is not specified, then only query plan elements10604** that correspond to query loops (the "SCAN..." and "SEARCH..." elements of10605** the EXPLAIN QUERY PLAN output) are available. Invoking API10606** sqlite3_stmt_scanstatus() is equivalent to calling10607** sqlite3_stmt_scanstatus_v2() with a zeroed flags parameter.10608**10609** Parameter "idx" identifies the specific query element to retrieve statistics10610** for. Query elements are numbered starting from zero. A value of -1 may10611** retrieve statistics for the entire query. ^If idx is out of range10612** - less than -1 or greater than or equal to the total number of query10613** elements used to implement the statement - a non-zero value is returned and10614** the variable that pOut points to is unchanged.10615**10616** See also: [sqlite3_stmt_scanstatus_reset()]10617*/10618SQLITE_API int sqlite3_stmt_scanstatus(10619sqlite3_stmt *pStmt, /* Prepared statement for which info desired */10620int idx, /* Index of loop to report on */10621int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */10622void *pOut /* Result written here */10623);10624SQLITE_API int sqlite3_stmt_scanstatus_v2(10625sqlite3_stmt *pStmt, /* Prepared statement for which info desired */10626int idx, /* Index of loop to report on */10627int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */10628int flags, /* Mask of flags defined below */10629void *pOut /* Result written here */10630);1063110632/*10633** CAPI3REF: Prepared Statement Scan Status10634** KEYWORDS: {scan status flags}10635*/10636#define SQLITE_SCANSTAT_COMPLEX 0x00011063710638/*10639** CAPI3REF: Zero Scan-Status Counters10640** METHOD: sqlite3_stmt10641**10642** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.10643**10644** This API is only available if the library is built with pre-processor10645** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.10646*/10647SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);1064810649/*10650** CAPI3REF: Flush caches to disk mid-transaction10651** METHOD: sqlite310652**10653** ^If a write-transaction is open on [database connection] D when the10654** [sqlite3_db_cacheflush(D)] interface is invoked, any dirty10655** pages in the pager-cache that are not currently in use are written out10656** to disk. A dirty page may be in use if a database cursor created by an10657** active SQL statement is reading from it, or if it is page 1 of a database10658** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)]10659** interface flushes caches for all schemas - "main", "temp", and10660** any [attached] databases.10661**10662** ^If this function needs to obtain extra database locks before dirty pages10663** can be flushed to disk, it does so. ^If those locks cannot be obtained10664** immediately and there is a busy-handler callback configured, it is invoked10665** in the usual manner. ^If the required lock still cannot be obtained, then10666** the database is skipped and an attempt made to flush any dirty pages10667** belonging to the next (if any) database. ^If any databases are skipped10668** because locks cannot be obtained, but no other error occurs, this10669** function returns SQLITE_BUSY.10670**10671** ^If any other error occurs while flushing dirty pages to disk (for10672** example an IO error or out-of-memory condition), then processing is10673** abandoned and an SQLite [error code] is returned to the caller immediately.10674**10675** ^Otherwise, if no error occurs, [sqlite3_db_cacheflush()] returns SQLITE_OK.10676**10677** ^This function does not set the database handle error code or message10678** returned by the [sqlite3_errcode()] and [sqlite3_errmsg()] functions.10679*/10680SQLITE_API int sqlite3_db_cacheflush(sqlite3*);1068110682/*10683** CAPI3REF: The pre-update hook.10684** METHOD: sqlite310685**10686** ^These interfaces are only available if SQLite is compiled using the10687** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option.10688**10689** ^The [sqlite3_preupdate_hook()] interface registers a callback function10690** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation10691** on a database table.10692** ^At most one preupdate hook may be registered at a time on a single10693** [database connection]; each call to [sqlite3_preupdate_hook()] overrides10694** the previous setting.10695** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()]10696** with a NULL pointer as the second parameter.10697** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as10698** the first parameter to callbacks.10699**10700** ^The preupdate hook only fires for changes to real database tables; the10701** preupdate hook is not invoked for changes to [virtual tables] or to10702** system tables like sqlite_sequence or sqlite_stat1.10703**10704** ^The second parameter to the preupdate callback is a pointer to10705** the [database connection] that registered the preupdate hook.10706** ^The third parameter to the preupdate callback is one of the constants10707** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the10708** kind of update operation that is about to occur.10709** ^(The fourth parameter to the preupdate callback is the name of the10710** database within the database connection that is being modified. This10711** will be "main" for the main database or "temp" for TEMP tables or10712** the name given after the AS keyword in the [ATTACH] statement for attached10713** databases.)^10714** ^The fifth parameter to the preupdate callback is the name of the10715** table that is being modified.10716**10717** For an UPDATE or DELETE operation on a [rowid table], the sixth10718** parameter passed to the preupdate callback is the initial [rowid] of the10719** row being modified or deleted. For an INSERT operation on a rowid table,10720** or any operation on a WITHOUT ROWID table, the value of the sixth10721** parameter is undefined. For an INSERT or UPDATE on a rowid table the10722** seventh parameter is the final rowid value of the row being inserted10723** or updated. The value of the seventh parameter passed to the callback10724** function is not defined for operations on WITHOUT ROWID tables, or for10725** DELETE operations on rowid tables.10726**10727** ^The sqlite3_preupdate_hook(D,C,P) function returns the P argument from10728** the previous call on the same [database connection] D, or NULL for10729** the first call on D.10730**10731** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],10732** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces10733** provide additional information about a preupdate event. These routines10734** may only be called from within a preupdate callback. Invoking any of10735** these routines from outside of a preupdate callback or with a10736** [database connection] pointer that is different from the one supplied10737** to the preupdate callback results in undefined and probably undesirable10738** behavior.10739**10740** ^The [sqlite3_preupdate_count(D)] interface returns the number of columns10741** in the row that is being inserted, updated, or deleted.10742**10743** ^The [sqlite3_preupdate_old(D,N,P)] interface writes into P a pointer to10744** a [protected sqlite3_value] that contains the value of the Nth column of10745** the table row before it is updated. The N parameter must be between 010746** and one less than the number of columns or the behavior will be10747** undefined. This must only be used within SQLITE_UPDATE and SQLITE_DELETE10748** preupdate callbacks; if it is used by an SQLITE_INSERT callback then the10749** behavior is undefined. The [sqlite3_value] that P points to10750** will be destroyed when the preupdate callback returns.10751**10752** ^The [sqlite3_preupdate_new(D,N,P)] interface writes into P a pointer to10753** a [protected sqlite3_value] that contains the value of the Nth column of10754** the table row after it is updated. The N parameter must be between 010755** and one less than the number of columns or the behavior will be10756** undefined. This must only be used within SQLITE_INSERT and SQLITE_UPDATE10757** preupdate callbacks; if it is used by an SQLITE_DELETE callback then the10758** behavior is undefined. The [sqlite3_value] that P points to10759** will be destroyed when the preupdate callback returns.10760**10761** ^The [sqlite3_preupdate_depth(D)] interface returns 0 if the preupdate10762** callback was invoked as a result of a direct insert, update, or delete10763** operation; or 1 for inserts, updates, or deletes invoked by top-level10764** triggers; or 2 for changes resulting from triggers called by top-level10765** triggers; and so forth.10766**10767** When the [sqlite3_blob_write()] API is used to update a blob column,10768** the pre-update hook is invoked with SQLITE_DELETE, because10769** the new values are not yet available. In this case, when a10770** callback made with op==SQLITE_DELETE is actually a write using the10771** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns10772** the index of the column being written. In other cases, where the10773** pre-update hook is being invoked for some other reason, including a10774** regular DELETE, sqlite3_preupdate_blobwrite() returns -1.10775**10776** See also: [sqlite3_update_hook()]10777*/10778#if defined(SQLITE_ENABLE_PREUPDATE_HOOK)10779SQLITE_API void *sqlite3_preupdate_hook(10780sqlite3 *db,10781void(*xPreUpdate)(10782void *pCtx, /* Copy of third arg to preupdate_hook() */10783sqlite3 *db, /* Database handle */10784int op, /* SQLITE_UPDATE, DELETE or INSERT */10785char const *zDb, /* Database name */10786char const *zName, /* Table name */10787sqlite3_int64 iKey1, /* Rowid of row about to be deleted/updated */10788sqlite3_int64 iKey2 /* New rowid value (for a rowid UPDATE) */10789),10790void*10791);10792SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);10793SQLITE_API int sqlite3_preupdate_count(sqlite3 *);10794SQLITE_API int sqlite3_preupdate_depth(sqlite3 *);10795SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);10796SQLITE_API int sqlite3_preupdate_blobwrite(sqlite3 *);10797#endif1079810799/*10800** CAPI3REF: Low-level system error code10801** METHOD: sqlite310802**10803** ^Attempt to return the underlying operating system error code or error10804** number that caused the most recent I/O error or failure to open a file.10805** The return value is OS-dependent. For example, on unix systems, after10806** [sqlite3_open_v2()] returns [SQLITE_CANTOPEN], this interface could be10807** called to get back the underlying "errno" that caused the problem, such10808** as ENOSPC, EAUTH, EISDIR, and so forth.10809*/10810SQLITE_API int sqlite3_system_errno(sqlite3*);1081110812/*10813** CAPI3REF: Database Snapshot10814** KEYWORDS: {snapshot} {sqlite3_snapshot}10815**10816** An instance of the snapshot object records the state of a [WAL mode]10817** database for some specific point in history.10818**10819** In [WAL mode], multiple [database connections] that are open on the10820** same database file can each be reading a different historical version10821** of the database file. When a [database connection] begins a read10822** transaction, that connection sees an unchanging copy of the database10823** as it existed for the point in time when the transaction first started.10824** Subsequent changes to the database from other connections are not seen10825** by the reader until a new read transaction is started.10826**10827** The sqlite3_snapshot object records state information about an historical10828** version of the database file so that it is possible to later open a new read10829** transaction that sees that historical version of the database rather than10830** the most recent version.10831*/10832typedef struct sqlite3_snapshot {10833unsigned char hidden[48];10834} sqlite3_snapshot;1083510836/*10837** CAPI3REF: Record A Database Snapshot10838** CONSTRUCTOR: sqlite3_snapshot10839**10840** ^The [sqlite3_snapshot_get(D,S,P)] interface attempts to make a10841** new [sqlite3_snapshot] object that records the current state of10842** schema S in database connection D. ^On success, the10843** [sqlite3_snapshot_get(D,S,P)] interface writes a pointer to the newly10844** created [sqlite3_snapshot] object into *P and returns SQLITE_OK.10845** If there is not already a read-transaction open on schema S when10846** this function is called, one is opened automatically.10847**10848** If a read-transaction is opened by this function, then it is guaranteed10849** that the returned snapshot object may not be invalidated by a database10850** writer or checkpointer until after the read-transaction is closed. This10851** is not guaranteed if a read-transaction is already open when this10852** function is called. In that case, any subsequent write or checkpoint10853** operation on the database may invalidate the returned snapshot handle,10854** even while the read-transaction remains open.10855**10856** The following must be true for this function to succeed. If any of10857** the following statements are false when sqlite3_snapshot_get() is10858** called, SQLITE_ERROR is returned. The final value of *P is undefined10859** in this case.10860**10861** <ul>10862** <li> The database handle must not be in [autocommit mode].10863**10864** <li> Schema S of [database connection] D must be a [WAL mode] database.10865**10866** <li> There must not be a write transaction open on schema S of database10867** connection D.10868**10869** <li> One or more transactions must have been written to the current wal10870** file since it was created on disk (by any connection). This means10871** that a snapshot cannot be taken on a wal mode database with no wal10872** file immediately after it is first opened. At least one transaction10873** must be written to it first.10874** </ul>10875**10876** This function may also return SQLITE_NOMEM. If it is called with the10877** database handle in autocommit mode but fails for some other reason,10878** whether or not a read transaction is opened on schema S is undefined.10879**10880** The [sqlite3_snapshot] object returned from a successful call to10881** [sqlite3_snapshot_get()] must be freed using [sqlite3_snapshot_free()]10882** to avoid a memory leak.10883**10884** The [sqlite3_snapshot_get()] interface is only available when the10885** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.10886*/10887SQLITE_API int sqlite3_snapshot_get(10888sqlite3 *db,10889const char *zSchema,10890sqlite3_snapshot **ppSnapshot10891);1089210893/*10894** CAPI3REF: Start a read transaction on an historical snapshot10895** METHOD: sqlite3_snapshot10896**10897** ^The [sqlite3_snapshot_open(D,S,P)] interface either starts a new read10898** transaction or upgrades an existing one for schema S of10899** [database connection] D such that the read transaction refers to10900** historical [snapshot] P, rather than the most recent change to the10901** database. ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK10902** on success or an appropriate [error code] if it fails.10903**10904** ^In order to succeed, the database connection must not be in10905** [autocommit mode] when [sqlite3_snapshot_open(D,S,P)] is called. If there10906** is already a read transaction open on schema S, then the database handle10907** must have no active statements (SELECT statements that have been passed10908** to sqlite3_step() but not sqlite3_reset() or sqlite3_finalize()).10909** SQLITE_ERROR is returned if either of these conditions is violated, or10910** if schema S does not exist, or if the snapshot object is invalid.10911**10912** ^A call to sqlite3_snapshot_open() will fail to open if the specified10913** snapshot has been overwritten by a [checkpoint]. In this case10914** SQLITE_ERROR_SNAPSHOT is returned.10915**10916** If there is already a read transaction open when this function is10917** invoked, then the same read transaction remains open (on the same10918** database snapshot) if SQLITE_ERROR, SQLITE_BUSY or SQLITE_ERROR_SNAPSHOT10919** is returned. If another error code - for example SQLITE_PROTOCOL or an10920** SQLITE_IOERR error code - is returned, then the final state of the10921** read transaction is undefined. If SQLITE_OK is returned, then the10922** read transaction is now open on database snapshot P.10923**10924** ^(A call to [sqlite3_snapshot_open(D,S,P)] will fail if the10925** database connection D does not know that the database file for10926** schema S is in [WAL mode]. A database connection might not know10927** that the database file is in [WAL mode] if there has been no prior10928** I/O on that database connection, or if the database entered [WAL mode]10929** after the most recent I/O on the database connection.)^10930** (Hint: Run "[PRAGMA application_id]" against a newly opened10931** database connection in order to make it ready to use snapshots.)10932**10933** The [sqlite3_snapshot_open()] interface is only available when the10934** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.10935*/10936SQLITE_API int sqlite3_snapshot_open(10937sqlite3 *db,10938const char *zSchema,10939sqlite3_snapshot *pSnapshot10940);1094110942/*10943** CAPI3REF: Destroy a snapshot10944** DESTRUCTOR: sqlite3_snapshot10945**10946** ^The [sqlite3_snapshot_free(P)] interface destroys [sqlite3_snapshot] P.10947** The application must eventually free every [sqlite3_snapshot] object10948** using this routine to avoid a memory leak.10949**10950** The [sqlite3_snapshot_free()] interface is only available when the10951** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.10952*/10953SQLITE_API void sqlite3_snapshot_free(sqlite3_snapshot*);1095410955/*10956** CAPI3REF: Compare the ages of two snapshot handles.10957** METHOD: sqlite3_snapshot10958**10959** The sqlite3_snapshot_cmp(P1, P2) interface is used to compare the ages10960** of two valid snapshot handles.10961**10962** If the two snapshot handles are not associated with the same database10963** file, the result of the comparison is undefined.10964**10965** Additionally, the result of the comparison is only valid if both of the10966** snapshot handles were obtained by calling sqlite3_snapshot_get() since the10967** last time the wal file was deleted. The wal file is deleted when the10968** database is changed back to rollback mode or when the number of database10969** clients drops to zero. If either snapshot handle was obtained before the10970** wal file was last deleted, the value returned by this function10971** is undefined.10972**10973** Otherwise, this API returns a negative value if P1 refers to an older10974** snapshot than P2, zero if the two handles refer to the same database10975** snapshot, and a positive value if P1 is a newer snapshot than P2.10976**10977** This interface is only available if SQLite is compiled with the10978** [SQLITE_ENABLE_SNAPSHOT] option.10979*/10980SQLITE_API int sqlite3_snapshot_cmp(10981sqlite3_snapshot *p1,10982sqlite3_snapshot *p210983);1098410985/*10986** CAPI3REF: Recover snapshots from a wal file10987** METHOD: sqlite3_snapshot10988**10989** If a [WAL file] remains on disk after all database connections close10990** (either through the use of the [SQLITE_FCNTL_PERSIST_WAL] [file control]10991** or because the last process to have the database opened exited without10992** calling [sqlite3_close()]) and a new connection is subsequently opened10993** on that database and [WAL file], the [sqlite3_snapshot_open()] interface10994** will only be able to open the last transaction added to the WAL file10995** even though the WAL file contains other valid transactions.10996**10997** This function attempts to scan the WAL file associated with database zDb10998** of database handle db and make all valid snapshots available to10999** sqlite3_snapshot_open(). It is an error if there is already a read11000** transaction open on the database, or if the database is not a WAL mode11001** database.11002**11003** SQLITE_OK is returned if successful, or an SQLite error code otherwise.11004**11005** This interface is only available if SQLite is compiled with the11006** [SQLITE_ENABLE_SNAPSHOT] option.11007*/11008SQLITE_API int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);1100911010/*11011** CAPI3REF: Serialize a database11012**11013** The sqlite3_serialize(D,S,P,F) interface returns a pointer to11014** memory that is a serialization of the S database on11015** [database connection] D. If S is a NULL pointer, the main database is used.11016** If P is not a NULL pointer, then the size of the database in bytes11017** is written into *P.11018**11019** For an ordinary on-disk database file, the serialization is just a11020** copy of the disk file. For an in-memory database or a "TEMP" database,11021** the serialization is the same sequence of bytes which would be written11022** to disk if that database were backed up to disk.11023**11024** The usual case is that sqlite3_serialize() copies the serialization of11025** the database into memory obtained from [sqlite3_malloc64()] and returns11026** a pointer to that memory. The caller is responsible for freeing the11027** returned value to avoid a memory leak. However, if the F argument11028** contains the SQLITE_SERIALIZE_NOCOPY bit, then no memory allocations11029** are made, and the sqlite3_serialize() function will return a pointer11030** to the contiguous memory representation of the database that SQLite11031** is currently using for that database, or NULL if no such contiguous11032** memory representation of the database exists. A contiguous memory11033** representation of the database will usually only exist if there has11034** been a prior call to [sqlite3_deserialize(D,S,...)] with the same11035** values of D and S.11036** The size of the database is written into *P even if the11037** SQLITE_SERIALIZE_NOCOPY bit is set but no contiguous copy11038** of the database exists.11039**11040** After the call, if the SQLITE_SERIALIZE_NOCOPY bit had been set,11041** the returned buffer content will remain accessible and unchanged11042** until either the next write operation on the connection or when11043** the connection is closed, and applications must not modify the11044** buffer. If the bit had been clear, the returned buffer will not11045** be accessed by SQLite after the call.11046**11047** A call to sqlite3_serialize(D,S,P,F) might return NULL even if the11048** SQLITE_SERIALIZE_NOCOPY bit is omitted from argument F if a memory11049** allocation error occurs.11050**11051** This interface is omitted if SQLite is compiled with the11052** [SQLITE_OMIT_DESERIALIZE] option.11053*/11054SQLITE_API unsigned char *sqlite3_serialize(11055sqlite3 *db, /* The database connection */11056const char *zSchema, /* Which DB to serialize. ex: "main", "temp", ... */11057sqlite3_int64 *piSize, /* Write size of the DB here, if not NULL */11058unsigned int mFlags /* Zero or more SQLITE_SERIALIZE_* flags */11059);1106011061/*11062** CAPI3REF: Flags for sqlite3_serialize11063**11064** Zero or more of the following constants can be OR-ed together for11065** the F argument to [sqlite3_serialize(D,S,P,F)].11066**11067** SQLITE_SERIALIZE_NOCOPY means that [sqlite3_serialize()] will return11068** a pointer to contiguous in-memory database that it is currently using,11069** without making a copy of the database. If SQLite is not currently using11070** a contiguous in-memory database, then this option causes11071** [sqlite3_serialize()] to return a NULL pointer. SQLite will only be11072** using a contiguous in-memory database if it has been initialized by a11073** prior call to [sqlite3_deserialize()].11074*/11075#define SQLITE_SERIALIZE_NOCOPY 0x001 /* Do no memory allocations */1107611077/*11078** CAPI3REF: Deserialize a database11079**11080** The sqlite3_deserialize(D,S,P,N,M,F) interface causes the11081** [database connection] D to disconnect from database S and then11082** reopen S as an in-memory database based on the serialization11083** contained in P. If S is a NULL pointer, the main database is11084** used. The serialized database P is N bytes in size. M is the size11085** of the buffer P, which might be larger than N. If M is larger than11086** N, and the SQLITE_DESERIALIZE_READONLY bit is not set in F, then11087** SQLite is permitted to add content to the in-memory database as11088** long as the total size does not exceed M bytes.11089**11090** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will11091** invoke sqlite3_free() on the serialization buffer when the database11092** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then11093** SQLite will try to increase the buffer size using sqlite3_realloc64()11094** if writes on the database cause it to grow larger than M bytes.11095**11096** Applications must not modify the buffer P or invalidate it before11097** the database connection D is closed.11098**11099** The sqlite3_deserialize() interface will fail with SQLITE_BUSY if the11100** database is currently in a read transaction or is involved in a backup11101** operation.11102**11103** It is not possible to deserialize into the TEMP database. If the11104** S argument to sqlite3_deserialize(D,S,P,N,M,F) is "temp" then the11105** function returns SQLITE_ERROR.11106**11107** The deserialized database should not be in [WAL mode]. If the database11108** is in WAL mode, then any attempt to use the database file will result11109** in an [SQLITE_CANTOPEN] error. The application can set the11110** [file format version numbers] (bytes 18 and 19) of the input database P11111** to 0x01 prior to invoking sqlite3_deserialize(D,S,P,N,M,F) to force the11112** database file into rollback mode and work around this limitation.11113**11114** If sqlite3_deserialize(D,S,P,N,M,F) fails for any reason and if the11115** SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then11116** [sqlite3_free()] is invoked on argument P prior to returning.11117**11118** This interface is omitted if SQLite is compiled with the11119** [SQLITE_OMIT_DESERIALIZE] option.11120*/11121SQLITE_API int sqlite3_deserialize(11122sqlite3 *db, /* The database connection */11123const char *zSchema, /* Which DB to reopen with the deserialization */11124unsigned char *pData, /* The serialized database content */11125sqlite3_int64 szDb, /* Number of bytes in the deserialization */11126sqlite3_int64 szBuf, /* Total size of buffer pData[] */11127unsigned mFlags /* Zero or more SQLITE_DESERIALIZE_* flags */11128);1112911130/*11131** CAPI3REF: Flags for sqlite3_deserialize()11132**11133** The following are allowed values for the 6th argument (the F argument) to11134** the [sqlite3_deserialize(D,S,P,N,M,F)] interface.11135**11136** The SQLITE_DESERIALIZE_FREEONCLOSE means that the database serialization11137** in the P argument is held in memory obtained from [sqlite3_malloc64()]11138** and that SQLite should take ownership of this memory and automatically11139** free it when it has finished using it. Without this flag, the caller11140** is responsible for freeing any dynamically allocated memory.11141**11142** The SQLITE_DESERIALIZE_RESIZEABLE flag means that SQLite is allowed to11143** grow the size of the database using calls to [sqlite3_realloc64()]. This11144** flag should only be used if SQLITE_DESERIALIZE_FREEONCLOSE is also used.11145** Without this flag, the deserialized database cannot increase in size beyond11146** the number of bytes specified by the M parameter.11147**11148** The SQLITE_DESERIALIZE_READONLY flag means that the deserialized database11149** should be treated as read-only.11150*/11151#define SQLITE_DESERIALIZE_FREEONCLOSE 1 /* Call sqlite3_free() on close */11152#define SQLITE_DESERIALIZE_RESIZEABLE 2 /* Resize using sqlite3_realloc64() */11153#define SQLITE_DESERIALIZE_READONLY 4 /* Database is read-only */1115411155/*11156** CAPI3REF: Bind array values to the CARRAY table-valued function11157**11158** The sqlite3_carray_bind(S,I,P,N,F,X) interface binds an array value to11159** one of the first argument of the [carray() table-valued function]. The11160** S parameter is a pointer to the [prepared statement] that uses the carray()11161** functions. I is the parameter index to be bound. P is a pointer to the11162** array to be bound, and N is the number of eements in the array. The11163** F argument is one of constants [SQLITE_CARRAY_INT32], [SQLITE_CARRAY_INT64],11164** [SQLITE_CARRAY_DOUBLE], [SQLITE_CARRAY_TEXT], or [SQLITE_CARRAY_BLOB] to11165** indicate the datatype of the array being bound. The X argument is not a11166** NULL pointer, then SQLite will invoke the function X on the P parameter11167** after it has finished using P, even if the call to11168** sqlite3_carray_bind() fails. The special-case finalizer11169** SQLITE_TRANSIENT has no effect here.11170*/11171SQLITE_API int sqlite3_carray_bind(11172sqlite3_stmt *pStmt, /* Statement to be bound */11173int i, /* Parameter index */11174void *aData, /* Pointer to array data */11175int nData, /* Number of data elements */11176int mFlags, /* CARRAY flags */11177void (*xDel)(void*) /* Destructor for aData */11178);1117911180/*11181** CAPI3REF: Datatypes for the CARRAY table-valued function11182**11183** The fifth argument to the [sqlite3_carray_bind()] interface musts be11184** one of the following constants, to specify the datatype of the array11185** that is being bound into the [carray table-valued function].11186*/11187#define SQLITE_CARRAY_INT32 0 /* Data is 32-bit signed integers */11188#define SQLITE_CARRAY_INT64 1 /* Data is 64-bit signed integers */11189#define SQLITE_CARRAY_DOUBLE 2 /* Data is doubles */11190#define SQLITE_CARRAY_TEXT 3 /* Data is char* */11191#define SQLITE_CARRAY_BLOB 4 /* Data is struct iovec */1119211193/*11194** Versions of the above #defines that omit the initial SQLITE_, for11195** legacy compatibility.11196*/11197#define CARRAY_INT32 0 /* Data is 32-bit signed integers */11198#define CARRAY_INT64 1 /* Data is 64-bit signed integers */11199#define CARRAY_DOUBLE 2 /* Data is doubles */11200#define CARRAY_TEXT 3 /* Data is char* */11201#define CARRAY_BLOB 4 /* Data is struct iovec */1120211203/*11204** Undo the hack that converts floating point types to integer for11205** builds on processors without floating point support.11206*/11207#ifdef SQLITE_OMIT_FLOATING_POINT11208# undef double11209#endif1121011211#if defined(__wasi__)11212# undef SQLITE_WASI11213# define SQLITE_WASI 111214# ifndef SQLITE_OMIT_LOAD_EXTENSION11215# define SQLITE_OMIT_LOAD_EXTENSION11216# endif11217# ifndef SQLITE_THREADSAFE11218# define SQLITE_THREADSAFE 011219# endif11220#endif1122111222#ifdef __cplusplus11223} /* End of the 'extern "C"' block */11224#endif11225/* #endif for SQLITE3_H will be added by mksqlite3.tcl */1122611227/******** Begin file sqlite3rtree.h *********/11228/*11229** 2010 August 3011230**11231** The author disclaims copyright to this source code. In place of11232** a legal notice, here is a blessing:11233**11234** May you do good and not evil.11235** May you find forgiveness for yourself and forgive others.11236** May you share freely, never taking more than you give.11237**11238*************************************************************************11239*/1124011241#ifndef _SQLITE3RTREE_H_11242#define _SQLITE3RTREE_H_112431124411245#ifdef __cplusplus11246extern "C" {11247#endif1124811249typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry;11250typedef struct sqlite3_rtree_query_info sqlite3_rtree_query_info;1125111252/* The double-precision datatype used by RTree depends on the11253** SQLITE_RTREE_INT_ONLY compile-time option.11254*/11255#ifdef SQLITE_RTREE_INT_ONLY11256typedef sqlite3_int64 sqlite3_rtree_dbl;11257#else11258typedef double sqlite3_rtree_dbl;11259#endif1126011261/*11262** Register a geometry callback named zGeom that can be used as part of an11263** R-Tree geometry query as follows:11264**11265** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...)11266*/11267SQLITE_API int sqlite3_rtree_geometry_callback(11268sqlite3 *db,11269const char *zGeom,11270int (*xGeom)(sqlite3_rtree_geometry*, int, sqlite3_rtree_dbl*,int*),11271void *pContext11272);112731127411275/*11276** A pointer to a structure of the following type is passed as the first11277** argument to callbacks registered using rtree_geometry_callback().11278*/11279struct sqlite3_rtree_geometry {11280void *pContext; /* Copy of pContext passed to s_r_g_c() */11281int nParam; /* Size of array aParam[] */11282sqlite3_rtree_dbl *aParam; /* Parameters passed to SQL geom function */11283void *pUser; /* Callback implementation user data */11284void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */11285};1128611287/*11288** Register a 2nd-generation geometry callback named zScore that can be11289** used as part of an R-Tree geometry query as follows:11290**11291** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zQueryFunc(... params ...)11292*/11293SQLITE_API int sqlite3_rtree_query_callback(11294sqlite3 *db,11295const char *zQueryFunc,11296int (*xQueryFunc)(sqlite3_rtree_query_info*),11297void *pContext,11298void (*xDestructor)(void*)11299);113001130111302/*11303** A pointer to a structure of the following type is passed as the11304** argument to scored geometry callback registered using11305** sqlite3_rtree_query_callback().11306**11307** Note that the first 5 fields of this structure are identical to11308** sqlite3_rtree_geometry. This structure is a subclass of11309** sqlite3_rtree_geometry.11310*/11311struct sqlite3_rtree_query_info {11312void *pContext; /* pContext from when function registered */11313int nParam; /* Number of function parameters */11314sqlite3_rtree_dbl *aParam; /* value of function parameters */11315void *pUser; /* callback can use this, if desired */11316void (*xDelUser)(void*); /* function to free pUser */11317sqlite3_rtree_dbl *aCoord; /* Coordinates of node or entry to check */11318unsigned int *anQueue; /* Number of pending entries in the queue */11319int nCoord; /* Number of coordinates */11320int iLevel; /* Level of current node or entry */11321int mxLevel; /* The largest iLevel value in the tree */11322sqlite3_int64 iRowid; /* Rowid for current entry */11323sqlite3_rtree_dbl rParentScore; /* Score of parent node */11324int eParentWithin; /* Visibility of parent node */11325int eWithin; /* OUT: Visibility */11326sqlite3_rtree_dbl rScore; /* OUT: Write the score here */11327/* The following fields are only available in 3.8.11 and later */11328sqlite3_value **apSqlParam; /* Original SQL values of parameters */11329};1133011331/*11332** Allowed values for sqlite3_rtree_query.eWithin and .eParentWithin.11333*/11334#define NOT_WITHIN 0 /* Object completely outside of query region */11335#define PARTLY_WITHIN 1 /* Object partially overlaps query region */11336#define FULLY_WITHIN 2 /* Object fully contained within query region */113371133811339#ifdef __cplusplus11340} /* end of the 'extern "C"' block */11341#endif1134211343#endif /* ifndef _SQLITE3RTREE_H_ */1134411345/******** End of sqlite3rtree.h *********/11346/******** Begin file sqlite3session.h *********/1134711348#if !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION)11349#define __SQLITESESSION_H_ 11135011351/*11352** Make sure we can call this stuff from C++.11353*/11354#ifdef __cplusplus11355extern "C" {11356#endif113571135811359/*11360** CAPI3REF: Session Object Handle11361**11362** An instance of this object is a [session] that can be used to11363** record changes to a database.11364*/11365typedef struct sqlite3_session sqlite3_session;1136611367/*11368** CAPI3REF: Changeset Iterator Handle11369**11370** An instance of this object acts as a cursor for iterating11371** over the elements of a [changeset] or [patchset].11372*/11373typedef struct sqlite3_changeset_iter sqlite3_changeset_iter;1137411375/*11376** CAPI3REF: Create A New Session Object11377** CONSTRUCTOR: sqlite3_session11378**11379** Create a new session object attached to database handle db. If successful,11380** a pointer to the new object is written to *ppSession and SQLITE_OK is11381** returned. If an error occurs, *ppSession is set to NULL and an SQLite11382** error code (e.g. SQLITE_NOMEM) is returned.11383**11384** It is possible to create multiple session objects attached to a single11385** database handle.11386**11387** Session objects created using this function should be deleted using the11388** [sqlite3session_delete()] function before the database handle that they11389** are attached to is itself closed. If the database handle is closed before11390** the session object is deleted, then the results of calling any session11391** module function, including [sqlite3session_delete()] on the session object11392** are undefined.11393**11394** Because the session module uses the [sqlite3_preupdate_hook()] API, it11395** is not possible for an application to register a pre-update hook on a11396** database handle that has one or more session objects attached. Nor is11397** it possible to create a session object attached to a database handle for11398** which a pre-update hook is already defined. The results of attempting11399** either of these things are undefined.11400**11401** The session object will be used to create changesets for tables in11402** database zDb, where zDb is either "main", or "temp", or the name of an11403** attached database. It is not an error if database zDb is not attached11404** to the database when the session object is created.11405*/11406SQLITE_API int sqlite3session_create(11407sqlite3 *db, /* Database handle */11408const char *zDb, /* Name of db (e.g. "main") */11409sqlite3_session **ppSession /* OUT: New session object */11410);1141111412/*11413** CAPI3REF: Delete A Session Object11414** DESTRUCTOR: sqlite3_session11415**11416** Delete a session object previously allocated using11417** [sqlite3session_create()]. Once a session object has been deleted, the11418** results of attempting to use pSession with any other session module11419** function are undefined.11420**11421** Session objects must be deleted before the database handle to which they11422** are attached is closed. Refer to the documentation for11423** [sqlite3session_create()] for details.11424*/11425SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);1142611427/*11428** CAPI3REF: Configure a Session Object11429** METHOD: sqlite3_session11430**11431** This method is used to configure a session object after it has been11432** created. At present the only valid values for the second parameter are11433** [SQLITE_SESSION_OBJCONFIG_SIZE] and [SQLITE_SESSION_OBJCONFIG_ROWID].11434**11435*/11436SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);1143711438/*11439** CAPI3REF: Options for sqlite3session_object_config11440**11441** The following values may passed as the the 2nd parameter to11442** sqlite3session_object_config().11443**11444** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>11445** This option is used to set, clear or query the flag that enables11446** the [sqlite3session_changeset_size()] API. Because it imposes some11447** computational overhead, this API is disabled by default. Argument11448** pArg must point to a value of type (int). If the value is initially11449** 0, then the sqlite3session_changeset_size() API is disabled. If it11450** is greater than 0, then the same API is enabled. Or, if the initial11451** value is less than zero, no change is made. In all cases the (int)11452** variable is set to 1 if the sqlite3session_changeset_size() API is11453** enabled following the current call, or 0 otherwise.11454**11455** It is an error (SQLITE_MISUSE) to attempt to modify this setting after11456** the first table has been attached to the session object.11457**11458** <dt>SQLITE_SESSION_OBJCONFIG_ROWID <dd>11459** This option is used to set, clear or query the flag that enables11460** collection of data for tables with no explicit PRIMARY KEY.11461**11462** Normally, tables with no explicit PRIMARY KEY are simply ignored11463** by the sessions module. However, if this flag is set, it behaves11464** as if such tables have a column "_rowid_ INTEGER PRIMARY KEY" inserted11465** as their leftmost columns.11466**11467** It is an error (SQLITE_MISUSE) to attempt to modify this setting after11468** the first table has been attached to the session object.11469*/11470#define SQLITE_SESSION_OBJCONFIG_SIZE 111471#define SQLITE_SESSION_OBJCONFIG_ROWID 21147211473/*11474** CAPI3REF: Enable Or Disable A Session Object11475** METHOD: sqlite3_session11476**11477** Enable or disable the recording of changes by a session object. When11478** enabled, a session object records changes made to the database. When11479** disabled - it does not. A newly created session object is enabled.11480** Refer to the documentation for [sqlite3session_changeset()] for further11481** details regarding how enabling and disabling a session object affects11482** the eventual changesets.11483**11484** Passing zero to this function disables the session. Passing a value11485** greater than zero enables it. Passing a value less than zero is a11486** no-op, and may be used to query the current state of the session.11487**11488** The return value indicates the final state of the session object: 0 if11489** the session is disabled, or 1 if it is enabled.11490*/11491SQLITE_API int sqlite3session_enable(sqlite3_session *pSession, int bEnable);1149211493/*11494** CAPI3REF: Set Or Clear the Indirect Change Flag11495** METHOD: sqlite3_session11496**11497** Each change recorded by a session object is marked as either direct or11498** indirect. A change is marked as indirect if either:11499**11500** <ul>11501** <li> The session object "indirect" flag is set when the change is11502** made, or11503** <li> The change is made by an SQL trigger or foreign key action11504** instead of directly as a result of a users SQL statement.11505** </ul>11506**11507** If a single row is affected by more than one operation within a session,11508** then the change is considered indirect if all operations meet the criteria11509** for an indirect change above, or direct otherwise.11510**11511** This function is used to set, clear or query the session object indirect11512** flag. If the second argument passed to this function is zero, then the11513** indirect flag is cleared. If it is greater than zero, the indirect flag11514** is set. Passing a value less than zero does not modify the current value11515** of the indirect flag, and may be used to query the current state of the11516** indirect flag for the specified session object.11517**11518** The return value indicates the final state of the indirect flag: 0 if11519** it is clear, or 1 if it is set.11520*/11521SQLITE_API int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);1152211523/*11524** CAPI3REF: Attach A Table To A Session Object11525** METHOD: sqlite3_session11526**11527** If argument zTab is not NULL, then it is the name of a table to attach11528** to the session object passed as the first argument. All subsequent changes11529** made to the table while the session object is enabled will be recorded. See11530** documentation for [sqlite3session_changeset()] for further details.11531**11532** Or, if argument zTab is NULL, then changes are recorded for all tables11533** in the database. If additional tables are added to the database (by11534** executing "CREATE TABLE" statements) after this call is made, changes for11535** the new tables are also recorded.11536**11537** Changes can only be recorded for tables that have a PRIMARY KEY explicitly11538** defined as part of their CREATE TABLE statement. It does not matter if the11539** PRIMARY KEY is an "INTEGER PRIMARY KEY" (rowid alias) or not. The PRIMARY11540** KEY may consist of a single column, or may be a composite key.11541**11542** It is not an error if the named table does not exist in the database. Nor11543** is it an error if the named table does not have a PRIMARY KEY. However,11544** no changes will be recorded in either of these scenarios.11545**11546** Changes are not recorded for individual rows that have NULL values stored11547** in one or more of their PRIMARY KEY columns.11548**11549** SQLITE_OK is returned if the call completes without error. Or, if an error11550** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.11551**11552** <h3>Special sqlite_stat1 Handling</h3>11553**11554** As of SQLite version 3.22.0, the "sqlite_stat1" table is an exception to11555** some of the rules above. In SQLite, the schema of sqlite_stat1 is:11556** <pre>11557** CREATE TABLE sqlite_stat1(tbl,idx,stat)11558** </pre>11559**11560** Even though sqlite_stat1 does not have a PRIMARY KEY, changes are11561** recorded for it as if the PRIMARY KEY is (tbl,idx). Additionally, changes11562** are recorded for rows for which (idx IS NULL) is true. However, for such11563** rows a zero-length blob (SQL value X'') is stored in the changeset or11564** patchset instead of a NULL value. This allows such changesets to be11565** manipulated by legacy implementations of sqlite3changeset_invert(),11566** concat() and similar.11567**11568** The sqlite3changeset_apply() function automatically converts the11569** zero-length blob back to a NULL value when updating the sqlite_stat111570** table. However, if the application calls sqlite3changeset_new(),11571** sqlite3changeset_old() or sqlite3changeset_conflict on a changeset11572** iterator directly (including on a changeset iterator passed to a11573** conflict-handler callback) then the X'' value is returned. The application11574** must translate X'' to NULL itself if required.11575**11576** Legacy (older than 3.22.0) versions of the sessions module cannot capture11577** changes made to the sqlite_stat1 table. Legacy versions of the11578** sqlite3changeset_apply() function silently ignore any modifications to the11579** sqlite_stat1 table that are part of a changeset or patchset.11580*/11581SQLITE_API int sqlite3session_attach(11582sqlite3_session *pSession, /* Session object */11583const char *zTab /* Table name */11584);1158511586/*11587** CAPI3REF: Set a table filter on a Session Object.11588** METHOD: sqlite3_session11589**11590** The second argument (xFilter) is the "filter callback". For changes to rows11591** in tables that are not attached to the Session object, the filter is called11592** to determine whether changes to the table's rows should be tracked or not.11593** If xFilter returns 0, changes are not tracked. Note that once a table is11594** attached, xFilter will not be called again.11595*/11596SQLITE_API void sqlite3session_table_filter(11597sqlite3_session *pSession, /* Session object */11598int(*xFilter)(11599void *pCtx, /* Copy of third arg to _filter_table() */11600const char *zTab /* Table name */11601),11602void *pCtx /* First argument passed to xFilter */11603);1160411605/*11606** CAPI3REF: Generate A Changeset From A Session Object11607** METHOD: sqlite3_session11608**11609** Obtain a changeset containing changes to the tables attached to the11610** session object passed as the first argument. If successful,11611** set *ppChangeset to point to a buffer containing the changeset11612** and *pnChangeset to the size of the changeset in bytes before returning11613** SQLITE_OK. If an error occurs, set both *ppChangeset and *pnChangeset to11614** zero and return an SQLite error code.11615**11616** A changeset consists of zero or more INSERT, UPDATE and/or DELETE changes,11617** each representing a change to a single row of an attached table. An INSERT11618** change contains the values of each field of a new database row. A DELETE11619** contains the original values of each field of a deleted database row. An11620** UPDATE change contains the original values of each field of an updated11621** database row along with the updated values for each updated non-primary-key11622** column. It is not possible for an UPDATE change to represent a change that11623** modifies the values of primary key columns. If such a change is made, it11624** is represented in a changeset as a DELETE followed by an INSERT.11625**11626** Changes are not recorded for rows that have NULL values stored in one or11627** more of their PRIMARY KEY columns. If such a row is inserted or deleted,11628** no corresponding change is present in the changesets returned by this11629** function. If an existing row with one or more NULL values stored in11630** PRIMARY KEY columns is updated so that all PRIMARY KEY columns are non-NULL,11631** only an INSERT is appears in the changeset. Similarly, if an existing row11632** with non-NULL PRIMARY KEY values is updated so that one or more of its11633** PRIMARY KEY columns are set to NULL, the resulting changeset contains a11634** DELETE change only.11635**11636** The contents of a changeset may be traversed using an iterator created11637** using the [sqlite3changeset_start()] API. A changeset may be applied to11638** a database with a compatible schema using the [sqlite3changeset_apply()]11639** API.11640**11641** Within a changeset generated by this function, all changes related to a11642** single table are grouped together. In other words, when iterating through11643** a changeset or when applying a changeset to a database, all changes related11644** to a single table are processed before moving on to the next table. Tables11645** are sorted in the same order in which they were attached (or auto-attached)11646** to the sqlite3_session object. The order in which the changes related to11647** a single table are stored is undefined.11648**11649** Following a successful call to this function, it is the responsibility of11650** the caller to eventually free the buffer that *ppChangeset points to using11651** [sqlite3_free()].11652**11653** <h3>Changeset Generation</h3>11654**11655** Once a table has been attached to a session object, the session object11656** records the primary key values of all new rows inserted into the table.11657** It also records the original primary key and other column values of any11658** deleted or updated rows. For each unique primary key value, data is only11659** recorded once - the first time a row with said primary key is inserted,11660** updated or deleted in the lifetime of the session.11661**11662** There is one exception to the previous paragraph: when a row is inserted,11663** updated or deleted, if one or more of its primary key columns contain a11664** NULL value, no record of the change is made.11665**11666** The session object therefore accumulates two types of records - those11667** that consist of primary key values only (created when the user inserts11668** a new record) and those that consist of the primary key values and the11669** original values of other table columns (created when the users deletes11670** or updates a record).11671**11672** When this function is called, the requested changeset is created using11673** both the accumulated records and the current contents of the database11674** file. Specifically:11675**11676** <ul>11677** <li> For each record generated by an insert, the database is queried11678** for a row with a matching primary key. If one is found, an INSERT11679** change is added to the changeset. If no such row is found, no change11680** is added to the changeset.11681**11682** <li> For each record generated by an update or delete, the database is11683** queried for a row with a matching primary key. If such a row is11684** found and one or more of the non-primary key fields have been11685** modified from their original values, an UPDATE change is added to11686** the changeset. Or, if no such row is found in the table, a DELETE11687** change is added to the changeset. If there is a row with a matching11688** primary key in the database, but all fields contain their original11689** values, no change is added to the changeset.11690** </ul>11691**11692** This means, amongst other things, that if a row is inserted and then later11693** deleted while a session object is active, neither the insert nor the delete11694** will be present in the changeset. Or if a row is deleted and then later a11695** row with the same primary key values inserted while a session object is11696** active, the resulting changeset will contain an UPDATE change instead of11697** a DELETE and an INSERT.11698**11699** When a session object is disabled (see the [sqlite3session_enable()] API),11700** it does not accumulate records when rows are inserted, updated or deleted.11701** This may appear to have some counter-intuitive effects if a single row11702** is written to more than once during a session. For example, if a row11703** is inserted while a session object is enabled, then later deleted while11704** the same session object is disabled, no INSERT record will appear in the11705** changeset, even though the delete took place while the session was disabled.11706** Or, if one field of a row is updated while a session is enabled, and11707** then another field of the same row is updated while the session is disabled,11708** the resulting changeset will contain an UPDATE change that updates both11709** fields.11710*/11711SQLITE_API int sqlite3session_changeset(11712sqlite3_session *pSession, /* Session object */11713int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */11714void **ppChangeset /* OUT: Buffer containing changeset */11715);1171611717/*11718** CAPI3REF: Return An Upper-limit For The Size Of The Changeset11719** METHOD: sqlite3_session11720**11721** By default, this function always returns 0. For it to return11722** a useful result, the sqlite3_session object must have been configured11723** to enable this API using sqlite3session_object_config() with the11724** SQLITE_SESSION_OBJCONFIG_SIZE verb.11725**11726** When enabled, this function returns an upper limit, in bytes, for the size11727** of the changeset that might be produced if sqlite3session_changeset() were11728** called. The final changeset size might be equal to or smaller than the11729** size in bytes returned by this function.11730*/11731SQLITE_API sqlite3_int64 sqlite3session_changeset_size(sqlite3_session *pSession);1173211733/*11734** CAPI3REF: Load The Difference Between Tables Into A Session11735** METHOD: sqlite3_session11736**11737** If it is not already attached to the session object passed as the first11738** argument, this function attaches table zTbl in the same manner as the11739** [sqlite3session_attach()] function. If zTbl does not exist, or if it11740** does not have a primary key, this function is a no-op (but does not return11741** an error).11742**11743** Argument zFromDb must be the name of a database ("main", "temp" etc.)11744** attached to the same database handle as the session object that contains11745** a table compatible with the table attached to the session by this function.11746** A table is considered compatible if it:11747**11748** <ul>11749** <li> Has the same name,11750** <li> Has the same set of columns declared in the same order, and11751** <li> Has the same PRIMARY KEY definition.11752** </ul>11753**11754** If the tables are not compatible, SQLITE_SCHEMA is returned. If the tables11755** are compatible but do not have any PRIMARY KEY columns, it is not an error11756** but no changes are added to the session object. As with other session11757** APIs, tables without PRIMARY KEYs are simply ignored.11758**11759** This function adds a set of changes to the session object that could be11760** used to update the table in database zFrom (call this the "from-table")11761** so that its content is the same as the table attached to the session11762** object (call this the "to-table"). Specifically:11763**11764** <ul>11765** <li> For each row (primary key) that exists in the to-table but not in11766** the from-table, an INSERT record is added to the session object.11767**11768** <li> For each row (primary key) that exists in the to-table but not in11769** the from-table, a DELETE record is added to the session object.11770**11771** <li> For each row (primary key) that exists in both tables, but features11772** different non-PK values in each, an UPDATE record is added to the11773** session.11774** </ul>11775**11776** To clarify, if this function is called and then a changeset constructed11777** using [sqlite3session_changeset()], then after applying that changeset to11778** database zFrom the contents of the two compatible tables would be11779** identical.11780**11781** Unless the call to this function is a no-op as described above, it is an11782** error if database zFrom does not exist or does not contain the required11783** compatible table.11784**11785** If the operation is successful, SQLITE_OK is returned. Otherwise, an SQLite11786** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg11787** may be set to point to a buffer containing an English language error11788** message. It is the responsibility of the caller to free this buffer using11789** sqlite3_free().11790*/11791SQLITE_API int sqlite3session_diff(11792sqlite3_session *pSession,11793const char *zFromDb,11794const char *zTbl,11795char **pzErrMsg11796);117971179811799/*11800** CAPI3REF: Generate A Patchset From A Session Object11801** METHOD: sqlite3_session11802**11803** The differences between a patchset and a changeset are that:11804**11805** <ul>11806** <li> DELETE records consist of the primary key fields only. The11807** original values of other fields are omitted.11808** <li> The original values of any modified fields are omitted from11809** UPDATE records.11810** </ul>11811**11812** A patchset blob may be used with up to date versions of all11813** sqlite3changeset_xxx API functions except for sqlite3changeset_invert(),11814** which returns SQLITE_CORRUPT if it is passed a patchset. Similarly,11815** attempting to use a patchset blob with old versions of the11816** sqlite3changeset_xxx APIs also provokes an SQLITE_CORRUPT error.11817**11818** Because the non-primary key "old.*" fields are omitted, no11819** SQLITE_CHANGESET_DATA conflicts can be detected or reported if a patchset11820** is passed to the sqlite3changeset_apply() API. Other conflict types work11821** in the same way as for changesets.11822**11823** Changes within a patchset are ordered in the same way as for changesets11824** generated by the sqlite3session_changeset() function (i.e. all changes for11825** a single table are grouped together, tables appear in the order in which11826** they were attached to the session object).11827*/11828SQLITE_API int sqlite3session_patchset(11829sqlite3_session *pSession, /* Session object */11830int *pnPatchset, /* OUT: Size of buffer at *ppPatchset */11831void **ppPatchset /* OUT: Buffer containing patchset */11832);1183311834/*11835** CAPI3REF: Test if a changeset has recorded any changes.11836**11837** Return non-zero if no changes to attached tables have been recorded by11838** the session object passed as the first argument. Otherwise, if one or11839** more changes have been recorded, return zero.11840**11841** Even if this function returns zero, it is possible that calling11842** [sqlite3session_changeset()] on the session handle may still return a11843** changeset that contains no changes. This can happen when a row in11844** an attached table is modified and then later on the original values11845** are restored. However, if this function returns non-zero, then it is11846** guaranteed that a call to sqlite3session_changeset() will return a11847** changeset containing zero changes.11848*/11849SQLITE_API int sqlite3session_isempty(sqlite3_session *pSession);1185011851/*11852** CAPI3REF: Query for the amount of heap memory used by a session object.11853**11854** This API returns the total amount of heap memory in bytes currently11855** used by the session object passed as the only argument.11856*/11857SQLITE_API sqlite3_int64 sqlite3session_memory_used(sqlite3_session *pSession);1185811859/*11860** CAPI3REF: Create An Iterator To Traverse A Changeset11861** CONSTRUCTOR: sqlite3_changeset_iter11862**11863** Create an iterator used to iterate through the contents of a changeset.11864** If successful, *pp is set to point to the iterator handle and SQLITE_OK11865** is returned. Otherwise, if an error occurs, *pp is set to zero and an11866** SQLite error code is returned.11867**11868** The following functions can be used to advance and query a changeset11869** iterator created by this function:11870**11871** <ul>11872** <li> [sqlite3changeset_next()]11873** <li> [sqlite3changeset_op()]11874** <li> [sqlite3changeset_new()]11875** <li> [sqlite3changeset_old()]11876** </ul>11877**11878** It is the responsibility of the caller to eventually destroy the iterator11879** by passing it to [sqlite3changeset_finalize()]. The buffer containing the11880** changeset (pChangeset) must remain valid until after the iterator is11881** destroyed.11882**11883** Assuming the changeset blob was created by one of the11884** [sqlite3session_changeset()], [sqlite3changeset_concat()] or11885** [sqlite3changeset_invert()] functions, all changes within the changeset11886** that apply to a single table are grouped together. This means that when11887** an application iterates through a changeset using an iterator created by11888** this function, all changes that relate to a single table are visited11889** consecutively. There is no chance that the iterator will visit a change11890** the applies to table X, then one for table Y, and then later on visit11891** another change for table X.11892**11893** The behavior of sqlite3changeset_start_v2() and its streaming equivalent11894** may be modified by passing a combination of11895** [SQLITE_CHANGESETSTART_INVERT | supported flags] as the 4th parameter.11896**11897** Note that the sqlite3changeset_start_v2() API is still <b>experimental</b>11898** and therefore subject to change.11899*/11900SQLITE_API int sqlite3changeset_start(11901sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */11902int nChangeset, /* Size of changeset blob in bytes */11903void *pChangeset /* Pointer to blob containing changeset */11904);11905SQLITE_API int sqlite3changeset_start_v2(11906sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */11907int nChangeset, /* Size of changeset blob in bytes */11908void *pChangeset, /* Pointer to blob containing changeset */11909int flags /* SESSION_CHANGESETSTART_* flags */11910);1191111912/*11913** CAPI3REF: Flags for sqlite3changeset_start_v211914**11915** The following flags may passed via the 4th parameter to11916** [sqlite3changeset_start_v2] and [sqlite3changeset_start_v2_strm]:11917**11918** <dt>SQLITE_CHANGESETSTART_INVERT <dd>11919** Invert the changeset while iterating through it. This is equivalent to11920** inverting a changeset using sqlite3changeset_invert() before applying it.11921** It is an error to specify this flag with a patchset.11922*/11923#define SQLITE_CHANGESETSTART_INVERT 0x0002119241192511926/*11927** CAPI3REF: Advance A Changeset Iterator11928** METHOD: sqlite3_changeset_iter11929**11930** This function may only be used with iterators created by the function11931** [sqlite3changeset_start()]. If it is called on an iterator passed to11932** a conflict-handler callback by [sqlite3changeset_apply()], SQLITE_MISUSE11933** is returned and the call has no effect.11934**11935** Immediately after an iterator is created by sqlite3changeset_start(), it11936** does not point to any change in the changeset. Assuming the changeset11937** is not empty, the first call to this function advances the iterator to11938** point to the first change in the changeset. Each subsequent call advances11939** the iterator to point to the next change in the changeset (if any). If11940** no error occurs and the iterator points to a valid change after a call11941** to sqlite3changeset_next() has advanced it, SQLITE_ROW is returned.11942** Otherwise, if all changes in the changeset have already been visited,11943** SQLITE_DONE is returned.11944**11945** If an error occurs, an SQLite error code is returned. Possible error11946** codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or11947** SQLITE_NOMEM.11948*/11949SQLITE_API int sqlite3changeset_next(sqlite3_changeset_iter *pIter);1195011951/*11952** CAPI3REF: Obtain The Current Operation From A Changeset Iterator11953** METHOD: sqlite3_changeset_iter11954**11955** The pIter argument passed to this function may either be an iterator11956** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator11957** created by [sqlite3changeset_start()]. In the latter case, the most recent11958** call to [sqlite3changeset_next()] must have returned [SQLITE_ROW]. If this11959** is not the case, this function returns [SQLITE_MISUSE].11960**11961** Arguments pOp, pnCol and pzTab may not be NULL. Upon return, three11962** outputs are set through these pointers:11963**11964** *pOp is set to one of [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE],11965** depending on the type of change that the iterator currently points to;11966**11967** *pnCol is set to the number of columns in the table affected by the change; and11968**11969** *pzTab is set to point to a nul-terminated utf-8 encoded string containing11970** the name of the table affected by the current change. The buffer remains11971** valid until either sqlite3changeset_next() is called on the iterator11972** or until the conflict-handler function returns.11973**11974** If pbIndirect is not NULL, then *pbIndirect is set to true (1) if the change11975** is an indirect change, or false (0) otherwise. See the documentation for11976** [sqlite3session_indirect()] for a description of direct and indirect11977** changes.11978**11979** If no error occurs, SQLITE_OK is returned. If an error does occur, an11980** SQLite error code is returned. The values of the output variables may not11981** be trusted in this case.11982*/11983SQLITE_API int sqlite3changeset_op(11984sqlite3_changeset_iter *pIter, /* Iterator object */11985const char **pzTab, /* OUT: Pointer to table name */11986int *pnCol, /* OUT: Number of columns in table */11987int *pOp, /* OUT: SQLITE_INSERT, DELETE or UPDATE */11988int *pbIndirect /* OUT: True for an 'indirect' change */11989);1199011991/*11992** CAPI3REF: Obtain The Primary Key Definition Of A Table11993** METHOD: sqlite3_changeset_iter11994**11995** For each modified table, a changeset includes the following:11996**11997** <ul>11998** <li> The number of columns in the table, and11999** <li> Which of those columns make up the tables PRIMARY KEY.12000** </ul>12001**12002** This function is used to find which columns comprise the PRIMARY KEY of12003** the table modified by the change that iterator pIter currently points to.12004** If successful, *pabPK is set to point to an array of nCol entries, where12005** nCol is the number of columns in the table. Elements of *pabPK are set to12006** 0x01 if the corresponding column is part of the tables primary key, or12007** 0x00 if it is not.12008**12009** If argument pnCol is not NULL, then *pnCol is set to the number of columns12010** in the table.12011**12012** If this function is called when the iterator does not point to a valid12013** entry, SQLITE_MISUSE is returned and the output variables zeroed. Otherwise,12014** SQLITE_OK is returned and the output variables populated as described12015** above.12016*/12017SQLITE_API int sqlite3changeset_pk(12018sqlite3_changeset_iter *pIter, /* Iterator object */12019unsigned char **pabPK, /* OUT: Array of boolean - true for PK cols */12020int *pnCol /* OUT: Number of entries in output array */12021);1202212023/*12024** CAPI3REF: Obtain old.* Values From A Changeset Iterator12025** METHOD: sqlite3_changeset_iter12026**12027** The pIter argument passed to this function may either be an iterator12028** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator12029** created by [sqlite3changeset_start()]. In the latter case, the most recent12030** call to [sqlite3changeset_next()] must have returned SQLITE_ROW.12031** Furthermore, it may only be called if the type of change that the iterator12032** currently points to is either [SQLITE_DELETE] or [SQLITE_UPDATE]. Otherwise,12033** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL.12034**12035** Argument iVal must be greater than or equal to 0, and less than the number12036** of columns in the table affected by the current change. Otherwise,12037** [SQLITE_RANGE] is returned and *ppValue is set to NULL.12038**12039** If successful, this function sets *ppValue to point to a protected12040** sqlite3_value object containing the iVal'th value from the vector of12041** original row values stored as part of the UPDATE or DELETE change and12042** returns SQLITE_OK. The name of the function comes from the fact that this12043** is similar to the "old.*" columns available to update or delete triggers.12044**12045** If some other error occurs (e.g. an OOM condition), an SQLite error code12046** is returned and *ppValue is set to NULL.12047*/12048SQLITE_API int sqlite3changeset_old(12049sqlite3_changeset_iter *pIter, /* Changeset iterator */12050int iVal, /* Column number */12051sqlite3_value **ppValue /* OUT: Old value (or NULL pointer) */12052);1205312054/*12055** CAPI3REF: Obtain new.* Values From A Changeset Iterator12056** METHOD: sqlite3_changeset_iter12057**12058** The pIter argument passed to this function may either be an iterator12059** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator12060** created by [sqlite3changeset_start()]. In the latter case, the most recent12061** call to [sqlite3changeset_next()] must have returned SQLITE_ROW.12062** Furthermore, it may only be called if the type of change that the iterator12063** currently points to is either [SQLITE_UPDATE] or [SQLITE_INSERT]. Otherwise,12064** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL.12065**12066** Argument iVal must be greater than or equal to 0, and less than the number12067** of columns in the table affected by the current change. Otherwise,12068** [SQLITE_RANGE] is returned and *ppValue is set to NULL.12069**12070** If successful, this function sets *ppValue to point to a protected12071** sqlite3_value object containing the iVal'th value from the vector of12072** new row values stored as part of the UPDATE or INSERT change and12073** returns SQLITE_OK. If the change is an UPDATE and does not include12074** a new value for the requested column, *ppValue is set to NULL and12075** SQLITE_OK returned. The name of the function comes from the fact that12076** this is similar to the "new.*" columns available to update or delete12077** triggers.12078**12079** If some other error occurs (e.g. an OOM condition), an SQLite error code12080** is returned and *ppValue is set to NULL.12081*/12082SQLITE_API int sqlite3changeset_new(12083sqlite3_changeset_iter *pIter, /* Changeset iterator */12084int iVal, /* Column number */12085sqlite3_value **ppValue /* OUT: New value (or NULL pointer) */12086);1208712088/*12089** CAPI3REF: Obtain Conflicting Row Values From A Changeset Iterator12090** METHOD: sqlite3_changeset_iter12091**12092** This function should only be used with iterator objects passed to a12093** conflict-handler callback by [sqlite3changeset_apply()] with either12094** [SQLITE_CHANGESET_DATA] or [SQLITE_CHANGESET_CONFLICT]. If this function12095** is called on any other iterator, [SQLITE_MISUSE] is returned and *ppValue12096** is set to NULL.12097**12098** Argument iVal must be greater than or equal to 0, and less than the number12099** of columns in the table affected by the current change. Otherwise,12100** [SQLITE_RANGE] is returned and *ppValue is set to NULL.12101**12102** If successful, this function sets *ppValue to point to a protected12103** sqlite3_value object containing the iVal'th value from the12104** "conflicting row" associated with the current conflict-handler callback12105** and returns SQLITE_OK.12106**12107** If some other error occurs (e.g. an OOM condition), an SQLite error code12108** is returned and *ppValue is set to NULL.12109*/12110SQLITE_API int sqlite3changeset_conflict(12111sqlite3_changeset_iter *pIter, /* Changeset iterator */12112int iVal, /* Column number */12113sqlite3_value **ppValue /* OUT: Value from conflicting row */12114);1211512116/*12117** CAPI3REF: Determine The Number Of Foreign Key Constraint Violations12118** METHOD: sqlite3_changeset_iter12119**12120** This function may only be called with an iterator passed to an12121** SQLITE_CHANGESET_FOREIGN_KEY conflict handler callback. In this case12122** it sets the output variable to the total number of known foreign key12123** violations in the destination database and returns SQLITE_OK.12124**12125** In all other cases this function returns SQLITE_MISUSE.12126*/12127SQLITE_API int sqlite3changeset_fk_conflicts(12128sqlite3_changeset_iter *pIter, /* Changeset iterator */12129int *pnOut /* OUT: Number of FK violations */12130);121311213212133/*12134** CAPI3REF: Finalize A Changeset Iterator12135** METHOD: sqlite3_changeset_iter12136**12137** This function is used to finalize an iterator allocated with12138** [sqlite3changeset_start()].12139**12140** This function should only be called on iterators created using the12141** [sqlite3changeset_start()] function. If an application calls this12142** function with an iterator passed to a conflict-handler by12143** [sqlite3changeset_apply()], [SQLITE_MISUSE] is immediately returned and the12144** call has no effect.12145**12146** If an error was encountered within a call to an sqlite3changeset_xxx()12147** function (for example an [SQLITE_CORRUPT] in [sqlite3changeset_next()] or an12148** [SQLITE_NOMEM] in [sqlite3changeset_new()]) then an error code corresponding12149** to that error is returned by this function. Otherwise, SQLITE_OK is12150** returned. This is to allow the following pattern (pseudo-code):12151**12152** <pre>12153** sqlite3changeset_start();12154** while( SQLITE_ROW==sqlite3changeset_next() ){12155** // Do something with change.12156** }12157** rc = sqlite3changeset_finalize();12158** if( rc!=SQLITE_OK ){12159** // An error has occurred12160** }12161** </pre>12162*/12163SQLITE_API int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);1216412165/*12166** CAPI3REF: Invert A Changeset12167**12168** This function is used to "invert" a changeset object. Applying an inverted12169** changeset to a database reverses the effects of applying the uninverted12170** changeset. Specifically:12171**12172** <ul>12173** <li> Each DELETE change is changed to an INSERT, and12174** <li> Each INSERT change is changed to a DELETE, and12175** <li> For each UPDATE change, the old.* and new.* values are exchanged.12176** </ul>12177**12178** This function does not change the order in which changes appear within12179** the changeset. It merely reverses the sense of each individual change.12180**12181** If successful, a pointer to a buffer containing the inverted changeset12182** is stored in *ppOut, the size of the same buffer is stored in *pnOut, and12183** SQLITE_OK is returned. If an error occurs, both *pnOut and *ppOut are12184** zeroed and an SQLite error code returned.12185**12186** It is the responsibility of the caller to eventually call sqlite3_free()12187** on the *ppOut pointer to free the buffer allocation following a successful12188** call to this function.12189**12190** WARNING/TODO: This function currently assumes that the input is a valid12191** changeset. If it is not, the results are undefined.12192*/12193SQLITE_API int sqlite3changeset_invert(12194int nIn, const void *pIn, /* Input changeset */12195int *pnOut, void **ppOut /* OUT: Inverse of input */12196);1219712198/*12199** CAPI3REF: Concatenate Two Changeset Objects12200**12201** This function is used to concatenate two changesets, A and B, into a12202** single changeset. The result is a changeset equivalent to applying12203** changeset A followed by changeset B.12204**12205** This function combines the two input changesets using an12206** sqlite3_changegroup object. Calling it produces similar results as the12207** following code fragment:12208**12209** <pre>12210** sqlite3_changegroup *pGrp;12211** rc = sqlite3_changegroup_new(&pGrp);12212** if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nA, pA);12213** if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nB, pB);12214** if( rc==SQLITE_OK ){12215** rc = sqlite3changegroup_output(pGrp, pnOut, ppOut);12216** }else{12217** *ppOut = 0;12218** *pnOut = 0;12219** }12220** </pre>12221**12222** Refer to the sqlite3_changegroup documentation below for details.12223*/12224SQLITE_API int sqlite3changeset_concat(12225int nA, /* Number of bytes in buffer pA */12226void *pA, /* Pointer to buffer containing changeset A */12227int nB, /* Number of bytes in buffer pB */12228void *pB, /* Pointer to buffer containing changeset B */12229int *pnOut, /* OUT: Number of bytes in output changeset */12230void **ppOut /* OUT: Buffer containing output changeset */12231);1223212233/*12234** CAPI3REF: Changegroup Handle12235**12236** A changegroup is an object used to combine two or more12237** [changesets] or [patchsets]12238*/12239typedef struct sqlite3_changegroup sqlite3_changegroup;1224012241/*12242** CAPI3REF: Create A New Changegroup Object12243** CONSTRUCTOR: sqlite3_changegroup12244**12245** An sqlite3_changegroup object is used to combine two or more changesets12246** (or patchsets) into a single changeset (or patchset). A single changegroup12247** object may combine changesets or patchsets, but not both. The output is12248** always in the same format as the input.12249**12250** If successful, this function returns SQLITE_OK and populates (*pp) with12251** a pointer to a new sqlite3_changegroup object before returning. The caller12252** should eventually free the returned object using a call to12253** sqlite3changegroup_delete(). If an error occurs, an SQLite error code12254** (i.e. SQLITE_NOMEM) is returned and *pp is set to NULL.12255**12256** The usual usage pattern for an sqlite3_changegroup object is as follows:12257**12258** <ul>12259** <li> It is created using a call to sqlite3changegroup_new().12260**12261** <li> Zero or more changesets (or patchsets) are added to the object12262** by calling sqlite3changegroup_add().12263**12264** <li> The result of combining all input changesets together is obtained12265** by the application via a call to sqlite3changegroup_output().12266**12267** <li> The object is deleted using a call to sqlite3changegroup_delete().12268** </ul>12269**12270** Any number of calls to add() and output() may be made between the calls to12271** new() and delete(), and in any order.12272**12273** As well as the regular sqlite3changegroup_add() and12274** sqlite3changegroup_output() functions, also available are the streaming12275** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm().12276*/12277SQLITE_API int sqlite3changegroup_new(sqlite3_changegroup **pp);1227812279/*12280** CAPI3REF: Add a Schema to a Changegroup12281** METHOD: sqlite3_changegroup_schema12282**12283** This method may be used to optionally enforce the rule that the changesets12284** added to the changegroup handle must match the schema of database zDb12285** ("main", "temp", or the name of an attached database). If12286** sqlite3changegroup_add() is called to add a changeset that is not compatible12287** with the configured schema, SQLITE_SCHEMA is returned and the changegroup12288** object is left in an undefined state.12289**12290** A changeset schema is considered compatible with the database schema in12291** the same way as for sqlite3changeset_apply(). Specifically, for each12292** table in the changeset, there exists a database table with:12293**12294** <ul>12295** <li> The name identified by the changeset, and12296** <li> at least as many columns as recorded in the changeset, and12297** <li> the primary key columns in the same position as recorded in12298** the changeset.12299** </ul>12300**12301** The output of the changegroup object always has the same schema as the12302** database nominated using this function. In cases where changesets passed12303** to sqlite3changegroup_add() have fewer columns than the corresponding table12304** in the database schema, these are filled in using the default column12305** values from the database schema. This makes it possible to combined12306** changesets that have different numbers of columns for a single table12307** within a changegroup, provided that they are otherwise compatible.12308*/12309SQLITE_API int sqlite3changegroup_schema(sqlite3_changegroup*, sqlite3*, const char *zDb);1231012311/*12312** CAPI3REF: Add A Changeset To A Changegroup12313** METHOD: sqlite3_changegroup12314**12315** Add all changes within the changeset (or patchset) in buffer pData (size12316** nData bytes) to the changegroup.12317**12318** If the buffer contains a patchset, then all prior calls to this function12319** on the same changegroup object must also have specified patchsets. Or, if12320** the buffer contains a changeset, so must have the earlier calls to this12321** function. Otherwise, SQLITE_ERROR is returned and no changes are added12322** to the changegroup.12323**12324** Rows within the changeset and changegroup are identified by the values in12325** their PRIMARY KEY columns. A change in the changeset is considered to12326** apply to the same row as a change already present in the changegroup if12327** the two rows have the same primary key.12328**12329** Changes to rows that do not already appear in the changegroup are12330** simply copied into it. Or, if both the new changeset and the changegroup12331** contain changes that apply to a single row, the final contents of the12332** changegroup depends on the type of each change, as follows:12333**12334** <table border=1 style="margin-left:8ex;margin-right:8ex">12335** <tr><th style="white-space:pre">Existing Change </th>12336** <th style="white-space:pre">New Change </th>12337** <th>Output Change12338** <tr><td>INSERT <td>INSERT <td>12339** The new change is ignored. This case does not occur if the new12340** changeset was recorded immediately after the changesets already12341** added to the changegroup.12342** <tr><td>INSERT <td>UPDATE <td>12343** The INSERT change remains in the changegroup. The values in the12344** INSERT change are modified as if the row was inserted by the12345** existing change and then updated according to the new change.12346** <tr><td>INSERT <td>DELETE <td>12347** The existing INSERT is removed from the changegroup. The DELETE is12348** not added.12349** <tr><td>UPDATE <td>INSERT <td>12350** The new change is ignored. This case does not occur if the new12351** changeset was recorded immediately after the changesets already12352** added to the changegroup.12353** <tr><td>UPDATE <td>UPDATE <td>12354** The existing UPDATE remains within the changegroup. It is amended12355** so that the accompanying values are as if the row was updated once12356** by the existing change and then again by the new change.12357** <tr><td>UPDATE <td>DELETE <td>12358** The existing UPDATE is replaced by the new DELETE within the12359** changegroup.12360** <tr><td>DELETE <td>INSERT <td>12361** If one or more of the column values in the row inserted by the12362** new change differ from those in the row deleted by the existing12363** change, the existing DELETE is replaced by an UPDATE within the12364** changegroup. Otherwise, if the inserted row is exactly the same12365** as the deleted row, the existing DELETE is simply discarded.12366** <tr><td>DELETE <td>UPDATE <td>12367** The new change is ignored. This case does not occur if the new12368** changeset was recorded immediately after the changesets already12369** added to the changegroup.12370** <tr><td>DELETE <td>DELETE <td>12371** The new change is ignored. This case does not occur if the new12372** changeset was recorded immediately after the changesets already12373** added to the changegroup.12374** </table>12375**12376** If the new changeset contains changes to a table that is already present12377** in the changegroup, then the number of columns and the position of the12378** primary key columns for the table must be consistent. If this is not the12379** case, this function fails with SQLITE_SCHEMA. Except, if the changegroup12380** object has been configured with a database schema using the12381** sqlite3changegroup_schema() API, then it is possible to combine changesets12382** with different numbers of columns for a single table, provided that12383** they are otherwise compatible.12384**12385** If the input changeset appears to be corrupt and the corruption is12386** detected, SQLITE_CORRUPT is returned. Or, if an out-of-memory condition12387** occurs during processing, this function returns SQLITE_NOMEM.12388**12389** In all cases, if an error occurs the state of the final contents of the12390** changegroup is undefined. If no error occurs, SQLITE_OK is returned.12391*/12392SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);1239312394/*12395** CAPI3REF: Add A Single Change To A Changegroup12396** METHOD: sqlite3_changegroup12397**12398** This function adds the single change currently indicated by the iterator12399** passed as the second argument to the changegroup object. The rules for12400** adding the change are just as described for [sqlite3changegroup_add()].12401**12402** If the change is successfully added to the changegroup, SQLITE_OK is12403** returned. Otherwise, an SQLite error code is returned.12404**12405** The iterator must point to a valid entry when this function is called.12406** If it does not, SQLITE_ERROR is returned and no change is added to the12407** changegroup. Additionally, the iterator must not have been opened with12408** the SQLITE_CHANGESETAPPLY_INVERT flag. In this case SQLITE_ERROR is also12409** returned.12410*/12411SQLITE_API int sqlite3changegroup_add_change(12412sqlite3_changegroup*,12413sqlite3_changeset_iter*12414);12415124161241712418/*12419** CAPI3REF: Obtain A Composite Changeset From A Changegroup12420** METHOD: sqlite3_changegroup12421**12422** Obtain a buffer containing a changeset (or patchset) representing the12423** current contents of the changegroup. If the inputs to the changegroup12424** were themselves changesets, the output is a changeset. Or, if the12425** inputs were patchsets, the output is also a patchset.12426**12427** As with the output of the sqlite3session_changeset() and12428** sqlite3session_patchset() functions, all changes related to a single12429** table are grouped together in the output of this function. Tables appear12430** in the same order as for the very first changeset added to the changegroup.12431** If the second or subsequent changesets added to the changegroup contain12432** changes for tables that do not appear in the first changeset, they are12433** appended onto the end of the output changeset, again in the order in12434** which they are first encountered.12435**12436** If an error occurs, an SQLite error code is returned and the output12437** variables (*pnData) and (*ppData) are set to 0. Otherwise, SQLITE_OK12438** is returned and the output variables are set to the size of and a12439** pointer to the output buffer, respectively. In this case it is the12440** responsibility of the caller to eventually free the buffer using a12441** call to sqlite3_free().12442*/12443SQLITE_API int sqlite3changegroup_output(12444sqlite3_changegroup*,12445int *pnData, /* OUT: Size of output buffer in bytes */12446void **ppData /* OUT: Pointer to output buffer */12447);1244812449/*12450** CAPI3REF: Delete A Changegroup Object12451** DESTRUCTOR: sqlite3_changegroup12452*/12453SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*);1245412455/*12456** CAPI3REF: Apply A Changeset To A Database12457**12458** Apply a changeset or patchset to a database. These functions attempt to12459** update the "main" database attached to handle db with the changes found in12460** the changeset passed via the second and third arguments.12461**12462** All changes made by these functions are enclosed in a savepoint transaction.12463** If any other error (aside from a constraint failure when attempting to12464** write to the target database) occurs, then the savepoint transaction is12465** rolled back, restoring the target database to its original state, and an12466** SQLite error code returned. Additionally, starting with version 3.51.0,12467** an error code and error message that may be accessed using the12468** [sqlite3_errcode()] and [sqlite3_errmsg()] APIs are left in the database12469** handle.12470**12471** The fourth argument (xFilter) passed to these functions is the "filter12472** callback". This may be passed NULL, in which case all changes in the12473** changeset are applied to the database. For sqlite3changeset_apply() and12474** sqlite3_changeset_apply_v2(), if it is not NULL, then it is invoked once12475** for each table affected by at least one change in the changeset. In this12476** case the table name is passed as the second argument, and a copy of12477** the context pointer passed as the sixth argument to apply() or apply_v2()12478** as the first. If the "filter callback" returns zero, then no attempt is12479** made to apply any changes to the table. Otherwise, if the return value is12480** non-zero, all changes related to the table are attempted.12481**12482** For sqlite3_changeset_apply_v3(), the xFilter callback is invoked once12483** per change. The second argument in this case is an sqlite3_changeset_iter12484** that may be queried using the usual APIs for the details of the current12485** change. If the "filter callback" returns zero in this case, then no attempt12486** is made to apply the current change. If it returns non-zero, the change12487** is applied.12488**12489** For each table that is not excluded by the filter callback, this function12490** tests that the target database contains a compatible table. A table is12491** considered compatible if all of the following are true:12492**12493** <ul>12494** <li> The table has the same name as the name recorded in the12495** changeset, and12496** <li> The table has at least as many columns as recorded in the12497** changeset, and12498** <li> The table has primary key columns in the same position as12499** recorded in the changeset.12500** </ul>12501**12502** If there is no compatible table, it is not an error, but none of the12503** changes associated with the table are applied. A warning message is issued12504** via the sqlite3_log() mechanism with the error code SQLITE_SCHEMA. At most12505** one such warning is issued for each table in the changeset.12506**12507** For each change for which there is a compatible table, an attempt is made12508** to modify the table contents according to each UPDATE, INSERT or DELETE12509** change that is not excluded by a filter callback. If a change cannot be12510** applied cleanly, the conflict handler function passed as the fifth argument12511** to sqlite3changeset_apply() may be invoked. A description of exactly when12512** the conflict handler is invoked for each type of change is below.12513**12514** Unlike the xFilter argument, xConflict may not be passed NULL. The results12515** of passing anything other than a valid function pointer as the xConflict12516** argument are undefined.12517**12518** Each time the conflict handler function is invoked, it must return one12519** of [SQLITE_CHANGESET_OMIT], [SQLITE_CHANGESET_ABORT] or12520** [SQLITE_CHANGESET_REPLACE]. SQLITE_CHANGESET_REPLACE may only be returned12521** if the second argument passed to the conflict handler is either12522** SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If the conflict-handler12523** returns an illegal value, any changes already made are rolled back and12524** the call to sqlite3changeset_apply() returns SQLITE_MISUSE. Different12525** actions are taken by sqlite3changeset_apply() depending on the value12526** returned by each invocation of the conflict-handler function. Refer to12527** the documentation for the three12528** [SQLITE_CHANGESET_OMIT|available return values] for details.12529**12530** <dl>12531** <dt>DELETE Changes<dd>12532** For each DELETE change, the function checks if the target database12533** contains a row with the same primary key value (or values) as the12534** original row values stored in the changeset. If it does, and the values12535** stored in all non-primary key columns also match the values stored in12536** the changeset the row is deleted from the target database.12537**12538** If a row with matching primary key values is found, but one or more of12539** the non-primary key fields contains a value different from the original12540** row value stored in the changeset, the conflict-handler function is12541** invoked with [SQLITE_CHANGESET_DATA] as the second argument. If the12542** database table has more columns than are recorded in the changeset,12543** only the values of those non-primary key fields are compared against12544** the current database contents - any trailing database table columns12545** are ignored.12546**12547** If no row with matching primary key values is found in the database,12548** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]12549** passed as the second argument.12550**12551** If the DELETE operation is attempted, but SQLite returns SQLITE_CONSTRAINT12552** (which can only happen if a foreign key constraint is violated), the12553** conflict-handler function is invoked with [SQLITE_CHANGESET_CONSTRAINT]12554** passed as the second argument. This includes the case where the DELETE12555** operation is attempted because an earlier call to the conflict handler12556** function returned [SQLITE_CHANGESET_REPLACE].12557**12558** <dt>INSERT Changes<dd>12559** For each INSERT change, an attempt is made to insert the new row into12560** the database. If the changeset row contains fewer fields than the12561** database table, the trailing fields are populated with their default12562** values.12563**12564** If the attempt to insert the row fails because the database already12565** contains a row with the same primary key values, the conflict handler12566** function is invoked with the second argument set to12567** [SQLITE_CHANGESET_CONFLICT].12568**12569** If the attempt to insert the row fails because of some other constraint12570** violation (e.g. NOT NULL or UNIQUE), the conflict handler function is12571** invoked with the second argument set to [SQLITE_CHANGESET_CONSTRAINT].12572** This includes the case where the INSERT operation is re-attempted because12573** an earlier call to the conflict handler function returned12574** [SQLITE_CHANGESET_REPLACE].12575**12576** <dt>UPDATE Changes<dd>12577** For each UPDATE change, the function checks if the target database12578** contains a row with the same primary key value (or values) as the12579** original row values stored in the changeset. If it does, and the values12580** stored in all modified non-primary key columns also match the values12581** stored in the changeset the row is updated within the target database.12582**12583** If a row with matching primary key values is found, but one or more of12584** the modified non-primary key fields contains a value different from an12585** original row value stored in the changeset, the conflict-handler function12586** is invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since12587** UPDATE changes only contain values for non-primary key fields that are12588** to be modified, only those fields need to match the original values to12589** avoid the SQLITE_CHANGESET_DATA conflict-handler callback.12590**12591** If no row with matching primary key values is found in the database,12592** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]12593** passed as the second argument.12594**12595** If the UPDATE operation is attempted, but SQLite returns12596** SQLITE_CONSTRAINT, the conflict-handler function is invoked with12597** [SQLITE_CHANGESET_CONSTRAINT] passed as the second argument.12598** This includes the case where the UPDATE operation is attempted after12599** an earlier call to the conflict handler function returned12600** [SQLITE_CHANGESET_REPLACE].12601** </dl>12602**12603** It is safe to execute SQL statements, including those that write to the12604** table that the callback related to, from within the xConflict callback.12605** This can be used to further customize the application's conflict12606** resolution strategy.12607**12608** If the output parameters (ppRebase) and (pnRebase) are non-NULL and12609** the input is a changeset (not a patchset), then sqlite3changeset_apply_v2()12610** may set (*ppRebase) to point to a "rebase" that may be used with the12611** sqlite3_rebaser APIs buffer before returning. In this case (*pnRebase)12612** is set to the size of the buffer in bytes. It is the responsibility of the12613** caller to eventually free any such buffer using sqlite3_free(). The buffer12614** is only allocated and populated if one or more conflicts were encountered12615** while applying the patchset. See comments surrounding the sqlite3_rebaser12616** APIs for further details.12617**12618** The behavior of sqlite3changeset_apply_v2() and its streaming equivalent12619** may be modified by passing a combination of12620** [SQLITE_CHANGESETAPPLY_NOSAVEPOINT | supported flags] as the 9th parameter.12621**12622** Note that the sqlite3changeset_apply_v2() API is still <b>experimental</b>12623** and therefore subject to change.12624*/12625SQLITE_API int sqlite3changeset_apply(12626sqlite3 *db, /* Apply change to "main" db of this handle */12627int nChangeset, /* Size of changeset in bytes */12628void *pChangeset, /* Changeset blob */12629int(*xFilter)(12630void *pCtx, /* Copy of sixth arg to _apply() */12631const char *zTab /* Table name */12632),12633int(*xConflict)(12634void *pCtx, /* Copy of sixth arg to _apply() */12635int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */12636sqlite3_changeset_iter *p /* Handle describing change and conflict */12637),12638void *pCtx /* First argument passed to xConflict */12639);12640SQLITE_API int sqlite3changeset_apply_v2(12641sqlite3 *db, /* Apply change to "main" db of this handle */12642int nChangeset, /* Size of changeset in bytes */12643void *pChangeset, /* Changeset blob */12644int(*xFilter)(12645void *pCtx, /* Copy of sixth arg to _apply() */12646const char *zTab /* Table name */12647),12648int(*xConflict)(12649void *pCtx, /* Copy of sixth arg to _apply() */12650int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */12651sqlite3_changeset_iter *p /* Handle describing change and conflict */12652),12653void *pCtx, /* First argument passed to xConflict */12654void **ppRebase, int *pnRebase, /* OUT: Rebase data */12655int flags /* SESSION_CHANGESETAPPLY_* flags */12656);12657SQLITE_API int sqlite3changeset_apply_v3(12658sqlite3 *db, /* Apply change to "main" db of this handle */12659int nChangeset, /* Size of changeset in bytes */12660void *pChangeset, /* Changeset blob */12661int(*xFilter)(12662void *pCtx, /* Copy of sixth arg to _apply() */12663sqlite3_changeset_iter *p /* Handle describing change */12664),12665int(*xConflict)(12666void *pCtx, /* Copy of sixth arg to _apply() */12667int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */12668sqlite3_changeset_iter *p /* Handle describing change and conflict */12669),12670void *pCtx, /* First argument passed to xConflict */12671void **ppRebase, int *pnRebase, /* OUT: Rebase data */12672int flags /* SESSION_CHANGESETAPPLY_* flags */12673);1267412675/*12676** CAPI3REF: Flags for sqlite3changeset_apply_v212677**12678** The following flags may passed via the 9th parameter to12679** [sqlite3changeset_apply_v2] and [sqlite3changeset_apply_v2_strm]:12680**12681** <dl>12682** <dt>SQLITE_CHANGESETAPPLY_NOSAVEPOINT <dd>12683** Usually, the sessions module encloses all operations performed by12684** a single call to apply_v2() or apply_v2_strm() in a [SAVEPOINT]. The12685** SAVEPOINT is committed if the changeset or patchset is successfully12686** applied, or rolled back if an error occurs. Specifying this flag12687** causes the sessions module to omit this savepoint. In this case, if the12688** caller has an open transaction or savepoint when apply_v2() is called,12689** it may revert the partially applied changeset by rolling it back.12690**12691** <dt>SQLITE_CHANGESETAPPLY_INVERT <dd>12692** Invert the changeset before applying it. This is equivalent to inverting12693** a changeset using sqlite3changeset_invert() before applying it. It is12694** an error to specify this flag with a patchset.12695**12696** <dt>SQLITE_CHANGESETAPPLY_IGNORENOOP <dd>12697** Do not invoke the conflict handler callback for any changes that12698** would not actually modify the database even if they were applied.12699** Specifically, this means that the conflict handler is not invoked12700** for:12701** <ul>12702** <li>a delete change if the row being deleted cannot be found,12703** <li>an update change if the modified fields are already set to12704** their new values in the conflicting row, or12705** <li>an insert change if all fields of the conflicting row match12706** the row being inserted.12707** </ul>12708**12709** <dt>SQLITE_CHANGESETAPPLY_FKNOACTION <dd>12710** If this flag it set, then all foreign key constraints in the target12711** database behave as if they were declared with "ON UPDATE NO ACTION ON12712** DELETE NO ACTION", even if they are actually CASCADE, RESTRICT, SET NULL12713** or SET DEFAULT.12714*/12715#define SQLITE_CHANGESETAPPLY_NOSAVEPOINT 0x000112716#define SQLITE_CHANGESETAPPLY_INVERT 0x000212717#define SQLITE_CHANGESETAPPLY_IGNORENOOP 0x000412718#define SQLITE_CHANGESETAPPLY_FKNOACTION 0x00081271912720/*12721** CAPI3REF: Constants Passed To The Conflict Handler12722**12723** Values that may be passed as the second argument to a conflict-handler.12724**12725** <dl>12726** <dt>SQLITE_CHANGESET_DATA<dd>12727** The conflict handler is invoked with CHANGESET_DATA as the second argument12728** when processing a DELETE or UPDATE change if a row with the required12729** PRIMARY KEY fields is present in the database, but one or more other12730** (non primary-key) fields modified by the update do not contain the12731** expected "before" values.12732**12733** The conflicting row, in this case, is the database row with the matching12734** primary key.12735**12736** <dt>SQLITE_CHANGESET_NOTFOUND<dd>12737** The conflict handler is invoked with CHANGESET_NOTFOUND as the second12738** argument when processing a DELETE or UPDATE change if a row with the12739** required PRIMARY KEY fields is not present in the database.12740**12741** There is no conflicting row in this case. The results of invoking the12742** sqlite3changeset_conflict() API are undefined.12743**12744** <dt>SQLITE_CHANGESET_CONFLICT<dd>12745** CHANGESET_CONFLICT is passed as the second argument to the conflict12746** handler while processing an INSERT change if the operation would result12747** in duplicate primary key values.12748**12749** The conflicting row in this case is the database row with the matching12750** primary key.12751**12752** <dt>SQLITE_CHANGESET_FOREIGN_KEY<dd>12753** If foreign key handling is enabled, and applying a changeset leaves the12754** database in a state containing foreign key violations, the conflict12755** handler is invoked with CHANGESET_FOREIGN_KEY as the second argument12756** exactly once before the changeset is committed. If the conflict handler12757** returns CHANGESET_OMIT, the changes, including those that caused the12758** foreign key constraint violation, are committed. Or, if it returns12759** CHANGESET_ABORT, the changeset is rolled back.12760**12761** No current or conflicting row information is provided. The only function12762** it is possible to call on the supplied sqlite3_changeset_iter handle12763** is sqlite3changeset_fk_conflicts().12764**12765** <dt>SQLITE_CHANGESET_CONSTRAINT<dd>12766** If any other constraint violation occurs while applying a change (i.e.12767** a UNIQUE, CHECK or NOT NULL constraint), the conflict handler is12768** invoked with CHANGESET_CONSTRAINT as the second argument.12769**12770** There is no conflicting row in this case. The results of invoking the12771** sqlite3changeset_conflict() API are undefined.12772**12773** </dl>12774*/12775#define SQLITE_CHANGESET_DATA 112776#define SQLITE_CHANGESET_NOTFOUND 212777#define SQLITE_CHANGESET_CONFLICT 312778#define SQLITE_CHANGESET_CONSTRAINT 412779#define SQLITE_CHANGESET_FOREIGN_KEY 51278012781/*12782** CAPI3REF: Constants Returned By The Conflict Handler12783**12784** A conflict handler callback must return one of the following three values.12785**12786** <dl>12787** <dt>SQLITE_CHANGESET_OMIT<dd>12788** If a conflict handler returns this value no special action is taken. The12789** change that caused the conflict is not applied. The session module12790** continues to the next change in the changeset.12791**12792** <dt>SQLITE_CHANGESET_REPLACE<dd>12793** This value may only be returned if the second argument to the conflict12794** handler was SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If this12795** is not the case, any changes applied so far are rolled back and the12796** call to sqlite3changeset_apply() returns SQLITE_MISUSE.12797**12798** If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_DATA conflict12799** handler, then the conflicting row is either updated or deleted, depending12800** on the type of change.12801**12802** If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_CONFLICT conflict12803** handler, then the conflicting row is removed from the database and a12804** second attempt to apply the change is made. If this second attempt fails,12805** the original row is restored to the database before continuing.12806**12807** <dt>SQLITE_CHANGESET_ABORT<dd>12808** If this value is returned, any changes applied so far are rolled back12809** and the call to sqlite3changeset_apply() returns SQLITE_ABORT.12810** </dl>12811*/12812#define SQLITE_CHANGESET_OMIT 012813#define SQLITE_CHANGESET_REPLACE 112814#define SQLITE_CHANGESET_ABORT 21281512816/*12817** CAPI3REF: Rebasing changesets12818** EXPERIMENTAL12819**12820** Suppose there is a site hosting a database in state S0. And that12821** modifications are made that move that database to state S1 and a12822** changeset recorded (the "local" changeset). Then, a changeset based12823** on S0 is received from another site (the "remote" changeset) and12824** applied to the database. The database is then in state12825** (S1+"remote"), where the exact state depends on any conflict12826** resolution decisions (OMIT or REPLACE) made while applying "remote".12827** Rebasing a changeset is to update it to take those conflict12828** resolution decisions into account, so that the same conflicts12829** do not have to be resolved elsewhere in the network.12830**12831** For example, if both the local and remote changesets contain an12832** INSERT of the same key on "CREATE TABLE t1(a PRIMARY KEY, b)":12833**12834** local: INSERT INTO t1 VALUES(1, 'v1');12835** remote: INSERT INTO t1 VALUES(1, 'v2');12836**12837** and the conflict resolution is REPLACE, then the INSERT change is12838** removed from the local changeset (it was overridden). Or, if the12839** conflict resolution was "OMIT", then the local changeset is modified12840** to instead contain:12841**12842** UPDATE t1 SET b = 'v2' WHERE a=1;12843**12844** Changes within the local changeset are rebased as follows:12845**12846** <dl>12847** <dt>Local INSERT<dd>12848** This may only conflict with a remote INSERT. If the conflict12849** resolution was OMIT, then add an UPDATE change to the rebased12850** changeset. Or, if the conflict resolution was REPLACE, add12851** nothing to the rebased changeset.12852**12853** <dt>Local DELETE<dd>12854** This may conflict with a remote UPDATE or DELETE. In both cases the12855** only possible resolution is OMIT. If the remote operation was a12856** DELETE, then add no change to the rebased changeset. If the remote12857** operation was an UPDATE, then the old.* fields of change are updated12858** to reflect the new.* values in the UPDATE.12859**12860** <dt>Local UPDATE<dd>12861** This may conflict with a remote UPDATE or DELETE. If it conflicts12862** with a DELETE, and the conflict resolution was OMIT, then the update12863** is changed into an INSERT. Any undefined values in the new.* record12864** from the update change are filled in using the old.* values from12865** the conflicting DELETE. Or, if the conflict resolution was REPLACE,12866** the UPDATE change is simply omitted from the rebased changeset.12867**12868** If conflict is with a remote UPDATE and the resolution is OMIT, then12869** the old.* values are rebased using the new.* values in the remote12870** change. Or, if the resolution is REPLACE, then the change is copied12871** into the rebased changeset with updates to columns also updated by12872** the conflicting remote UPDATE removed. If this means no columns would12873** be updated, the change is omitted.12874** </dl>12875**12876** A local change may be rebased against multiple remote changes12877** simultaneously. If a single key is modified by multiple remote12878** changesets, they are combined as follows before the local changeset12879** is rebased:12880**12881** <ul>12882** <li> If there has been one or more REPLACE resolutions on a12883** key, it is rebased according to a REPLACE.12884**12885** <li> If there have been no REPLACE resolutions on a key, then12886** the local changeset is rebased according to the most recent12887** of the OMIT resolutions.12888** </ul>12889**12890** Note that conflict resolutions from multiple remote changesets are12891** combined on a per-field basis, not per-row. This means that in the12892** case of multiple remote UPDATE operations, some fields of a single12893** local change may be rebased for REPLACE while others are rebased for12894** OMIT.12895**12896** In order to rebase a local changeset, the remote changeset must first12897** be applied to the local database using sqlite3changeset_apply_v2() and12898** the buffer of rebase information captured. Then:12899**12900** <ol>12901** <li> An sqlite3_rebaser object is created by calling12902** sqlite3rebaser_create().12903** <li> The new object is configured with the rebase buffer obtained from12904** sqlite3changeset_apply_v2() by calling sqlite3rebaser_configure().12905** If the local changeset is to be rebased against multiple remote12906** changesets, then sqlite3rebaser_configure() should be called12907** multiple times, in the same order that the multiple12908** sqlite3changeset_apply_v2() calls were made.12909** <li> Each local changeset is rebased by calling sqlite3rebaser_rebase().12910** <li> The sqlite3_rebaser object is deleted by calling12911** sqlite3rebaser_delete().12912** </ol>12913*/12914typedef struct sqlite3_rebaser sqlite3_rebaser;1291512916/*12917** CAPI3REF: Create a changeset rebaser object.12918** EXPERIMENTAL12919**12920** Allocate a new changeset rebaser object. If successful, set (*ppNew) to12921** point to the new object and return SQLITE_OK. Otherwise, if an error12922** occurs, return an SQLite error code (e.g. SQLITE_NOMEM) and set (*ppNew)12923** to NULL.12924*/12925SQLITE_API int sqlite3rebaser_create(sqlite3_rebaser **ppNew);1292612927/*12928** CAPI3REF: Configure a changeset rebaser object.12929** EXPERIMENTAL12930**12931** Configure the changeset rebaser object to rebase changesets according12932** to the conflict resolutions described by buffer pRebase (size nRebase12933** bytes), which must have been obtained from a previous call to12934** sqlite3changeset_apply_v2().12935*/12936SQLITE_API int sqlite3rebaser_configure(12937sqlite3_rebaser*,12938int nRebase, const void *pRebase12939);1294012941/*12942** CAPI3REF: Rebase a changeset12943** EXPERIMENTAL12944**12945** Argument pIn must point to a buffer containing a changeset nIn bytes12946** in size. This function allocates and populates a buffer with a copy12947** of the changeset rebased according to the configuration of the12948** rebaser object passed as the first argument. If successful, (*ppOut)12949** is set to point to the new buffer containing the rebased changeset and12950** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the12951** responsibility of the caller to eventually free the new buffer using12952** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut)12953** are set to zero and an SQLite error code returned.12954*/12955SQLITE_API int sqlite3rebaser_rebase(12956sqlite3_rebaser*,12957int nIn, const void *pIn,12958int *pnOut, void **ppOut12959);1296012961/*12962** CAPI3REF: Delete a changeset rebaser object.12963** EXPERIMENTAL12964**12965** Delete the changeset rebaser object and all associated resources. There12966** should be one call to this function for each successful invocation12967** of sqlite3rebaser_create().12968*/12969SQLITE_API void sqlite3rebaser_delete(sqlite3_rebaser *p);1297012971/*12972** CAPI3REF: Streaming Versions of API functions.12973**12974** The six streaming API xxx_strm() functions serve similar purposes to the12975** corresponding non-streaming API functions:12976**12977** <table border=1 style="margin-left:8ex;margin-right:8ex">12978** <tr><th>Streaming function<th>Non-streaming equivalent</th>12979** <tr><td>sqlite3changeset_apply_strm<td>[sqlite3changeset_apply]12980** <tr><td>sqlite3changeset_apply_strm_v2<td>[sqlite3changeset_apply_v2]12981** <tr><td>sqlite3changeset_concat_strm<td>[sqlite3changeset_concat]12982** <tr><td>sqlite3changeset_invert_strm<td>[sqlite3changeset_invert]12983** <tr><td>sqlite3changeset_start_strm<td>[sqlite3changeset_start]12984** <tr><td>sqlite3session_changeset_strm<td>[sqlite3session_changeset]12985** <tr><td>sqlite3session_patchset_strm<td>[sqlite3session_patchset]12986** </table>12987**12988** Non-streaming functions that accept changesets (or patchsets) as input12989** require that the entire changeset be stored in a single buffer in memory.12990** Similarly, those that return a changeset or patchset do so by returning12991** a pointer to a single large buffer allocated using sqlite3_malloc().12992** Normally this is convenient. However, if an application running in a12993** low-memory environment is required to handle very large changesets, the12994** large contiguous memory allocations required can become onerous.12995**12996** In order to avoid this problem, instead of a single large buffer, input12997** is passed to a streaming API functions by way of a callback function that12998** the sessions module invokes to incrementally request input data as it is12999** required. In all cases, a pair of API function parameters such as13000**13001** <pre>13002** int nChangeset,13003** void *pChangeset,13004** </pre>13005**13006** Is replaced by:13007**13008** <pre>13009** int (*xInput)(void *pIn, void *pData, int *pnData),13010** void *pIn,13011** </pre>13012**13013** Each time the xInput callback is invoked by the sessions module, the first13014** argument passed is a copy of the supplied pIn context pointer. The second13015** argument, pData, points to a buffer (*pnData) bytes in size. Assuming no13016** error occurs the xInput method should copy up to (*pnData) bytes of data13017** into the buffer and set (*pnData) to the actual number of bytes copied13018** before returning SQLITE_OK. If the input is completely exhausted, (*pnData)13019** should be set to zero to indicate this. Or, if an error occurs, an SQLite13020** error code should be returned. In all cases, if an xInput callback returns13021** an error, all processing is abandoned and the streaming API function13022** returns a copy of the error code to the caller.13023**13024** In the case of sqlite3changeset_start_strm(), the xInput callback may be13025** invoked by the sessions module at any point during the lifetime of the13026** iterator. If such an xInput callback returns an error, the iterator enters13027** an error state, whereby all subsequent calls to iterator functions13028** immediately fail with the same error code as returned by xInput.13029**13030** Similarly, streaming API functions that return changesets (or patchsets)13031** return them in chunks by way of a callback function instead of via a13032** pointer to a single large buffer. In this case, a pair of parameters such13033** as:13034**13035** <pre>13036** int *pnChangeset,13037** void **ppChangeset,13038** </pre>13039**13040** Is replaced by:13041**13042** <pre>13043** int (*xOutput)(void *pOut, const void *pData, int nData),13044** void *pOut13045** </pre>13046**13047** The xOutput callback is invoked zero or more times to return data to13048** the application. The first parameter passed to each call is a copy of the13049** pOut pointer supplied by the application. The second parameter, pData,13050** points to a buffer nData bytes in size containing the chunk of output13051** data being returned. If the xOutput callback successfully processes the13052** supplied data, it should return SQLITE_OK to indicate success. Otherwise,13053** it should return some other SQLite error code. In this case processing13054** is immediately abandoned and the streaming API function returns a copy13055** of the xOutput error code to the application.13056**13057** The sessions module never invokes an xOutput callback with the third13058** parameter set to a value less than or equal to zero. Other than this,13059** no guarantees are made as to the size of the chunks of data returned.13060*/13061SQLITE_API int sqlite3changeset_apply_strm(13062sqlite3 *db, /* Apply change to "main" db of this handle */13063int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */13064void *pIn, /* First arg for xInput */13065int(*xFilter)(13066void *pCtx, /* Copy of sixth arg to _apply() */13067const char *zTab /* Table name */13068),13069int(*xConflict)(13070void *pCtx, /* Copy of sixth arg to _apply() */13071int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */13072sqlite3_changeset_iter *p /* Handle describing change and conflict */13073),13074void *pCtx /* First argument passed to xConflict */13075);13076SQLITE_API int sqlite3changeset_apply_v2_strm(13077sqlite3 *db, /* Apply change to "main" db of this handle */13078int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */13079void *pIn, /* First arg for xInput */13080int(*xFilter)(13081void *pCtx, /* Copy of sixth arg to _apply() */13082const char *zTab /* Table name */13083),13084int(*xConflict)(13085void *pCtx, /* Copy of sixth arg to _apply() */13086int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */13087sqlite3_changeset_iter *p /* Handle describing change and conflict */13088),13089void *pCtx, /* First argument passed to xConflict */13090void **ppRebase, int *pnRebase,13091int flags13092);13093SQLITE_API int sqlite3changeset_apply_v3_strm(13094sqlite3 *db, /* Apply change to "main" db of this handle */13095int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */13096void *pIn, /* First arg for xInput */13097int(*xFilter)(13098void *pCtx, /* Copy of sixth arg to _apply() */13099sqlite3_changeset_iter *p13100),13101int(*xConflict)(13102void *pCtx, /* Copy of sixth arg to _apply() */13103int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */13104sqlite3_changeset_iter *p /* Handle describing change and conflict */13105),13106void *pCtx, /* First argument passed to xConflict */13107void **ppRebase, int *pnRebase,13108int flags13109);13110SQLITE_API int sqlite3changeset_concat_strm(13111int (*xInputA)(void *pIn, void *pData, int *pnData),13112void *pInA,13113int (*xInputB)(void *pIn, void *pData, int *pnData),13114void *pInB,13115int (*xOutput)(void *pOut, const void *pData, int nData),13116void *pOut13117);13118SQLITE_API int sqlite3changeset_invert_strm(13119int (*xInput)(void *pIn, void *pData, int *pnData),13120void *pIn,13121int (*xOutput)(void *pOut, const void *pData, int nData),13122void *pOut13123);13124SQLITE_API int sqlite3changeset_start_strm(13125sqlite3_changeset_iter **pp,13126int (*xInput)(void *pIn, void *pData, int *pnData),13127void *pIn13128);13129SQLITE_API int sqlite3changeset_start_v2_strm(13130sqlite3_changeset_iter **pp,13131int (*xInput)(void *pIn, void *pData, int *pnData),13132void *pIn,13133int flags13134);13135SQLITE_API int sqlite3session_changeset_strm(13136sqlite3_session *pSession,13137int (*xOutput)(void *pOut, const void *pData, int nData),13138void *pOut13139);13140SQLITE_API int sqlite3session_patchset_strm(13141sqlite3_session *pSession,13142int (*xOutput)(void *pOut, const void *pData, int nData),13143void *pOut13144);13145SQLITE_API int sqlite3changegroup_add_strm(sqlite3_changegroup*,13146int (*xInput)(void *pIn, void *pData, int *pnData),13147void *pIn13148);13149SQLITE_API int sqlite3changegroup_output_strm(sqlite3_changegroup*,13150int (*xOutput)(void *pOut, const void *pData, int nData),13151void *pOut13152);13153SQLITE_API int sqlite3rebaser_rebase_strm(13154sqlite3_rebaser *pRebaser,13155int (*xInput)(void *pIn, void *pData, int *pnData),13156void *pIn,13157int (*xOutput)(void *pOut, const void *pData, int nData),13158void *pOut13159);1316013161/*13162** CAPI3REF: Configure global parameters13163**13164** The sqlite3session_config() interface is used to make global configuration13165** changes to the sessions module in order to tune it to the specific needs13166** of the application.13167**13168** The sqlite3session_config() interface is not threadsafe. If it is invoked13169** while any other thread is inside any other sessions method then the13170** results are undefined. Furthermore, if it is invoked after any sessions13171** related objects have been created, the results are also undefined.13172**13173** The first argument to the sqlite3session_config() function must be one13174** of the SQLITE_SESSION_CONFIG_XXX constants defined below. The13175** interpretation of the (void*) value passed as the second parameter and13176** the effect of calling this function depends on the value of the first13177** parameter.13178**13179** <dl>13180** <dt>SQLITE_SESSION_CONFIG_STRMSIZE<dd>13181** By default, the sessions module streaming interfaces attempt to input13182** and output data in approximately 1 KiB chunks. This operand may be used13183** to set and query the value of this configuration setting. The pointer13184** passed as the second argument must point to a value of type (int).13185** If this value is greater than 0, it is used as the new streaming data13186** chunk size for both input and output. Before returning, the (int) value13187** pointed to by pArg is set to the final value of the streaming interface13188** chunk size.13189** </dl>13190**13191** This function returns SQLITE_OK if successful, or an SQLite error code13192** otherwise.13193*/13194SQLITE_API int sqlite3session_config(int op, void *pArg);1319513196/*13197** CAPI3REF: Values for sqlite3session_config().13198*/13199#define SQLITE_SESSION_CONFIG_STRMSIZE 11320013201/*13202** Make sure we can call this stuff from C++.13203*/13204#ifdef __cplusplus13205}13206#endif1320713208#endif /* !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION) */1320913210/******** End of sqlite3session.h *********/13211/******** Begin file fts5.h *********/13212/*13213** 2014 May 3113214**13215** The author disclaims copyright to this source code. In place of13216** a legal notice, here is a blessing:13217**13218** May you do good and not evil.13219** May you find forgiveness for yourself and forgive others.13220** May you share freely, never taking more than you give.13221**13222******************************************************************************13223**13224** Interfaces to extend FTS5. Using the interfaces defined in this file,13225** FTS5 may be extended with:13226**13227** * custom tokenizers, and13228** * custom auxiliary functions.13229*/132301323113232#ifndef _FTS5_H13233#define _FTS5_H132341323513236#ifdef __cplusplus13237extern "C" {13238#endif1323913240/*************************************************************************13241** CUSTOM AUXILIARY FUNCTIONS13242**13243** Virtual table implementations may overload SQL functions by implementing13244** the sqlite3_module.xFindFunction() method.13245*/1324613247typedef struct Fts5ExtensionApi Fts5ExtensionApi;13248typedef struct Fts5Context Fts5Context;13249typedef struct Fts5PhraseIter Fts5PhraseIter;1325013251typedef void (*fts5_extension_function)(13252const Fts5ExtensionApi *pApi, /* API offered by current FTS version */13253Fts5Context *pFts, /* First arg to pass to pApi functions */13254sqlite3_context *pCtx, /* Context for returning result/error */13255int nVal, /* Number of values in apVal[] array */13256sqlite3_value **apVal /* Array of trailing arguments */13257);1325813259struct Fts5PhraseIter {13260const unsigned char *a;13261const unsigned char *b;13262};1326313264/*13265** EXTENSION API FUNCTIONS13266**13267** xUserData(pFts):13268** Return a copy of the pUserData pointer passed to the xCreateFunction()13269** API when the extension function was registered.13270**13271** xColumnTotalSize(pFts, iCol, pnToken):13272** If parameter iCol is less than zero, set output variable *pnToken13273** to the total number of tokens in the FTS5 table. Or, if iCol is13274** non-negative but less than the number of columns in the table, return13275** the total number of tokens in column iCol, considering all rows in13276** the FTS5 table.13277**13278** If parameter iCol is greater than or equal to the number of columns13279** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.13280** an OOM condition or IO error), an appropriate SQLite error code is13281** returned.13282**13283** xColumnCount(pFts):13284** Return the number of columns in the table.13285**13286** xColumnSize(pFts, iCol, pnToken):13287** If parameter iCol is less than zero, set output variable *pnToken13288** to the total number of tokens in the current row. Or, if iCol is13289** non-negative but less than the number of columns in the table, set13290** *pnToken to the number of tokens in column iCol of the current row.13291**13292** If parameter iCol is greater than or equal to the number of columns13293** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.13294** an OOM condition or IO error), an appropriate SQLite error code is13295** returned.13296**13297** This function may be quite inefficient if used with an FTS5 table13298** created with the "columnsize=0" option.13299**13300** xColumnText:13301** If parameter iCol is less than zero, or greater than or equal to the13302** number of columns in the table, SQLITE_RANGE is returned.13303**13304** Otherwise, this function attempts to retrieve the text of column iCol of13305** the current document. If successful, (*pz) is set to point to a buffer13306** containing the text in utf-8 encoding, (*pn) is set to the size in bytes13307** (not characters) of the buffer and SQLITE_OK is returned. Otherwise,13308** if an error occurs, an SQLite error code is returned and the final values13309** of (*pz) and (*pn) are undefined.13310**13311** xPhraseCount:13312** Returns the number of phrases in the current query expression.13313**13314** xPhraseSize:13315** If parameter iCol is less than zero, or greater than or equal to the13316** number of phrases in the current query, as returned by xPhraseCount,13317** 0 is returned. Otherwise, this function returns the number of tokens in13318** phrase iPhrase of the query. Phrases are numbered starting from zero.13319**13320** xInstCount:13321** Set *pnInst to the total number of occurrences of all phrases within13322** the query within the current row. Return SQLITE_OK if successful, or13323** an error code (i.e. SQLITE_NOMEM) if an error occurs.13324**13325** This API can be quite slow if used with an FTS5 table created with the13326** "detail=none" or "detail=column" option. If the FTS5 table is created13327** with either "detail=none" or "detail=column" and "content=" option13328** (i.e. if it is a contentless table), then this API always returns 0.13329**13330** xInst:13331** Query for the details of phrase match iIdx within the current row.13332** Phrase matches are numbered starting from zero, so the iIdx argument13333** should be greater than or equal to zero and smaller than the value13334** output by xInstCount(). If iIdx is less than zero or greater than13335** or equal to the value returned by xInstCount(), SQLITE_RANGE is returned.13336**13337** Otherwise, output parameter *piPhrase is set to the phrase number, *piCol13338** to the column in which it occurs and *piOff the token offset of the13339** first token of the phrase. SQLITE_OK is returned if successful, or an13340** error code (i.e. SQLITE_NOMEM) if an error occurs.13341**13342** This API can be quite slow if used with an FTS5 table created with the13343** "detail=none" or "detail=column" option.13344**13345** xRowid:13346** Returns the rowid of the current row.13347**13348** xTokenize:13349** Tokenize text using the tokenizer belonging to the FTS5 table.13350**13351** xQueryPhrase(pFts5, iPhrase, pUserData, xCallback):13352** This API function is used to query the FTS table for phrase iPhrase13353** of the current query. Specifically, a query equivalent to:13354**13355** ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid13356**13357** with $p set to a phrase equivalent to the phrase iPhrase of the13358** current query is executed. Any column filter that applies to13359** phrase iPhrase of the current query is included in $p. For each13360** row visited, the callback function passed as the fourth argument13361** is invoked. The context and API objects passed to the callback13362** function may be used to access the properties of each matched row.13363** Invoking Api.xUserData() returns a copy of the pointer passed as13364** the third argument to pUserData.13365**13366** If parameter iPhrase is less than zero, or greater than or equal to13367** the number of phrases in the query, as returned by xPhraseCount(),13368** this function returns SQLITE_RANGE.13369**13370** If the callback function returns any value other than SQLITE_OK, the13371** query is abandoned and the xQueryPhrase function returns immediately.13372** If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK.13373** Otherwise, the error code is propagated upwards.13374**13375** If the query runs to completion without incident, SQLITE_OK is returned.13376** Or, if some error occurs before the query completes or is aborted by13377** the callback, an SQLite error code is returned.13378**13379**13380** xSetAuxdata(pFts5, pAux, xDelete)13381**13382** Save the pointer passed as the second argument as the extension function's13383** "auxiliary data". The pointer may then be retrieved by the current or any13384** future invocation of the same fts5 extension function made as part of13385** the same MATCH query using the xGetAuxdata() API.13386**13387** Each extension function is allocated a single auxiliary data slot for13388** each FTS query (MATCH expression). If the extension function is invoked13389** more than once for a single FTS query, then all invocations share a13390** single auxiliary data context.13391**13392** If there is already an auxiliary data pointer when this function is13393** invoked, then it is replaced by the new pointer. If an xDelete callback13394** was specified along with the original pointer, it is invoked at this13395** point.13396**13397** The xDelete callback, if one is specified, is also invoked on the13398** auxiliary data pointer after the FTS5 query has finished.13399**13400** If an error (e.g. an OOM condition) occurs within this function,13401** the auxiliary data is set to NULL and an error code returned. If the13402** xDelete parameter was not NULL, it is invoked on the auxiliary data13403** pointer before returning.13404**13405**13406** xGetAuxdata(pFts5, bClear)13407**13408** Returns the current auxiliary data pointer for the fts5 extension13409** function. See the xSetAuxdata() method for details.13410**13411** If the bClear argument is non-zero, then the auxiliary data is cleared13412** (set to NULL) before this function returns. In this case the xDelete,13413** if any, is not invoked.13414**13415**13416** xRowCount(pFts5, pnRow)13417**13418** This function is used to retrieve the total number of rows in the table.13419** In other words, the same value that would be returned by:13420**13421** SELECT count(*) FROM ftstable;13422**13423** xPhraseFirst()13424** This function is used, along with type Fts5PhraseIter and the xPhraseNext13425** method, to iterate through all instances of a single query phrase within13426** the current row. This is the same information as is accessible via the13427** xInstCount/xInst APIs. While the xInstCount/xInst APIs are more convenient13428** to use, this API may be faster under some circumstances. To iterate13429** through instances of phrase iPhrase, use the following code:13430**13431** Fts5PhraseIter iter;13432** int iCol, iOff;13433** for(pApi->xPhraseFirst(pFts, iPhrase, &iter, &iCol, &iOff);13434** iCol>=0;13435** pApi->xPhraseNext(pFts, &iter, &iCol, &iOff)13436** ){13437** // An instance of phrase iPhrase at offset iOff of column iCol13438** }13439**13440** The Fts5PhraseIter structure is defined above. Applications should not13441** modify this structure directly - it should only be used as shown above13442** with the xPhraseFirst() and xPhraseNext() API methods (and by13443** xPhraseFirstColumn() and xPhraseNextColumn() as illustrated below).13444**13445** This API can be quite slow if used with an FTS5 table created with the13446** "detail=none" or "detail=column" option. If the FTS5 table is created13447** with either "detail=none" or "detail=column" and "content=" option13448** (i.e. if it is a contentless table), then this API always iterates13449** through an empty set (all calls to xPhraseFirst() set iCol to -1).13450**13451** In all cases, matches are visited in (column ASC, offset ASC) order.13452** i.e. all those in column 0, sorted by offset, followed by those in13453** column 1, etc.13454**13455** xPhraseNext()13456** See xPhraseFirst above.13457**13458** xPhraseFirstColumn()13459** This function and xPhraseNextColumn() are similar to the xPhraseFirst()13460** and xPhraseNext() APIs described above. The difference is that instead13461** of iterating through all instances of a phrase in the current row, these13462** APIs are used to iterate through the set of columns in the current row13463** that contain one or more instances of a specified phrase. For example:13464**13465** Fts5PhraseIter iter;13466** int iCol;13467** for(pApi->xPhraseFirstColumn(pFts, iPhrase, &iter, &iCol);13468** iCol>=0;13469** pApi->xPhraseNextColumn(pFts, &iter, &iCol)13470** ){13471** // Column iCol contains at least one instance of phrase iPhrase13472** }13473**13474** This API can be quite slow if used with an FTS5 table created with the13475** "detail=none" option. If the FTS5 table is created with either13476** "detail=none" "content=" option (i.e. if it is a contentless table),13477** then this API always iterates through an empty set (all calls to13478** xPhraseFirstColumn() set iCol to -1).13479**13480** The information accessed using this API and its companion13481** xPhraseFirstColumn() may also be obtained using xPhraseFirst/xPhraseNext13482** (or xInst/xInstCount). The chief advantage of this API is that it is13483** significantly more efficient than those alternatives when used with13484** "detail=column" tables.13485**13486** xPhraseNextColumn()13487** See xPhraseFirstColumn above.13488**13489** xQueryToken(pFts5, iPhrase, iToken, ppToken, pnToken)13490** This is used to access token iToken of phrase iPhrase of the current13491** query. Before returning, output parameter *ppToken is set to point13492** to a buffer containing the requested token, and *pnToken to the13493** size of this buffer in bytes.13494**13495** If iPhrase or iToken are less than zero, or if iPhrase is greater than13496** or equal to the number of phrases in the query as reported by13497** xPhraseCount(), or if iToken is equal to or greater than the number of13498** tokens in the phrase, SQLITE_RANGE is returned and *ppToken and *pnToken13499are both zeroed.13500**13501** The output text is not a copy of the query text that specified the13502** token. It is the output of the tokenizer module. For tokendata=113503** tables, this includes any embedded 0x00 and trailing data.13504**13505** xInstToken(pFts5, iIdx, iToken, ppToken, pnToken)13506** This is used to access token iToken of phrase hit iIdx within the13507** current row. If iIdx is less than zero or greater than or equal to the13508** value returned by xInstCount(), SQLITE_RANGE is returned. Otherwise,13509** output variable (*ppToken) is set to point to a buffer containing the13510** matching document token, and (*pnToken) to the size of that buffer in13511** bytes.13512**13513** The output text is not a copy of the document text that was tokenized.13514** It is the output of the tokenizer module. For tokendata=1 tables, this13515** includes any embedded 0x00 and trailing data.13516**13517** This API may be slow in some cases if the token identified by parameters13518** iIdx and iToken matched a prefix token in the query. In most cases, the13519** first call to this API for each prefix token in the query is forced13520** to scan the portion of the full-text index that matches the prefix13521** token to collect the extra data required by this API. If the prefix13522** token matches a large number of token instances in the document set,13523** this may be a performance problem.13524**13525** If the user knows in advance that a query may use this API for a13526** prefix token, FTS5 may be configured to collect all required data as part13527** of the initial querying of the full-text index, avoiding the second scan13528** entirely. This also causes prefix queries that do not use this API to13529** run more slowly and use more memory. FTS5 may be configured in this way13530** either on a per-table basis using the [FTS5 insttoken | 'insttoken']13531** option, or on a per-query basis using the13532** [fts5_insttoken | fts5_insttoken()] user function.13533**13534** This API can be quite slow if used with an FTS5 table created with the13535** "detail=none" or "detail=column" option.13536**13537** xColumnLocale(pFts5, iIdx, pzLocale, pnLocale)13538** If parameter iCol is less than zero, or greater than or equal to the13539** number of columns in the table, SQLITE_RANGE is returned.13540**13541** Otherwise, this function attempts to retrieve the locale associated13542** with column iCol of the current row. Usually, there is no associated13543** locale, and output parameters (*pzLocale) and (*pnLocale) are set13544** to NULL and 0, respectively. However, if the fts5_locale() function13545** was used to associate a locale with the value when it was inserted13546** into the fts5 table, then (*pzLocale) is set to point to a nul-terminated13547** buffer containing the name of the locale in utf-8 encoding. (*pnLocale)13548** is set to the size in bytes of the buffer, not including the13549** nul-terminator.13550**13551** If successful, SQLITE_OK is returned. Or, if an error occurs, an13552** SQLite error code is returned. The final value of the output parameters13553** is undefined in this case.13554**13555** xTokenize_v2:13556** Tokenize text using the tokenizer belonging to the FTS5 table. This13557** API is the same as the xTokenize() API, except that it allows a tokenizer13558** locale to be specified.13559*/13560struct Fts5ExtensionApi {13561int iVersion; /* Currently always set to 4 */1356213563void *(*xUserData)(Fts5Context*);1356413565int (*xColumnCount)(Fts5Context*);13566int (*xRowCount)(Fts5Context*, sqlite3_int64 *pnRow);13567int (*xColumnTotalSize)(Fts5Context*, int iCol, sqlite3_int64 *pnToken);1356813569int (*xTokenize)(Fts5Context*,13570const char *pText, int nText, /* Text to tokenize */13571void *pCtx, /* Context passed to xToken() */13572int (*xToken)(void*, int, const char*, int, int, int) /* Callback */13573);1357413575int (*xPhraseCount)(Fts5Context*);13576int (*xPhraseSize)(Fts5Context*, int iPhrase);1357713578int (*xInstCount)(Fts5Context*, int *pnInst);13579int (*xInst)(Fts5Context*, int iIdx, int *piPhrase, int *piCol, int *piOff);1358013581sqlite3_int64 (*xRowid)(Fts5Context*);13582int (*xColumnText)(Fts5Context*, int iCol, const char **pz, int *pn);13583int (*xColumnSize)(Fts5Context*, int iCol, int *pnToken);1358413585int (*xQueryPhrase)(Fts5Context*, int iPhrase, void *pUserData,13586int(*)(const Fts5ExtensionApi*,Fts5Context*,void*)13587);13588int (*xSetAuxdata)(Fts5Context*, void *pAux, void(*xDelete)(void*));13589void *(*xGetAuxdata)(Fts5Context*, int bClear);1359013591int (*xPhraseFirst)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*, int*);13592void (*xPhraseNext)(Fts5Context*, Fts5PhraseIter*, int *piCol, int *piOff);1359313594int (*xPhraseFirstColumn)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*);13595void (*xPhraseNextColumn)(Fts5Context*, Fts5PhraseIter*, int *piCol);1359613597/* Below this point are iVersion>=3 only */13598int (*xQueryToken)(Fts5Context*,13599int iPhrase, int iToken,13600const char **ppToken, int *pnToken13601);13602int (*xInstToken)(Fts5Context*, int iIdx, int iToken, const char**, int*);1360313604/* Below this point are iVersion>=4 only */13605int (*xColumnLocale)(Fts5Context*, int iCol, const char **pz, int *pn);13606int (*xTokenize_v2)(Fts5Context*,13607const char *pText, int nText, /* Text to tokenize */13608const char *pLocale, int nLocale, /* Locale to pass to tokenizer */13609void *pCtx, /* Context passed to xToken() */13610int (*xToken)(void*, int, const char*, int, int, int) /* Callback */13611);13612};1361313614/*13615** CUSTOM AUXILIARY FUNCTIONS13616*************************************************************************/1361713618/*************************************************************************13619** CUSTOM TOKENIZERS13620**13621** Applications may also register custom tokenizer types. A tokenizer13622** is registered by providing fts5 with a populated instance of the13623** following structure. All structure methods must be defined, setting13624** any member of the fts5_tokenizer struct to NULL leads to undefined13625** behaviour. The structure methods are expected to function as follows:13626**13627** xCreate:13628** This function is used to allocate and initialize a tokenizer instance.13629** A tokenizer instance is required to actually tokenize text.13630**13631** The first argument passed to this function is a copy of the (void*)13632** pointer provided by the application when the fts5_tokenizer_v2 object13633** was registered with FTS5 (the third argument to xCreateTokenizer()).13634** The second and third arguments are an array of nul-terminated strings13635** containing the tokenizer arguments, if any, specified following the13636** tokenizer name as part of the CREATE VIRTUAL TABLE statement used13637** to create the FTS5 table.13638**13639** The final argument is an output variable. If successful, (*ppOut)13640** should be set to point to the new tokenizer handle and SQLITE_OK13641** returned. If an error occurs, some value other than SQLITE_OK should13642** be returned. In this case, fts5 assumes that the final value of *ppOut13643** is undefined.13644**13645** xDelete:13646** This function is invoked to delete a tokenizer handle previously13647** allocated using xCreate(). Fts5 guarantees that this function will13648** be invoked exactly once for each successful call to xCreate().13649**13650** xTokenize:13651** This function is expected to tokenize the nText byte string indicated13652** by argument pText. pText may or may not be nul-terminated. The first13653** argument passed to this function is a pointer to an Fts5Tokenizer object13654** returned by an earlier call to xCreate().13655**13656** The third argument indicates the reason that FTS5 is requesting13657** tokenization of the supplied text. This is always one of the following13658** four values:13659**13660** <ul><li> <b>FTS5_TOKENIZE_DOCUMENT</b> - A document is being inserted into13661** or removed from the FTS table. The tokenizer is being invoked to13662** determine the set of tokens to add to (or delete from) the13663** FTS index.13664**13665** <li> <b>FTS5_TOKENIZE_QUERY</b> - A MATCH query is being executed13666** against the FTS index. The tokenizer is being called to tokenize13667** a bareword or quoted string specified as part of the query.13668**13669** <li> <b>(FTS5_TOKENIZE_QUERY | FTS5_TOKENIZE_PREFIX)</b> - Same as13670** FTS5_TOKENIZE_QUERY, except that the bareword or quoted string is13671** followed by a "*" character, indicating that the last token13672** returned by the tokenizer will be treated as a token prefix.13673**13674** <li> <b>FTS5_TOKENIZE_AUX</b> - The tokenizer is being invoked to13675** satisfy an fts5_api.xTokenize() request made by an auxiliary13676** function. Or an fts5_api.xColumnSize() request made by the same13677** on a columnsize=0 database.13678** </ul>13679**13680** The sixth and seventh arguments passed to xTokenize() - pLocale and13681** nLocale - are a pointer to a buffer containing the locale to use for13682** tokenization (e.g. "en_US") and its size in bytes, respectively. The13683** pLocale buffer is not nul-terminated. pLocale may be passed NULL (in13684** which case nLocale is always 0) to indicate that the tokenizer should13685** use its default locale.13686**13687** For each token in the input string, the supplied callback xToken() must13688** be invoked. The first argument to it should be a copy of the pointer13689** passed as the second argument to xTokenize(). The third and fourth13690** arguments are a pointer to a buffer containing the token text, and the13691** size of the token in bytes. The 4th and 5th arguments are the byte offsets13692** of the first byte of and first byte immediately following the text from13693** which the token is derived within the input.13694**13695** The second argument passed to the xToken() callback ("tflags") should13696** normally be set to 0. The exception is if the tokenizer supports13697** synonyms. In this case see the discussion below for details.13698**13699** FTS5 assumes the xToken() callback is invoked for each token in the13700** order that they occur within the input text.13701**13702** If an xToken() callback returns any value other than SQLITE_OK, then13703** the tokenization should be abandoned and the xTokenize() method should13704** immediately return a copy of the xToken() return value. Or, if the13705** input buffer is exhausted, xTokenize() should return SQLITE_OK. Finally,13706** if an error occurs with the xTokenize() implementation itself, it13707** may abandon the tokenization and return any error code other than13708** SQLITE_OK or SQLITE_DONE.13709**13710** If the tokenizer is registered using an fts5_tokenizer_v2 object,13711** then the xTokenize() method has two additional arguments - pLocale13712** and nLocale. These specify the locale that the tokenizer should use13713** for the current request. If pLocale and nLocale are both 0, then the13714** tokenizer should use its default locale. Otherwise, pLocale points to13715** an nLocale byte buffer containing the name of the locale to use as utf-813716** text. pLocale is not nul-terminated.13717**13718** FTS5_TOKENIZER13719**13720** There is also an fts5_tokenizer object. This is an older, deprecated,13721** version of fts5_tokenizer_v2. It is similar except that:13722**13723** <ul>13724** <li> There is no "iVersion" field, and13725** <li> The xTokenize() method does not take a locale argument.13726** </ul>13727**13728** Legacy fts5_tokenizer tokenizers must be registered using the13729** legacy xCreateTokenizer() function, instead of xCreateTokenizer_v2().13730**13731** Tokenizer implementations registered using either API may be retrieved13732** using both xFindTokenizer() and xFindTokenizer_v2().13733**13734** SYNONYM SUPPORT13735**13736** Custom tokenizers may also support synonyms. Consider a case in which a13737** user wishes to query for a phrase such as "first place". Using the13738** built-in tokenizers, the FTS5 query 'first + place' will match instances13739** of "first place" within the document set, but not alternative forms13740** such as "1st place". In some applications, it would be better to match13741** all instances of "first place" or "1st place" regardless of which form13742** the user specified in the MATCH query text.13743**13744** There are several ways to approach this in FTS5:13745**13746** <ol><li> By mapping all synonyms to a single token. In this case, using13747** the above example, this means that the tokenizer returns the13748** same token for inputs "first" and "1st". Say that token is in13749** fact "first", so that when the user inserts the document "I won13750** 1st place" entries are added to the index for tokens "i", "won",13751** "first" and "place". If the user then queries for '1st + place',13752** the tokenizer substitutes "first" for "1st" and the query works13753** as expected.13754**13755** <li> By querying the index for all synonyms of each query term13756** separately. In this case, when tokenizing query text, the13757** tokenizer may provide multiple synonyms for a single term13758** within the document. FTS5 then queries the index for each13759** synonym individually. For example, faced with the query:13760**13761** <codeblock>13762** ... MATCH 'first place'</codeblock>13763**13764** the tokenizer offers both "1st" and "first" as synonyms for the13765** first token in the MATCH query and FTS5 effectively runs a query13766** similar to:13767**13768** <codeblock>13769** ... MATCH '(first OR 1st) place'</codeblock>13770**13771** except that, for the purposes of auxiliary functions, the query13772** still appears to contain just two phrases - "(first OR 1st)"13773** being treated as a single phrase.13774**13775** <li> By adding multiple synonyms for a single term to the FTS index.13776** Using this method, when tokenizing document text, the tokenizer13777** provides multiple synonyms for each token. So that when a13778** document such as "I won first place" is tokenized, entries are13779** added to the FTS index for "i", "won", "first", "1st" and13780** "place".13781**13782** This way, even if the tokenizer does not provide synonyms13783** when tokenizing query text (it should not - to do so would be13784** inefficient), it doesn't matter if the user queries for13785** 'first + place' or '1st + place', as there are entries in the13786** FTS index corresponding to both forms of the first token.13787** </ol>13788**13789** Whether it is parsing document or query text, any call to xToken that13790** specifies a <i>tflags</i> argument with the FTS5_TOKEN_COLOCATED bit13791** is considered to supply a synonym for the previous token. For example,13792** when parsing the document "I won first place", a tokenizer that supports13793** synonyms would call xToken() 5 times, as follows:13794**13795** <codeblock>13796** xToken(pCtx, 0, "i", 1, 0, 1);13797** xToken(pCtx, 0, "won", 3, 2, 5);13798** xToken(pCtx, 0, "first", 5, 6, 11);13799** xToken(pCtx, FTS5_TOKEN_COLOCATED, "1st", 3, 6, 11);13800** xToken(pCtx, 0, "place", 5, 12, 17);13801**</codeblock>13802**13803** It is an error to specify the FTS5_TOKEN_COLOCATED flag the first time13804** xToken() is called. Multiple synonyms may be specified for a single token13805** by making multiple calls to xToken(FTS5_TOKEN_COLOCATED) in sequence.13806** There is no limit to the number of synonyms that may be provided for a13807** single token.13808**13809** In many cases, method (1) above is the best approach. It does not add13810** extra data to the FTS index or require FTS5 to query for multiple terms,13811** so it is efficient in terms of disk space and query speed. However, it13812** does not support prefix queries very well. If, as suggested above, the13813** token "first" is substituted for "1st" by the tokenizer, then the query:13814**13815** <codeblock>13816** ... MATCH '1s*'</codeblock>13817**13818** will not match documents that contain the token "1st" (as the tokenizer13819** will probably not map "1s" to any prefix of "first").13820**13821** For full prefix support, method (3) may be preferred. In this case,13822** because the index contains entries for both "first" and "1st", prefix13823** queries such as 'fi*' or '1s*' will match correctly. However, because13824** extra entries are added to the FTS index, this method uses more space13825** within the database.13826**13827** Method (2) offers a midpoint between (1) and (3). Using this method,13828** a query such as '1s*' will match documents that contain the literal13829** token "1st", but not "first" (assuming the tokenizer is not able to13830** provide synonyms for prefixes). However, a non-prefix query like '1st'13831** will match against "1st" and "first". This method does not require13832** extra disk space, as no extra entries are added to the FTS index.13833** On the other hand, it may require more CPU cycles to run MATCH queries,13834** as separate queries of the FTS index are required for each synonym.13835**13836** When using methods (2) or (3), it is important that the tokenizer only13837** provide synonyms when tokenizing document text (method (3)) or query13838** text (method (2)), not both. Doing so will not cause any errors, but is13839** inefficient.13840*/13841typedef struct Fts5Tokenizer Fts5Tokenizer;13842typedef struct fts5_tokenizer_v2 fts5_tokenizer_v2;13843struct fts5_tokenizer_v2 {13844int iVersion; /* Currently always 2 */1384513846int (*xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut);13847void (*xDelete)(Fts5Tokenizer*);13848int (*xTokenize)(Fts5Tokenizer*,13849void *pCtx,13850int flags, /* Mask of FTS5_TOKENIZE_* flags */13851const char *pText, int nText,13852const char *pLocale, int nLocale,13853int (*xToken)(13854void *pCtx, /* Copy of 2nd argument to xTokenize() */13855int tflags, /* Mask of FTS5_TOKEN_* flags */13856const char *pToken, /* Pointer to buffer containing token */13857int nToken, /* Size of token in bytes */13858int iStart, /* Byte offset of token within input text */13859int iEnd /* Byte offset of end of token within input text */13860)13861);13862};1386313864/*13865** New code should use the fts5_tokenizer_v2 type to define tokenizer13866** implementations. The following type is included for legacy applications13867** that still use it.13868*/13869typedef struct fts5_tokenizer fts5_tokenizer;13870struct fts5_tokenizer {13871int (*xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut);13872void (*xDelete)(Fts5Tokenizer*);13873int (*xTokenize)(Fts5Tokenizer*,13874void *pCtx,13875int flags, /* Mask of FTS5_TOKENIZE_* flags */13876const char *pText, int nText,13877int (*xToken)(13878void *pCtx, /* Copy of 2nd argument to xTokenize() */13879int tflags, /* Mask of FTS5_TOKEN_* flags */13880const char *pToken, /* Pointer to buffer containing token */13881int nToken, /* Size of token in bytes */13882int iStart, /* Byte offset of token within input text */13883int iEnd /* Byte offset of end of token within input text */13884)13885);13886};138871388813889/* Flags that may be passed as the third argument to xTokenize() */13890#define FTS5_TOKENIZE_QUERY 0x000113891#define FTS5_TOKENIZE_PREFIX 0x000213892#define FTS5_TOKENIZE_DOCUMENT 0x000413893#define FTS5_TOKENIZE_AUX 0x00081389413895/* Flags that may be passed by the tokenizer implementation back to FTS513896** as the third argument to the supplied xToken callback. */13897#define FTS5_TOKEN_COLOCATED 0x0001 /* Same position as prev. token */1389813899/*13900** END OF CUSTOM TOKENIZERS13901*************************************************************************/1390213903/*************************************************************************13904** FTS5 EXTENSION REGISTRATION API13905*/13906typedef struct fts5_api fts5_api;13907struct fts5_api {13908int iVersion; /* Currently always set to 3 */1390913910/* Create a new tokenizer */13911int (*xCreateTokenizer)(13912fts5_api *pApi,13913const char *zName,13914void *pUserData,13915fts5_tokenizer *pTokenizer,13916void (*xDestroy)(void*)13917);1391813919/* Find an existing tokenizer */13920int (*xFindTokenizer)(13921fts5_api *pApi,13922const char *zName,13923void **ppUserData,13924fts5_tokenizer *pTokenizer13925);1392613927/* Create a new auxiliary function */13928int (*xCreateFunction)(13929fts5_api *pApi,13930const char *zName,13931void *pUserData,13932fts5_extension_function xFunction,13933void (*xDestroy)(void*)13934);1393513936/* APIs below this point are only available if iVersion>=3 */1393713938/* Create a new tokenizer */13939int (*xCreateTokenizer_v2)(13940fts5_api *pApi,13941const char *zName,13942void *pUserData,13943fts5_tokenizer_v2 *pTokenizer,13944void (*xDestroy)(void*)13945);1394613947/* Find an existing tokenizer */13948int (*xFindTokenizer_v2)(13949fts5_api *pApi,13950const char *zName,13951void **ppUserData,13952fts5_tokenizer_v2 **ppTokenizer13953);13954};1395513956/*13957** END OF REGISTRATION API13958*************************************************************************/1395913960#ifdef __cplusplus13961} /* end of the 'extern "C"' block */13962#endif1396313964#endif /* _FTS5_H */1396513966/******** End of fts5.h *********/13967#endif /* SQLITE3_H */139681396913970