/*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.50.1"149#define SQLITE_VERSION_NUMBER 3050001150#define SQLITE_SOURCE_ID "2025-06-06 14:52:32 b77dc5e0f596d2140d9ac682b2893ff65d3a4140aa86067a3efebe29dc914c95"151152/*153** CAPI3REF: Run-Time Library Version Numbers154** KEYWORDS: sqlite3_version sqlite3_sourceid155**156** These interfaces provide the same information as the [SQLITE_VERSION],157** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros158** but are associated with the library instead of the header file. ^(Cautious159** programmers might include assert() statements in their application to160** verify that values returned by these interfaces match the macros in161** the header, and thus ensure that the application is162** compiled with matching library and header files.163**164** <blockquote><pre>165** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );166** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 );167** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );168** </pre></blockquote>)^169**170** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]171** macro. ^The sqlite3_libversion() function returns a pointer to the172** to the sqlite3_version[] string constant. The sqlite3_libversion()173** function is provided for use in DLLs since DLL users usually do not have174** direct access to string constants within the DLL. ^The175** sqlite3_libversion_number() function returns an integer equal to176** [SQLITE_VERSION_NUMBER]. ^(The sqlite3_sourceid() function returns177** a pointer to a string constant whose value is the same as the178** [SQLITE_SOURCE_ID] C preprocessor macro. Except if SQLite is built179** using an edited copy of [the amalgamation], then the last four characters180** of the hash might be different from [SQLITE_SOURCE_ID].)^181**182** See also: [sqlite_version()] and [sqlite_source_id()].183*/184SQLITE_API SQLITE_EXTERN const char sqlite3_version[];185SQLITE_API const char *sqlite3_libversion(void);186SQLITE_API const char *sqlite3_sourceid(void);187SQLITE_API int sqlite3_libversion_number(void);188189/*190** CAPI3REF: Run-Time Library Compilation Options Diagnostics191**192** ^The sqlite3_compileoption_used() function returns 0 or 1193** indicating whether the specified option was defined at194** compile time. ^The SQLITE_ prefix may be omitted from the195** option name passed to sqlite3_compileoption_used().196**197** ^The sqlite3_compileoption_get() function allows iterating198** over the list of options that were defined at compile time by199** returning the N-th compile time option string. ^If N is out of range,200** sqlite3_compileoption_get() returns a NULL pointer. ^The SQLITE_201** prefix is omitted from any strings returned by202** sqlite3_compileoption_get().203**204** ^Support for the diagnostic functions sqlite3_compileoption_used()205** and sqlite3_compileoption_get() may be omitted by specifying the206** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time.207**208** See also: SQL functions [sqlite_compileoption_used()] and209** [sqlite_compileoption_get()] and the [compile_options pragma].210*/211#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS212SQLITE_API int sqlite3_compileoption_used(const char *zOptName);213SQLITE_API const char *sqlite3_compileoption_get(int N);214#else215# define sqlite3_compileoption_used(X) 0216# define sqlite3_compileoption_get(X) ((void*)0)217#endif218219/*220** CAPI3REF: Test To See If The Library Is Threadsafe221**222** ^The sqlite3_threadsafe() function returns zero if and only if223** SQLite was compiled with mutexing code omitted due to the224** [SQLITE_THREADSAFE] compile-time option being set to 0.225**226** SQLite can be compiled with or without mutexes. When227** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes228** are enabled and SQLite is threadsafe. When the229** [SQLITE_THREADSAFE] macro is 0,230** the mutexes are omitted. Without the mutexes, it is not safe231** to use SQLite concurrently from more than one thread.232**233** Enabling mutexes incurs a measurable performance penalty.234** So if speed is of utmost importance, it makes sense to disable235** the mutexes. But for maximum safety, mutexes should be enabled.236** ^The default behavior is for mutexes to be enabled.237**238** This interface can be used by an application to make sure that the239** version of SQLite that it is linking against was compiled with240** the desired setting of the [SQLITE_THREADSAFE] macro.241**242** This interface only reports on the compile-time mutex setting243** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with244** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but245** can be fully or partially disabled using a call to [sqlite3_config()]246** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD],247** or [SQLITE_CONFIG_SERIALIZED]. ^(The return value of the248** sqlite3_threadsafe() function shows only the compile-time setting of249** thread safety, not any run-time changes to that setting made by250** sqlite3_config(). In other words, the return value from sqlite3_threadsafe()251** is unchanged by calls to sqlite3_config().)^252**253** See the [threading mode] documentation for additional information.254*/255SQLITE_API int sqlite3_threadsafe(void);256257/*258** CAPI3REF: Database Connection Handle259** KEYWORDS: {database connection} {database connections}260**261** Each open SQLite database is represented by a pointer to an instance of262** the opaque structure named "sqlite3". It is useful to think of an sqlite3263** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and264** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()]265** and [sqlite3_close_v2()] are its destructors. There are many other266** interfaces (such as267** [sqlite3_prepare_v2()], [sqlite3_create_function()], and268** [sqlite3_busy_timeout()] to name but three) that are methods on an269** sqlite3 object.270*/271typedef struct sqlite3 sqlite3;272273/*274** CAPI3REF: 64-Bit Integer Types275** KEYWORDS: sqlite_int64 sqlite_uint64276**277** Because there is no cross-platform way to specify 64-bit integer types278** SQLite includes typedefs for 64-bit signed and unsigned integers.279**280** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions.281** The sqlite_int64 and sqlite_uint64 types are supported for backwards282** compatibility only.283**284** ^The sqlite3_int64 and sqlite_int64 types can store integer values285** between -9223372036854775808 and +9223372036854775807 inclusive. ^The286** sqlite3_uint64 and sqlite_uint64 types can store integer values287** between 0 and +18446744073709551615 inclusive.288*/289#ifdef SQLITE_INT64_TYPE290typedef SQLITE_INT64_TYPE sqlite_int64;291# ifdef SQLITE_UINT64_TYPE292typedef SQLITE_UINT64_TYPE sqlite_uint64;293# else294typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;295# endif296#elif defined(_MSC_VER) || defined(__BORLANDC__)297typedef __int64 sqlite_int64;298typedef unsigned __int64 sqlite_uint64;299#else300typedef long long int sqlite_int64;301typedef unsigned long long int sqlite_uint64;302#endif303typedef sqlite_int64 sqlite3_int64;304typedef sqlite_uint64 sqlite3_uint64;305306/*307** If compiling for a processor that lacks floating point support,308** substitute integer for floating-point.309*/310#ifdef SQLITE_OMIT_FLOATING_POINT311# define double sqlite3_int64312#endif313314/*315** CAPI3REF: Closing A Database Connection316** DESTRUCTOR: sqlite3317**318** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors319** for the [sqlite3] object.320** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if321** the [sqlite3] object is successfully destroyed and all associated322** resources are deallocated.323**324** Ideally, applications should [sqlite3_finalize | finalize] all325** [prepared statements], [sqlite3_blob_close | close] all [BLOB handles], and326** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated327** with the [sqlite3] object prior to attempting to close the object.328** ^If the database connection is associated with unfinalized prepared329** statements, BLOB handlers, and/or unfinished sqlite3_backup objects then330** sqlite3_close() will leave the database connection open and return331** [SQLITE_BUSY]. ^If sqlite3_close_v2() is called with unfinalized prepared332** statements, unclosed BLOB handlers, and/or unfinished sqlite3_backups,333** it returns [SQLITE_OK] regardless, but instead of deallocating the database334** connection immediately, it marks the database connection as an unusable335** "zombie" and makes arrangements to automatically deallocate the database336** connection after all prepared statements are finalized, all BLOB handles337** are closed, and all backups have finished. The sqlite3_close_v2() interface338** is intended for use with host languages that are garbage collected, and339** where the order in which destructors are called is arbitrary.340**341** ^If an [sqlite3] object is destroyed while a transaction is open,342** the transaction is automatically rolled back.343**344** The C parameter to [sqlite3_close(C)] and [sqlite3_close_v2(C)]345** must be either a NULL346** pointer or an [sqlite3] object pointer obtained347** from [sqlite3_open()], [sqlite3_open16()], or348** [sqlite3_open_v2()], and not previously closed.349** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer350** argument is a harmless no-op.351*/352SQLITE_API int sqlite3_close(sqlite3*);353SQLITE_API int sqlite3_close_v2(sqlite3*);354355/*356** The type for a callback function.357** This is legacy and deprecated. It is included for historical358** compatibility and is not documented.359*/360typedef int (*sqlite3_callback)(void*,int,char**, char**);361362/*363** CAPI3REF: One-Step Query Execution Interface364** METHOD: sqlite3365**366** The sqlite3_exec() interface is a convenience wrapper around367** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()],368** that allows an application to run multiple statements of SQL369** without having to use a lot of C code.370**371** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,372** semicolon-separate SQL statements passed into its 2nd argument,373** in the context of the [database connection] passed in as its 1st374** argument. ^If the callback function of the 3rd argument to375** sqlite3_exec() is not NULL, then it is invoked for each result row376** coming out of the evaluated SQL statements. ^The 4th argument to377** sqlite3_exec() is relayed through to the 1st argument of each378** callback invocation. ^If the callback pointer to sqlite3_exec()379** is NULL, then no callback is ever invoked and result rows are380** ignored.381**382** ^If an error occurs while evaluating the SQL statements passed into383** sqlite3_exec(), then execution of the current statement stops and384** subsequent statements are skipped. ^If the 5th parameter to sqlite3_exec()385** is not NULL then any error message is written into memory obtained386** from [sqlite3_malloc()] and passed back through the 5th parameter.387** To avoid memory leaks, the application should invoke [sqlite3_free()]388** on error message strings returned through the 5th parameter of389** sqlite3_exec() after the error message string is no longer needed.390** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors391** occur, then sqlite3_exec() sets the pointer in its 5th parameter to392** NULL before returning.393**394** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec()395** routine returns SQLITE_ABORT without invoking the callback again and396** without running any subsequent SQL statements.397**398** ^The 2nd argument to the sqlite3_exec() callback function is the399** number of columns in the result. ^The 3rd argument to the sqlite3_exec()400** callback is an array of pointers to strings obtained as if from401** [sqlite3_column_text()], one for each column. ^If an element of a402** result row is NULL then the corresponding string pointer for the403** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the404** sqlite3_exec() callback is an array of pointers to strings where each405** entry represents the name of corresponding result column as obtained406** from [sqlite3_column_name()].407**408** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer409** to an empty string, or a pointer that contains only whitespace and/or410** SQL comments, then no SQL statements are evaluated and the database411** is not changed.412**413** Restrictions:414**415** <ul>416** <li> The application must ensure that the 1st parameter to sqlite3_exec()417** is a valid and open [database connection].418** <li> The application must not close the [database connection] specified by419** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running.420** <li> The application must not modify the SQL statement text passed into421** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running.422** <li> The application must not dereference the arrays or string pointers423** passed as the 3rd and 4th callback parameters after it returns.424** </ul>425*/426SQLITE_API int sqlite3_exec(427sqlite3*, /* An open database */428const char *sql, /* SQL to be evaluated */429int (*callback)(void*,int,char**,char**), /* Callback function */430void *, /* 1st argument to callback */431char **errmsg /* Error msg written here */432);433434/*435** CAPI3REF: Result Codes436** KEYWORDS: {result code definitions}437**438** Many SQLite functions return an integer result code from the set shown439** here in order to indicate success or failure.440**441** New error codes may be added in future versions of SQLite.442**443** See also: [extended result code definitions]444*/445#define SQLITE_OK 0 /* Successful result */446/* beginning-of-error-codes */447#define SQLITE_ERROR 1 /* Generic error */448#define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */449#define SQLITE_PERM 3 /* Access permission denied */450#define SQLITE_ABORT 4 /* Callback routine requested an abort */451#define SQLITE_BUSY 5 /* The database file is locked */452#define SQLITE_LOCKED 6 /* A table in the database is locked */453#define SQLITE_NOMEM 7 /* A malloc() failed */454#define SQLITE_READONLY 8 /* Attempt to write a readonly database */455#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/456#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */457#define SQLITE_CORRUPT 11 /* The database disk image is malformed */458#define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */459#define SQLITE_FULL 13 /* Insertion failed because database is full */460#define SQLITE_CANTOPEN 14 /* Unable to open the database file */461#define SQLITE_PROTOCOL 15 /* Database lock protocol error */462#define SQLITE_EMPTY 16 /* Internal use only */463#define SQLITE_SCHEMA 17 /* The database schema changed */464#define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */465#define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */466#define SQLITE_MISMATCH 20 /* Data type mismatch */467#define SQLITE_MISUSE 21 /* Library used incorrectly */468#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */469#define SQLITE_AUTH 23 /* Authorization denied */470#define SQLITE_FORMAT 24 /* Not used */471#define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */472#define SQLITE_NOTADB 26 /* File opened that is not a database file */473#define SQLITE_NOTICE 27 /* Notifications from sqlite3_log() */474#define SQLITE_WARNING 28 /* Warnings from sqlite3_log() */475#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */476#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */477/* end-of-error-codes */478479/*480** CAPI3REF: Extended Result Codes481** KEYWORDS: {extended result code definitions}482**483** In its default configuration, SQLite API routines return one of 30 integer484** [result codes]. However, experience has shown that many of485** these result codes are too coarse-grained. They do not provide as486** much information about problems as programmers might like. In an effort to487** address this, newer versions of SQLite (version 3.3.8 [dateof:3.3.8]488** and later) include489** support for additional result codes that provide more detailed information490** about errors. These [extended result codes] are enabled or disabled491** on a per database connection basis using the492** [sqlite3_extended_result_codes()] API. Or, the extended code for493** the most recent error can be obtained using494** [sqlite3_extended_errcode()].495*/496#define SQLITE_ERROR_MISSING_COLLSEQ (SQLITE_ERROR | (1<<8))497#define SQLITE_ERROR_RETRY (SQLITE_ERROR | (2<<8))498#define SQLITE_ERROR_SNAPSHOT (SQLITE_ERROR | (3<<8))499#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8))500#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8))501#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8))502#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8))503#define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8))504#define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8))505#define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8))506#define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8))507#define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8))508#define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8))509#define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8))510#define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8))511#define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8))512#define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))513#define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8))514#define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8))515#define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8))516#define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8))517#define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8))518#define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8))519#define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8))520#define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))521#define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8))522#define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))523#define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8))524#define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8))525#define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8))526#define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8))527#define SQLITE_IOERR_BEGIN_ATOMIC (SQLITE_IOERR | (29<<8))528#define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8))529#define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8))530#define SQLITE_IOERR_DATA (SQLITE_IOERR | (32<<8))531#define SQLITE_IOERR_CORRUPTFS (SQLITE_IOERR | (33<<8))532#define SQLITE_IOERR_IN_PAGE (SQLITE_IOERR | (34<<8))533#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))534#define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8))535#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))536#define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))537#define SQLITE_BUSY_TIMEOUT (SQLITE_BUSY | (3<<8))538#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))539#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))540#define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))541#define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))542#define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */543#define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8))544#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))545#define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8))546#define SQLITE_CORRUPT_INDEX (SQLITE_CORRUPT | (3<<8))547#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))548#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))549#define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))550#define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))551#define SQLITE_READONLY_CANTINIT (SQLITE_READONLY | (5<<8))552#define SQLITE_READONLY_DIRECTORY (SQLITE_READONLY | (6<<8))553#define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))554#define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))555#define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))556#define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))557#define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))558#define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8))559#define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8))560#define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))561#define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))562#define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))563#define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))564#define SQLITE_CONSTRAINT_PINNED (SQLITE_CONSTRAINT |(11<<8))565#define SQLITE_CONSTRAINT_DATATYPE (SQLITE_CONSTRAINT |(12<<8))566#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))567#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))568#define SQLITE_NOTICE_RBU (SQLITE_NOTICE | (3<<8))569#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))570#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))571#define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))572#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */573574/*575** CAPI3REF: Flags For File Open Operations576**577** These bit values are intended for use in the578** 3rd parameter to the [sqlite3_open_v2()] interface and579** in the 4th parameter to the [sqlite3_vfs.xOpen] method.580**581** Only those flags marked as "Ok for sqlite3_open_v2()" may be582** used as the third argument to the [sqlite3_open_v2()] interface.583** The other flags have historically been ignored by sqlite3_open_v2(),584** though future versions of SQLite might change so that an error is585** raised if any of the disallowed bits are passed into sqlite3_open_v2().586** Applications should not depend on the historical behavior.587**588** Note in particular that passing the SQLITE_OPEN_EXCLUSIVE flag into589** [sqlite3_open_v2()] does *not* cause the underlying database file590** to be opened using O_EXCL. Passing SQLITE_OPEN_EXCLUSIVE into591** [sqlite3_open_v2()] has historically be a no-op and might become an592** error in future versions of SQLite.593*/594#define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */595#define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */596#define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */597#define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */598#define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */599#define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */600#define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */601#define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */602#define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */603#define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */604#define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */605#define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */606#define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */607#define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */608#define SQLITE_OPEN_SUPER_JOURNAL 0x00004000 /* VFS only */609#define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */610#define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */611#define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */612#define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */613#define SQLITE_OPEN_WAL 0x00080000 /* VFS only */614#define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */615#define SQLITE_OPEN_EXRESCODE 0x02000000 /* Extended result codes */616617/* Reserved: 0x00F00000 */618/* Legacy compatibility: */619#define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */620621622/*623** CAPI3REF: Device Characteristics624**625** The xDeviceCharacteristics method of the [sqlite3_io_methods]626** object returns an integer which is a vector of these627** bit values expressing I/O characteristics of the mass storage628** device that holds the file that the [sqlite3_io_methods]629** refers to.630**631** The SQLITE_IOCAP_ATOMIC property means that all writes of632** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values633** mean that writes of blocks that are nnn bytes in size and634** are aligned to an address which is an integer multiple of635** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means636** that when data is appended to a file, the data is appended637** first then the size of the file is extended, never the other638** way around. The SQLITE_IOCAP_SEQUENTIAL property means that639** information is written to disk in the same order as calls640** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that641** after reboot following a crash or power loss, the only bytes in a642** file that were written at the application level might have changed643** and that adjacent bytes, even bytes within the same sector are644** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN645** flag indicates that a file cannot be deleted when open. The646** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on647** read-only media and cannot be changed even by processes with648** elevated privileges.649**650** The SQLITE_IOCAP_BATCH_ATOMIC property means that the underlying651** filesystem supports doing multiple write operations atomically when those652** write operations are bracketed by [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] and653** [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE].654**655** The SQLITE_IOCAP_SUBPAGE_READ property means that it is ok to read656** from the database file in amounts that are not a multiple of the657** page size and that do not begin at a page boundary. Without this658** property, SQLite is careful to only do full-page reads and write659** on aligned pages, with the one exception that it will do a sub-page660** read of the first page to access the database header.661*/662#define SQLITE_IOCAP_ATOMIC 0x00000001663#define SQLITE_IOCAP_ATOMIC512 0x00000002664#define SQLITE_IOCAP_ATOMIC1K 0x00000004665#define SQLITE_IOCAP_ATOMIC2K 0x00000008666#define SQLITE_IOCAP_ATOMIC4K 0x00000010667#define SQLITE_IOCAP_ATOMIC8K 0x00000020668#define SQLITE_IOCAP_ATOMIC16K 0x00000040669#define SQLITE_IOCAP_ATOMIC32K 0x00000080670#define SQLITE_IOCAP_ATOMIC64K 0x00000100671#define SQLITE_IOCAP_SAFE_APPEND 0x00000200672#define SQLITE_IOCAP_SEQUENTIAL 0x00000400673#define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800674#define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000675#define SQLITE_IOCAP_IMMUTABLE 0x00002000676#define SQLITE_IOCAP_BATCH_ATOMIC 0x00004000677#define SQLITE_IOCAP_SUBPAGE_READ 0x00008000678679/*680** CAPI3REF: File Locking Levels681**682** SQLite uses one of these integer values as the second683** argument to calls it makes to the xLock() and xUnlock() methods684** of an [sqlite3_io_methods] object. These values are ordered from685** lest restrictive to most restrictive.686**687** The argument to xLock() is always SHARED or higher. The argument to688** xUnlock is either SHARED or NONE.689*/690#define SQLITE_LOCK_NONE 0 /* xUnlock() only */691#define SQLITE_LOCK_SHARED 1 /* xLock() or xUnlock() */692#define SQLITE_LOCK_RESERVED 2 /* xLock() only */693#define SQLITE_LOCK_PENDING 3 /* xLock() only */694#define SQLITE_LOCK_EXCLUSIVE 4 /* xLock() only */695696/*697** CAPI3REF: Synchronization Type Flags698**699** When SQLite invokes the xSync() method of an700** [sqlite3_io_methods] object it uses a combination of701** these integer values as the second argument.702**703** When the SQLITE_SYNC_DATAONLY flag is used, it means that the704** sync operation only needs to flush data to mass storage. Inode705** information need not be flushed. If the lower four bits of the flag706** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics.707** If the lower four bits equal SQLITE_SYNC_FULL, that means708** to use Mac OS X style fullsync instead of fsync().709**710** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags711** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL712** settings. The [synchronous pragma] determines when calls to the713** xSync VFS method occur and applies uniformly across all platforms.714** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how715** energetic or rigorous or forceful the sync operations are and716** only make a difference on Mac OSX for the default SQLite code.717** (Third-party VFS implementations might also make the distinction718** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the719** operating systems natively supported by SQLite, only Mac OSX720** cares about the difference.)721*/722#define SQLITE_SYNC_NORMAL 0x00002723#define SQLITE_SYNC_FULL 0x00003724#define SQLITE_SYNC_DATAONLY 0x00010725726/*727** CAPI3REF: OS Interface Open File Handle728**729** An [sqlite3_file] object represents an open file in the730** [sqlite3_vfs | OS interface layer]. Individual OS interface731** implementations will732** want to subclass this object by appending additional fields733** for their own use. The pMethods entry is a pointer to an734** [sqlite3_io_methods] object that defines methods for performing735** I/O operations on the open file.736*/737typedef struct sqlite3_file sqlite3_file;738struct sqlite3_file {739const struct sqlite3_io_methods *pMethods; /* Methods for an open file */740};741742/*743** CAPI3REF: OS Interface File Virtual Methods Object744**745** Every file opened by the [sqlite3_vfs.xOpen] method populates an746** [sqlite3_file] object (or, more commonly, a subclass of the747** [sqlite3_file] object) with a pointer to an instance of this object.748** This object defines the methods used to perform various operations749** against the open file represented by the [sqlite3_file] object.750**751** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element752** to a non-NULL pointer, then the sqlite3_io_methods.xClose method753** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The754** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen]755** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element756** to NULL.757**758** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or759** [SQLITE_SYNC_FULL]. The first choice is the normal fsync().760** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY]761** flag may be ORed in to indicate that only the data of the file762** and not its inode needs to be synced.763**764** The integer values to xLock() and xUnlock() are one of765** <ul>766** <li> [SQLITE_LOCK_NONE],767** <li> [SQLITE_LOCK_SHARED],768** <li> [SQLITE_LOCK_RESERVED],769** <li> [SQLITE_LOCK_PENDING], or770** <li> [SQLITE_LOCK_EXCLUSIVE].771** </ul>772** xLock() upgrades the database file lock. In other words, xLock() moves the773** database file lock in the direction NONE toward EXCLUSIVE. The argument to774** xLock() is always one of SHARED, RESERVED, PENDING, or EXCLUSIVE, never775** SQLITE_LOCK_NONE. If the database file lock is already at or above the776** requested lock, then the call to xLock() is a no-op.777** xUnlock() downgrades the database file lock to either SHARED or NONE.778** If the lock is already at or below the requested lock state, then the call779** to xUnlock() is a no-op.780** The xCheckReservedLock() method checks whether any database connection,781** either in this process or in some other process, is holding a RESERVED,782** PENDING, or EXCLUSIVE lock on the file. It returns, via its output783** pointer parameter, true if such a lock exists and false otherwise.784**785** The xFileControl() method is a generic interface that allows custom786** VFS implementations to directly control an open file using the787** [sqlite3_file_control()] interface. The second "op" argument is an788** integer opcode. The third argument is a generic pointer intended to789** point to a structure that may contain arguments or space in which to790** write return values. Potential uses for xFileControl() might be791** functions to enable blocking locks with timeouts, to change the792** locking strategy (for example to use dot-file locks), to inquire793** about the status of a lock, or to break stale locks. The SQLite794** core reserves all opcodes less than 100 for its own use.795** A [file control opcodes | list of opcodes] less than 100 is available.796** Applications that define a custom xFileControl method should use opcodes797** greater than 100 to avoid conflicts. VFS implementations should798** return [SQLITE_NOTFOUND] for file control opcodes that they do not799** recognize.800**801** The xSectorSize() method returns the sector size of the802** device that underlies the file. The sector size is the803** minimum write that can be performed without disturbing804** other bytes in the file. The xDeviceCharacteristics()805** method returns a bit vector describing behaviors of the806** underlying device:807**808** <ul>809** <li> [SQLITE_IOCAP_ATOMIC]810** <li> [SQLITE_IOCAP_ATOMIC512]811** <li> [SQLITE_IOCAP_ATOMIC1K]812** <li> [SQLITE_IOCAP_ATOMIC2K]813** <li> [SQLITE_IOCAP_ATOMIC4K]814** <li> [SQLITE_IOCAP_ATOMIC8K]815** <li> [SQLITE_IOCAP_ATOMIC16K]816** <li> [SQLITE_IOCAP_ATOMIC32K]817** <li> [SQLITE_IOCAP_ATOMIC64K]818** <li> [SQLITE_IOCAP_SAFE_APPEND]819** <li> [SQLITE_IOCAP_SEQUENTIAL]820** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]821** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]822** <li> [SQLITE_IOCAP_IMMUTABLE]823** <li> [SQLITE_IOCAP_BATCH_ATOMIC]824** <li> [SQLITE_IOCAP_SUBPAGE_READ]825** </ul>826**827** The SQLITE_IOCAP_ATOMIC property means that all writes of828** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values829** mean that writes of blocks that are nnn bytes in size and830** are aligned to an address which is an integer multiple of831** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means832** that when data is appended to a file, the data is appended833** first then the size of the file is extended, never the other834** way around. The SQLITE_IOCAP_SEQUENTIAL property means that835** information is written to disk in the same order as calls836** to xWrite().837**838** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill839** in the unread portions of the buffer with zeros. A VFS that840** fails to zero-fill short reads might seem to work. However,841** failure to zero-fill short reads will eventually lead to842** database corruption.843*/844typedef struct sqlite3_io_methods sqlite3_io_methods;845struct sqlite3_io_methods {846int iVersion;847int (*xClose)(sqlite3_file*);848int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);849int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst);850int (*xTruncate)(sqlite3_file*, sqlite3_int64 size);851int (*xSync)(sqlite3_file*, int flags);852int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize);853int (*xLock)(sqlite3_file*, int);854int (*xUnlock)(sqlite3_file*, int);855int (*xCheckReservedLock)(sqlite3_file*, int *pResOut);856int (*xFileControl)(sqlite3_file*, int op, void *pArg);857int (*xSectorSize)(sqlite3_file*);858int (*xDeviceCharacteristics)(sqlite3_file*);859/* Methods above are valid for version 1 */860int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**);861int (*xShmLock)(sqlite3_file*, int offset, int n, int flags);862void (*xShmBarrier)(sqlite3_file*);863int (*xShmUnmap)(sqlite3_file*, int deleteFlag);864/* Methods above are valid for version 2 */865int (*xFetch)(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp);866int (*xUnfetch)(sqlite3_file*, sqlite3_int64 iOfst, void *p);867/* Methods above are valid for version 3 */868/* Additional methods may be added in future releases */869};870871/*872** CAPI3REF: Standard File Control Opcodes873** KEYWORDS: {file control opcodes} {file control opcode}874**875** These integer constants are opcodes for the xFileControl method876** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]877** interface.878**879** <ul>880** <li>[[SQLITE_FCNTL_LOCKSTATE]]881** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This882** opcode causes the xFileControl method to write the current state of883** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],884** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])885** into an integer that the pArg argument points to.886** This capability is only available if SQLite is compiled with [SQLITE_DEBUG].887**888** <li>[[SQLITE_FCNTL_SIZE_HINT]]889** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS890** layer a hint of how large the database file will grow to be during the891** current transaction. This hint is not guaranteed to be accurate but it892** is often close. The underlying VFS might choose to preallocate database893** file space based on this hint in order to help writes to the database894** file run faster.895**896** <li>[[SQLITE_FCNTL_SIZE_LIMIT]]897** The [SQLITE_FCNTL_SIZE_LIMIT] opcode is used by in-memory VFS that898** implements [sqlite3_deserialize()] to set an upper bound on the size899** of the in-memory database. The argument is a pointer to a [sqlite3_int64].900** If the integer pointed to is negative, then it is filled in with the901** current limit. Otherwise the limit is set to the larger of the value902** of the integer pointed to and the current database size. The integer903** pointed to is set to the new limit.904**905** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]906** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS907** extends and truncates the database file in chunks of a size specified908** by the user. The fourth argument to [sqlite3_file_control()] should909** point to an integer (type int) containing the new chunk-size to use910** for the nominated database. Allocating database file space in large911** chunks (say 1MB at a time), may reduce file-system fragmentation and912** improve performance on some systems.913**914** <li>[[SQLITE_FCNTL_FILE_POINTER]]915** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer916** to the [sqlite3_file] object associated with a particular database917** connection. See also [SQLITE_FCNTL_JOURNAL_POINTER].918**919** <li>[[SQLITE_FCNTL_JOURNAL_POINTER]]920** The [SQLITE_FCNTL_JOURNAL_POINTER] opcode is used to obtain a pointer921** to the [sqlite3_file] object associated with the journal file (either922** the [rollback journal] or the [write-ahead log]) for a particular database923** connection. See also [SQLITE_FCNTL_FILE_POINTER].924**925** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]926** No longer in use.927**928** <li>[[SQLITE_FCNTL_SYNC]]929** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and930** sent to the VFS immediately before the xSync method is invoked on a931** database file descriptor. Or, if the xSync method is not invoked932** because the user has configured SQLite with933** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place934** of the xSync method. In most cases, the pointer argument passed with935** this file-control is NULL. However, if the database file is being synced936** as part of a multi-database commit, the argument points to a nul-terminated937** string containing the transactions super-journal file name. VFSes that938** do not need this signal should silently ignore this opcode. Applications939** should not call [sqlite3_file_control()] with this opcode as doing so may940** disrupt the operation of the specialized VFSes that do require it.941**942** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]943** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite944** and sent to the VFS after a transaction has been committed immediately945** but before the database is unlocked. VFSes that do not need this signal946** should silently ignore this opcode. Applications should not call947** [sqlite3_file_control()] with this opcode as doing so may disrupt the948** operation of the specialized VFSes that do require it.949**950** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]951** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic952** retry counts and intervals for certain disk I/O operations for the953** windows [VFS] in order to provide robustness in the presence of954** anti-virus programs. By default, the windows VFS will retry file read,955** file write, and file delete operations up to 10 times, with a delay956** of 25 milliseconds before the first retry and with the delay increasing957** by an additional 25 milliseconds with each subsequent retry. This958** opcode allows these two values (10 retries and 25 milliseconds of delay)959** to be adjusted. The values are changed for all database connections960** within the same process. The argument is a pointer to an array of two961** integers where the first integer is the new retry count and the second962** integer is the delay. If either integer is negative, then the setting963** is not changed but instead the prior value of that setting is written964** into the array entry, allowing the current retry settings to be965** interrogated. The zDbName parameter is ignored.966**967** <li>[[SQLITE_FCNTL_PERSIST_WAL]]968** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the969** persistent [WAL | Write Ahead Log] setting. By default, the auxiliary970** write ahead log ([WAL file]) and shared memory971** files used for transaction control972** are automatically deleted when the latest connection to the database973** closes. Setting persistent WAL mode causes those files to persist after974** close. Persisting the files is useful when other processes that do not975** have write permission on the directory containing the database file want976** to read the database file, as the WAL and shared memory files must exist977** in order for the database to be readable. The fourth parameter to978** [sqlite3_file_control()] for this opcode should be a pointer to an integer.979** That integer is 0 to disable persistent WAL mode or 1 to enable persistent980** WAL mode. If the integer is -1, then it is overwritten with the current981** WAL persistence setting.982**983** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]]984** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the985** persistent "powersafe-overwrite" or "PSOW" setting. The PSOW setting986** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the987** xDeviceCharacteristics methods. The fourth parameter to988** [sqlite3_file_control()] for this opcode should be a pointer to an integer.989** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage990** mode. If the integer is -1, then it is overwritten with the current991** zero-damage mode setting.992**993** <li>[[SQLITE_FCNTL_OVERWRITE]]994** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening995** a write transaction to indicate that, unless it is rolled back for some996** reason, the entire database file will be overwritten by the current997** transaction. This is used by VACUUM operations.998**999** <li>[[SQLITE_FCNTL_VFSNAME]]1000** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of1001** all [VFSes] in the VFS stack. The names are of all VFS shims and the1002** final bottom-level VFS are written into memory obtained from1003** [sqlite3_malloc()] and the result is stored in the char* variable1004** that the fourth parameter of [sqlite3_file_control()] points to.1005** The caller is responsible for freeing the memory when done. As with1006** all file-control actions, there is no guarantee that this will actually1007** do anything. Callers should initialize the char* variable to a NULL1008** pointer in case this file-control is not implemented. This file-control1009** is intended for diagnostic use only.1010**1011** <li>[[SQLITE_FCNTL_VFS_POINTER]]1012** ^The [SQLITE_FCNTL_VFS_POINTER] opcode finds a pointer to the top-level1013** [VFSes] currently in use. ^(The argument X in1014** sqlite3_file_control(db,SQLITE_FCNTL_VFS_POINTER,X) must be1015** of type "[sqlite3_vfs] **". This opcodes will set *X1016** to a pointer to the top-level VFS.)^1017** ^When there are multiple VFS shims in the stack, this opcode finds the1018** upper-most shim only.1019**1020** <li>[[SQLITE_FCNTL_PRAGMA]]1021** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA]1022** file control is sent to the open [sqlite3_file] object corresponding1023** to the database file to which the pragma statement refers. ^The argument1024** to the [SQLITE_FCNTL_PRAGMA] file control is an array of1025** pointers to strings (char**) in which the second element of the array1026** is the name of the pragma and the third element is the argument to the1027** pragma or NULL if the pragma has no argument. ^The handler for an1028** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element1029** of the char** argument point to a string obtained from [sqlite3_mprintf()]1030** or the equivalent and that string will become the result of the pragma or1031** the error message if the pragma fails. ^If the1032** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal1033** [PRAGMA] processing continues. ^If the [SQLITE_FCNTL_PRAGMA]1034** file control returns [SQLITE_OK], then the parser assumes that the1035** VFS has handled the PRAGMA itself and the parser generates a no-op1036** prepared statement if result string is NULL, or that returns a copy1037** of the result string if the string is non-NULL.1038** ^If the [SQLITE_FCNTL_PRAGMA] file control returns1039** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means1040** that the VFS encountered an error while handling the [PRAGMA] and the1041** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA]1042** file control occurs at the beginning of pragma statement analysis and so1043** it is able to override built-in [PRAGMA] statements.1044**1045** <li>[[SQLITE_FCNTL_BUSYHANDLER]]1046** ^The [SQLITE_FCNTL_BUSYHANDLER]1047** file-control may be invoked by SQLite on the database file handle1048** shortly after it is opened in order to provide a custom VFS with access1049** to the connection's busy-handler callback. The argument is of type (void**)1050** - an array of two (void *) values. The first (void *) actually points1051** to a function of type (int (*)(void *)). In order to invoke the connection's1052** busy-handler, this function should be invoked with the second (void *) in1053** the array as the only argument. If it returns non-zero, then the operation1054** should be retried. If it returns zero, the custom VFS should abandon the1055** current operation.1056**1057** <li>[[SQLITE_FCNTL_TEMPFILENAME]]1058** ^Applications can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control1059** to have SQLite generate a1060** temporary filename using the same algorithm that is followed to generate1061** temporary filenames for TEMP tables and other internal uses. The1062** argument should be a char** which will be filled with the filename1063** written into memory obtained from [sqlite3_malloc()]. The caller should1064** invoke [sqlite3_free()] on the result to avoid a memory leak.1065**1066** <li>[[SQLITE_FCNTL_MMAP_SIZE]]1067** The [SQLITE_FCNTL_MMAP_SIZE] file control is used to query or set the1068** maximum number of bytes that will be used for memory-mapped I/O.1069** The argument is a pointer to a value of type sqlite3_int64 that1070** is an advisory maximum number of bytes in the file to memory map. The1071** pointer is overwritten with the old value. The limit is not changed if1072** the value originally pointed to is negative, and so the current limit1073** can be queried by passing in a pointer to a negative number. This1074** file-control is used internally to implement [PRAGMA mmap_size].1075**1076** <li>[[SQLITE_FCNTL_TRACE]]1077** The [SQLITE_FCNTL_TRACE] file control provides advisory information1078** to the VFS about what the higher layers of the SQLite stack are doing.1079** This file control is used by some VFS activity tracing [shims].1080** The argument is a zero-terminated string. Higher layers in the1081** SQLite stack may generate instances of this file control if1082** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled.1083**1084** <li>[[SQLITE_FCNTL_HAS_MOVED]]1085** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a1086** pointer to an integer and it writes a boolean into that integer depending1087** on whether or not the file has been renamed, moved, or deleted since it1088** was first opened.1089**1090** <li>[[SQLITE_FCNTL_WIN32_GET_HANDLE]]1091** The [SQLITE_FCNTL_WIN32_GET_HANDLE] opcode can be used to obtain the1092** underlying native file handle associated with a file handle. This file1093** control interprets its argument as a pointer to a native file handle and1094** writes the resulting value there.1095**1096** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]]1097** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This1098** opcode causes the xFileControl method to swap the file handle with the one1099** pointed to by the pArg argument. This capability is used during testing1100** and only needs to be supported when SQLITE_TEST is defined.1101**1102** <li>[[SQLITE_FCNTL_NULL_IO]]1103** The [SQLITE_FCNTL_NULL_IO] opcode sets the low-level file descriptor1104** or file handle for the [sqlite3_file] object such that it will no longer1105** read or write to the database file.1106**1107** <li>[[SQLITE_FCNTL_WAL_BLOCK]]1108** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might1109** be advantageous to block on the next WAL lock if the lock is not immediately1110** available. The WAL subsystem issues this signal during rare1111** circumstances in order to fix a problem with priority inversion.1112** Applications should <em>not</em> use this file-control.1113**1114** <li>[[SQLITE_FCNTL_ZIPVFS]]1115** The [SQLITE_FCNTL_ZIPVFS] opcode is implemented by zipvfs only. All other1116** VFS should return SQLITE_NOTFOUND for this opcode.1117**1118** <li>[[SQLITE_FCNTL_RBU]]1119** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by1120** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for1121** this opcode.1122**1123** <li>[[SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]]1124** If the [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] opcode returns SQLITE_OK, then1125** the file descriptor is placed in "batch write mode", which1126** means all subsequent write operations will be deferred and done1127** atomically at the next [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]. Systems1128** that do not support batch atomic writes will return SQLITE_NOTFOUND.1129** ^Following a successful SQLITE_FCNTL_BEGIN_ATOMIC_WRITE and prior to1130** the closing [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] or1131** [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE], SQLite will make1132** no VFS interface calls on the same [sqlite3_file] file descriptor1133** except for calls to the xWrite method and the xFileControl method1134** with [SQLITE_FCNTL_SIZE_HINT].1135**1136** <li>[[SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]]1137** The [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] opcode causes all write1138** operations since the previous successful call to1139** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be performed atomically.1140** This file control returns [SQLITE_OK] if and only if the writes were1141** all performed successfully and have been committed to persistent storage.1142** ^Regardless of whether or not it is successful, this file control takes1143** the file descriptor out of batch write mode so that all subsequent1144** write operations are independent.1145** ^SQLite will never invoke SQLITE_FCNTL_COMMIT_ATOMIC_WRITE without1146** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].1147**1148** <li>[[SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE]]1149** The [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE] opcode causes all write1150** operations since the previous successful call to1151** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be rolled back.1152** ^This file control takes the file descriptor out of batch write mode1153** so that all subsequent write operations are independent.1154** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without1155** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].1156**1157** <li>[[SQLITE_FCNTL_LOCK_TIMEOUT]]1158** The [SQLITE_FCNTL_LOCK_TIMEOUT] opcode is used to configure a VFS1159** to block for up to M milliseconds before failing when attempting to1160** obtain a file lock using the xLock or xShmLock methods of the VFS.1161** The parameter is a pointer to a 32-bit signed integer that contains1162** the value that M is to be set to. Before returning, the 32-bit signed1163** integer is overwritten with the previous value of M.1164**1165** <li>[[SQLITE_FCNTL_BLOCK_ON_CONNECT]]1166** The [SQLITE_FCNTL_BLOCK_ON_CONNECT] opcode is used to configure the1167** VFS to block when taking a SHARED lock to connect to a wal mode database.1168** This is used to implement the functionality associated with1169** SQLITE_SETLK_BLOCK_ON_CONNECT.1170**1171** <li>[[SQLITE_FCNTL_DATA_VERSION]]1172** The [SQLITE_FCNTL_DATA_VERSION] opcode is used to detect changes to1173** a database file. The argument is a pointer to a 32-bit unsigned integer.1174** The "data version" for the pager is written into the pointer. The1175** "data version" changes whenever any change occurs to the corresponding1176** database file, either through SQL statements on the same database1177** connection or through transactions committed by separate database1178** connections possibly in other processes. The [sqlite3_total_changes()]1179** interface can be used to find if any database on the connection has changed,1180** but that interface responds to changes on TEMP as well as MAIN and does1181** not provide a mechanism to detect changes to MAIN only. Also, the1182** [sqlite3_total_changes()] interface responds to internal changes only and1183** omits changes made by other database connections. The1184** [PRAGMA data_version] command provides a mechanism to detect changes to1185** a single attached database that occur due to other database connections,1186** but omits changes implemented by the database connection on which it is1187** called. This file control is the only mechanism to detect changes that1188** happen either internally or externally and that are associated with1189** a particular attached database.1190**1191** <li>[[SQLITE_FCNTL_CKPT_START]]1192** The [SQLITE_FCNTL_CKPT_START] opcode is invoked from within a checkpoint1193** in wal mode before the client starts to copy pages from the wal1194** file to the database file.1195**1196** <li>[[SQLITE_FCNTL_CKPT_DONE]]1197** The [SQLITE_FCNTL_CKPT_DONE] opcode is invoked from within a checkpoint1198** in wal mode after the client has finished copying pages from the wal1199** file to the database file, but before the *-shm file is updated to1200** record the fact that the pages have been checkpointed.1201**1202** <li>[[SQLITE_FCNTL_EXTERNAL_READER]]1203** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect1204** whether or not there is a database client in another process with a wal-mode1205** transaction open on the database or not. It is only available on unix.The1206** (void*) argument passed with this file-control should be a pointer to a1207** value of type (int). The integer value is set to 1 if the database is a wal1208** mode database and there exists at least one client in another process that1209** currently has an SQL transaction open on the database. It is set to 0 if1210** the database is not a wal-mode db, or if there is no such connection in any1211** other process. This opcode cannot be used to detect transactions opened1212** by clients within the current process, only within other processes.1213**1214** <li>[[SQLITE_FCNTL_CKSM_FILE]]1215** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use internally by the1216** [checksum VFS shim] only.1217**1218** <li>[[SQLITE_FCNTL_RESET_CACHE]]1219** If there is currently no transaction open on the database, and the1220** database is not a temp db, then the [SQLITE_FCNTL_RESET_CACHE] file-control1221** purges the contents of the in-memory page cache. If there is an open1222** transaction, or if the db is a temp-db, this opcode is a no-op, not an error.1223** </ul>1224*/1225#define SQLITE_FCNTL_LOCKSTATE 11226#define SQLITE_FCNTL_GET_LOCKPROXYFILE 21227#define SQLITE_FCNTL_SET_LOCKPROXYFILE 31228#define SQLITE_FCNTL_LAST_ERRNO 41229#define SQLITE_FCNTL_SIZE_HINT 51230#define SQLITE_FCNTL_CHUNK_SIZE 61231#define SQLITE_FCNTL_FILE_POINTER 71232#define SQLITE_FCNTL_SYNC_OMITTED 81233#define SQLITE_FCNTL_WIN32_AV_RETRY 91234#define SQLITE_FCNTL_PERSIST_WAL 101235#define SQLITE_FCNTL_OVERWRITE 111236#define SQLITE_FCNTL_VFSNAME 121237#define SQLITE_FCNTL_POWERSAFE_OVERWRITE 131238#define SQLITE_FCNTL_PRAGMA 141239#define SQLITE_FCNTL_BUSYHANDLER 151240#define SQLITE_FCNTL_TEMPFILENAME 161241#define SQLITE_FCNTL_MMAP_SIZE 181242#define SQLITE_FCNTL_TRACE 191243#define SQLITE_FCNTL_HAS_MOVED 201244#define SQLITE_FCNTL_SYNC 211245#define SQLITE_FCNTL_COMMIT_PHASETWO 221246#define SQLITE_FCNTL_WIN32_SET_HANDLE 231247#define SQLITE_FCNTL_WAL_BLOCK 241248#define SQLITE_FCNTL_ZIPVFS 251249#define SQLITE_FCNTL_RBU 261250#define SQLITE_FCNTL_VFS_POINTER 271251#define SQLITE_FCNTL_JOURNAL_POINTER 281252#define SQLITE_FCNTL_WIN32_GET_HANDLE 291253#define SQLITE_FCNTL_PDB 301254#define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 311255#define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 321256#define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 331257#define SQLITE_FCNTL_LOCK_TIMEOUT 341258#define SQLITE_FCNTL_DATA_VERSION 351259#define SQLITE_FCNTL_SIZE_LIMIT 361260#define SQLITE_FCNTL_CKPT_DONE 371261#define SQLITE_FCNTL_RESERVE_BYTES 381262#define SQLITE_FCNTL_CKPT_START 391263#define SQLITE_FCNTL_EXTERNAL_READER 401264#define SQLITE_FCNTL_CKSM_FILE 411265#define SQLITE_FCNTL_RESET_CACHE 421266#define SQLITE_FCNTL_NULL_IO 431267#define SQLITE_FCNTL_BLOCK_ON_CONNECT 4412681269/* deprecated names */1270#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE1271#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE1272#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO127312741275/*1276** CAPI3REF: Mutex Handle1277**1278** The mutex module within SQLite defines [sqlite3_mutex] to be an1279** abstract type for a mutex object. The SQLite core never looks1280** at the internal representation of an [sqlite3_mutex]. It only1281** deals with pointers to the [sqlite3_mutex] object.1282**1283** Mutexes are created using [sqlite3_mutex_alloc()].1284*/1285typedef struct sqlite3_mutex sqlite3_mutex;12861287/*1288** CAPI3REF: Loadable Extension Thunk1289**1290** A pointer to the opaque sqlite3_api_routines structure is passed as1291** the third parameter to entry points of [loadable extensions]. This1292** structure must be typedefed in order to work around compiler warnings1293** on some platforms.1294*/1295typedef struct sqlite3_api_routines sqlite3_api_routines;12961297/*1298** CAPI3REF: File Name1299**1300** Type [sqlite3_filename] is used by SQLite to pass filenames to the1301** xOpen method of a [VFS]. It may be cast to (const char*) and treated1302** as a normal, nul-terminated, UTF-8 buffer containing the filename, but1303** may also be passed to special APIs such as:1304**1305** <ul>1306** <li> sqlite3_filename_database()1307** <li> sqlite3_filename_journal()1308** <li> sqlite3_filename_wal()1309** <li> sqlite3_uri_parameter()1310** <li> sqlite3_uri_boolean()1311** <li> sqlite3_uri_int64()1312** <li> sqlite3_uri_key()1313** </ul>1314*/1315typedef const char *sqlite3_filename;13161317/*1318** CAPI3REF: OS Interface Object1319**1320** An instance of the sqlite3_vfs object defines the interface between1321** the SQLite core and the underlying operating system. The "vfs"1322** in the name of the object stands for "virtual file system". See1323** the [VFS | VFS documentation] for further information.1324**1325** The VFS interface is sometimes extended by adding new methods onto1326** the end. Each time such an extension occurs, the iVersion field1327** is incremented. The iVersion value started out as 1 in1328** SQLite [version 3.5.0] on [dateof:3.5.0], then increased to 21329** with SQLite [version 3.7.0] on [dateof:3.7.0], and then increased1330** to 3 with SQLite [version 3.7.6] on [dateof:3.7.6]. Additional fields1331** may be appended to the sqlite3_vfs object and the iVersion value1332** may increase again in future versions of SQLite.1333** Note that due to an oversight, the structure1334** of the sqlite3_vfs object changed in the transition from1335** SQLite [version 3.5.9] to [version 3.6.0] on [dateof:3.6.0]1336** and yet the iVersion field was not increased.1337**1338** The szOsFile field is the size of the subclassed [sqlite3_file]1339** structure used by this VFS. mxPathname is the maximum length of1340** a pathname in this VFS.1341**1342** Registered sqlite3_vfs objects are kept on a linked list formed by1343** the pNext pointer. The [sqlite3_vfs_register()]1344** and [sqlite3_vfs_unregister()] interfaces manage this list1345** in a thread-safe way. The [sqlite3_vfs_find()] interface1346** searches the list. Neither the application code nor the VFS1347** implementation should use the pNext pointer.1348**1349** The pNext field is the only field in the sqlite3_vfs1350** structure that SQLite will ever modify. SQLite will only access1351** or modify this field while holding a particular static mutex.1352** The application should never modify anything within the sqlite3_vfs1353** object once the object has been registered.1354**1355** The zName field holds the name of the VFS module. The name must1356** be unique across all VFS modules.1357**1358** [[sqlite3_vfs.xOpen]]1359** ^SQLite guarantees that the zFilename parameter to xOpen1360** is either a NULL pointer or string obtained1361** from xFullPathname() with an optional suffix added.1362** ^If a suffix is added to the zFilename parameter, it will1363** consist of a single "-" character followed by no more than1364** 11 alphanumeric and/or "-" characters.1365** ^SQLite further guarantees that1366** the string will be valid and unchanged until xClose() is1367** called. Because of the previous sentence,1368** the [sqlite3_file] can safely store a pointer to the1369** filename if it needs to remember the filename for some reason.1370** If the zFilename parameter to xOpen is a NULL pointer then xOpen1371** must invent its own temporary name for the file. ^Whenever the1372** xFilename parameter is NULL it will also be the case that the1373** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE].1374**1375** The flags argument to xOpen() includes all bits set in1376** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()]1377** or [sqlite3_open16()] is used, then flags includes at least1378** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE].1379** If xOpen() opens a file read-only then it sets *pOutFlags to1380** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set.1381**1382** ^(SQLite will also add one of the following flags to the xOpen()1383** call, depending on the object being opened:1384**1385** <ul>1386** <li> [SQLITE_OPEN_MAIN_DB]1387** <li> [SQLITE_OPEN_MAIN_JOURNAL]1388** <li> [SQLITE_OPEN_TEMP_DB]1389** <li> [SQLITE_OPEN_TEMP_JOURNAL]1390** <li> [SQLITE_OPEN_TRANSIENT_DB]1391** <li> [SQLITE_OPEN_SUBJOURNAL]1392** <li> [SQLITE_OPEN_SUPER_JOURNAL]1393** <li> [SQLITE_OPEN_WAL]1394** </ul>)^1395**1396** The file I/O implementation can use the object type flags to1397** change the way it deals with files. For example, an application1398** that does not care about crash recovery or rollback might make1399** the open of a journal file a no-op. Writes to this journal would1400** also be no-ops, and any attempt to read the journal would return1401** SQLITE_IOERR. Or the implementation might recognize that a database1402** file will be doing page-aligned sector reads and writes in a random1403** order and set up its I/O subsystem accordingly.1404**1405** SQLite might also add one of the following flags to the xOpen method:1406**1407** <ul>1408** <li> [SQLITE_OPEN_DELETEONCLOSE]1409** <li> [SQLITE_OPEN_EXCLUSIVE]1410** </ul>1411**1412** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be1413** deleted when it is closed. ^The [SQLITE_OPEN_DELETEONCLOSE]1414** will be set for TEMP databases and their journals, transient1415** databases, and subjournals.1416**1417** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction1418** with the [SQLITE_OPEN_CREATE] flag, which are both directly1419** analogous to the O_EXCL and O_CREAT flags of the POSIX open()1420** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the1421** SQLITE_OPEN_CREATE, is used to indicate that file should always1422** be created, and that it is an error if it already exists.1423** It is <i>not</i> used to indicate the file should be opened1424** for exclusive access.1425**1426** ^At least szOsFile bytes of memory are allocated by SQLite1427** to hold the [sqlite3_file] structure passed as the third1428** argument to xOpen. The xOpen method does not have to1429** allocate the structure; it should just fill it in. Note that1430** the xOpen method must set the sqlite3_file.pMethods to either1431** a valid [sqlite3_io_methods] object or to NULL. xOpen must do1432** this even if the open fails. SQLite expects that the sqlite3_file.pMethods1433** element will be valid after xOpen returns regardless of the success1434** or failure of the xOpen call.1435**1436** [[sqlite3_vfs.xAccess]]1437** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS]1438** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to1439** test whether a file is readable and writable, or [SQLITE_ACCESS_READ]1440** to test whether a file is at least readable. The SQLITE_ACCESS_READ1441** flag is never actually used and is not implemented in the built-in1442** VFSes of SQLite. The file is named by the second argument and can be a1443** directory. The xAccess method returns [SQLITE_OK] on success or some1444** non-zero error code if there is an I/O error or if the name of1445** the file given in the second argument is illegal. If SQLITE_OK1446** is returned, then non-zero or zero is written into *pResOut to indicate1447** whether or not the file is accessible.1448**1449** ^SQLite will always allocate at least mxPathname+1 bytes for the1450** output buffer xFullPathname. The exact size of the output buffer1451** is also passed as a parameter to both methods. If the output buffer1452** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is1453** handled as a fatal error by SQLite, vfs implementations should endeavor1454** to prevent this by setting mxPathname to a sufficiently large value.1455**1456** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()1457** interfaces are not strictly a part of the filesystem, but they are1458** included in the VFS structure for completeness.1459** The xRandomness() function attempts to return nBytes bytes1460** of good-quality randomness into zOut. The return value is1461** the actual number of bytes of randomness obtained.1462** The xSleep() method causes the calling thread to sleep for at1463** least the number of microseconds given. ^The xCurrentTime()1464** method returns a Julian Day Number for the current date and time as1465** a floating point value.1466** ^The xCurrentTimeInt64() method returns, as an integer, the Julian1467** Day Number multiplied by 86400000 (the number of milliseconds in1468** a 24-hour day).1469** ^SQLite will use the xCurrentTimeInt64() method to get the current1470** date and time if that method is available (if iVersion is 2 or1471** greater and the function pointer is not NULL) and will fall back1472** to xCurrentTime() if xCurrentTimeInt64() is unavailable.1473**1474** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces1475** are not used by the SQLite core. These optional interfaces are provided1476** by some VFSes to facilitate testing of the VFS code. By overriding1477** system calls with functions under its control, a test program can1478** simulate faults and error conditions that would otherwise be difficult1479** or impossible to induce. The set of system calls that can be overridden1480** varies from one VFS to another, and from one version of the same VFS to the1481** next. Applications that use these interfaces must be prepared for any1482** or all of these interfaces to be NULL or for their behavior to change1483** from one release to the next. Applications must not attempt to access1484** any of these methods if the iVersion of the VFS is less than 3.1485*/1486typedef struct sqlite3_vfs sqlite3_vfs;1487typedef void (*sqlite3_syscall_ptr)(void);1488struct sqlite3_vfs {1489int iVersion; /* Structure version number (currently 3) */1490int szOsFile; /* Size of subclassed sqlite3_file */1491int mxPathname; /* Maximum file pathname length */1492sqlite3_vfs *pNext; /* Next registered VFS */1493const char *zName; /* Name of this virtual file system */1494void *pAppData; /* Pointer to application-specific data */1495int (*xOpen)(sqlite3_vfs*, sqlite3_filename zName, sqlite3_file*,1496int flags, int *pOutFlags);1497int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);1498int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);1499int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);1500void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);1501void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);1502void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void);1503void (*xDlClose)(sqlite3_vfs*, void*);1504int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut);1505int (*xSleep)(sqlite3_vfs*, int microseconds);1506int (*xCurrentTime)(sqlite3_vfs*, double*);1507int (*xGetLastError)(sqlite3_vfs*, int, char *);1508/*1509** The methods above are in version 1 of the sqlite_vfs object1510** definition. Those that follow are added in version 2 or later1511*/1512int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);1513/*1514** The methods above are in versions 1 and 2 of the sqlite_vfs object.1515** Those below are for version 3 and greater.1516*/1517int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr);1518sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName);1519const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName);1520/*1521** The methods above are in versions 1 through 3 of the sqlite_vfs object.1522** New fields may be appended in future versions. The iVersion1523** value will increment whenever this happens.1524*/1525};15261527/*1528** CAPI3REF: Flags for the xAccess VFS method1529**1530** These integer constants can be used as the third parameter to1531** the xAccess method of an [sqlite3_vfs] object. They determine1532** what kind of permissions the xAccess method is looking for.1533** With SQLITE_ACCESS_EXISTS, the xAccess method1534** simply checks whether the file exists.1535** With SQLITE_ACCESS_READWRITE, the xAccess method1536** checks whether the named directory is both readable and writable1537** (in other words, if files can be added, removed, and renamed within1538** the directory).1539** The SQLITE_ACCESS_READWRITE constant is currently used only by the1540** [temp_store_directory pragma], though this could change in a future1541** release of SQLite.1542** With SQLITE_ACCESS_READ, the xAccess method1543** checks whether the file is readable. The SQLITE_ACCESS_READ constant is1544** currently unused, though it might be used in a future release of1545** SQLite.1546*/1547#define SQLITE_ACCESS_EXISTS 01548#define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */1549#define SQLITE_ACCESS_READ 2 /* Unused */15501551/*1552** CAPI3REF: Flags for the xShmLock VFS method1553**1554** These integer constants define the various locking operations1555** allowed by the xShmLock method of [sqlite3_io_methods]. The1556** following are the only legal combinations of flags to the1557** xShmLock method:1558**1559** <ul>1560** <li> SQLITE_SHM_LOCK | SQLITE_SHM_SHARED1561** <li> SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE1562** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED1563** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE1564** </ul>1565**1566** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as1567** was given on the corresponding lock.1568**1569** The xShmLock method can transition between unlocked and SHARED or1570** between unlocked and EXCLUSIVE. It cannot transition between SHARED1571** and EXCLUSIVE.1572*/1573#define SQLITE_SHM_UNLOCK 11574#define SQLITE_SHM_LOCK 21575#define SQLITE_SHM_SHARED 41576#define SQLITE_SHM_EXCLUSIVE 815771578/*1579** CAPI3REF: Maximum xShmLock index1580**1581** The xShmLock method on [sqlite3_io_methods] may use values1582** between 0 and this upper bound as its "offset" argument.1583** The SQLite core will never attempt to acquire or release a1584** lock outside of this range1585*/1586#define SQLITE_SHM_NLOCK 8158715881589/*1590** CAPI3REF: Initialize The SQLite Library1591**1592** ^The sqlite3_initialize() routine initializes the1593** SQLite library. ^The sqlite3_shutdown() routine1594** deallocates any resources that were allocated by sqlite3_initialize().1595** These routines are designed to aid in process initialization and1596** shutdown on embedded systems. Workstation applications using1597** SQLite normally do not need to invoke either of these routines.1598**1599** A call to sqlite3_initialize() is an "effective" call if it is1600** the first time sqlite3_initialize() is invoked during the lifetime of1601** the process, or if it is the first time sqlite3_initialize() is invoked1602** following a call to sqlite3_shutdown(). ^(Only an effective call1603** of sqlite3_initialize() does any initialization. All other calls1604** are harmless no-ops.)^1605**1606** A call to sqlite3_shutdown() is an "effective" call if it is the first1607** call to sqlite3_shutdown() since the last sqlite3_initialize(). ^(Only1608** an effective call to sqlite3_shutdown() does any deinitialization.1609** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^1610**1611** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown()1612** is not. The sqlite3_shutdown() interface must only be called from a1613** single thread. All open [database connections] must be closed and all1614** other SQLite resources must be deallocated prior to invoking1615** sqlite3_shutdown().1616**1617** Among other things, ^sqlite3_initialize() will invoke1618** sqlite3_os_init(). Similarly, ^sqlite3_shutdown()1619** will invoke sqlite3_os_end().1620**1621** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success.1622** ^If for some reason, sqlite3_initialize() is unable to initialize1623** the library (perhaps it is unable to allocate a needed resource such1624** as a mutex) it returns an [error code] other than [SQLITE_OK].1625**1626** ^The sqlite3_initialize() routine is called internally by many other1627** SQLite interfaces so that an application usually does not need to1628** invoke sqlite3_initialize() directly. For example, [sqlite3_open()]1629** calls sqlite3_initialize() so the SQLite library will be automatically1630** initialized when [sqlite3_open()] is called if it has not be initialized1631** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]1632** compile-time option, then the automatic calls to sqlite3_initialize()1633** are omitted and the application must call sqlite3_initialize() directly1634** prior to using any other SQLite interface. For maximum portability,1635** it is recommended that applications always invoke sqlite3_initialize()1636** directly prior to using any other SQLite interface. Future releases1637** of SQLite may require this. In other words, the behavior exhibited1638** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the1639** default behavior in some future release of SQLite.1640**1641** The sqlite3_os_init() routine does operating-system specific1642** initialization of the SQLite library. The sqlite3_os_end()1643** routine undoes the effect of sqlite3_os_init(). Typical tasks1644** performed by these routines include allocation or deallocation1645** of static resources, initialization of global variables,1646** setting up a default [sqlite3_vfs] module, or setting up1647** a default configuration using [sqlite3_config()].1648**1649** The application should never invoke either sqlite3_os_init()1650** or sqlite3_os_end() directly. The application should only invoke1651** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init()1652** interface is called automatically by sqlite3_initialize() and1653** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate1654** implementations for sqlite3_os_init() and sqlite3_os_end()1655** are built into SQLite when it is compiled for Unix, Windows, or OS/2.1656** When [custom builds | built for other platforms]1657** (using the [SQLITE_OS_OTHER=1] compile-time1658** option) the application must supply a suitable implementation for1659** sqlite3_os_init() and sqlite3_os_end(). An application-supplied1660** implementation of sqlite3_os_init() or sqlite3_os_end()1661** must return [SQLITE_OK] on success and some other [error code] upon1662** failure.1663*/1664SQLITE_API int sqlite3_initialize(void);1665SQLITE_API int sqlite3_shutdown(void);1666SQLITE_API int sqlite3_os_init(void);1667SQLITE_API int sqlite3_os_end(void);16681669/*1670** CAPI3REF: Configuring The SQLite Library1671**1672** The sqlite3_config() interface is used to make global configuration1673** changes to SQLite in order to tune SQLite to the specific needs of1674** the application. The default configuration is recommended for most1675** applications and so this routine is usually not necessary. It is1676** provided to support rare applications with unusual needs.1677**1678** <b>The sqlite3_config() interface is not threadsafe. The application1679** must ensure that no other SQLite interfaces are invoked by other1680** threads while sqlite3_config() is running.</b>1681**1682** The first argument to sqlite3_config() is an integer1683** [configuration option] that determines1684** what property of SQLite is to be configured. Subsequent arguments1685** vary depending on the [configuration option]1686** in the first argument.1687**1688** For most configuration options, the sqlite3_config() interface1689** may only be invoked prior to library initialization using1690** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].1691** The exceptional configuration options that may be invoked at any time1692** are called "anytime configuration options".1693** ^If sqlite3_config() is called after [sqlite3_initialize()] and before1694** [sqlite3_shutdown()] with a first argument that is not an anytime1695** configuration option, then the sqlite3_config() call will return SQLITE_MISUSE.1696** Note, however, that ^sqlite3_config() can be called as part of the1697** implementation of an application-defined [sqlite3_os_init()].1698**1699** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].1700** ^If the option is unknown or SQLite is unable to set the option1701** then this routine returns a non-zero [error code].1702*/1703SQLITE_API int sqlite3_config(int, ...);17041705/*1706** CAPI3REF: Configure database connections1707** METHOD: sqlite31708**1709** The sqlite3_db_config() interface is used to make configuration1710** changes to a [database connection]. The interface is similar to1711** [sqlite3_config()] except that the changes apply to a single1712** [database connection] (specified in the first argument).1713**1714** The second argument to sqlite3_db_config(D,V,...) is the1715** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code1716** that indicates what aspect of the [database connection] is being configured.1717** Subsequent arguments vary depending on the configuration verb.1718**1719** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if1720** the call is considered successful.1721*/1722SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...);17231724/*1725** CAPI3REF: Memory Allocation Routines1726**1727** An instance of this object defines the interface between SQLite1728** and low-level memory allocation routines.1729**1730** This object is used in only one place in the SQLite interface.1731** A pointer to an instance of this object is the argument to1732** [sqlite3_config()] when the configuration option is1733** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC].1734** By creating an instance of this object1735** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC])1736** during configuration, an application can specify an alternative1737** memory allocation subsystem for SQLite to use for all of its1738** dynamic memory needs.1739**1740** Note that SQLite comes with several [built-in memory allocators]1741** that are perfectly adequate for the overwhelming majority of applications1742** and that this object is only useful to a tiny minority of applications1743** with specialized memory allocation requirements. This object is1744** also used during testing of SQLite in order to specify an alternative1745** memory allocator that simulates memory out-of-memory conditions in1746** order to verify that SQLite recovers gracefully from such1747** conditions.1748**1749** The xMalloc, xRealloc, and xFree methods must work like the1750** malloc(), realloc() and free() functions from the standard C library.1751** ^SQLite guarantees that the second argument to1752** xRealloc is always a value returned by a prior call to xRoundup.1753**1754** xSize should return the allocated size of a memory allocation1755** previously obtained from xMalloc or xRealloc. The allocated size1756** is always at least as big as the requested size but may be larger.1757**1758** The xRoundup method returns what would be the allocated size of1759** a memory allocation given a particular requested size. Most memory1760** allocators round up memory allocations at least to the next multiple1761** of 8. Some allocators round up to a larger multiple or to a power of 2.1762** Every memory allocation request coming in through [sqlite3_malloc()]1763** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0,1764** that causes the corresponding memory allocation to fail.1765**1766** The xInit method initializes the memory allocator. For example,1767** it might allocate any required mutexes or initialize internal data1768** structures. The xShutdown method is invoked (indirectly) by1769** [sqlite3_shutdown()] and should deallocate any resources acquired1770** by xInit. The pAppData pointer is used as the only parameter to1771** xInit and xShutdown.1772**1773** SQLite holds the [SQLITE_MUTEX_STATIC_MAIN] mutex when it invokes1774** the xInit method, so the xInit method need not be threadsafe. The1775** xShutdown method is only called from [sqlite3_shutdown()] so it does1776** not need to be threadsafe either. For all other methods, SQLite1777** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the1778** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which1779** it is by default) and so the methods are automatically serialized.1780** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other1781** methods must be threadsafe or else make their own arrangements for1782** serialization.1783**1784** SQLite will never invoke xInit() more than once without an intervening1785** call to xShutdown().1786*/1787typedef struct sqlite3_mem_methods sqlite3_mem_methods;1788struct sqlite3_mem_methods {1789void *(*xMalloc)(int); /* Memory allocation function */1790void (*xFree)(void*); /* Free a prior allocation */1791void *(*xRealloc)(void*,int); /* Resize an allocation */1792int (*xSize)(void*); /* Return the size of an allocation */1793int (*xRoundup)(int); /* Round up request size to allocation size */1794int (*xInit)(void*); /* Initialize the memory allocator */1795void (*xShutdown)(void*); /* Deinitialize the memory allocator */1796void *pAppData; /* Argument to xInit() and xShutdown() */1797};17981799/*1800** CAPI3REF: Configuration Options1801** KEYWORDS: {configuration option}1802**1803** These constants are the available integer configuration options that1804** can be passed as the first argument to the [sqlite3_config()] interface.1805**1806** Most of the configuration options for sqlite3_config()1807** will only work if invoked prior to [sqlite3_initialize()] or after1808** [sqlite3_shutdown()]. The few exceptions to this rule are called1809** "anytime configuration options".1810** ^Calling [sqlite3_config()] with a first argument that is not an1811** anytime configuration option in between calls to [sqlite3_initialize()] and1812** [sqlite3_shutdown()] is a no-op that returns SQLITE_MISUSE.1813**1814** The set of anytime configuration options can change (by insertions1815** and/or deletions) from one release of SQLite to the next.1816** As of SQLite version 3.42.0, the complete set of anytime configuration1817** options is:1818** <ul>1819** <li> SQLITE_CONFIG_LOG1820** <li> SQLITE_CONFIG_PCACHE_HDRSZ1821** </ul>1822**1823** New configuration options may be added in future releases of SQLite.1824** Existing configuration options might be discontinued. Applications1825** should check the return code from [sqlite3_config()] to make sure that1826** the call worked. The [sqlite3_config()] interface will return a1827** non-zero [error code] if a discontinued or unsupported configuration option1828** is invoked.1829**1830** <dl>1831** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt>1832** <dd>There are no arguments to this option. ^This option sets the1833** [threading mode] to Single-thread. In other words, it disables1834** all mutexing and puts SQLite into a mode where it can only be used1835** by a single thread. ^If SQLite is compiled with1836** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then1837** it is not possible to change the [threading mode] from its default1838** value of Single-thread and so [sqlite3_config()] will return1839** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD1840** configuration option.</dd>1841**1842** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt>1843** <dd>There are no arguments to this option. ^This option sets the1844** [threading mode] to Multi-thread. In other words, it disables1845** mutexing on [database connection] and [prepared statement] objects.1846** The application is responsible for serializing access to1847** [database connections] and [prepared statements]. But other mutexes1848** are enabled so that SQLite will be safe to use in a multi-threaded1849** environment as long as no two threads attempt to use the same1850** [database connection] at the same time. ^If SQLite is compiled with1851** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then1852** it is not possible to set the Multi-thread [threading mode] and1853** [sqlite3_config()] will return [SQLITE_ERROR] if called with the1854** SQLITE_CONFIG_MULTITHREAD configuration option.</dd>1855**1856** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt>1857** <dd>There are no arguments to this option. ^This option sets the1858** [threading mode] to Serialized. In other words, this option enables1859** all mutexes including the recursive1860** mutexes on [database connection] and [prepared statement] objects.1861** In this mode (which is the default when SQLite is compiled with1862** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access1863** to [database connections] and [prepared statements] so that the1864** application is free to use the same [database connection] or the1865** same [prepared statement] in different threads at the same time.1866** ^If SQLite is compiled with1867** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then1868** it is not possible to set the Serialized [threading mode] and1869** [sqlite3_config()] will return [SQLITE_ERROR] if called with the1870** SQLITE_CONFIG_SERIALIZED configuration option.</dd>1871**1872** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>1873** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is1874** a pointer to an instance of the [sqlite3_mem_methods] structure.1875** The argument specifies1876** alternative low-level memory allocation routines to be used in place of1877** the memory allocation routines built into SQLite.)^ ^SQLite makes1878** its own private copy of the content of the [sqlite3_mem_methods] structure1879** before the [sqlite3_config()] call returns.</dd>1880**1881** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>1882** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which1883** is a pointer to an instance of the [sqlite3_mem_methods] structure.1884** The [sqlite3_mem_methods]1885** structure is filled with the currently defined memory allocation routines.)^1886** This option can be used to overload the default memory allocation1887** routines with a wrapper that simulations memory allocation failure or1888** tracks memory usage, for example. </dd>1889**1890** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt>1891** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes single argument of1892** type int, interpreted as a boolean, which if true provides a hint to1893** SQLite that it should avoid large memory allocations if possible.1894** SQLite will run faster if it is free to make large memory allocations,1895** but some application might prefer to run slower in exchange for1896** guarantees about memory fragmentation that are possible if large1897** allocations are avoided. This hint is normally off.1898** </dd>1899**1900** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>1901** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,1902** interpreted as a boolean, which enables or disables the collection of1903** memory allocation statistics. ^(When memory allocation statistics are1904** disabled, the following SQLite interfaces become non-operational:1905** <ul>1906** <li> [sqlite3_hard_heap_limit64()]1907** <li> [sqlite3_memory_used()]1908** <li> [sqlite3_memory_highwater()]1909** <li> [sqlite3_soft_heap_limit64()]1910** <li> [sqlite3_status64()]1911** </ul>)^1912** ^Memory allocation statistics are enabled by default unless SQLite is1913** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory1914** allocation statistics are disabled by default.1915** </dd>1916**1917** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>1918** <dd> The SQLITE_CONFIG_SCRATCH option is no longer used.1919** </dd>1920**1921** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>1922** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool1923** that SQLite can use for the database page cache with the default page1924** cache implementation.1925** This configuration option is a no-op if an application-defined page1926** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2].1927** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to1928** 8-byte aligned memory (pMem), the size of each page cache line (sz),1929** and the number of cache lines (N).1930** The sz argument should be the size of the largest database page1931** (a power of two between 512 and 65536) plus some extra bytes for each1932** page header. ^The number of extra bytes needed by the page header1933** can be determined using [SQLITE_CONFIG_PCACHE_HDRSZ].1934** ^It is harmless, apart from the wasted memory,1935** for the sz parameter to be larger than necessary. The pMem1936** argument must be either a NULL pointer or a pointer to an 8-byte1937** aligned block of memory of at least sz*N bytes, otherwise1938** subsequent behavior is undefined.1939** ^When pMem is not NULL, SQLite will strive to use the memory provided1940** to satisfy page cache needs, falling back to [sqlite3_malloc()] if1941** a page cache line is larger than sz bytes or if all of the pMem buffer1942** is exhausted.1943** ^If pMem is NULL and N is non-zero, then each database connection1944** does an initial bulk allocation for page cache memory1945** from [sqlite3_malloc()] sufficient for N cache lines if N is positive or1946** of -1024*N bytes if N is negative, . ^If additional1947** page cache memory is needed beyond what is provided by the initial1948** allocation, then SQLite goes to [sqlite3_malloc()] separately for each1949** additional cache line. </dd>1950**1951** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>1952** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer1953** that SQLite will use for all of its dynamic memory allocation needs1954** beyond those provided for by [SQLITE_CONFIG_PAGECACHE].1955** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled1956** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns1957** [SQLITE_ERROR] if invoked otherwise.1958** ^There are three arguments to SQLITE_CONFIG_HEAP:1959** An 8-byte aligned pointer to the memory,1960** the number of bytes in the memory buffer, and the minimum allocation size.1961** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts1962** to using its default memory allocator (the system malloc() implementation),1963** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the1964** memory pointer is not NULL then the alternative memory1965** allocator is engaged to handle all of SQLites memory allocation needs.1966** The first pointer (the memory pointer) must be aligned to an 8-byte1967** boundary or subsequent behavior of SQLite will be undefined.1968** The minimum allocation size is capped at 2**12. Reasonable values1969** for the minimum allocation size are 2**5 through 2**8.</dd>1970**1971** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>1972** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a1973** pointer to an instance of the [sqlite3_mutex_methods] structure.1974** The argument specifies alternative low-level mutex routines to be used1975** in place the mutex routines built into SQLite.)^ ^SQLite makes a copy of1976** the content of the [sqlite3_mutex_methods] structure before the call to1977** [sqlite3_config()] returns. ^If SQLite is compiled with1978** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then1979** the entire mutexing subsystem is omitted from the build and hence calls to1980** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will1981** return [SQLITE_ERROR].</dd>1982**1983** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>1984** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which1985** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The1986** [sqlite3_mutex_methods]1987** structure is filled with the currently defined mutex routines.)^1988** This option can be used to overload the default mutex allocation1989** routines with a wrapper used to track mutex usage for performance1990** profiling or testing, for example. ^If SQLite is compiled with1991** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then1992** the entire mutexing subsystem is omitted from the build and hence calls to1993** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will1994** return [SQLITE_ERROR].</dd>1995**1996** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>1997** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine1998** the default size of [lookaside memory] on each [database connection].1999** The first argument is the2000** size of each lookaside buffer slot ("sz") and the second is the number of2001** slots allocated to each database connection ("cnt").)^2002** ^(SQLITE_CONFIG_LOOKASIDE sets the <i>default</i> lookaside size.2003** The [SQLITE_DBCONFIG_LOOKASIDE] option to [sqlite3_db_config()] can2004** be used to change the lookaside configuration on individual connections.)^2005** The [-DSQLITE_DEFAULT_LOOKASIDE] option can be used to change the2006** default lookaside configuration at compile-time.2007** </dd>2008**2009** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>2010** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is2011** a pointer to an [sqlite3_pcache_methods2] object. This object specifies2012** the interface to a custom page cache implementation.)^2013** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>2014**2015** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>2016** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which2017** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of2018** the current page cache implementation into that object.)^ </dd>2019**2020** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>2021** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite2022** global [error log].2023** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a2024** function with a call signature of void(*)(void*,int,const char*),2025** and a pointer to void. ^If the function pointer is not NULL, it is2026** invoked by [sqlite3_log()] to process each logging event. ^If the2027** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op.2028** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is2029** passed through as the first parameter to the application-defined logger2030** function whenever that function is invoked. ^The second parameter to2031** the logger function is a copy of the first parameter to the corresponding2032** [sqlite3_log()] call and is intended to be a [result code] or an2033** [extended result code]. ^The third parameter passed to the logger is2034** log message after formatting via [sqlite3_snprintf()].2035** The SQLite logging interface is not reentrant; the logger function2036** supplied by the application must not invoke any SQLite interface.2037** In a multi-threaded application, the application-defined logger2038** function must be threadsafe. </dd>2039**2040** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI2041** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int.2042** If non-zero, then URI handling is globally enabled. If the parameter is zero,2043** then URI handling is globally disabled.)^ ^If URI handling is globally2044** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()],2045** [sqlite3_open16()] or2046** specified as part of [ATTACH] commands are interpreted as URIs, regardless2047** of whether or not the [SQLITE_OPEN_URI] flag is set when the database2048** connection is opened. ^If it is globally disabled, filenames are2049** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the2050** database connection is opened. ^(By default, URI handling is globally2051** disabled. The default value may be changed by compiling with the2052** [SQLITE_USE_URI] symbol defined.)^2053**2054** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN2055** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer2056** argument which is interpreted as a boolean in order to enable or disable2057** the use of covering indices for full table scans in the query optimizer.2058** ^The default setting is determined2059** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"2060** if that compile-time option is omitted.2061** The ability to disable the use of covering indices for full table scans2062** is because some incorrectly coded legacy applications might malfunction2063** when the optimization is enabled. Providing the ability to2064** disable the optimization allows the older, buggy application code to work2065** without change even with newer versions of SQLite.2066**2067** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]]2068** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE2069** <dd> These options are obsolete and should not be used by new code.2070** They are retained for backwards compatibility but are now no-ops.2071** </dd>2072**2073** [[SQLITE_CONFIG_SQLLOG]]2074** <dt>SQLITE_CONFIG_SQLLOG2075** <dd>This option is only available if sqlite is compiled with the2076** [SQLITE_ENABLE_SQLLOG] pre-processor macro defined. The first argument should2077** be a pointer to a function of type void(*)(void*,sqlite3*,const char*, int).2078** The second should be of type (void*). The callback is invoked by the library2079** in three separate circumstances, identified by the value passed as the2080** fourth parameter. If the fourth parameter is 0, then the database connection2081** passed as the second argument has just been opened. The third argument2082** points to a buffer containing the name of the main database file. If the2083** fourth parameter is 1, then the SQL statement that the third parameter2084** points to has just been executed. Or, if the fourth parameter is 2, then2085** the connection being passed as the second parameter is being closed. The2086** third parameter is passed NULL In this case. An example of using this2087** configuration option can be seen in the "test_sqllog.c" source file in2088** the canonical SQLite source tree.</dd>2089**2090** [[SQLITE_CONFIG_MMAP_SIZE]]2091** <dt>SQLITE_CONFIG_MMAP_SIZE2092** <dd>^SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values2093** that are the default mmap size limit (the default setting for2094** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.2095** ^The default setting can be overridden by each database connection using2096** either the [PRAGMA mmap_size] command, or by using the2097** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size2098** will be silently truncated if necessary so that it does not exceed the2099** compile-time maximum mmap size set by the2100** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^2101** ^If either argument to this option is negative, then that argument is2102** changed to its compile-time default.2103**2104** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]2105** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE2106** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is2107** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro2108** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value2109** that specifies the maximum size of the created heap.2110**2111** [[SQLITE_CONFIG_PCACHE_HDRSZ]]2112** <dt>SQLITE_CONFIG_PCACHE_HDRSZ2113** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which2114** is a pointer to an integer and writes into that integer the number of extra2115** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].2116** The amount of extra space required can change depending on the compiler,2117** target platform, and SQLite version.2118**2119** [[SQLITE_CONFIG_PMASZ]]2120** <dt>SQLITE_CONFIG_PMASZ2121** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which2122** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded2123** sorter to that integer. The default minimum PMA Size is set by the2124** [SQLITE_SORTER_PMASZ] compile-time option. New threads are launched2125** to help with sort operations when multithreaded sorting2126** is enabled (using the [PRAGMA threads] command) and the amount of content2127** to be sorted exceeds the page size times the minimum of the2128** [PRAGMA cache_size] setting and this value.2129**2130** [[SQLITE_CONFIG_STMTJRNL_SPILL]]2131** <dt>SQLITE_CONFIG_STMTJRNL_SPILL2132** <dd>^The SQLITE_CONFIG_STMTJRNL_SPILL option takes a single parameter which2133** becomes the [statement journal] spill-to-disk threshold.2134** [Statement journals] are held in memory until their size (in bytes)2135** exceeds this threshold, at which point they are written to disk.2136** Or if the threshold is -1, statement journals are always held2137** exclusively in memory.2138** Since many statement journals never become large, setting the spill2139** threshold to a value such as 64KiB can greatly reduce the amount of2140** I/O required to support statement rollback.2141** The default value for this setting is controlled by the2142** [SQLITE_STMTJRNL_SPILL] compile-time option.2143**2144** [[SQLITE_CONFIG_SORTERREF_SIZE]]2145** <dt>SQLITE_CONFIG_SORTERREF_SIZE2146** <dd>The SQLITE_CONFIG_SORTERREF_SIZE option accepts a single parameter2147** of type (int) - the new value of the sorter-reference size threshold.2148** Usually, when SQLite uses an external sort to order records according2149** to an ORDER BY clause, all fields required by the caller are present in the2150** sorted records. However, if SQLite determines based on the declared type2151** of a table column that its values are likely to be very large - larger2152** than the configured sorter-reference size threshold - then a reference2153** is stored in each sorted record and the required column values loaded2154** from the database as records are returned in sorted order. The default2155** value for this option is to never use this optimization. Specifying a2156** negative value for this option restores the default behavior.2157** This option is only available if SQLite is compiled with the2158** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option.2159**2160** [[SQLITE_CONFIG_MEMDB_MAXSIZE]]2161** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE2162** <dd>The SQLITE_CONFIG_MEMDB_MAXSIZE option accepts a single parameter2163** [sqlite3_int64] parameter which is the default maximum size for an in-memory2164** database created using [sqlite3_deserialize()]. This default maximum2165** size can be adjusted up or down for individual databases using the2166** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control]. If this2167** configuration setting is never used, then the default maximum is determined2168** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that2169** compile-time option is not set, then the default maximum is 1073741824.2170**2171** [[SQLITE_CONFIG_ROWID_IN_VIEW]]2172** <dt>SQLITE_CONFIG_ROWID_IN_VIEW2173** <dd>The SQLITE_CONFIG_ROWID_IN_VIEW option enables or disables the ability2174** for VIEWs to have a ROWID. The capability can only be enabled if SQLite is2175** compiled with -DSQLITE_ALLOW_ROWID_IN_VIEW, in which case the capability2176** defaults to on. This configuration option queries the current setting or2177** changes the setting to off or on. The argument is a pointer to an integer.2178** If that integer initially holds a value of 1, then the ability for VIEWs to2179** have ROWIDs is activated. If the integer initially holds zero, then the2180** ability is deactivated. Any other initial value for the integer leaves the2181** setting unchanged. After changes, if any, the integer is written with2182** a 1 or 0, if the ability for VIEWs to have ROWIDs is on or off. If SQLite2183** is compiled without -DSQLITE_ALLOW_ROWID_IN_VIEW (which is the usual and2184** recommended case) then the integer is always filled with zero, regardless2185** if its initial value.2186** </dl>2187*/2188#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */2189#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */2190#define SQLITE_CONFIG_SERIALIZED 3 /* nil */2191#define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */2192#define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */2193#define SQLITE_CONFIG_SCRATCH 6 /* No longer used */2194#define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */2195#define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */2196#define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */2197#define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */2198#define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */2199/* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */2200#define SQLITE_CONFIG_LOOKASIDE 13 /* int int */2201#define SQLITE_CONFIG_PCACHE 14 /* no-op */2202#define SQLITE_CONFIG_GETPCACHE 15 /* no-op */2203#define SQLITE_CONFIG_LOG 16 /* xFunc, void* */2204#define SQLITE_CONFIG_URI 17 /* int */2205#define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */2206#define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */2207#define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */2208#define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */2209#define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */2210#define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */2211#define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */2212#define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */2213#define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */2214#define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */2215#define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */2216#define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */2217#define SQLITE_CONFIG_ROWID_IN_VIEW 30 /* int* */22182219/*2220** CAPI3REF: Database Connection Configuration Options2221**2222** These constants are the available integer configuration options that2223** can be passed as the second parameter to the [sqlite3_db_config()] interface.2224**2225** The [sqlite3_db_config()] interface is a var-args functions. It takes a2226** variable number of parameters, though always at least two. The number of2227** parameters passed into sqlite3_db_config() depends on which of these2228** constants is given as the second parameter. This documentation page2229** refers to parameters beyond the second as "arguments". Thus, when this2230** page says "the N-th argument" it means "the N-th parameter past the2231** configuration option" or "the (N+2)-th parameter to sqlite3_db_config()".2232**2233** New configuration options may be added in future releases of SQLite.2234** Existing configuration options might be discontinued. Applications2235** should check the return code from [sqlite3_db_config()] to make sure that2236** the call worked. ^The [sqlite3_db_config()] interface will return a2237** non-zero [error code] if a discontinued or unsupported configuration option2238** is invoked.2239**2240** <dl>2241** [[SQLITE_DBCONFIG_LOOKASIDE]]2242** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>2243** <dd> The SQLITE_DBCONFIG_LOOKASIDE option is used to adjust the2244** configuration of the [lookaside memory allocator] within a database2245** connection.2246** The arguments to the SQLITE_DBCONFIG_LOOKASIDE option are <i>not</i>2247** in the [DBCONFIG arguments|usual format].2248** The SQLITE_DBCONFIG_LOOKASIDE option takes three arguments, not two,2249** so that a call to [sqlite3_db_config()] that uses SQLITE_DBCONFIG_LOOKASIDE2250** should have a total of five parameters.2251** <ol>2252** <li><p>The first argument ("buf") is a2253** pointer to a memory buffer to use for lookaside memory.2254** The first argument may be NULL in which case SQLite will allocate the2255** lookaside buffer itself using [sqlite3_malloc()].2256** <li><P>The second argument ("sz") is the2257** size of each lookaside buffer slot. Lookaside is disabled if "sz"2258** is less than 8. The "sz" argument should be a multiple of 8 less than2259** 65536. If "sz" does not meet this constraint, it is reduced in size until2260** it does.2261** <li><p>The third argument ("cnt") is the number of slots. Lookaside is disabled2262** if "cnt"is less than 1. The "cnt" value will be reduced, if necessary, so2263** that the product of "sz" and "cnt" does not exceed 2,147,418,112. The "cnt"2264** parameter is usually chosen so that the product of "sz" and "cnt" is less2265** than 1,000,000.2266** </ol>2267** <p>If the "buf" argument is not NULL, then it must2268** point to a memory buffer with a size that is greater than2269** or equal to the product of "sz" and "cnt".2270** The buffer must be aligned to an 8-byte boundary.2271** The lookaside memory2272** configuration for a database connection can only be changed when that2273** connection is not currently using lookaside memory, or in other words2274** when the value returned by [SQLITE_DBSTATUS_LOOKASIDE_USED] is zero.2275** Any attempt to change the lookaside memory configuration when lookaside2276** memory is in use leaves the configuration unchanged and returns2277** [SQLITE_BUSY].2278** If the "buf" argument is NULL and an attempt2279** to allocate memory based on "sz" and "cnt" fails, then2280** lookaside is silently disabled.2281** <p>2282** The [SQLITE_CONFIG_LOOKASIDE] configuration option can be used to set the2283** default lookaside configuration at initialization. The2284** [-DSQLITE_DEFAULT_LOOKASIDE] option can be used to set the default lookaside2285** configuration at compile-time. Typical values for lookaside are 1200 for2286** "sz" and 40 to 100 for "cnt".2287** </dd>2288**2289** [[SQLITE_DBCONFIG_ENABLE_FKEY]]2290** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>2291** <dd> ^This option is used to enable or disable the enforcement of2292** [foreign key constraints]. This is the same setting that is2293** enabled or disabled by the [PRAGMA foreign_keys] statement.2294** The first argument is an integer which is 0 to disable FK enforcement,2295** positive to enable FK enforcement or negative to leave FK enforcement2296** unchanged. The second parameter is a pointer to an integer into which2297** is written 0 or 1 to indicate whether FK enforcement is off or on2298** following this call. The second parameter may be a NULL pointer, in2299** which case the FK enforcement setting is not reported back. </dd>2300**2301** [[SQLITE_DBCONFIG_ENABLE_TRIGGER]]2302** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>2303** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].2304** There should be two additional arguments.2305** The first argument is an integer which is 0 to disable triggers,2306** positive to enable triggers or negative to leave the setting unchanged.2307** The second parameter is a pointer to an integer into which2308** is written 0 or 1 to indicate whether triggers are disabled or enabled2309** following this call. The second parameter may be a NULL pointer, in2310** which case the trigger setting is not reported back.2311**2312** <p>Originally this option disabled all triggers. ^(However, since2313** SQLite version 3.35.0, TEMP triggers are still allowed even if2314** this option is off. So, in other words, this option now only disables2315** triggers in the main database schema or in the schemas of [ATTACH]-ed2316** databases.)^ </dd>2317**2318** [[SQLITE_DBCONFIG_ENABLE_VIEW]]2319** <dt>SQLITE_DBCONFIG_ENABLE_VIEW</dt>2320** <dd> ^This option is used to enable or disable [CREATE VIEW | views].2321** There must be two additional arguments.2322** The first argument is an integer which is 0 to disable views,2323** positive to enable views or negative to leave the setting unchanged.2324** The second parameter is a pointer to an integer into which2325** is written 0 or 1 to indicate whether views are disabled or enabled2326** following this call. The second parameter may be a NULL pointer, in2327** which case the view setting is not reported back.2328**2329** <p>Originally this option disabled all views. ^(However, since2330** SQLite version 3.35.0, TEMP views are still allowed even if2331** this option is off. So, in other words, this option now only disables2332** views in the main database schema or in the schemas of ATTACH-ed2333** databases.)^ </dd>2334**2335** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]2336** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>2337** <dd> ^This option is used to enable or disable the2338** [fts3_tokenizer()] function which is part of the2339** [FTS3] full-text search engine extension.2340** There must be two additional arguments.2341** The first argument is an integer which is 0 to disable fts3_tokenizer() or2342** positive to enable fts3_tokenizer() or negative to leave the setting2343** unchanged.2344** The second parameter is a pointer to an integer into which2345** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled2346** following this call. The second parameter may be a NULL pointer, in2347** which case the new setting is not reported back. </dd>2348**2349** [[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION]]2350** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>2351** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]2352** interface independently of the [load_extension()] SQL function.2353** The [sqlite3_enable_load_extension()] API enables or disables both the2354** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].2355** There must be two additional arguments.2356** When the first argument to this interface is 1, then only the C-API is2357** enabled and the SQL function remains disabled. If the first argument to2358** this interface is 0, then both the C-API and the SQL function are disabled.2359** If the first argument is -1, then no changes are made to state of either the2360** C-API or the SQL function.2361** The second parameter is a pointer to an integer into which2362** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface2363** is disabled or enabled following this call. The second parameter may2364** be a NULL pointer, in which case the new setting is not reported back.2365** </dd>2366**2367** [[SQLITE_DBCONFIG_MAINDBNAME]] <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>2368** <dd> ^This option is used to change the name of the "main" database2369** schema. This option does not follow the2370** [DBCONFIG arguments|usual SQLITE_DBCONFIG argument format].2371** This option takes exactly one additional argument so that the2372** [sqlite3_db_config()] call has a total of three parameters. The2373** extra argument must be a pointer to a constant UTF8 string which2374** will become the new schema name in place of "main". ^SQLite does2375** not make a copy of the new main schema name string, so the application2376** must ensure that the argument passed into SQLITE_DBCONFIG MAINDBNAME2377** is unchanged until after the database connection closes.2378** </dd>2379**2380** [[SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE]]2381** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>2382** <dd> Usually, when a database in [WAL mode] is closed or detached from a2383** database handle, SQLite checks if if there are other connections to the2384** same database, and if there are no other database connection (if the2385** connection being closed is the last open connection to the database),2386** then SQLite performs a [checkpoint] before closing the connection and2387** deletes the WAL file. The SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE option can2388** be used to override that behavior. The first argument passed to this2389** operation (the third parameter to [sqlite3_db_config()]) is an integer2390** which is positive to disable checkpoints-on-close, or zero (the default)2391** to enable them, and negative to leave the setting unchanged.2392** The second argument (the fourth parameter) is a pointer to an integer2393** into which is written 0 or 1 to indicate whether checkpoints-on-close2394** have been disabled - 0 if they are not disabled, 1 if they are.2395** </dd>2396**2397** [[SQLITE_DBCONFIG_ENABLE_QPSG]] <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>2398** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates2399** the [query planner stability guarantee] (QPSG). When the QPSG is active,2400** a single SQL query statement will always use the same algorithm regardless2401** of values of [bound parameters].)^ The QPSG disables some query optimizations2402** that look at the values of bound parameters, which can make some queries2403** slower. But the QPSG has the advantage of more predictable behavior. With2404** the QPSG active, SQLite will always use the same query plan in the field as2405** was used during testing in the lab.2406** The first argument to this setting is an integer which is 0 to disable2407** the QPSG, positive to enable QPSG, or negative to leave the setting2408** unchanged. The second parameter is a pointer to an integer into which2409** is written 0 or 1 to indicate whether the QPSG is disabled or enabled2410** following this call.2411** </dd>2412**2413** [[SQLITE_DBCONFIG_TRIGGER_EQP]] <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt>2414** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not2415** include output for any operations performed by trigger programs. This2416** option is used to set or clear (the default) a flag that governs this2417** behavior. The first parameter passed to this operation is an integer -2418** positive to enable output for trigger programs, or zero to disable it,2419** or negative to leave the setting unchanged.2420** The second parameter is a pointer to an integer into which is written2421** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if2422** it is not disabled, 1 if it is.2423** </dd>2424**2425** [[SQLITE_DBCONFIG_RESET_DATABASE]] <dt>SQLITE_DBCONFIG_RESET_DATABASE</dt>2426** <dd> Set the SQLITE_DBCONFIG_RESET_DATABASE flag and then run2427** [VACUUM] in order to reset a database back to an empty database2428** with no schema and no content. The following process works even for2429** a badly corrupted database file:2430** <ol>2431** <li> If the database connection is newly opened, make sure it has read the2432** database schema by preparing then discarding some query against the2433** database, or calling sqlite3_table_column_metadata(), ignoring any2434** errors. This step is only necessary if the application desires to keep2435** the database in WAL mode after the reset if it was in WAL mode before2436** the reset.2437** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0);2438** <li> [sqlite3_exec](db, "[VACUUM]", 0, 0, 0);2439** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);2440** </ol>2441** Because resetting a database is destructive and irreversible, the2442** process requires the use of this obscure API and multiple steps to2443** help ensure that it does not happen by accident. Because this2444** feature must be capable of resetting corrupt databases, and2445** shutting down virtual tables may require access to that corrupt2446** storage, the library must abandon any installed virtual tables2447** without calling their xDestroy() methods.2448**2449** [[SQLITE_DBCONFIG_DEFENSIVE]] <dt>SQLITE_DBCONFIG_DEFENSIVE</dt>2450** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the2451** "defensive" flag for a database connection. When the defensive2452** flag is enabled, language features that allow ordinary SQL to2453** deliberately corrupt the database file are disabled. The disabled2454** features include but are not limited to the following:2455** <ul>2456** <li> The [PRAGMA writable_schema=ON] statement.2457** <li> The [PRAGMA journal_mode=OFF] statement.2458** <li> The [PRAGMA schema_version=N] statement.2459** <li> Writes to the [sqlite_dbpage] virtual table.2460** <li> Direct writes to [shadow tables].2461** </ul>2462** </dd>2463**2464** [[SQLITE_DBCONFIG_WRITABLE_SCHEMA]] <dt>SQLITE_DBCONFIG_WRITABLE_SCHEMA</dt>2465** <dd>The SQLITE_DBCONFIG_WRITABLE_SCHEMA option activates or deactivates the2466** "writable_schema" flag. This has the same effect and is logically equivalent2467** to setting [PRAGMA writable_schema=ON] or [PRAGMA writable_schema=OFF].2468** The first argument to this setting is an integer which is 0 to disable2469** the writable_schema, positive to enable writable_schema, or negative to2470** leave the setting unchanged. The second parameter is a pointer to an2471** integer into which is written 0 or 1 to indicate whether the writable_schema2472** is enabled or disabled following this call.2473** </dd>2474**2475** [[SQLITE_DBCONFIG_LEGACY_ALTER_TABLE]]2476** <dt>SQLITE_DBCONFIG_LEGACY_ALTER_TABLE</dt>2477** <dd>The SQLITE_DBCONFIG_LEGACY_ALTER_TABLE option activates or deactivates2478** the legacy behavior of the [ALTER TABLE RENAME] command such it2479** behaves as it did prior to [version 3.24.0] (2018-06-04). See the2480** "Compatibility Notice" on the [ALTER TABLE RENAME documentation] for2481** additional information. This feature can also be turned on and off2482** using the [PRAGMA legacy_alter_table] statement.2483** </dd>2484**2485** [[SQLITE_DBCONFIG_DQS_DML]]2486** <dt>SQLITE_DBCONFIG_DQS_DML</dt>2487** <dd>The SQLITE_DBCONFIG_DQS_DML option activates or deactivates2488** the legacy [double-quoted string literal] misfeature for DML statements2489** only, that is DELETE, INSERT, SELECT, and UPDATE statements. The2490** default value of this setting is determined by the [-DSQLITE_DQS]2491** compile-time option.2492** </dd>2493**2494** [[SQLITE_DBCONFIG_DQS_DDL]]2495** <dt>SQLITE_DBCONFIG_DQS_DDL</dt>2496** <dd>The SQLITE_DBCONFIG_DQS option activates or deactivates2497** the legacy [double-quoted string literal] misfeature for DDL statements,2498** such as CREATE TABLE and CREATE INDEX. The2499** default value of this setting is determined by the [-DSQLITE_DQS]2500** compile-time option.2501** </dd>2502**2503** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]2504** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</dt>2505** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to2506** assume that database schemas are untainted by malicious content.2507** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite2508** takes additional defensive steps to protect the application from harm2509** including:2510** <ul>2511** <li> Prohibit the use of SQL functions inside triggers, views,2512** CHECK constraints, DEFAULT clauses, expression indexes,2513** partial indexes, or generated columns2514** unless those functions are tagged with [SQLITE_INNOCUOUS].2515** <li> Prohibit the use of virtual tables inside of triggers or views2516** unless those virtual tables are tagged with [SQLITE_VTAB_INNOCUOUS].2517** </ul>2518** This setting defaults to "on" for legacy compatibility, however2519** all applications are advised to turn it off if possible. This setting2520** can also be controlled using the [PRAGMA trusted_schema] statement.2521** </dd>2522**2523** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]2524** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</dt>2525** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates2526** the legacy file format flag. When activated, this flag causes all newly2527** created database file to have a schema format version number (the 4-byte2528** integer found at offset 44 into the database header) of 1. This in turn2529** means that the resulting database file will be readable and writable by2530** any SQLite version back to 3.0.0 ([dateof:3.0.0]). Without this setting,2531** newly created databases are generally not understandable by SQLite versions2532** prior to 3.3.0 ([dateof:3.3.0]). As these words are written, there2533** is now scarcely any need to generate database files that are compatible2534** all the way back to version 3.0.0, and so this setting is of little2535** practical use, but is provided so that SQLite can continue to claim the2536** ability to generate new database files that are compatible with version2537** 3.0.0.2538** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on,2539** the [VACUUM] command will fail with an obscure error when attempting to2540** process a table with generated columns and a descending index. This is2541** not considered a bug since SQLite versions 3.3.0 and earlier do not support2542** either generated columns or descending indexes.2543** </dd>2544**2545** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]]2546** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt>2547** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in2548** SQLITE_ENABLE_STMT_SCANSTATUS builds. In this case, it sets or clears2549** a flag that enables collection of the sqlite3_stmt_scanstatus_v2()2550** statistics. For statistics to be collected, the flag must be set on2551** the database handle both when the SQL statement is prepared and when it2552** is stepped. The flag is set (collection of statistics is enabled)2553** by default. <p>This option takes two arguments: an integer and a pointer to2554** an integer.. The first argument is 1, 0, or -1 to enable, disable, or2555** leave unchanged the statement scanstatus option. If the second argument2556** is not NULL, then the value of the statement scanstatus setting after2557** processing the first argument is written into the integer that the second2558** argument points to.2559** </dd>2560**2561** [[SQLITE_DBCONFIG_REVERSE_SCANORDER]]2562** <dt>SQLITE_DBCONFIG_REVERSE_SCANORDER</dt>2563** <dd>The SQLITE_DBCONFIG_REVERSE_SCANORDER option changes the default order2564** in which tables and indexes are scanned so that the scans start at the end2565** and work toward the beginning rather than starting at the beginning and2566** working toward the end. Setting SQLITE_DBCONFIG_REVERSE_SCANORDER is the2567** same as setting [PRAGMA reverse_unordered_selects]. <p>This option takes2568** two arguments which are an integer and a pointer to an integer. The first2569** argument is 1, 0, or -1 to enable, disable, or leave unchanged the2570** reverse scan order flag, respectively. If the second argument is not NULL,2571** then 0 or 1 is written into the integer that the second argument points to2572** depending on if the reverse scan order flag is set after processing the2573** first argument.2574** </dd>2575**2576** [[SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE]]2577** <dt>SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE</dt>2578** <dd>The SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE option enables or disables2579** the ability of the [ATTACH DATABASE] SQL command to create a new database2580** file if the database filed named in the ATTACH command does not already2581** exist. This ability of ATTACH to create a new database is enabled by2582** default. Applications can disable or reenable the ability for ATTACH to2583** create new database files using this DBCONFIG option.<p>2584** This option takes two arguments which are an integer and a pointer2585** to an integer. The first argument is 1, 0, or -1 to enable, disable, or2586** leave unchanged the attach-create flag, respectively. If the second2587** argument is not NULL, then 0 or 1 is written into the integer that the2588** second argument points to depending on if the attach-create flag is set2589** after processing the first argument.2590** </dd>2591**2592** [[SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE]]2593** <dt>SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE</dt>2594** <dd>The SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE option enables or disables the2595** ability of the [ATTACH DATABASE] SQL command to open a database for writing.2596** This capability is enabled by default. Applications can disable or2597** reenable this capability using the current DBCONFIG option. If the2598** the this capability is disabled, the [ATTACH] command will still work,2599** but the database will be opened read-only. If this option is disabled,2600** then the ability to create a new database using [ATTACH] is also disabled,2601** regardless of the value of the [SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE]2602** option.<p>2603** This option takes two arguments which are an integer and a pointer2604** to an integer. The first argument is 1, 0, or -1 to enable, disable, or2605** leave unchanged the ability to ATTACH another database for writing,2606** respectively. If the second argument is not NULL, then 0 or 1 is written2607** into the integer to which the second argument points, depending on whether2608** the ability to ATTACH a read/write database is enabled or disabled2609** after processing the first argument.2610** </dd>2611**2612** [[SQLITE_DBCONFIG_ENABLE_COMMENTS]]2613** <dt>SQLITE_DBCONFIG_ENABLE_COMMENTS</dt>2614** <dd>The SQLITE_DBCONFIG_ENABLE_COMMENTS option enables or disables the2615** ability to include comments in SQL text. Comments are enabled by default.2616** An application can disable or reenable comments in SQL text using this2617** DBCONFIG option.<p>2618** This option takes two arguments which are an integer and a pointer2619** to an integer. The first argument is 1, 0, or -1 to enable, disable, or2620** leave unchanged the ability to use comments in SQL text,2621** respectively. If the second argument is not NULL, then 0 or 1 is written2622** into the integer that the second argument points to depending on if2623** comments are allowed in SQL text after processing the first argument.2624** </dd>2625**2626** </dl>2627**2628** [[DBCONFIG arguments]] <h3>Arguments To SQLITE_DBCONFIG Options</h3>2629**2630** <p>Most of the SQLITE_DBCONFIG options take two arguments, so that the2631** overall call to [sqlite3_db_config()] has a total of four parameters.2632** The first argument (the third parameter to sqlite3_db_config()) is a integer.2633** The second argument is a pointer to an integer. If the first argument is 1,2634** then the option becomes enabled. If the first integer argument is 0, then the2635** option is disabled. If the first argument is -1, then the option setting2636** is unchanged. The second argument, the pointer to an integer, may be NULL.2637** If the second argument is not NULL, then a value of 0 or 1 is written into2638** the integer to which the second argument points, depending on whether the2639** setting is disabled or enabled after applying any changes specified by2640** the first argument.2641**2642** <p>While most SQLITE_DBCONFIG options use the argument format2643** described in the previous paragraph, the [SQLITE_DBCONFIG_MAINDBNAME]2644** and [SQLITE_DBCONFIG_LOOKASIDE] options are different. See the2645** documentation of those exceptional options for details.2646*/2647#define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */2648#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */2649#define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */2650#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */2651#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */2652#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */2653#define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */2654#define SQLITE_DBCONFIG_ENABLE_QPSG 1007 /* int int* */2655#define SQLITE_DBCONFIG_TRIGGER_EQP 1008 /* int int* */2656#define SQLITE_DBCONFIG_RESET_DATABASE 1009 /* int int* */2657#define SQLITE_DBCONFIG_DEFENSIVE 1010 /* int int* */2658#define SQLITE_DBCONFIG_WRITABLE_SCHEMA 1011 /* int int* */2659#define SQLITE_DBCONFIG_LEGACY_ALTER_TABLE 1012 /* int int* */2660#define SQLITE_DBCONFIG_DQS_DML 1013 /* int int* */2661#define SQLITE_DBCONFIG_DQS_DDL 1014 /* int int* */2662#define SQLITE_DBCONFIG_ENABLE_VIEW 1015 /* int int* */2663#define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT 1016 /* int int* */2664#define SQLITE_DBCONFIG_TRUSTED_SCHEMA 1017 /* int int* */2665#define SQLITE_DBCONFIG_STMT_SCANSTATUS 1018 /* int int* */2666#define SQLITE_DBCONFIG_REVERSE_SCANORDER 1019 /* int int* */2667#define SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE 1020 /* int int* */2668#define SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE 1021 /* int int* */2669#define SQLITE_DBCONFIG_ENABLE_COMMENTS 1022 /* int int* */2670#define SQLITE_DBCONFIG_MAX 1022 /* Largest DBCONFIG */26712672/*2673** CAPI3REF: Enable Or Disable Extended Result Codes2674** METHOD: sqlite32675**2676** ^The sqlite3_extended_result_codes() routine enables or disables the2677** [extended result codes] feature of SQLite. ^The extended result2678** codes are disabled by default for historical compatibility.2679*/2680SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff);26812682/*2683** CAPI3REF: Last Insert Rowid2684** METHOD: sqlite32685**2686** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables)2687** has a unique 64-bit signed2688** integer key called the [ROWID | "rowid"]. ^The rowid is always available2689** as an undeclared column named ROWID, OID, or _ROWID_ as long as those2690** names are not also used by explicitly declared columns. ^If2691** the table has a column of type [INTEGER PRIMARY KEY] then that column2692** is another alias for the rowid.2693**2694** ^The sqlite3_last_insert_rowid(D) interface usually returns the [rowid] of2695** the most recent successful [INSERT] into a rowid table or [virtual table]2696** on database connection D. ^Inserts into [WITHOUT ROWID] tables are not2697** recorded. ^If no successful [INSERT]s into rowid tables have ever occurred2698** on the database connection D, then sqlite3_last_insert_rowid(D) returns2699** zero.2700**2701** As well as being set automatically as rows are inserted into database2702** tables, the value returned by this function may be set explicitly by2703** [sqlite3_set_last_insert_rowid()]2704**2705** Some virtual table implementations may INSERT rows into rowid tables as2706** part of committing a transaction (e.g. to flush data accumulated in memory2707** to disk). In this case subsequent calls to this function return the rowid2708** associated with these internal INSERT operations, which leads to2709** unintuitive results. Virtual table implementations that do write to rowid2710** tables in this way can avoid this problem by restoring the original2711** rowid value using [sqlite3_set_last_insert_rowid()] before returning2712** control to the user.2713**2714** ^(If an [INSERT] occurs within a trigger then this routine will2715** return the [rowid] of the inserted row as long as the trigger is2716** running. Once the trigger program ends, the value returned2717** by this routine reverts to what it was before the trigger was fired.)^2718**2719** ^An [INSERT] that fails due to a constraint violation is not a2720** successful [INSERT] and does not change the value returned by this2721** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK,2722** and INSERT OR ABORT make no changes to the return value of this2723** routine when their insertion fails. ^(When INSERT OR REPLACE2724** encounters a constraint violation, it does not fail. The2725** INSERT continues to completion after deleting rows that caused2726** the constraint problem so INSERT OR REPLACE will always change2727** the return value of this interface.)^2728**2729** ^For the purposes of this routine, an [INSERT] is considered to2730** be successful even if it is subsequently rolled back.2731**2732** This function is accessible to SQL statements via the2733** [last_insert_rowid() SQL function].2734**2735** If a separate thread performs a new [INSERT] on the same2736** database connection while the [sqlite3_last_insert_rowid()]2737** function is running and thus changes the last insert [rowid],2738** then the value returned by [sqlite3_last_insert_rowid()] is2739** unpredictable and might not equal either the old or the new2740** last insert [rowid].2741*/2742SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);27432744/*2745** CAPI3REF: Set the Last Insert Rowid value.2746** METHOD: sqlite32747**2748** The sqlite3_set_last_insert_rowid(D, R) method allows the application to2749** set the value returned by calling sqlite3_last_insert_rowid(D) to R2750** without inserting a row into the database.2751*/2752SQLITE_API void sqlite3_set_last_insert_rowid(sqlite3*,sqlite3_int64);27532754/*2755** CAPI3REF: Count The Number Of Rows Modified2756** METHOD: sqlite32757**2758** ^These functions return the number of rows modified, inserted or2759** deleted by the most recently completed INSERT, UPDATE or DELETE2760** statement on the database connection specified by the only parameter.2761** The two functions are identical except for the type of the return value2762** and that if the number of rows modified by the most recent INSERT, UPDATE,2763** or DELETE is greater than the maximum value supported by type "int", then2764** the return value of sqlite3_changes() is undefined. ^Executing any other2765** type of SQL statement does not modify the value returned by these functions.2766** For the purposes of this interface, a CREATE TABLE AS SELECT statement2767** does not count as an INSERT, UPDATE or DELETE statement and hence the rows2768** added to the new table by the CREATE TABLE AS SELECT statement are not2769** counted.2770**2771** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are2772** considered - auxiliary changes caused by [CREATE TRIGGER | triggers],2773** [foreign key actions] or [REPLACE] constraint resolution are not counted.2774**2775** Changes to a view that are intercepted by2776** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value2777** returned by sqlite3_changes() immediately after an INSERT, UPDATE or2778** DELETE statement run on a view is always zero. Only changes made to real2779** tables are counted.2780**2781** Things are more complicated if the sqlite3_changes() function is2782** executed while a trigger program is running. This may happen if the2783** program uses the [changes() SQL function], or if some other callback2784** function invokes sqlite3_changes() directly. Essentially:2785**2786** <ul>2787** <li> ^(Before entering a trigger program the value returned by2788** sqlite3_changes() function is saved. After the trigger program2789** has finished, the original value is restored.)^2790**2791** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE2792** statement sets the value returned by sqlite3_changes()2793** upon completion as normal. Of course, this value will not include2794** any changes performed by sub-triggers, as the sqlite3_changes()2795** value will be saved and restored after each sub-trigger has run.)^2796** </ul>2797**2798** ^This means that if the changes() SQL function (or similar) is used2799** by the first INSERT, UPDATE or DELETE statement within a trigger, it2800** returns the value as set when the calling statement began executing.2801** ^If it is used by the second or subsequent such statement within a trigger2802** program, the value returned reflects the number of rows modified by the2803** previous INSERT, UPDATE or DELETE statement within the same trigger.2804**2805** If a separate thread makes changes on the same database connection2806** while [sqlite3_changes()] is running then the value returned2807** is unpredictable and not meaningful.2808**2809** See also:2810** <ul>2811** <li> the [sqlite3_total_changes()] interface2812** <li> the [count_changes pragma]2813** <li> the [changes() SQL function]2814** <li> the [data_version pragma]2815** </ul>2816*/2817SQLITE_API int sqlite3_changes(sqlite3*);2818SQLITE_API sqlite3_int64 sqlite3_changes64(sqlite3*);28192820/*2821** CAPI3REF: Total Number Of Rows Modified2822** METHOD: sqlite32823**2824** ^These functions return the total number of rows inserted, modified or2825** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed2826** since the database connection was opened, including those executed as2827** part of trigger programs. The two functions are identical except for the2828** type of the return value and that if the number of rows modified by the2829** connection exceeds the maximum value supported by type "int", then2830** the return value of sqlite3_total_changes() is undefined. ^Executing2831** any other type of SQL statement does not affect the value returned by2832** sqlite3_total_changes().2833**2834** ^Changes made as part of [foreign key actions] are included in the2835** count, but those made as part of REPLACE constraint resolution are2836** not. ^Changes to a view that are intercepted by INSTEAD OF triggers2837** are not counted.2838**2839** The [sqlite3_total_changes(D)] interface only reports the number2840** of rows that changed due to SQL statement run against database2841** connection D. Any changes by other database connections are ignored.2842** To detect changes against a database file from other database2843** connections use the [PRAGMA data_version] command or the2844** [SQLITE_FCNTL_DATA_VERSION] [file control].2845**2846** If a separate thread makes changes on the same database connection2847** while [sqlite3_total_changes()] is running then the value2848** returned is unpredictable and not meaningful.2849**2850** See also:2851** <ul>2852** <li> the [sqlite3_changes()] interface2853** <li> the [count_changes pragma]2854** <li> the [changes() SQL function]2855** <li> the [data_version pragma]2856** <li> the [SQLITE_FCNTL_DATA_VERSION] [file control]2857** </ul>2858*/2859SQLITE_API int sqlite3_total_changes(sqlite3*);2860SQLITE_API sqlite3_int64 sqlite3_total_changes64(sqlite3*);28612862/*2863** CAPI3REF: Interrupt A Long-Running Query2864** METHOD: sqlite32865**2866** ^This function causes any pending database operation to abort and2867** return at its earliest opportunity. This routine is typically2868** called in response to a user action such as pressing "Cancel"2869** or Ctrl-C where the user wants a long query operation to halt2870** immediately.2871**2872** ^It is safe to call this routine from a thread different from the2873** thread that is currently running the database operation. But it2874** is not safe to call this routine with a [database connection] that2875** is closed or might close before sqlite3_interrupt() returns.2876**2877** ^If an SQL operation is very nearly finished at the time when2878** sqlite3_interrupt() is called, then it might not have an opportunity2879** to be interrupted and might continue to completion.2880**2881** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT].2882** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE2883** that is inside an explicit transaction, then the entire transaction2884** will be rolled back automatically.2885**2886** ^The sqlite3_interrupt(D) call is in effect until all currently running2887** SQL statements on [database connection] D complete. ^Any new SQL statements2888** that are started after the sqlite3_interrupt() call and before the2889** running statement count reaches zero are interrupted as if they had been2890** running prior to the sqlite3_interrupt() call. ^New SQL statements2891** that are started after the running statement count reaches zero are2892** not effected by the sqlite3_interrupt().2893** ^A call to sqlite3_interrupt(D) that occurs when there are no running2894** SQL statements is a no-op and has no effect on SQL statements2895** that are started after the sqlite3_interrupt() call returns.2896**2897** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether2898** or not an interrupt is currently in effect for [database connection] D.2899** It returns 1 if an interrupt is currently in effect, or 0 otherwise.2900*/2901SQLITE_API void sqlite3_interrupt(sqlite3*);2902SQLITE_API int sqlite3_is_interrupted(sqlite3*);29032904/*2905** CAPI3REF: Determine If An SQL Statement Is Complete2906**2907** These routines are useful during command-line input to determine if the2908** currently entered text seems to form a complete SQL statement or2909** if additional input is needed before sending the text into2910** SQLite for parsing. ^These routines return 1 if the input string2911** appears to be a complete SQL statement. ^A statement is judged to be2912** complete if it ends with a semicolon token and is not a prefix of a2913** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within2914** string literals or quoted identifier names or comments are not2915** independent tokens (they are part of the token in which they are2916** embedded) and thus do not count as a statement terminator. ^Whitespace2917** and comments that follow the final semicolon are ignored.2918**2919** ^These routines return 0 if the statement is incomplete. ^If a2920** memory allocation fails, then SQLITE_NOMEM is returned.2921**2922** ^These routines do not parse the SQL statements thus2923** will not detect syntactically incorrect SQL.2924**2925** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior2926** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked2927** automatically by sqlite3_complete16(). If that initialization fails,2928** then the return value from sqlite3_complete16() will be non-zero2929** regardless of whether or not the input SQL is complete.)^2930**2931** The input to [sqlite3_complete()] must be a zero-terminated2932** UTF-8 string.2933**2934** The input to [sqlite3_complete16()] must be a zero-terminated2935** UTF-16 string in native byte order.2936*/2937SQLITE_API int sqlite3_complete(const char *sql);2938SQLITE_API int sqlite3_complete16(const void *sql);29392940/*2941** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors2942** KEYWORDS: {busy-handler callback} {busy handler}2943** METHOD: sqlite32944**2945** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X2946** that might be invoked with argument P whenever2947** an attempt is made to access a database table associated with2948** [database connection] D when another thread2949** or process has the table locked.2950** The sqlite3_busy_handler() interface is used to implement2951** [sqlite3_busy_timeout()] and [PRAGMA busy_timeout].2952**2953** ^If the busy callback is NULL, then [SQLITE_BUSY]2954** is returned immediately upon encountering the lock. ^If the busy callback2955** is not NULL, then the callback might be invoked with two arguments.2956**2957** ^The first argument to the busy handler is a copy of the void* pointer which2958** is the third argument to sqlite3_busy_handler(). ^The second argument to2959** the busy handler callback is the number of times that the busy handler has2960** been invoked previously for the same locking event. ^If the2961** busy callback returns 0, then no additional attempts are made to2962** access the database and [SQLITE_BUSY] is returned2963** to the application.2964** ^If the callback returns non-zero, then another attempt2965** is made to access the database and the cycle repeats.2966**2967** The presence of a busy handler does not guarantee that it will be invoked2968** when there is lock contention. ^If SQLite determines that invoking the busy2969** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY]2970** to the application instead of invoking the2971** busy handler.2972** Consider a scenario where one process is holding a read lock that2973** it is trying to promote to a reserved lock and2974** a second process is holding a reserved lock that it is trying2975** to promote to an exclusive lock. The first process cannot proceed2976** because it is blocked by the second and the second process cannot2977** proceed because it is blocked by the first. If both processes2978** invoke the busy handlers, neither will make any progress. Therefore,2979** SQLite returns [SQLITE_BUSY] for the first process, hoping that this2980** will induce the first process to release its read lock and allow2981** the second process to proceed.2982**2983** ^The default busy callback is NULL.2984**2985** ^(There can only be a single busy handler defined for each2986** [database connection]. Setting a new busy handler clears any2987** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()]2988** or evaluating [PRAGMA busy_timeout=N] will change the2989** busy handler and thus clear any previously set busy handler.2990**2991** The busy callback should not take any actions which modify the2992** database connection that invoked the busy handler. In other words,2993** the busy handler is not reentrant. Any such actions2994** result in undefined behavior.2995**2996** A busy handler must not close the database connection2997** or [prepared statement] that invoked the busy handler.2998*/2999SQLITE_API int sqlite3_busy_handler(sqlite3*,int(*)(void*,int),void*);30003001/*3002** CAPI3REF: Set A Busy Timeout3003** METHOD: sqlite33004**3005** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps3006** for a specified amount of time when a table is locked. ^The handler3007** will sleep multiple times until at least "ms" milliseconds of sleeping3008** have accumulated. ^After at least "ms" milliseconds of sleeping,3009** the handler returns 0 which causes [sqlite3_step()] to return3010** [SQLITE_BUSY].3011**3012** ^Calling this routine with an argument less than or equal to zero3013** turns off all busy handlers.3014**3015** ^(There can only be a single busy handler for a particular3016** [database connection] at any given moment. If another busy handler3017** was defined (using [sqlite3_busy_handler()]) prior to calling3018** this routine, that other busy handler is cleared.)^3019**3020** See also: [PRAGMA busy_timeout]3021*/3022SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms);30233024/*3025** CAPI3REF: Set the Setlk Timeout3026** METHOD: sqlite33027**3028** This routine is only useful in SQLITE_ENABLE_SETLK_TIMEOUT builds. If3029** the VFS supports blocking locks, it sets the timeout in ms used by3030** eligible locks taken on wal mode databases by the specified database3031** handle. In non-SQLITE_ENABLE_SETLK_TIMEOUT builds, or if the VFS does3032** not support blocking locks, this function is a no-op.3033**3034** Passing 0 to this function disables blocking locks altogether. Passing3035** -1 to this function requests that the VFS blocks for a long time -3036** indefinitely if possible. The results of passing any other negative value3037** are undefined.3038**3039** Internally, each SQLite database handle store two timeout values - the3040** busy-timeout (used for rollback mode databases, or if the VFS does not3041** support blocking locks) and the setlk-timeout (used for blocking locks3042** on wal-mode databases). The sqlite3_busy_timeout() method sets both3043** values, this function sets only the setlk-timeout value. Therefore,3044** to configure separate busy-timeout and setlk-timeout values for a single3045** database handle, call sqlite3_busy_timeout() followed by this function.3046**3047** Whenever the number of connections to a wal mode database falls from3048** 1 to 0, the last connection takes an exclusive lock on the database,3049** then checkpoints and deletes the wal file. While it is doing this, any3050** new connection that tries to read from the database fails with an3051** SQLITE_BUSY error. Or, if the SQLITE_SETLK_BLOCK_ON_CONNECT flag is3052** passed to this API, the new connection blocks until the exclusive lock3053** has been released.3054*/3055SQLITE_API int sqlite3_setlk_timeout(sqlite3*, int ms, int flags);30563057/*3058** CAPI3REF: Flags for sqlite3_setlk_timeout()3059*/3060#define SQLITE_SETLK_BLOCK_ON_CONNECT 0x0130613062/*3063** CAPI3REF: Convenience Routines For Running Queries3064** METHOD: sqlite33065**3066** This is a legacy interface that is preserved for backwards compatibility.3067** Use of this interface is not recommended.3068**3069** Definition: A <b>result table</b> is memory data structure created by the3070** [sqlite3_get_table()] interface. A result table records the3071** complete query results from one or more queries.3072**3073** The table conceptually has a number of rows and columns. But3074** these numbers are not part of the result table itself. These3075** numbers are obtained separately. Let N be the number of rows3076** and M be the number of columns.3077**3078** A result table is an array of pointers to zero-terminated UTF-8 strings.3079** There are (N+1)*M elements in the array. The first M pointers point3080** to zero-terminated strings that contain the names of the columns.3081** The remaining entries all point to query results. NULL values result3082** in NULL pointers. All other values are in their UTF-8 zero-terminated3083** string representation as returned by [sqlite3_column_text()].3084**3085** A result table might consist of one or more memory allocations.3086** It is not safe to pass a result table directly to [sqlite3_free()].3087** A result table should be deallocated using [sqlite3_free_table()].3088**3089** ^(As an example of the result table format, suppose a query result3090** is as follows:3091**3092** <blockquote><pre>3093** Name | Age3094** -----------------------3095** Alice | 433096** Bob | 283097** Cindy | 213098** </pre></blockquote>3099**3100** There are two columns (M==2) and three rows (N==3). Thus the3101** result table has 8 entries. Suppose the result table is stored3102** in an array named azResult. Then azResult holds this content:3103**3104** <blockquote><pre>3105** azResult[0] = "Name";3106** azResult[1] = "Age";3107** azResult[2] = "Alice";3108** azResult[3] = "43";3109** azResult[4] = "Bob";3110** azResult[5] = "28";3111** azResult[6] = "Cindy";3112** azResult[7] = "21";3113** </pre></blockquote>)^3114**3115** ^The sqlite3_get_table() function evaluates one or more3116** semicolon-separated SQL statements in the zero-terminated UTF-83117** string of its 2nd parameter and returns a result table to the3118** pointer given in its 3rd parameter.3119**3120** After the application has finished with the result from sqlite3_get_table(),3121** it must pass the result table pointer to sqlite3_free_table() in order to3122** release the memory that was malloced. Because of the way the3123** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling3124** function must not try to call [sqlite3_free()] directly. Only3125** [sqlite3_free_table()] is able to release the memory properly and safely.3126**3127** The sqlite3_get_table() interface is implemented as a wrapper around3128** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access3129** to any internal data structures of SQLite. It uses only the public3130** interface defined here. As a consequence, errors that occur in the3131** wrapper layer outside of the internal [sqlite3_exec()] call are not3132** reflected in subsequent calls to [sqlite3_errcode()] or3133** [sqlite3_errmsg()].3134*/3135SQLITE_API int sqlite3_get_table(3136sqlite3 *db, /* An open database */3137const char *zSql, /* SQL to be evaluated */3138char ***pazResult, /* Results of the query */3139int *pnRow, /* Number of result rows written here */3140int *pnColumn, /* Number of result columns written here */3141char **pzErrmsg /* Error msg written here */3142);3143SQLITE_API void sqlite3_free_table(char **result);31443145/*3146** CAPI3REF: Formatted String Printing Functions3147**3148** These routines are work-alikes of the "printf()" family of functions3149** from the standard C library.3150** These routines understand most of the common formatting options from3151** the standard library printf()3152** plus some additional non-standard formats ([%q], [%Q], [%w], and [%z]).3153** See the [built-in printf()] documentation for details.3154**3155** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their3156** results into memory obtained from [sqlite3_malloc64()].3157** The strings returned by these two routines should be3158** released by [sqlite3_free()]. ^Both routines return a3159** NULL pointer if [sqlite3_malloc64()] is unable to allocate enough3160** memory to hold the resulting string.3161**3162** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from3163** the standard C library. The result is written into the3164** buffer supplied as the second parameter whose size is given by3165** the first parameter. Note that the order of the3166** first two parameters is reversed from snprintf().)^ This is an3167** historical accident that cannot be fixed without breaking3168** backwards compatibility. ^(Note also that sqlite3_snprintf()3169** returns a pointer to its buffer instead of the number of3170** characters actually written into the buffer.)^ We admit that3171** the number of characters written would be a more useful return3172** value but we cannot change the implementation of sqlite3_snprintf()3173** now without breaking compatibility.3174**3175** ^As long as the buffer size is greater than zero, sqlite3_snprintf()3176** guarantees that the buffer is always zero-terminated. ^The first3177** parameter "n" is the total size of the buffer, including space for3178** the zero terminator. So the longest string that can be completely3179** written will be n-1 characters.3180**3181** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().3182**3183** See also: [built-in printf()], [printf() SQL function]3184*/3185SQLITE_API char *sqlite3_mprintf(const char*,...);3186SQLITE_API char *sqlite3_vmprintf(const char*, va_list);3187SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);3188SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);31893190/*3191** CAPI3REF: Memory Allocation Subsystem3192**3193** The SQLite core uses these three routines for all of its own3194** internal memory allocation needs. "Core" in the previous sentence3195** does not include operating-system specific [VFS] implementation. The3196** Windows VFS uses native malloc() and free() for some operations.3197**3198** ^The sqlite3_malloc() routine returns a pointer to a block3199** of memory at least N bytes in length, where N is the parameter.3200** ^If sqlite3_malloc() is unable to obtain sufficient free3201** memory, it returns a NULL pointer. ^If the parameter N to3202** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns3203** a NULL pointer.3204**3205** ^The sqlite3_malloc64(N) routine works just like3206** sqlite3_malloc(N) except that N is an unsigned 64-bit integer instead3207** of a signed 32-bit integer.3208**3209** ^Calling sqlite3_free() with a pointer previously returned3210** by sqlite3_malloc() or sqlite3_realloc() releases that memory so3211** that it might be reused. ^The sqlite3_free() routine is3212** a no-op if is called with a NULL pointer. Passing a NULL pointer3213** to sqlite3_free() is harmless. After being freed, memory3214** should neither be read nor written. Even reading previously freed3215** memory might result in a segmentation fault or other severe error.3216** Memory corruption, a segmentation fault, or other severe error3217** might result if sqlite3_free() is called with a non-NULL pointer that3218** was not obtained from sqlite3_malloc() or sqlite3_realloc().3219**3220** ^The sqlite3_realloc(X,N) interface attempts to resize a3221** prior memory allocation X to be at least N bytes.3222** ^If the X parameter to sqlite3_realloc(X,N)3223** is a NULL pointer then its behavior is identical to calling3224** sqlite3_malloc(N).3225** ^If the N parameter to sqlite3_realloc(X,N) is zero or3226** negative then the behavior is exactly the same as calling3227** sqlite3_free(X).3228** ^sqlite3_realloc(X,N) returns a pointer to a memory allocation3229** of at least N bytes in size or NULL if insufficient memory is available.3230** ^If M is the size of the prior allocation, then min(N,M) bytes3231** of the prior allocation are copied into the beginning of buffer returned3232** by sqlite3_realloc(X,N) and the prior allocation is freed.3233** ^If sqlite3_realloc(X,N) returns NULL and N is positive, then the3234** prior allocation is not freed.3235**3236** ^The sqlite3_realloc64(X,N) interfaces works the same as3237** sqlite3_realloc(X,N) except that N is a 64-bit unsigned integer instead3238** of a 32-bit signed integer.3239**3240** ^If X is a memory allocation previously obtained from sqlite3_malloc(),3241** sqlite3_malloc64(), sqlite3_realloc(), or sqlite3_realloc64(), then3242** sqlite3_msize(X) returns the size of that memory allocation in bytes.3243** ^The value returned by sqlite3_msize(X) might be larger than the number3244** of bytes requested when X was allocated. ^If X is a NULL pointer then3245** sqlite3_msize(X) returns zero. If X points to something that is not3246** the beginning of memory allocation, or if it points to a formerly3247** valid memory allocation that has now been freed, then the behavior3248** of sqlite3_msize(X) is undefined and possibly harmful.3249**3250** ^The memory returned by sqlite3_malloc(), sqlite3_realloc(),3251** sqlite3_malloc64(), and sqlite3_realloc64()3252** is always aligned to at least an 8 byte boundary, or to a3253** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time3254** option is used.3255**3256** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()]3257** must be either NULL or else pointers obtained from a prior3258** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have3259** not yet been released.3260**3261** The application must not read or write any part of3262** a block of memory after it has been released using3263** [sqlite3_free()] or [sqlite3_realloc()].3264*/3265SQLITE_API void *sqlite3_malloc(int);3266SQLITE_API void *sqlite3_malloc64(sqlite3_uint64);3267SQLITE_API void *sqlite3_realloc(void*, int);3268SQLITE_API void *sqlite3_realloc64(void*, sqlite3_uint64);3269SQLITE_API void sqlite3_free(void*);3270SQLITE_API sqlite3_uint64 sqlite3_msize(void*);32713272/*3273** CAPI3REF: Memory Allocator Statistics3274**3275** SQLite provides these two interfaces for reporting on the status3276** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()]3277** routines, which form the built-in memory allocation subsystem.3278**3279** ^The [sqlite3_memory_used()] routine returns the number of bytes3280** of memory currently outstanding (malloced but not freed).3281** ^The [sqlite3_memory_highwater()] routine returns the maximum3282** value of [sqlite3_memory_used()] since the high-water mark3283** was last reset. ^The values returned by [sqlite3_memory_used()] and3284** [sqlite3_memory_highwater()] include any overhead3285** added by SQLite in its implementation of [sqlite3_malloc()],3286** but not overhead added by the any underlying system library3287** routines that [sqlite3_malloc()] may call.3288**3289** ^The memory high-water mark is reset to the current value of3290** [sqlite3_memory_used()] if and only if the parameter to3291** [sqlite3_memory_highwater()] is true. ^The value returned3292** by [sqlite3_memory_highwater(1)] is the high-water mark3293** prior to the reset.3294*/3295SQLITE_API sqlite3_int64 sqlite3_memory_used(void);3296SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag);32973298/*3299** CAPI3REF: Pseudo-Random Number Generator3300**3301** SQLite contains a high-quality pseudo-random number generator (PRNG) used to3302** select random [ROWID | ROWIDs] when inserting new records into a table that3303** already uses the largest possible [ROWID]. The PRNG is also used for3304** the built-in random() and randomblob() SQL functions. This interface allows3305** applications to access the same PRNG for other purposes.3306**3307** ^A call to this routine stores N bytes of randomness into buffer P.3308** ^The P parameter can be a NULL pointer.3309**3310** ^If this routine has not been previously called or if the previous3311** call had N less than one or a NULL pointer for P, then the PRNG is3312** seeded using randomness obtained from the xRandomness method of3313** the default [sqlite3_vfs] object.3314** ^If the previous call to this routine had an N of 1 or more and a3315** non-NULL P then the pseudo-randomness is generated3316** internally and without recourse to the [sqlite3_vfs] xRandomness3317** method.3318*/3319SQLITE_API void sqlite3_randomness(int N, void *P);33203321/*3322** CAPI3REF: Compile-Time Authorization Callbacks3323** METHOD: sqlite33324** KEYWORDS: {authorizer callback}3325**3326** ^This routine registers an authorizer callback with a particular3327** [database connection], supplied in the first argument.3328** ^The authorizer callback is invoked as SQL statements are being compiled3329** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],3330** [sqlite3_prepare_v3()], [sqlite3_prepare16()], [sqlite3_prepare16_v2()],3331** and [sqlite3_prepare16_v3()]. ^At various3332** points during the compilation process, as logic is being created3333** to perform various actions, the authorizer callback is invoked to3334** see if those actions are allowed. ^The authorizer callback should3335** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the3336** specific action but allow the SQL statement to continue to be3337** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be3338** rejected with an error. ^If the authorizer callback returns3339** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY]3340** then the [sqlite3_prepare_v2()] or equivalent call that triggered3341** the authorizer will fail with an error message.3342**3343** When the callback returns [SQLITE_OK], that means the operation3344** requested is ok. ^When the callback returns [SQLITE_DENY], the3345** [sqlite3_prepare_v2()] or equivalent call that triggered the3346** authorizer will fail with an error message explaining that3347** access is denied.3348**3349** ^The first parameter to the authorizer callback is a copy of the third3350** parameter to the sqlite3_set_authorizer() interface. ^The second parameter3351** to the callback is an integer [SQLITE_COPY | action code] that specifies3352** the particular action to be authorized. ^The third through sixth parameters3353** to the callback are either NULL pointers or zero-terminated strings3354** that contain additional details about the action to be authorized.3355** Applications must always be prepared to encounter a NULL pointer in any3356** of the third through the sixth parameters of the authorization callback.3357**3358** ^If the action code is [SQLITE_READ]3359** and the callback returns [SQLITE_IGNORE] then the3360** [prepared statement] statement is constructed to substitute3361** a NULL value in place of the table column that would have3362** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE]3363** return can be used to deny an untrusted user access to individual3364** columns of a table.3365** ^When a table is referenced by a [SELECT] but no column values are3366** extracted from that table (for example in a query like3367** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback3368** is invoked once for that table with a column name that is an empty string.3369** ^If the action code is [SQLITE_DELETE] and the callback returns3370** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the3371** [truncate optimization] is disabled and all rows are deleted individually.3372**3373** An authorizer is used when [sqlite3_prepare | preparing]3374** SQL statements from an untrusted source, to ensure that the SQL statements3375** do not try to access data they are not allowed to see, or that they do not3376** try to execute malicious statements that damage the database. For3377** example, an application may allow a user to enter arbitrary3378** SQL queries for evaluation by a database. But the application does3379** not want the user to be able to make arbitrary changes to the3380** database. An authorizer could then be put in place while the3381** user-entered SQL is being [sqlite3_prepare | prepared] that3382** disallows everything except [SELECT] statements.3383**3384** Applications that need to process SQL from untrusted sources3385** might also consider lowering resource limits using [sqlite3_limit()]3386** and limiting database size using the [max_page_count] [PRAGMA]3387** in addition to using an authorizer.3388**3389** ^(Only a single authorizer can be in place on a database connection3390** at a time. Each call to sqlite3_set_authorizer overrides the3391** previous call.)^ ^Disable the authorizer by installing a NULL callback.3392** The authorizer is disabled by default.3393**3394** The authorizer callback must not do anything that will modify3395** the database connection that invoked the authorizer callback.3396** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their3397** database connections for the meaning of "modify" in this paragraph.3398**3399** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the3400** statement might be re-prepared during [sqlite3_step()] due to a3401** schema change. Hence, the application should ensure that the3402** correct authorizer callback remains in place during the [sqlite3_step()].3403**3404** ^Note that the authorizer callback is invoked only during3405** [sqlite3_prepare()] or its variants. Authorization is not3406** performed during statement evaluation in [sqlite3_step()], unless3407** as stated in the previous paragraph, sqlite3_step() invokes3408** sqlite3_prepare_v2() to reprepare a statement after a schema change.3409*/3410SQLITE_API int sqlite3_set_authorizer(3411sqlite3*,3412int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),3413void *pUserData3414);34153416/*3417** CAPI3REF: Authorizer Return Codes3418**3419** The [sqlite3_set_authorizer | authorizer callback function] must3420** return either [SQLITE_OK] or one of these two constants in order3421** to signal SQLite whether or not the action is permitted. See the3422** [sqlite3_set_authorizer | authorizer documentation] for additional3423** information.3424**3425** Note that SQLITE_IGNORE is also used as a [conflict resolution mode]3426** returned from the [sqlite3_vtab_on_conflict()] interface.3427*/3428#define SQLITE_DENY 1 /* Abort the SQL statement with an error */3429#define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */34303431/*3432** CAPI3REF: Authorizer Action Codes3433**3434** The [sqlite3_set_authorizer()] interface registers a callback function3435** that is invoked to authorize certain SQL statement actions. The3436** second parameter to the callback is an integer code that specifies3437** what action is being authorized. These are the integer action codes that3438** the authorizer callback may be passed.3439**3440** These action code values signify what kind of operation is to be3441** authorized. The 3rd and 4th parameters to the authorization3442** callback function will be parameters or NULL depending on which of these3443** codes is used as the second parameter. ^(The 5th parameter to the3444** authorizer callback is the name of the database ("main", "temp",3445** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback3446** is the name of the inner-most trigger or view that is responsible for3447** the access attempt or NULL if this access attempt is directly from3448** top-level SQL code.3449*/3450/******************************************* 3rd ************ 4th ***********/3451#define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */3452#define SQLITE_CREATE_TABLE 2 /* Table Name NULL */3453#define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */3454#define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */3455#define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */3456#define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */3457#define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */3458#define SQLITE_CREATE_VIEW 8 /* View Name NULL */3459#define SQLITE_DELETE 9 /* Table Name NULL */3460#define SQLITE_DROP_INDEX 10 /* Index Name Table Name */3461#define SQLITE_DROP_TABLE 11 /* Table Name NULL */3462#define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */3463#define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */3464#define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */3465#define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */3466#define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */3467#define SQLITE_DROP_VIEW 17 /* View Name NULL */3468#define SQLITE_INSERT 18 /* Table Name NULL */3469#define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */3470#define SQLITE_READ 20 /* Table Name Column Name */3471#define SQLITE_SELECT 21 /* NULL NULL */3472#define SQLITE_TRANSACTION 22 /* Operation NULL */3473#define SQLITE_UPDATE 23 /* Table Name Column Name */3474#define SQLITE_ATTACH 24 /* Filename NULL */3475#define SQLITE_DETACH 25 /* Database Name NULL */3476#define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */3477#define SQLITE_REINDEX 27 /* Index Name NULL */3478#define SQLITE_ANALYZE 28 /* Table Name NULL */3479#define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */3480#define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */3481#define SQLITE_FUNCTION 31 /* NULL Function Name */3482#define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */3483#define SQLITE_COPY 0 /* No longer used */3484#define SQLITE_RECURSIVE 33 /* NULL NULL */34853486/*3487** CAPI3REF: Deprecated Tracing And Profiling Functions3488** DEPRECATED3489**3490** These routines are deprecated. Use the [sqlite3_trace_v2()] interface3491** instead of the routines described here.3492**3493** These routines register callback functions that can be used for3494** tracing and profiling the execution of SQL statements.3495**3496** ^The callback function registered by sqlite3_trace() is invoked at3497** various times when an SQL statement is being run by [sqlite3_step()].3498** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the3499** SQL statement text as the statement first begins executing.3500** ^(Additional sqlite3_trace() callbacks might occur3501** as each triggered subprogram is entered. The callbacks for triggers3502** contain a UTF-8 SQL comment that identifies the trigger.)^3503**3504** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit3505** the length of [bound parameter] expansion in the output of sqlite3_trace().3506**3507** ^The callback function registered by sqlite3_profile() is invoked3508** as each SQL statement finishes. ^The profile callback contains3509** the original statement text and an estimate of wall-clock time3510** of how long that statement took to run. ^The profile callback3511** time is in units of nanoseconds, however the current implementation3512** is only capable of millisecond resolution so the six least significant3513** digits in the time are meaningless. Future versions of SQLite3514** might provide greater resolution on the profiler callback. Invoking3515** either [sqlite3_trace()] or [sqlite3_trace_v2()] will cancel the3516** profile callback.3517*/3518SQLITE_API SQLITE_DEPRECATED void *sqlite3_trace(sqlite3*,3519void(*xTrace)(void*,const char*), void*);3520SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3*,3521void(*xProfile)(void*,const char*,sqlite3_uint64), void*);35223523/*3524** CAPI3REF: SQL Trace Event Codes3525** KEYWORDS: SQLITE_TRACE3526**3527** These constants identify classes of events that can be monitored3528** using the [sqlite3_trace_v2()] tracing logic. The M argument3529** to [sqlite3_trace_v2(D,M,X,P)] is an OR-ed combination of one or more of3530** the following constants. ^The first argument to the trace callback3531** is one of the following constants.3532**3533** New tracing constants may be added in future releases.3534**3535** ^A trace callback has four arguments: xCallback(T,C,P,X).3536** ^The T argument is one of the integer type codes above.3537** ^The C argument is a copy of the context pointer passed in as the3538** fourth argument to [sqlite3_trace_v2()].3539** The P and X arguments are pointers whose meanings depend on T.3540**3541** <dl>3542** [[SQLITE_TRACE_STMT]] <dt>SQLITE_TRACE_STMT</dt>3543** <dd>^An SQLITE_TRACE_STMT callback is invoked when a prepared statement3544** first begins running and possibly at other times during the3545** execution of the prepared statement, such as at the start of each3546** trigger subprogram. ^The P argument is a pointer to the3547** [prepared statement]. ^The X argument is a pointer to a string which3548** is the unexpanded SQL text of the prepared statement or an SQL comment3549** that indicates the invocation of a trigger. ^The callback can compute3550** the same text that would have been returned by the legacy [sqlite3_trace()]3551** interface by using the X argument when X begins with "--" and invoking3552** [sqlite3_expanded_sql(P)] otherwise.3553**3554** [[SQLITE_TRACE_PROFILE]] <dt>SQLITE_TRACE_PROFILE</dt>3555** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same3556** information as is provided by the [sqlite3_profile()] callback.3557** ^The P argument is a pointer to the [prepared statement] and the3558** X argument points to a 64-bit integer which is approximately3559** the number of nanoseconds that the prepared statement took to run.3560** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.3561**3562** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt>3563** <dd>^An SQLITE_TRACE_ROW callback is invoked whenever a prepared3564** statement generates a single row of result.3565** ^The P argument is a pointer to the [prepared statement] and the3566** X argument is unused.3567**3568** [[SQLITE_TRACE_CLOSE]] <dt>SQLITE_TRACE_CLOSE</dt>3569** <dd>^An SQLITE_TRACE_CLOSE callback is invoked when a database3570** connection closes.3571** ^The P argument is a pointer to the [database connection] object3572** and the X argument is unused.3573** </dl>3574*/3575#define SQLITE_TRACE_STMT 0x013576#define SQLITE_TRACE_PROFILE 0x023577#define SQLITE_TRACE_ROW 0x043578#define SQLITE_TRACE_CLOSE 0x0835793580/*3581** CAPI3REF: SQL Trace Hook3582** METHOD: sqlite33583**3584** ^The sqlite3_trace_v2(D,M,X,P) interface registers a trace callback3585** function X against [database connection] D, using property mask M3586** and context pointer P. ^If the X callback is3587** NULL or if the M mask is zero, then tracing is disabled. The3588** M argument should be the bitwise OR-ed combination of3589** zero or more [SQLITE_TRACE] constants.3590**3591** ^Each call to either sqlite3_trace(D,X,P) or sqlite3_trace_v2(D,M,X,P)3592** overrides (cancels) all prior calls to sqlite3_trace(D,X,P) or3593** sqlite3_trace_v2(D,M,X,P) for the [database connection] D. Each3594** database connection may have at most one trace callback.3595**3596** ^The X callback is invoked whenever any of the events identified by3597** mask M occur. ^The integer return value from the callback is currently3598** ignored, though this may change in future releases. Callback3599** implementations should return zero to ensure future compatibility.3600**3601** ^A trace callback is invoked with four arguments: callback(T,C,P,X).3602** ^The T argument is one of the [SQLITE_TRACE]3603** constants to indicate why the callback was invoked.3604** ^The C argument is a copy of the context pointer.3605** The P and X arguments are pointers whose meanings depend on T.3606**3607** The sqlite3_trace_v2() interface is intended to replace the legacy3608** interfaces [sqlite3_trace()] and [sqlite3_profile()], both of which3609** are deprecated.3610*/3611SQLITE_API int sqlite3_trace_v2(3612sqlite3*,3613unsigned uMask,3614int(*xCallback)(unsigned,void*,void*,void*),3615void *pCtx3616);36173618/*3619** CAPI3REF: Query Progress Callbacks3620** METHOD: sqlite33621**3622** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback3623** function X to be invoked periodically during long running calls to3624** [sqlite3_step()] and [sqlite3_prepare()] and similar for3625** database connection D. An example use for this3626** interface is to keep a GUI updated during a large query.3627**3628** ^The parameter P is passed through as the only parameter to the3629** callback function X. ^The parameter N is the approximate number of3630** [virtual machine instructions] that are evaluated between successive3631** invocations of the callback X. ^If N is less than one then the progress3632** handler is disabled.3633**3634** ^Only a single progress handler may be defined at one time per3635** [database connection]; setting a new progress handler cancels the3636** old one. ^Setting parameter X to NULL disables the progress handler.3637** ^The progress handler is also disabled by setting N to a value less3638** than 1.3639**3640** ^If the progress callback returns non-zero, the operation is3641** interrupted. This feature can be used to implement a3642** "Cancel" button on a GUI progress dialog box.3643**3644** The progress handler callback must not do anything that will modify3645** the database connection that invoked the progress handler.3646** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their3647** database connections for the meaning of "modify" in this paragraph.3648**3649** The progress handler callback would originally only be invoked from the3650** bytecode engine. It still might be invoked during [sqlite3_prepare()]3651** and similar because those routines might force a reparse of the schema3652** which involves running the bytecode engine. However, beginning with3653** SQLite version 3.41.0, the progress handler callback might also be3654** invoked directly from [sqlite3_prepare()] while analyzing and generating3655** code for complex queries.3656*/3657SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);36583659/*3660** CAPI3REF: Opening A New Database Connection3661** CONSTRUCTOR: sqlite33662**3663** ^These routines open an SQLite database file as specified by the3664** filename argument. ^The filename argument is interpreted as UTF-8 for3665** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte3666** order for sqlite3_open16(). ^(A [database connection] handle is usually3667** returned in *ppDb, even if an error occurs. The only exception is that3668** if SQLite is unable to allocate memory to hold the [sqlite3] object,3669** a NULL will be written into *ppDb instead of a pointer to the [sqlite3]3670** object.)^ ^(If the database is opened (and/or created) successfully, then3671** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The3672** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain3673** an English language description of the error following a failure of any3674** of the sqlite3_open() routines.3675**3676** ^The default encoding will be UTF-8 for databases created using3677** sqlite3_open() or sqlite3_open_v2(). ^The default encoding for databases3678** created using sqlite3_open16() will be UTF-16 in the native byte order.3679**3680** Whether or not an error occurs when it is opened, resources3681** associated with the [database connection] handle should be released by3682** passing it to [sqlite3_close()] when it is no longer required.3683**3684** The sqlite3_open_v2() interface works like sqlite3_open()3685** except that it accepts two additional parameters for additional control3686** over the new database connection. ^(The flags parameter to3687** sqlite3_open_v2() must include, at a minimum, one of the following3688** three flag combinations:)^3689**3690** <dl>3691** ^(<dt>[SQLITE_OPEN_READONLY]</dt>3692** <dd>The database is opened in read-only mode. If the database does3693** not already exist, an error is returned.</dd>)^3694**3695** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>3696** <dd>The database is opened for reading and writing if possible, or3697** reading only if the file is write protected by the operating3698** system. In either case the database must already exist, otherwise3699** an error is returned. For historical reasons, if opening in3700** read-write mode fails due to OS-level permissions, an attempt is3701** made to open it in read-only mode. [sqlite3_db_readonly()] can be3702** used to determine whether the database is actually3703** read-write.</dd>)^3704**3705** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>3706** <dd>The database is opened for reading and writing, and is created if3707** it does not already exist. This is the behavior that is always used for3708** sqlite3_open() and sqlite3_open16().</dd>)^3709** </dl>3710**3711** In addition to the required flags, the following optional flags are3712** also supported:3713**3714** <dl>3715** ^(<dt>[SQLITE_OPEN_URI]</dt>3716** <dd>The filename can be interpreted as a URI if this flag is set.</dd>)^3717**3718** ^(<dt>[SQLITE_OPEN_MEMORY]</dt>3719** <dd>The database will be opened as an in-memory database. The database3720** is named by the "filename" argument for the purposes of cache-sharing,3721** if shared cache mode is enabled, but the "filename" is otherwise ignored.3722** </dd>)^3723**3724** ^(<dt>[SQLITE_OPEN_NOMUTEX]</dt>3725** <dd>The new database connection will use the "multi-thread"3726** [threading mode].)^ This means that separate threads are allowed3727** to use SQLite at the same time, as long as each thread is using3728** a different [database connection].3729**3730** ^(<dt>[SQLITE_OPEN_FULLMUTEX]</dt>3731** <dd>The new database connection will use the "serialized"3732** [threading mode].)^ This means the multiple threads can safely3733** attempt to use the same database connection at the same time.3734** (Mutexes will block any actual concurrency, but in this mode3735** there is no harm in trying.)3736**3737** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt>3738** <dd>The database is opened [shared cache] enabled, overriding3739** the default shared cache setting provided by3740** [sqlite3_enable_shared_cache()].)^3741** The [use of shared cache mode is discouraged] and hence shared cache3742** capabilities may be omitted from many builds of SQLite. In such cases,3743** this option is a no-op.3744**3745** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>3746** <dd>The database is opened [shared cache] disabled, overriding3747** the default shared cache setting provided by3748** [sqlite3_enable_shared_cache()].)^3749**3750** [[OPEN_EXRESCODE]] ^(<dt>[SQLITE_OPEN_EXRESCODE]</dt>3751** <dd>The database connection comes up in "extended result code mode".3752** In other words, the database behaves as if3753** [sqlite3_extended_result_codes(db,1)] were called on the database3754** connection as soon as the connection is created. In addition to setting3755** the extended result code mode, this flag also causes [sqlite3_open_v2()]3756** to return an extended result code.</dd>3757**3758** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>3759** <dd>The database filename is not allowed to contain a symbolic link</dd>3760** </dl>)^3761**3762** If the 3rd parameter to sqlite3_open_v2() is not one of the3763** required combinations shown above optionally combined with other3764** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]3765** then the behavior is undefined. Historic versions of SQLite3766** have silently ignored surplus bits in the flags parameter to3767** sqlite3_open_v2(), however that behavior might not be carried through3768** into future versions of SQLite and so applications should not rely3769** upon it. Note in particular that the SQLITE_OPEN_EXCLUSIVE flag is a no-op3770** for sqlite3_open_v2(). The SQLITE_OPEN_EXCLUSIVE does *not* cause3771** the open to fail if the database already exists. The SQLITE_OPEN_EXCLUSIVE3772** flag is intended for use by the [sqlite3_vfs|VFS interface] only, and not3773** by sqlite3_open_v2().3774**3775** ^The fourth parameter to sqlite3_open_v2() is the name of the3776** [sqlite3_vfs] object that defines the operating system interface that3777** the new database connection should use. ^If the fourth parameter is3778** a NULL pointer then the default [sqlite3_vfs] object is used.3779**3780** ^If the filename is ":memory:", then a private, temporary in-memory database3781** is created for the connection. ^This in-memory database will vanish when3782** the database connection is closed. Future versions of SQLite might3783** make use of additional special filenames that begin with the ":" character.3784** It is recommended that when a database filename actually does begin with3785** a ":" character you should prefix the filename with a pathname such as3786** "./" to avoid ambiguity.3787**3788** ^If the filename is an empty string, then a private, temporary3789** on-disk database will be created. ^This private database will be3790** automatically deleted as soon as the database connection is closed.3791**3792** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>3793**3794** ^If [URI filename] interpretation is enabled, and the filename argument3795** begins with "file:", then the filename is interpreted as a URI. ^URI3796** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is3797** set in the third argument to sqlite3_open_v2(), or if it has3798** been enabled globally using the [SQLITE_CONFIG_URI] option with the3799** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.3800** URI filename interpretation is turned off3801** by default, but future releases of SQLite might enable URI filename3802** interpretation by default. See "[URI filenames]" for additional3803** information.3804**3805** URI filenames are parsed according to RFC 3986. ^If the URI contains an3806** authority, then it must be either an empty string or the string3807** "localhost". ^If the authority is not an empty string or "localhost", an3808** error is returned to the caller. ^The fragment component of a URI, if3809** present, is ignored.3810**3811** ^SQLite uses the path component of the URI as the name of the disk file3812** which contains the database. ^If the path begins with a '/' character,3813** then it is interpreted as an absolute path. ^If the path does not begin3814** with a '/' (meaning that the authority section is omitted from the URI)3815** then the path is interpreted as a relative path.3816** ^(On windows, the first component of an absolute path3817** is a drive specification (e.g. "C:").)^3818**3819** [[core URI query parameters]]3820** The query component of a URI may contain parameters that are interpreted3821** either by SQLite itself, or by a [VFS | custom VFS implementation].3822** SQLite and its built-in [VFSes] interpret the3823** following query parameters:3824**3825** <ul>3826** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of3827** a VFS object that provides the operating system interface that should3828** be used to access the database file on disk. ^If this option is set to3829** an empty string the default VFS object is used. ^Specifying an unknown3830** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is3831** present, then the VFS specified by the option takes precedence over3832** the value passed as the fourth parameter to sqlite3_open_v2().3833**3834** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw",3835** "rwc", or "memory". Attempting to set it to any other value is3836** an error)^.3837** ^If "ro" is specified, then the database is opened for read-only3838** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the3839** third argument to sqlite3_open_v2(). ^If the mode option is set to3840** "rw", then the database is opened for read-write (but not create)3841** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had3842** been set. ^Value "rwc" is equivalent to setting both3843** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is3844** set to "memory" then a pure [in-memory database] that never reads3845** or writes from disk is used. ^It is an error to specify a value for3846** the mode parameter that is less restrictive than that specified by3847** the flags passed in the third parameter to sqlite3_open_v2().3848**3849** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or3850** "private". ^Setting it to "shared" is equivalent to setting the3851** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to3852** sqlite3_open_v2(). ^Setting the cache parameter to "private" is3853** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit.3854** ^If sqlite3_open_v2() is used and the "cache" parameter is present in3855** a URI filename, its value overrides any behavior requested by setting3856** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag.3857**3858** <li> <b>psow</b>: ^The psow parameter indicates whether or not the3859** [powersafe overwrite] property does or does not apply to the3860** storage media on which the database file resides.3861**3862** <li> <b>nolock</b>: ^The nolock parameter is a boolean query parameter3863** which if set disables file locking in rollback journal modes. This3864** is useful for accessing a database on a filesystem that does not3865** support locking. Caution: Database corruption might result if two3866** or more processes write to the same database and any one of those3867** processes uses nolock=1.3868**3869** <li> <b>immutable</b>: ^The immutable parameter is a boolean query3870** parameter that indicates that the database file is stored on3871** read-only media. ^When immutable is set, SQLite assumes that the3872** database file cannot be changed, even by a process with higher3873** privilege, and so the database is opened read-only and all locking3874** and change detection is disabled. Caution: Setting the immutable3875** property on a database file that does in fact change can result3876** in incorrect query results and/or [SQLITE_CORRUPT] errors.3877** See also: [SQLITE_IOCAP_IMMUTABLE].3878**3879** </ul>3880**3881** ^Specifying an unknown parameter in the query component of a URI is not an3882** error. Future versions of SQLite might understand additional query3883** parameters. See "[query parameters with special meaning to SQLite]" for3884** additional information.3885**3886** [[URI filename examples]] <h3>URI filename examples</h3>3887**3888** <table border="1" align=center cellpadding=5>3889** <tr><th> URI filenames <th> Results3890** <tr><td> file:data.db <td>3891** Open the file "data.db" in the current directory.3892** <tr><td> file:/home/fred/data.db<br>3893** file:///home/fred/data.db <br>3894** file://localhost/home/fred/data.db <br> <td>3895** Open the database file "/home/fred/data.db".3896** <tr><td> file://darkstar/home/fred/data.db <td>3897** An error. "darkstar" is not a recognized authority.3898** <tr><td style="white-space:nowrap">3899** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db3900** <td> Windows only: Open the file "data.db" on fred's desktop on drive3901** C:. Note that the %20 escaping in this example is not strictly3902** necessary - space characters can be used literally3903** in URI filenames.3904** <tr><td> file:data.db?mode=ro&cache=private <td>3905** Open file "data.db" in the current directory for read-only access.3906** Regardless of whether or not shared-cache mode is enabled by3907** default, use a private cache.3908** <tr><td> file:/home/fred/data.db?vfs=unix-dotfile <td>3909** Open file "/home/fred/data.db". Use the special VFS "unix-dotfile"3910** that uses dot-files in place of posix advisory locking.3911** <tr><td> file:data.db?mode=readonly <td>3912** An error. "readonly" is not a valid option for the "mode" parameter.3913** Use "ro" instead: "file:data.db?mode=ro".3914** </table>3915**3916** ^URI hexadecimal escape sequences (%HH) are supported within the path and3917** query components of a URI. A hexadecimal escape sequence consists of a3918** percent sign - "%" - followed by exactly two hexadecimal digits3919** specifying an octet value. ^Before the path or query components of a3920** URI filename are interpreted, they are encoded using UTF-8 and all3921** hexadecimal escape sequences replaced by a single byte containing the3922** corresponding octet. If this process generates an invalid UTF-8 encoding,3923** the results are undefined.3924**3925** <b>Note to Windows users:</b> The encoding used for the filename argument3926** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever3927** codepage is currently defined. Filenames containing international3928** characters must be converted to UTF-8 prior to passing them into3929** sqlite3_open() or sqlite3_open_v2().3930**3931** <b>Note to Windows Runtime users:</b> The temporary directory must be set3932** prior to calling sqlite3_open() or sqlite3_open_v2(). Otherwise, various3933** features that require the use of temporary files may fail.3934**3935** See also: [sqlite3_temp_directory]3936*/3937SQLITE_API int sqlite3_open(3938const char *filename, /* Database filename (UTF-8) */3939sqlite3 **ppDb /* OUT: SQLite db handle */3940);3941SQLITE_API int sqlite3_open16(3942const void *filename, /* Database filename (UTF-16) */3943sqlite3 **ppDb /* OUT: SQLite db handle */3944);3945SQLITE_API int sqlite3_open_v2(3946const char *filename, /* Database filename (UTF-8) */3947sqlite3 **ppDb, /* OUT: SQLite db handle */3948int flags, /* Flags */3949const char *zVfs /* Name of VFS module to use */3950);39513952/*3953** CAPI3REF: Obtain Values For URI Parameters3954**3955** These are utility routines, useful to [VFS|custom VFS implementations],3956** that check if a database file was a URI that contained a specific query3957** parameter, and if so obtains the value of that query parameter.3958**3959** The first parameter to these interfaces (hereafter referred to3960** as F) must be one of:3961** <ul>3962** <li> A database filename pointer created by the SQLite core and3963** passed into the xOpen() method of a VFS implementation, or3964** <li> A filename obtained from [sqlite3_db_filename()], or3965** <li> A new filename constructed using [sqlite3_create_filename()].3966** </ul>3967** If the F parameter is not one of the above, then the behavior is3968** undefined and probably undesirable. Older versions of SQLite were3969** more tolerant of invalid F parameters than newer versions.3970**3971** If F is a suitable filename (as described in the previous paragraph)3972** and if P is the name of the query parameter, then3973** sqlite3_uri_parameter(F,P) returns the value of the P3974** parameter if it exists or a NULL pointer if P does not appear as a3975** query parameter on F. If P is a query parameter of F and it3976** has no explicit value, then sqlite3_uri_parameter(F,P) returns3977** a pointer to an empty string.3978**3979** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean3980** parameter and returns true (1) or false (0) according to the value3981** of P. The sqlite3_uri_boolean(F,P,B) routine returns true (1) if the3982** value of query parameter P is one of "yes", "true", or "on" in any3983** case or if the value begins with a non-zero number. The3984** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of3985** query parameter P is one of "no", "false", or "off" in any case or3986** if the value begins with a numeric zero. If P is not a query3987** parameter on F or if the value of P does not match any of the3988** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0).3989**3990** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a3991** 64-bit signed integer and returns that integer, or D if P does not3992** exist. If the value of P is something other than an integer, then3993** zero is returned.3994**3995** The sqlite3_uri_key(F,N) returns a pointer to the name (not3996** the value) of the N-th query parameter for filename F, or a NULL3997** pointer if N is less than zero or greater than the number of query3998** parameters minus 1. The N value is zero-based so N should be 0 to obtain3999** the name of the first query parameter, 1 for the second parameter, and4000** so forth.4001**4002** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and4003** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and4004** is not a database file pathname pointer that the SQLite core passed4005** into the xOpen VFS method, then the behavior of this routine is undefined4006** and probably undesirable.4007**4008** Beginning with SQLite [version 3.31.0] ([dateof:3.31.0]) the input F4009** parameter can also be the name of a rollback journal file or WAL file4010** in addition to the main database file. Prior to version 3.31.0, these4011** routines would only work if F was the name of the main database file.4012** When the F parameter is the name of the rollback journal or WAL file,4013** it has access to all the same query parameters as were found on the4014** main database file.4015**4016** See the [URI filename] documentation for additional information.4017*/4018SQLITE_API const char *sqlite3_uri_parameter(sqlite3_filename z, const char *zParam);4019SQLITE_API int sqlite3_uri_boolean(sqlite3_filename z, const char *zParam, int bDefault);4020SQLITE_API sqlite3_int64 sqlite3_uri_int64(sqlite3_filename, const char*, sqlite3_int64);4021SQLITE_API const char *sqlite3_uri_key(sqlite3_filename z, int N);40224023/*4024** CAPI3REF: Translate filenames4025**4026** These routines are available to [VFS|custom VFS implementations] for4027** translating filenames between the main database file, the journal file,4028** and the WAL file.4029**4030** If F is the name of an sqlite database file, journal file, or WAL file4031** passed by the SQLite core into the VFS, then sqlite3_filename_database(F)4032** returns the name of the corresponding database file.4033**4034** If F is the name of an sqlite database file, journal file, or WAL file4035** passed by the SQLite core into the VFS, or if F is a database filename4036** obtained from [sqlite3_db_filename()], then sqlite3_filename_journal(F)4037** returns the name of the corresponding rollback journal file.4038**4039** If F is the name of an sqlite database file, journal file, or WAL file4040** that was passed by the SQLite core into the VFS, or if F is a database4041** filename obtained from [sqlite3_db_filename()], then4042** sqlite3_filename_wal(F) returns the name of the corresponding4043** WAL file.4044**4045** In all of the above, if F is not the name of a database, journal or WAL4046** filename passed into the VFS from the SQLite core and F is not the4047** return value from [sqlite3_db_filename()], then the result is4048** undefined and is likely a memory access violation.4049*/4050SQLITE_API const char *sqlite3_filename_database(sqlite3_filename);4051SQLITE_API const char *sqlite3_filename_journal(sqlite3_filename);4052SQLITE_API const char *sqlite3_filename_wal(sqlite3_filename);40534054/*4055** CAPI3REF: Database File Corresponding To A Journal4056**4057** ^If X is the name of a rollback or WAL-mode journal file that is4058** passed into the xOpen method of [sqlite3_vfs], then4059** sqlite3_database_file_object(X) returns a pointer to the [sqlite3_file]4060** object that represents the main database file.4061**4062** This routine is intended for use in custom [VFS] implementations4063** only. It is not a general-purpose interface.4064** The argument sqlite3_file_object(X) must be a filename pointer that4065** has been passed into [sqlite3_vfs].xOpen method where the4066** flags parameter to xOpen contains one of the bits4067** [SQLITE_OPEN_MAIN_JOURNAL] or [SQLITE_OPEN_WAL]. Any other use4068** of this routine results in undefined and probably undesirable4069** behavior.4070*/4071SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*);40724073/*4074** CAPI3REF: Create and Destroy VFS Filenames4075**4076** These interfaces are provided for use by [VFS shim] implementations and4077** are not useful outside of that context.4078**4079** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of4080** database filename D with corresponding journal file J and WAL file W and4081** with N URI parameters key/values pairs in the array P. The result from4082** sqlite3_create_filename(D,J,W,N,P) is a pointer to a database filename that4083** is safe to pass to routines like:4084** <ul>4085** <li> [sqlite3_uri_parameter()],4086** <li> [sqlite3_uri_boolean()],4087** <li> [sqlite3_uri_int64()],4088** <li> [sqlite3_uri_key()],4089** <li> [sqlite3_filename_database()],4090** <li> [sqlite3_filename_journal()], or4091** <li> [sqlite3_filename_wal()].4092** </ul>4093** If a memory allocation error occurs, sqlite3_create_filename() might4094** return a NULL pointer. The memory obtained from sqlite3_create_filename(X)4095** must be released by a corresponding call to sqlite3_free_filename(Y).4096**4097** The P parameter in sqlite3_create_filename(D,J,W,N,P) should be an array4098** of 2*N pointers to strings. Each pair of pointers in this array corresponds4099** to a key and value for a query parameter. The P parameter may be a NULL4100** pointer if N is zero. None of the 2*N pointers in the P array may be4101** NULL pointers and key pointers should not be empty strings.4102** None of the D, J, or W parameters to sqlite3_create_filename(D,J,W,N,P) may4103** be NULL pointers, though they can be empty strings.4104**4105** The sqlite3_free_filename(Y) routine releases a memory allocation4106** previously obtained from sqlite3_create_filename(). Invoking4107** sqlite3_free_filename(Y) where Y is a NULL pointer is a harmless no-op.4108**4109** If the Y parameter to sqlite3_free_filename(Y) is anything other4110** than a NULL pointer or a pointer previously acquired from4111** sqlite3_create_filename(), then bad things such as heap4112** corruption or segfaults may occur. The value Y should not be4113** used again after sqlite3_free_filename(Y) has been called. This means4114** that if the [sqlite3_vfs.xOpen()] method of a VFS has been called using Y,4115** then the corresponding [sqlite3_module.xClose() method should also be4116** invoked prior to calling sqlite3_free_filename(Y).4117*/4118SQLITE_API sqlite3_filename sqlite3_create_filename(4119const char *zDatabase,4120const char *zJournal,4121const char *zWal,4122int nParam,4123const char **azParam4124);4125SQLITE_API void sqlite3_free_filename(sqlite3_filename);41264127/*4128** CAPI3REF: Error Codes And Messages4129** METHOD: sqlite34130**4131** ^If the most recent sqlite3_* API call associated with4132** [database connection] D failed, then the sqlite3_errcode(D) interface4133** returns the numeric [result code] or [extended result code] for that4134** API call.4135** ^The sqlite3_extended_errcode()4136** interface is the same except that it always returns the4137** [extended result code] even when extended result codes are4138** disabled.4139**4140** The values returned by sqlite3_errcode() and/or4141** sqlite3_extended_errcode() might change with each API call.4142** Except, there are some interfaces that are guaranteed to never4143** change the value of the error code. The error-code preserving4144** interfaces include the following:4145**4146** <ul>4147** <li> sqlite3_errcode()4148** <li> sqlite3_extended_errcode()4149** <li> sqlite3_errmsg()4150** <li> sqlite3_errmsg16()4151** <li> sqlite3_error_offset()4152** </ul>4153**4154** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language4155** text that describes the error, as either UTF-8 or UTF-16 respectively,4156** or NULL if no error message is available.4157** (See how SQLite handles [invalid UTF] for exceptions to this rule.)4158** ^(Memory to hold the error message string is managed internally.4159** The application does not need to worry about freeing the result.4160** However, the error string might be overwritten or deallocated by4161** subsequent calls to other SQLite interface functions.)^4162**4163** ^The sqlite3_errstr(E) interface returns the English-language text4164** that describes the [result code] E, as UTF-8, or NULL if E is not an4165** result code for which a text error message is available.4166** ^(Memory to hold the error message string is managed internally4167** and must not be freed by the application)^.4168**4169** ^If the most recent error references a specific token in the input4170** SQL, the sqlite3_error_offset() interface returns the byte offset4171** of the start of that token. ^The byte offset returned by4172** sqlite3_error_offset() assumes that the input SQL is UTF8.4173** ^If the most recent error does not reference a specific token in the input4174** SQL, then the sqlite3_error_offset() function returns -1.4175**4176** When the serialized [threading mode] is in use, it might be the4177** case that a second error occurs on a separate thread in between4178** the time of the first error and the call to these interfaces.4179** When that happens, the second error will be reported since these4180** interfaces always report the most recent result. To avoid4181** this, each thread can obtain exclusive use of the [database connection] D4182** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning4183** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after4184** all calls to the interfaces listed here are completed.4185**4186** If an interface fails with SQLITE_MISUSE, that means the interface4187** was invoked incorrectly by the application. In that case, the4188** error code and message may or may not be set.4189*/4190SQLITE_API int sqlite3_errcode(sqlite3 *db);4191SQLITE_API int sqlite3_extended_errcode(sqlite3 *db);4192SQLITE_API const char *sqlite3_errmsg(sqlite3*);4193SQLITE_API const void *sqlite3_errmsg16(sqlite3*);4194SQLITE_API const char *sqlite3_errstr(int);4195SQLITE_API int sqlite3_error_offset(sqlite3 *db);41964197/*4198** CAPI3REF: Prepared Statement Object4199** KEYWORDS: {prepared statement} {prepared statements}4200**4201** An instance of this object represents a single SQL statement that4202** has been compiled into binary form and is ready to be evaluated.4203**4204** Think of each SQL statement as a separate computer program. The4205** original SQL text is source code. A prepared statement object4206** is the compiled object code. All SQL must be converted into a4207** prepared statement before it can be run.4208**4209** The life-cycle of a prepared statement object usually goes like this:4210**4211** <ol>4212** <li> Create the prepared statement object using [sqlite3_prepare_v2()].4213** <li> Bind values to [parameters] using the sqlite3_bind_*()4214** interfaces.4215** <li> Run the SQL by calling [sqlite3_step()] one or more times.4216** <li> Reset the prepared statement using [sqlite3_reset()] then go back4217** to step 2. Do this zero or more times.4218** <li> Destroy the object using [sqlite3_finalize()].4219** </ol>4220*/4221typedef struct sqlite3_stmt sqlite3_stmt;42224223/*4224** CAPI3REF: Run-time Limits4225** METHOD: sqlite34226**4227** ^(This interface allows the size of various constructs to be limited4228** on a connection by connection basis. The first parameter is the4229** [database connection] whose limit is to be set or queried. The4230** second parameter is one of the [limit categories] that define a4231** class of constructs to be size limited. The third parameter is the4232** new limit for that construct.)^4233**4234** ^If the new limit is a negative number, the limit is unchanged.4235** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a4236** [limits | hard upper bound]4237** set at compile-time by a C preprocessor macro called4238** [limits | SQLITE_MAX_<i>NAME</i>].4239** (The "_LIMIT_" in the name is changed to "_MAX_".))^4240** ^Attempts to increase a limit above its hard upper bound are4241** silently truncated to the hard upper bound.4242**4243** ^Regardless of whether or not the limit was changed, the4244** [sqlite3_limit()] interface returns the prior value of the limit.4245** ^Hence, to find the current value of a limit without changing it,4246** simply invoke this interface with the third parameter set to -1.4247**4248** Run-time limits are intended for use in applications that manage4249** both their own internal database and also databases that are controlled4250** by untrusted external sources. An example application might be a4251** web browser that has its own databases for storing history and4252** separate databases controlled by JavaScript applications downloaded4253** off the Internet. The internal databases can be given the4254** large, default limits. Databases managed by external sources can4255** be given much smaller limits designed to prevent a denial of service4256** attack. Developers might also want to use the [sqlite3_set_authorizer()]4257** interface to further control untrusted SQL. The size of the database4258** created by an untrusted script can be contained using the4259** [max_page_count] [PRAGMA].4260**4261** New run-time limit categories may be added in future releases.4262*/4263SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);42644265/*4266** CAPI3REF: Run-Time Limit Categories4267** KEYWORDS: {limit category} {*limit categories}4268**4269** These constants define various performance limits4270** that can be lowered at run-time using [sqlite3_limit()].4271** The synopsis of the meanings of the various limits is shown below.4272** Additional information is available at [limits | Limits in SQLite].4273**4274** <dl>4275** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt>4276** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^4277**4278** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt>4279** <dd>The maximum length of an SQL statement, in bytes.</dd>)^4280**4281** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt>4282** <dd>The maximum number of columns in a table definition or in the4283** result set of a [SELECT] or the maximum number of columns in an index4284** or in an ORDER BY or GROUP BY clause.</dd>)^4285**4286** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt>4287** <dd>The maximum depth of the parse tree on any expression.</dd>)^4288**4289** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>4290** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^4291**4292** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt>4293** <dd>The maximum number of instructions in a virtual machine program4294** used to implement an SQL statement. If [sqlite3_prepare_v2()] or4295** the equivalent tries to allocate space for more than this many opcodes4296** in a single prepared statement, an SQLITE_NOMEM error is returned.</dd>)^4297**4298** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt>4299** <dd>The maximum number of arguments on a function.</dd>)^4300**4301** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt>4302** <dd>The maximum number of [ATTACH | attached databases].)^</dd>4303**4304** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]]4305** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>4306** <dd>The maximum length of the pattern argument to the [LIKE] or4307** [GLOB] operators.</dd>)^4308**4309** [[SQLITE_LIMIT_VARIABLE_NUMBER]]4310** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>4311** <dd>The maximum index number of any [parameter] in an SQL statement.)^4312**4313** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt>4314** <dd>The maximum depth of recursion for triggers.</dd>)^4315**4316** [[SQLITE_LIMIT_WORKER_THREADS]] ^(<dt>SQLITE_LIMIT_WORKER_THREADS</dt>4317** <dd>The maximum number of auxiliary worker threads that a single4318** [prepared statement] may start.</dd>)^4319** </dl>4320*/4321#define SQLITE_LIMIT_LENGTH 04322#define SQLITE_LIMIT_SQL_LENGTH 14323#define SQLITE_LIMIT_COLUMN 24324#define SQLITE_LIMIT_EXPR_DEPTH 34325#define SQLITE_LIMIT_COMPOUND_SELECT 44326#define SQLITE_LIMIT_VDBE_OP 54327#define SQLITE_LIMIT_FUNCTION_ARG 64328#define SQLITE_LIMIT_ATTACHED 74329#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 84330#define SQLITE_LIMIT_VARIABLE_NUMBER 94331#define SQLITE_LIMIT_TRIGGER_DEPTH 104332#define SQLITE_LIMIT_WORKER_THREADS 1143334334/*4335** CAPI3REF: Prepare Flags4336**4337** These constants define various flags that can be passed into4338** "prepFlags" parameter of the [sqlite3_prepare_v3()] and4339** [sqlite3_prepare16_v3()] interfaces.4340**4341** New flags may be added in future releases of SQLite.4342**4343** <dl>4344** [[SQLITE_PREPARE_PERSISTENT]] ^(<dt>SQLITE_PREPARE_PERSISTENT</dt>4345** <dd>The SQLITE_PREPARE_PERSISTENT flag is a hint to the query planner4346** that the prepared statement will be retained for a long time and4347** probably reused many times.)^ ^Without this flag, [sqlite3_prepare_v3()]4348** and [sqlite3_prepare16_v3()] assume that the prepared statement will4349** be used just once or at most a few times and then destroyed using4350** [sqlite3_finalize()] relatively soon. The current implementation acts4351** on this hint by avoiding the use of [lookaside memory] so as not to4352** deplete the limited store of lookaside memory. Future versions of4353** SQLite may act on this hint differently.4354**4355** [[SQLITE_PREPARE_NORMALIZE]] <dt>SQLITE_PREPARE_NORMALIZE</dt>4356** <dd>The SQLITE_PREPARE_NORMALIZE flag is a no-op. This flag used4357** to be required for any prepared statement that wanted to use the4358** [sqlite3_normalized_sql()] interface. However, the4359** [sqlite3_normalized_sql()] interface is now available to all4360** prepared statements, regardless of whether or not they use this4361** flag.4362**4363** [[SQLITE_PREPARE_NO_VTAB]] <dt>SQLITE_PREPARE_NO_VTAB</dt>4364** <dd>The SQLITE_PREPARE_NO_VTAB flag causes the SQL compiler4365** to return an error (error code SQLITE_ERROR) if the statement uses4366** any virtual tables.4367**4368** [[SQLITE_PREPARE_DONT_LOG]] <dt>SQLITE_PREPARE_DONT_LOG</dt>4369** <dd>The SQLITE_PREPARE_DONT_LOG flag prevents SQL compiler4370** errors from being sent to the error log defined by4371** [SQLITE_CONFIG_LOG]. This can be used, for example, to do test4372** compiles to see if some SQL syntax is well-formed, without generating4373** messages on the global error log when it is not. If the test compile4374** fails, the sqlite3_prepare_v3() call returns the same error indications4375** with or without this flag; it just omits the call to [sqlite3_log()] that4376** logs the error.4377** </dl>4378*/4379#define SQLITE_PREPARE_PERSISTENT 0x014380#define SQLITE_PREPARE_NORMALIZE 0x024381#define SQLITE_PREPARE_NO_VTAB 0x044382#define SQLITE_PREPARE_DONT_LOG 0x1043834384/*4385** CAPI3REF: Compiling An SQL Statement4386** KEYWORDS: {SQL statement compiler}4387** METHOD: sqlite34388** CONSTRUCTOR: sqlite3_stmt4389**4390** To execute an SQL statement, it must first be compiled into a byte-code4391** program using one of these routines. Or, in other words, these routines4392** are constructors for the [prepared statement] object.4393**4394** The preferred routine to use is [sqlite3_prepare_v2()]. The4395** [sqlite3_prepare()] interface is legacy and should be avoided.4396** [sqlite3_prepare_v3()] has an extra "prepFlags" option that is used4397** for special purposes.4398**4399** The use of the UTF-8 interfaces is preferred, as SQLite currently4400** does all parsing using UTF-8. The UTF-16 interfaces are provided4401** as a convenience. The UTF-16 interfaces work by converting the4402** input text into UTF-8, then invoking the corresponding UTF-8 interface.4403**4404** The first argument, "db", is a [database connection] obtained from a4405** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or4406** [sqlite3_open16()]. The database connection must not have been closed.4407**4408** The second argument, "zSql", is the statement to be compiled, encoded4409** as either UTF-8 or UTF-16. The sqlite3_prepare(), sqlite3_prepare_v2(),4410** and sqlite3_prepare_v3()4411** interfaces use UTF-8, and sqlite3_prepare16(), sqlite3_prepare16_v2(),4412** and sqlite3_prepare16_v3() use UTF-16.4413**4414** ^If the nByte argument is negative, then zSql is read up to the4415** first zero terminator. ^If nByte is positive, then it is the maximum4416** number of bytes read from zSql. When nByte is positive, zSql is read4417** up to the first zero terminator or until the nByte bytes have been read,4418** whichever comes first. ^If nByte is zero, then no prepared4419** statement is generated.4420** If the caller knows that the supplied string is nul-terminated, then4421** there is a small performance advantage to passing an nByte parameter that4422** is the number of bytes in the input string <i>including</i>4423** the nul-terminator.4424** Note that nByte measure the length of the input in bytes, not4425** characters, even for the UTF-16 interfaces.4426**4427** ^If pzTail is not NULL then *pzTail is made to point to the first byte4428** past the end of the first SQL statement in zSql. These routines only4429** compile the first statement in zSql, so *pzTail is left pointing to4430** what remains uncompiled.4431**4432** ^*ppStmt is left pointing to a compiled [prepared statement] that can be4433** executed using [sqlite3_step()]. ^If there is an error, *ppStmt is set4434** to NULL. ^If the input text contains no SQL (if the input is an empty4435** string or a comment) then *ppStmt is set to NULL.4436** The calling procedure is responsible for deleting the compiled4437** SQL statement using [sqlite3_finalize()] after it has finished with it.4438** ppStmt may not be NULL.4439**4440** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK];4441** otherwise an [error code] is returned.4442**4443** The sqlite3_prepare_v2(), sqlite3_prepare_v3(), sqlite3_prepare16_v2(),4444** and sqlite3_prepare16_v3() interfaces are recommended for all new programs.4445** The older interfaces (sqlite3_prepare() and sqlite3_prepare16())4446** are retained for backwards compatibility, but their use is discouraged.4447** ^In the "vX" interfaces, the prepared statement4448** that is returned (the [sqlite3_stmt] object) contains a copy of the4449** original SQL text. This causes the [sqlite3_step()] interface to4450** behave differently in three ways:4451**4452** <ol>4453** <li>4454** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it4455** always used to do, [sqlite3_step()] will automatically recompile the SQL4456** statement and try to run it again. As many as [SQLITE_MAX_SCHEMA_RETRY]4457** retries will occur before sqlite3_step() gives up and returns an error.4458** </li>4459**4460** <li>4461** ^When an error occurs, [sqlite3_step()] will return one of the detailed4462** [error codes] or [extended error codes]. ^The legacy behavior was that4463** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code4464** and the application would have to make a second call to [sqlite3_reset()]4465** in order to find the underlying cause of the problem. With the "v2" prepare4466** interfaces, the underlying reason for the error is returned immediately.4467** </li>4468**4469** <li>4470** ^If the specific value bound to a [parameter | host parameter] in the4471** WHERE clause might influence the choice of query plan for a statement,4472** then the statement will be automatically recompiled, as if there had been4473** a schema change, on the first [sqlite3_step()] call following any change4474** to the [sqlite3_bind_text | bindings] of that [parameter].4475** ^The specific value of a WHERE-clause [parameter] might influence the4476** choice of query plan if the parameter is the left-hand side of a [LIKE]4477** or [GLOB] operator or if the parameter is compared to an indexed column4478** and the [SQLITE_ENABLE_STAT4] compile-time option is enabled.4479** </li>4480** </ol>4481**4482** <p>^sqlite3_prepare_v3() differs from sqlite3_prepare_v2() only in having4483** the extra prepFlags parameter, which is a bit array consisting of zero or4484** more of the [SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_*] flags. ^The4485** sqlite3_prepare_v2() interface works exactly the same as4486** sqlite3_prepare_v3() with a zero prepFlags parameter.4487*/4488SQLITE_API int sqlite3_prepare(4489sqlite3 *db, /* Database handle */4490const char *zSql, /* SQL statement, UTF-8 encoded */4491int nByte, /* Maximum length of zSql in bytes. */4492sqlite3_stmt **ppStmt, /* OUT: Statement handle */4493const char **pzTail /* OUT: Pointer to unused portion of zSql */4494);4495SQLITE_API int sqlite3_prepare_v2(4496sqlite3 *db, /* Database handle */4497const char *zSql, /* SQL statement, UTF-8 encoded */4498int nByte, /* Maximum length of zSql in bytes. */4499sqlite3_stmt **ppStmt, /* OUT: Statement handle */4500const char **pzTail /* OUT: Pointer to unused portion of zSql */4501);4502SQLITE_API int sqlite3_prepare_v3(4503sqlite3 *db, /* Database handle */4504const char *zSql, /* SQL statement, UTF-8 encoded */4505int nByte, /* Maximum length of zSql in bytes. */4506unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */4507sqlite3_stmt **ppStmt, /* OUT: Statement handle */4508const char **pzTail /* OUT: Pointer to unused portion of zSql */4509);4510SQLITE_API int sqlite3_prepare16(4511sqlite3 *db, /* Database handle */4512const void *zSql, /* SQL statement, UTF-16 encoded */4513int nByte, /* Maximum length of zSql in bytes. */4514sqlite3_stmt **ppStmt, /* OUT: Statement handle */4515const void **pzTail /* OUT: Pointer to unused portion of zSql */4516);4517SQLITE_API int sqlite3_prepare16_v2(4518sqlite3 *db, /* Database handle */4519const void *zSql, /* SQL statement, UTF-16 encoded */4520int nByte, /* Maximum length of zSql in bytes. */4521sqlite3_stmt **ppStmt, /* OUT: Statement handle */4522const void **pzTail /* OUT: Pointer to unused portion of zSql */4523);4524SQLITE_API int sqlite3_prepare16_v3(4525sqlite3 *db, /* Database handle */4526const void *zSql, /* SQL statement, UTF-16 encoded */4527int nByte, /* Maximum length of zSql in bytes. */4528unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_ flags */4529sqlite3_stmt **ppStmt, /* OUT: Statement handle */4530const void **pzTail /* OUT: Pointer to unused portion of zSql */4531);45324533/*4534** CAPI3REF: Retrieving Statement SQL4535** METHOD: sqlite3_stmt4536**4537** ^The sqlite3_sql(P) interface returns a pointer to a copy of the UTF-84538** SQL text used to create [prepared statement] P if P was4539** created by [sqlite3_prepare_v2()], [sqlite3_prepare_v3()],4540** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()].4541** ^The sqlite3_expanded_sql(P) interface returns a pointer to a UTF-84542** string containing the SQL text of prepared statement P with4543** [bound parameters] expanded.4544** ^The sqlite3_normalized_sql(P) interface returns a pointer to a UTF-84545** string containing the normalized SQL text of prepared statement P. The4546** semantics used to normalize a SQL statement are unspecified and subject4547** to change. At a minimum, literal values will be replaced with suitable4548** placeholders.4549**4550** ^(For example, if a prepared statement is created using the SQL4551** text "SELECT $abc,:xyz" and if parameter $abc is bound to integer 23454552** and parameter :xyz is unbound, then sqlite3_sql() will return4553** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql()4554** will return "SELECT 2345,NULL".)^4555**4556** ^The sqlite3_expanded_sql() interface returns NULL if insufficient memory4557** is available to hold the result, or if the result would exceed the4558** the maximum string length determined by the [SQLITE_LIMIT_LENGTH].4559**4560** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of4561** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time4562** option causes sqlite3_expanded_sql() to always return NULL.4563**4564** ^The strings returned by sqlite3_sql(P) and sqlite3_normalized_sql(P)4565** are managed by SQLite and are automatically freed when the prepared4566** statement is finalized.4567** ^The string returned by sqlite3_expanded_sql(P), on the other hand,4568** is obtained from [sqlite3_malloc()] and must be freed by the application4569** by passing it to [sqlite3_free()].4570**4571** ^The sqlite3_normalized_sql() interface is only available if4572** the [SQLITE_ENABLE_NORMALIZE] compile-time option is defined.4573*/4574SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt);4575SQLITE_API char *sqlite3_expanded_sql(sqlite3_stmt *pStmt);4576#ifdef SQLITE_ENABLE_NORMALIZE4577SQLITE_API const char *sqlite3_normalized_sql(sqlite3_stmt *pStmt);4578#endif45794580/*4581** CAPI3REF: Determine If An SQL Statement Writes The Database4582** METHOD: sqlite3_stmt4583**4584** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if4585** and only if the [prepared statement] X makes no direct changes to4586** the content of the database file.4587**4588** Note that [application-defined SQL functions] or4589** [virtual tables] might change the database indirectly as a side effect.4590** ^(For example, if an application defines a function "eval()" that4591** calls [sqlite3_exec()], then the following SQL statement would4592** change the database file through side-effects:4593**4594** <blockquote><pre>4595** SELECT eval('DELETE FROM t1') FROM t2;4596** </pre></blockquote>4597**4598** But because the [SELECT] statement does not change the database file4599** directly, sqlite3_stmt_readonly() would still return true.)^4600**4601** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK],4602** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true,4603** since the statements themselves do not actually modify the database but4604** rather they control the timing of when other statements modify the4605** database. ^The [ATTACH] and [DETACH] statements also cause4606** sqlite3_stmt_readonly() to return true since, while those statements4607** change the configuration of a database connection, they do not make4608** changes to the content of the database files on disk.4609** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since4610** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and4611** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so4612** sqlite3_stmt_readonly() returns false for those commands.4613**4614** ^This routine returns false if there is any possibility that the4615** statement might change the database file. ^A false return does4616** not guarantee that the statement will change the database file.4617** ^For example, an UPDATE statement might have a WHERE clause that4618** makes it a no-op, but the sqlite3_stmt_readonly() result would still4619** be false. ^Similarly, a CREATE TABLE IF NOT EXISTS statement is a4620** read-only no-op if the table already exists, but4621** sqlite3_stmt_readonly() still returns false for such a statement.4622**4623** ^If prepared statement X is an [EXPLAIN] or [EXPLAIN QUERY PLAN]4624** statement, then sqlite3_stmt_readonly(X) returns the same value as4625** if the EXPLAIN or EXPLAIN QUERY PLAN prefix were omitted.4626*/4627SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);46284629/*4630** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement4631** METHOD: sqlite3_stmt4632**4633** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the4634** prepared statement S is an EXPLAIN statement, or 2 if the4635** statement S is an EXPLAIN QUERY PLAN.4636** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is4637** an ordinary statement or a NULL pointer.4638*/4639SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt);46404641/*4642** CAPI3REF: Change The EXPLAIN Setting For A Prepared Statement4643** METHOD: sqlite3_stmt4644**4645** The sqlite3_stmt_explain(S,E) interface changes the EXPLAIN4646** setting for [prepared statement] S. If E is zero, then S becomes4647** a normal prepared statement. If E is 1, then S behaves as if4648** its SQL text began with "[EXPLAIN]". If E is 2, then S behaves as if4649** its SQL text began with "[EXPLAIN QUERY PLAN]".4650**4651** Calling sqlite3_stmt_explain(S,E) might cause S to be reprepared.4652** SQLite tries to avoid a reprepare, but a reprepare might be necessary4653** on the first transition into EXPLAIN or EXPLAIN QUERY PLAN mode.4654**4655** Because of the potential need to reprepare, a call to4656** sqlite3_stmt_explain(S,E) will fail with SQLITE_ERROR if S cannot be4657** reprepared because it was created using [sqlite3_prepare()] instead of4658** the newer [sqlite3_prepare_v2()] or [sqlite3_prepare_v3()] interfaces and4659** hence has no saved SQL text with which to reprepare.4660**4661** Changing the explain setting for a prepared statement does not change4662** the original SQL text for the statement. Hence, if the SQL text originally4663** began with EXPLAIN or EXPLAIN QUERY PLAN, but sqlite3_stmt_explain(S,0)4664** is called to convert the statement into an ordinary statement, the EXPLAIN4665** or EXPLAIN QUERY PLAN keywords will still appear in the sqlite3_sql(S)4666** output, even though the statement now acts like a normal SQL statement.4667**4668** This routine returns SQLITE_OK if the explain mode is successfully4669** changed, or an error code if the explain mode could not be changed.4670** The explain mode cannot be changed while a statement is active.4671** Hence, it is good practice to call [sqlite3_reset(S)]4672** immediately prior to calling sqlite3_stmt_explain(S,E).4673*/4674SQLITE_API int sqlite3_stmt_explain(sqlite3_stmt *pStmt, int eMode);46754676/*4677** CAPI3REF: Determine If A Prepared Statement Has Been Reset4678** METHOD: sqlite3_stmt4679**4680** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the4681** [prepared statement] S has been stepped at least once using4682** [sqlite3_step(S)] but has neither run to completion (returned4683** [SQLITE_DONE] from [sqlite3_step(S)]) nor4684** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S)4685** interface returns false if S is a NULL pointer. If S is not a4686** NULL pointer and is not a pointer to a valid [prepared statement]4687** object, then the behavior is undefined and probably undesirable.4688**4689** This interface can be used in combination [sqlite3_next_stmt()]4690** to locate all prepared statements associated with a database4691** connection that are in need of being reset. This can be used,4692** for example, in diagnostic routines to search for prepared4693** statements that are holding a transaction open.4694*/4695SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*);46964697/*4698** CAPI3REF: Dynamically Typed Value Object4699** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}4700**4701** SQLite uses the sqlite3_value object to represent all values4702** that can be stored in a database table. SQLite uses dynamic typing4703** for the values it stores. ^Values stored in sqlite3_value objects4704** can be integers, floating point values, strings, BLOBs, or NULL.4705**4706** An sqlite3_value object may be either "protected" or "unprotected".4707** Some interfaces require a protected sqlite3_value. Other interfaces4708** will accept either a protected or an unprotected sqlite3_value.4709** Every interface that accepts sqlite3_value arguments specifies4710** whether or not it requires a protected sqlite3_value. The4711** [sqlite3_value_dup()] interface can be used to construct a new4712** protected sqlite3_value from an unprotected sqlite3_value.4713**4714** The terms "protected" and "unprotected" refer to whether or not4715** a mutex is held. An internal mutex is held for a protected4716** sqlite3_value object but no mutex is held for an unprotected4717** sqlite3_value object. If SQLite is compiled to be single-threaded4718** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0)4719** or if SQLite is run in one of reduced mutex modes4720** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD]4721** then there is no distinction between protected and unprotected4722** sqlite3_value objects and they can be used interchangeably. However,4723** for maximum code portability it is recommended that applications4724** still make the distinction between protected and unprotected4725** sqlite3_value objects even when not strictly required.4726**4727** ^The sqlite3_value objects that are passed as parameters into the4728** implementation of [application-defined SQL functions] are protected.4729** ^The sqlite3_value objects returned by [sqlite3_vtab_rhs_value()]4730** are protected.4731** ^The sqlite3_value object returned by4732** [sqlite3_column_value()] is unprotected.4733** Unprotected sqlite3_value objects may only be used as arguments4734** to [sqlite3_result_value()], [sqlite3_bind_value()], and4735** [sqlite3_value_dup()].4736** The [sqlite3_value_blob | sqlite3_value_type()] family of4737** interfaces require protected sqlite3_value objects.4738*/4739typedef struct sqlite3_value sqlite3_value;47404741/*4742** CAPI3REF: SQL Function Context Object4743**4744** The context in which an SQL function executes is stored in an4745** sqlite3_context object. ^A pointer to an sqlite3_context object4746** is always first parameter to [application-defined SQL functions].4747** The application-defined SQL function implementation will pass this4748** pointer through into calls to [sqlite3_result_int | sqlite3_result()],4749** [sqlite3_aggregate_context()], [sqlite3_user_data()],4750** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()],4751** and/or [sqlite3_set_auxdata()].4752*/4753typedef struct sqlite3_context sqlite3_context;47544755/*4756** CAPI3REF: Binding Values To Prepared Statements4757** KEYWORDS: {host parameter} {host parameters} {host parameter name}4758** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}4759** METHOD: sqlite3_stmt4760**4761** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants,4762** literals may be replaced by a [parameter] that matches one of following4763** templates:4764**4765** <ul>4766** <li> ?4767** <li> ?NNN4768** <li> :VVV4769** <li> @VVV4770** <li> $VVV4771** </ul>4772**4773** In the templates above, NNN represents an integer literal,4774** and VVV represents an alphanumeric identifier.)^ ^The values of these4775** parameters (also called "host parameter names" or "SQL parameters")4776** can be set using the sqlite3_bind_*() routines defined here.4777**4778** ^The first argument to the sqlite3_bind_*() routines is always4779** a pointer to the [sqlite3_stmt] object returned from4780** [sqlite3_prepare_v2()] or its variants.4781**4782** ^The second argument is the index of the SQL parameter to be set.4783** ^The leftmost SQL parameter has an index of 1. ^When the same named4784** SQL parameter is used more than once, second and subsequent4785** occurrences have the same index as the first occurrence.4786** ^The index for named parameters can be looked up using the4787** [sqlite3_bind_parameter_index()] API if desired. ^The index4788** for "?NNN" parameters is the value of NNN.4789** ^The NNN value must be between 1 and the [sqlite3_limit()]4790** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 32766).4791**4792** ^The third argument is the value to bind to the parameter.4793** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16()4794** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter4795** is ignored and the end result is the same as sqlite3_bind_null().4796** ^If the third parameter to sqlite3_bind_text() is not NULL, then4797** it should be a pointer to well-formed UTF8 text.4798** ^If the third parameter to sqlite3_bind_text16() is not NULL, then4799** it should be a pointer to well-formed UTF16 text.4800** ^If the third parameter to sqlite3_bind_text64() is not NULL, then4801** it should be a pointer to a well-formed unicode string that is4802** either UTF8 if the sixth parameter is SQLITE_UTF8, or UTF164803** otherwise.4804**4805** [[byte-order determination rules]] ^The byte-order of4806** UTF16 input text is determined by the byte-order mark (BOM, U+FEFF)4807** found in first character, which is removed, or in the absence of a BOM4808** the byte order is the native byte order of the host4809** machine for sqlite3_bind_text16() or the byte order specified in4810** the 6th parameter for sqlite3_bind_text64().)^4811** ^If UTF16 input text contains invalid unicode4812** characters, then SQLite might change those invalid characters4813** into the unicode replacement character: U+FFFD.4814**4815** ^(In those routines that have a fourth argument, its value is the4816** number of bytes in the parameter. To be clear: the value is the4817** number of <u>bytes</u> in the value, not the number of characters.)^4818** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16()4819** is negative, then the length of the string is4820** the number of bytes up to the first zero terminator.4821** If the fourth parameter to sqlite3_bind_blob() is negative, then4822** the behavior is undefined.4823** If a non-negative fourth parameter is provided to sqlite3_bind_text()4824** or sqlite3_bind_text16() or sqlite3_bind_text64() then4825** that parameter must be the byte offset4826** where the NUL terminator would occur assuming the string were NUL4827** terminated. If any NUL characters occurs at byte offsets less than4828** the value of the fourth parameter then the resulting string value will4829** contain embedded NULs. The result of expressions involving strings4830** with embedded NULs is undefined.4831**4832** ^The fifth argument to the BLOB and string binding interfaces controls4833** or indicates the lifetime of the object referenced by the third parameter.4834** These three options exist:4835** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished4836** with it may be passed. ^It is called to dispose of the BLOB or string even4837** if the call to the bind API fails, except the destructor is not called if4838** the third parameter is a NULL pointer or the fourth parameter is negative.4839** ^ (2) The special constant, [SQLITE_STATIC], may be passed to indicate that4840** the application remains responsible for disposing of the object. ^In this4841** case, the object and the provided pointer to it must remain valid until4842** either the prepared statement is finalized or the same SQL parameter is4843** bound to something else, whichever occurs sooner.4844** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the4845** object is to be copied prior to the return from sqlite3_bind_*(). ^The4846** object and pointer to it must remain valid until then. ^SQLite will then4847** manage the lifetime of its private copy.4848**4849** ^The sixth argument to sqlite3_bind_text64() must be one of4850** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]4851** to specify the encoding of the text in the third parameter. If4852** the sixth argument to sqlite3_bind_text64() is not one of the4853** allowed values shown above, or if the text encoding is different4854** from the encoding specified by the sixth parameter, then the behavior4855** is undefined.4856**4857** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that4858** is filled with zeroes. ^A zeroblob uses a fixed amount of memory4859** (just an integer to hold its size) while it is being processed.4860** Zeroblobs are intended to serve as placeholders for BLOBs whose4861** content is later written using4862** [sqlite3_blob_open | incremental BLOB I/O] routines.4863** ^A negative value for the zeroblob results in a zero-length BLOB.4864**4865** ^The sqlite3_bind_pointer(S,I,P,T,D) routine causes the I-th parameter in4866** [prepared statement] S to have an SQL value of NULL, but to also be4867** associated with the pointer P of type T. ^D is either a NULL pointer or4868** a pointer to a destructor function for P. ^SQLite will invoke the4869** destructor D with a single argument of P when it is finished using4870** P. The T parameter should be a static string, preferably a string4871** literal. The sqlite3_bind_pointer() routine is part of the4872** [pointer passing interface] added for SQLite 3.20.0.4873**4874** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer4875** for the [prepared statement] or with a prepared statement for which4876** [sqlite3_step()] has been called more recently than [sqlite3_reset()],4877** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_()4878** routine is passed a [prepared statement] that has been finalized, the4879** result is undefined and probably harmful.4880**4881** ^Bindings are not cleared by the [sqlite3_reset()] routine.4882** ^Unbound parameters are interpreted as NULL.4883**4884** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an4885** [error code] if anything goes wrong.4886** ^[SQLITE_TOOBIG] might be returned if the size of a string or BLOB4887** exceeds limits imposed by [sqlite3_limit]([SQLITE_LIMIT_LENGTH]) or4888** [SQLITE_MAX_LENGTH].4889** ^[SQLITE_RANGE] is returned if the parameter4890** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails.4891**4892** See also: [sqlite3_bind_parameter_count()],4893** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()].4894*/4895SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));4896SQLITE_API int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,4897void(*)(void*));4898SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double);4899SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int);4900SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);4901SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int);4902SQLITE_API int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));4903SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*));4904SQLITE_API int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,4905void(*)(void*), unsigned char encoding);4906SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);4907SQLITE_API int sqlite3_bind_pointer(sqlite3_stmt*, int, void*, const char*,void(*)(void*));4908SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n);4909SQLITE_API int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64);49104911/*4912** CAPI3REF: Number Of SQL Parameters4913** METHOD: sqlite3_stmt4914**4915** ^This routine can be used to find the number of [SQL parameters]4916** in a [prepared statement]. SQL parameters are tokens of the4917** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as4918** placeholders for values that are [sqlite3_bind_blob | bound]4919** to the parameters at a later time.4920**4921** ^(This routine actually returns the index of the largest (rightmost)4922** parameter. For all forms except ?NNN, this will correspond to the4923** number of unique parameters. If parameters of the ?NNN form are used,4924** there may be gaps in the list.)^4925**4926** See also: [sqlite3_bind_blob|sqlite3_bind()],4927** [sqlite3_bind_parameter_name()], and4928** [sqlite3_bind_parameter_index()].4929*/4930SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*);49314932/*4933** CAPI3REF: Name Of A Host Parameter4934** METHOD: sqlite3_stmt4935**4936** ^The sqlite3_bind_parameter_name(P,N) interface returns4937** the name of the N-th [SQL parameter] in the [prepared statement] P.4938** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA"4939** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA"4940** respectively.4941** In other words, the initial ":" or "$" or "@" or "?"4942** is included as part of the name.)^4943** ^Parameters of the form "?" without a following integer have no name4944** and are referred to as "nameless" or "anonymous parameters".4945**4946** ^The first host parameter has an index of 1, not 0.4947**4948** ^If the value N is out of range or if the N-th parameter is4949** nameless, then NULL is returned. ^The returned string is4950** always in UTF-8 encoding even if the named parameter was4951** originally specified as UTF-16 in [sqlite3_prepare16()],4952** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()].4953**4954** See also: [sqlite3_bind_blob|sqlite3_bind()],4955** [sqlite3_bind_parameter_count()], and4956** [sqlite3_bind_parameter_index()].4957*/4958SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);49594960/*4961** CAPI3REF: Index Of A Parameter With A Given Name4962** METHOD: sqlite3_stmt4963**4964** ^Return the index of an SQL parameter given its name. ^The4965** index value returned is suitable for use as the second4966** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero4967** is returned if no matching parameter is found. ^The parameter4968** name must be given in UTF-8 even if the original statement4969** was prepared from UTF-16 text using [sqlite3_prepare16_v2()] or4970** [sqlite3_prepare16_v3()].4971**4972** See also: [sqlite3_bind_blob|sqlite3_bind()],4973** [sqlite3_bind_parameter_count()], and4974** [sqlite3_bind_parameter_name()].4975*/4976SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);49774978/*4979** CAPI3REF: Reset All Bindings On A Prepared Statement4980** METHOD: sqlite3_stmt4981**4982** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset4983** the [sqlite3_bind_blob | bindings] on a [prepared statement].4984** ^Use this routine to reset all host parameters to NULL.4985*/4986SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*);49874988/*4989** CAPI3REF: Number Of Columns In A Result Set4990** METHOD: sqlite3_stmt4991**4992** ^Return the number of columns in the result set returned by the4993** [prepared statement]. ^If this routine returns 0, that means the4994** [prepared statement] returns no data (for example an [UPDATE]).4995** ^However, just because this routine returns a positive number does not4996** mean that one or more rows of data will be returned. ^A SELECT statement4997** will always have a positive sqlite3_column_count() but depending on the4998** WHERE clause constraints and the table content, it might return no rows.4999**5000** See also: [sqlite3_data_count()]5001*/5002SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt);50035004/*5005** CAPI3REF: Column Names In A Result Set5006** METHOD: sqlite3_stmt5007**5008** ^These routines return the name assigned to a particular column5009** in the result set of a [SELECT] statement. ^The sqlite3_column_name()5010** interface returns a pointer to a zero-terminated UTF-8 string5011** and sqlite3_column_name16() returns a pointer to a zero-terminated5012** UTF-16 string. ^The first parameter is the [prepared statement]5013** that implements the [SELECT] statement. ^The second parameter is the5014** column number. ^The leftmost column is number 0.5015**5016** ^The returned string pointer is valid until either the [prepared statement]5017** is destroyed by [sqlite3_finalize()] or until the statement is automatically5018** reprepared by the first call to [sqlite3_step()] for a particular run5019** or until the next call to5020** sqlite3_column_name() or sqlite3_column_name16() on the same column.5021**5022** ^If sqlite3_malloc() fails during the processing of either routine5023** (for example during a conversion from UTF-8 to UTF-16) then a5024** NULL pointer is returned.5025**5026** ^The name of a result column is the value of the "AS" clause for5027** that column, if there is an AS clause. If there is no AS clause5028** then the name of the column is unspecified and may change from5029** one release of SQLite to the next.5030*/5031SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N);5032SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N);50335034/*5035** CAPI3REF: Source Of Data In A Query Result5036** METHOD: sqlite3_stmt5037**5038** ^These routines provide a means to determine the database, table, and5039** table column that is the origin of a particular result column in5040** [SELECT] statement.5041** ^The name of the database or table or column can be returned as5042** either a UTF-8 or UTF-16 string. ^The _database_ routines return5043** the database name, the _table_ routines return the table name, and5044** the origin_ routines return the column name.5045** ^The returned string is valid until the [prepared statement] is destroyed5046** using [sqlite3_finalize()] or until the statement is automatically5047** reprepared by the first call to [sqlite3_step()] for a particular run5048** or until the same information is requested5049** again in a different encoding.5050**5051** ^The names returned are the original un-aliased names of the5052** database, table, and column.5053**5054** ^The first argument to these interfaces is a [prepared statement].5055** ^These functions return information about the Nth result column returned by5056** the statement, where N is the second function argument.5057** ^The left-most column is column 0 for these routines.5058**5059** ^If the Nth column returned by the statement is an expression or5060** subquery and is not a column value, then all of these functions return5061** NULL. ^These routines might also return NULL if a memory allocation error5062** occurs. ^Otherwise, they return the name of the attached database, table,5063** or column that query result column was extracted from.5064**5065** ^As with all other SQLite APIs, those whose names end with "16" return5066** UTF-16 encoded strings and the other functions return UTF-8.5067**5068** ^These APIs are only available if the library was compiled with the5069** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol.5070**5071** If two or more threads call one or more5072** [sqlite3_column_database_name | column metadata interfaces]5073** for the same [prepared statement] and result column5074** at the same time then the results are undefined.5075*/5076SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int);5077SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int);5078SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int);5079SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int);5080SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int);5081SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int);50825083/*5084** CAPI3REF: Declared Datatype Of A Query Result5085** METHOD: sqlite3_stmt5086**5087** ^(The first parameter is a [prepared statement].5088** If this statement is a [SELECT] statement and the Nth column of the5089** returned result set of that [SELECT] is a table column (not an5090** expression or subquery) then the declared type of the table5091** column is returned.)^ ^If the Nth column of the result set is an5092** expression or subquery, then a NULL pointer is returned.5093** ^The returned string is always UTF-8 encoded.5094**5095** ^(For example, given the database schema:5096**5097** CREATE TABLE t1(c1 VARIANT);5098**5099** and the following statement to be compiled:5100**5101** SELECT c1 + 1, c1 FROM t1;5102**5103** this routine would return the string "VARIANT" for the second result5104** column (i==1), and a NULL pointer for the first result column (i==0).)^5105**5106** ^SQLite uses dynamic run-time typing. ^So just because a column5107** is declared to contain a particular type does not mean that the5108** data stored in that column is of the declared type. SQLite is5109** strongly typed, but the typing is dynamic not static. ^Type5110** is associated with individual values, not with the containers5111** used to hold those values.5112*/5113SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int);5114SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int);51155116/*5117** CAPI3REF: Evaluate An SQL Statement5118** METHOD: sqlite3_stmt5119**5120** After a [prepared statement] has been prepared using any of5121** [sqlite3_prepare_v2()], [sqlite3_prepare_v3()], [sqlite3_prepare16_v2()],5122** or [sqlite3_prepare16_v3()] or one of the legacy5123** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function5124** must be called one or more times to evaluate the statement.5125**5126** The details of the behavior of the sqlite3_step() interface depend5127** on whether the statement was prepared using the newer "vX" interfaces5128** [sqlite3_prepare_v3()], [sqlite3_prepare_v2()], [sqlite3_prepare16_v3()],5129** [sqlite3_prepare16_v2()] or the older legacy5130** interfaces [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the5131** new "vX" interface is recommended for new applications but the legacy5132** interface will continue to be supported.5133**5134** ^In the legacy interface, the return value will be either [SQLITE_BUSY],5135** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].5136** ^With the "v2" interface, any of the other [result codes] or5137** [extended result codes] might be returned as well.5138**5139** ^[SQLITE_BUSY] means that the database engine was unable to acquire the5140** database locks it needs to do its job. ^If the statement is a [COMMIT]5141** or occurs outside of an explicit transaction, then you can retry the5142** statement. If the statement is not a [COMMIT] and occurs within an5143** explicit transaction then you should rollback the transaction before5144** continuing.5145**5146** ^[SQLITE_DONE] means that the statement has finished executing5147** successfully. sqlite3_step() should not be called again on this virtual5148** machine without first calling [sqlite3_reset()] to reset the virtual5149** machine back to its initial state.5150**5151** ^If the SQL statement being executed returns any data, then [SQLITE_ROW]5152** is returned each time a new row of data is ready for processing by the5153** caller. The values may be accessed using the [column access functions].5154** sqlite3_step() is called again to retrieve the next row of data.5155**5156** ^[SQLITE_ERROR] means that a run-time error (such as a constraint5157** violation) has occurred. sqlite3_step() should not be called again on5158** the VM. More information may be found by calling [sqlite3_errmsg()].5159** ^With the legacy interface, a more specific error code (for example,5160** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)5161** can be obtained by calling [sqlite3_reset()] on the5162** [prepared statement]. ^In the "v2" interface,5163** the more specific error code is returned directly by sqlite3_step().5164**5165** [SQLITE_MISUSE] means that the this routine was called inappropriately.5166** Perhaps it was called on a [prepared statement] that has5167** already been [sqlite3_finalize | finalized] or on one that had5168** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could5169** be the case that the same database connection is being used by two or5170** more threads at the same moment in time.5171**5172** For all versions of SQLite up to and including 3.6.23.1, a call to5173** [sqlite3_reset()] was required after sqlite3_step() returned anything5174** other than [SQLITE_ROW] before any subsequent invocation of5175** sqlite3_step(). Failure to reset the prepared statement using5176** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from5177** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1]),5178** sqlite3_step() began5179** calling [sqlite3_reset()] automatically in this circumstance rather5180** than returning [SQLITE_MISUSE]. This is not considered a compatibility5181** break because any application that ever receives an SQLITE_MISUSE error5182** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option5183** can be used to restore the legacy behavior.5184**5185** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step()5186** API always returns a generic error code, [SQLITE_ERROR], following any5187** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call5188** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the5189** specific [error codes] that better describes the error.5190** We admit that this is a goofy design. The problem has been fixed5191** with the "v2" interface. If you prepare all of your SQL statements5192** using [sqlite3_prepare_v3()] or [sqlite3_prepare_v2()]5193** or [sqlite3_prepare16_v2()] or [sqlite3_prepare16_v3()] instead5194** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces,5195** then the more specific [error codes] are returned directly5196** by sqlite3_step(). The use of the "vX" interfaces is recommended.5197*/5198SQLITE_API int sqlite3_step(sqlite3_stmt*);51995200/*5201** CAPI3REF: Number of columns in a result set5202** METHOD: sqlite3_stmt5203**5204** ^The sqlite3_data_count(P) interface returns the number of columns in the5205** current row of the result set of [prepared statement] P.5206** ^If prepared statement P does not have results ready to return5207** (via calls to the [sqlite3_column_int | sqlite3_column()] family of5208** interfaces) then sqlite3_data_count(P) returns 0.5209** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer.5210** ^The sqlite3_data_count(P) routine returns 0 if the previous call to5211** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P)5212** will return non-zero if previous call to [sqlite3_step](P) returned5213** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum]5214** where it always returns zero since each step of that multi-step5215** pragma returns 0 columns of data.5216**5217** See also: [sqlite3_column_count()]5218*/5219SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt);52205221/*5222** CAPI3REF: Fundamental Datatypes5223** KEYWORDS: SQLITE_TEXT5224**5225** ^(Every value in SQLite has one of five fundamental datatypes:5226**5227** <ul>5228** <li> 64-bit signed integer5229** <li> 64-bit IEEE floating point number5230** <li> string5231** <li> BLOB5232** <li> NULL5233** </ul>)^5234**5235** These constants are codes for each of those types.5236**5237** Note that the SQLITE_TEXT constant was also used in SQLite version 25238** for a completely different meaning. Software that links against both5239** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not5240** SQLITE_TEXT.5241*/5242#define SQLITE_INTEGER 15243#define SQLITE_FLOAT 25244#define SQLITE_BLOB 45245#define SQLITE_NULL 55246#ifdef SQLITE_TEXT5247# undef SQLITE_TEXT5248#else5249# define SQLITE_TEXT 35250#endif5251#define SQLITE3_TEXT 352525253/*5254** CAPI3REF: Result Values From A Query5255** KEYWORDS: {column access functions}5256** METHOD: sqlite3_stmt5257**5258** <b>Summary:</b>5259** <blockquote><table border=0 cellpadding=0 cellspacing=0>5260** <tr><td><b>sqlite3_column_blob</b><td>→<td>BLOB result5261** <tr><td><b>sqlite3_column_double</b><td>→<td>REAL result5262** <tr><td><b>sqlite3_column_int</b><td>→<td>32-bit INTEGER result5263** <tr><td><b>sqlite3_column_int64</b><td>→<td>64-bit INTEGER result5264** <tr><td><b>sqlite3_column_text</b><td>→<td>UTF-8 TEXT result5265** <tr><td><b>sqlite3_column_text16</b><td>→<td>UTF-16 TEXT result5266** <tr><td><b>sqlite3_column_value</b><td>→<td>The result as an5267** [sqlite3_value|unprotected sqlite3_value] object.5268** <tr><td> <td> <td> 5269** <tr><td><b>sqlite3_column_bytes</b><td>→<td>Size of a BLOB5270** or a UTF-8 TEXT result in bytes5271** <tr><td><b>sqlite3_column_bytes16 </b>5272** <td>→ <td>Size of UTF-165273** TEXT in bytes5274** <tr><td><b>sqlite3_column_type</b><td>→<td>Default5275** datatype of the result5276** </table></blockquote>5277**5278** <b>Details:</b>5279**5280** ^These routines return information about a single column of the current5281** result row of a query. ^In every case the first argument is a pointer5282** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*]5283** that was returned from [sqlite3_prepare_v2()] or one of its variants)5284** and the second argument is the index of the column for which information5285** should be returned. ^The leftmost column of the result set has the index 0.5286** ^The number of columns in the result can be determined using5287** [sqlite3_column_count()].5288**5289** If the SQL statement does not currently point to a valid row, or if the5290** column index is out of range, the result is undefined.5291** These routines may only be called when the most recent call to5292** [sqlite3_step()] has returned [SQLITE_ROW] and neither5293** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently.5294** If any of these routines are called after [sqlite3_reset()] or5295** [sqlite3_finalize()] or after [sqlite3_step()] has returned5296** something other than [SQLITE_ROW], the results are undefined.5297** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()]5298** are called from a different thread while any of these routines5299** are pending, then the results are undefined.5300**5301** The first six interfaces (_blob, _double, _int, _int64, _text, and _text16)5302** each return the value of a result column in a specific data format. If5303** the result column is not initially in the requested format (for example,5304** if the query returns an integer but the sqlite3_column_text() interface5305** is used to extract the value) then an automatic type conversion is performed.5306**5307** ^The sqlite3_column_type() routine returns the5308** [SQLITE_INTEGER | datatype code] for the initial data type5309** of the result column. ^The returned value is one of [SQLITE_INTEGER],5310** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].5311** The return value of sqlite3_column_type() can be used to decide which5312** of the first six interface should be used to extract the column value.5313** The value returned by sqlite3_column_type() is only meaningful if no5314** automatic type conversions have occurred for the value in question.5315** After a type conversion, the result of calling sqlite3_column_type()5316** is undefined, though harmless. Future5317** versions of SQLite may change the behavior of sqlite3_column_type()5318** following a type conversion.5319**5320** If the result is a BLOB or a TEXT string, then the sqlite3_column_bytes()5321** or sqlite3_column_bytes16() interfaces can be used to determine the size5322** of that BLOB or string.5323**5324** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes()5325** routine returns the number of bytes in that BLOB or string.5326** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts5327** the string to UTF-8 and then returns the number of bytes.5328** ^If the result is a numeric value then sqlite3_column_bytes() uses5329** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns5330** the number of bytes in that string.5331** ^If the result is NULL, then sqlite3_column_bytes() returns zero.5332**5333** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16()5334** routine returns the number of bytes in that BLOB or string.5335** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts5336** the string to UTF-16 and then returns the number of bytes.5337** ^If the result is a numeric value then sqlite3_column_bytes16() uses5338** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns5339** the number of bytes in that string.5340** ^If the result is NULL, then sqlite3_column_bytes16() returns zero.5341**5342** ^The values returned by [sqlite3_column_bytes()] and5343** [sqlite3_column_bytes16()] do not include the zero terminators at the end5344** of the string. ^For clarity: the values returned by5345** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of5346** bytes in the string, not the number of characters.5347**5348** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(),5349** even empty strings, are always zero-terminated. ^The return5350** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer.5351**5352** ^Strings returned by sqlite3_column_text16() always have the endianness5353** which is native to the platform, regardless of the text encoding set5354** for the database.5355**5356** <b>Warning:</b> ^The object returned by [sqlite3_column_value()] is an5357** [unprotected sqlite3_value] object. In a multithreaded environment,5358** an unprotected sqlite3_value object may only be used safely with5359** [sqlite3_bind_value()] and [sqlite3_result_value()].5360** If the [unprotected sqlite3_value] object returned by5361** [sqlite3_column_value()] is used in any other way, including calls5362** to routines like [sqlite3_value_int()], [sqlite3_value_text()],5363** or [sqlite3_value_bytes()], the behavior is not threadsafe.5364** Hence, the sqlite3_column_value() interface5365** is normally only useful within the implementation of5366** [application-defined SQL functions] or [virtual tables], not within5367** top-level application code.5368**5369** These routines may attempt to convert the datatype of the result.5370** ^For example, if the internal representation is FLOAT and a text result5371** is requested, [sqlite3_snprintf()] is used internally to perform the5372** conversion automatically. ^(The following table details the conversions5373** that are applied:5374**5375** <blockquote>5376** <table border="1">5377** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion5378**5379** <tr><td> NULL <td> INTEGER <td> Result is 05380** <tr><td> NULL <td> FLOAT <td> Result is 0.05381** <tr><td> NULL <td> TEXT <td> Result is a NULL pointer5382** <tr><td> NULL <td> BLOB <td> Result is a NULL pointer5383** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float5384** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer5385** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT5386** <tr><td> FLOAT <td> INTEGER <td> [CAST] to INTEGER5387** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float5388** <tr><td> FLOAT <td> BLOB <td> [CAST] to BLOB5389** <tr><td> TEXT <td> INTEGER <td> [CAST] to INTEGER5390** <tr><td> TEXT <td> FLOAT <td> [CAST] to REAL5391** <tr><td> TEXT <td> BLOB <td> No change5392** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER5393** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL5394** <tr><td> BLOB <td> TEXT <td> [CAST] to TEXT, ensure zero terminator5395** </table>5396** </blockquote>)^5397**5398** Note that when type conversions occur, pointers returned by prior5399** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or5400** sqlite3_column_text16() may be invalidated.5401** Type conversions and pointer invalidations might occur5402** in the following cases:5403**5404** <ul>5405** <li> The initial content is a BLOB and sqlite3_column_text() or5406** sqlite3_column_text16() is called. A zero-terminator might5407** need to be added to the string.</li>5408** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or5409** sqlite3_column_text16() is called. The content must be converted5410** to UTF-16.</li>5411** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or5412** sqlite3_column_text() is called. The content must be converted5413** to UTF-8.</li>5414** </ul>5415**5416** ^Conversions between UTF-16be and UTF-16le are always done in place and do5417** not invalidate a prior pointer, though of course the content of the buffer5418** that the prior pointer references will have been modified. Other kinds5419** of conversion are done in place when it is possible, but sometimes they5420** are not possible and in those cases prior pointers are invalidated.5421**5422** The safest policy is to invoke these routines5423** in one of the following ways:5424**5425** <ul>5426** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li>5427** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li>5428** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li>5429** </ul>5430**5431** In other words, you should call sqlite3_column_text(),5432** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result5433** into the desired format, then invoke sqlite3_column_bytes() or5434** sqlite3_column_bytes16() to find the size of the result. Do not mix calls5435** to sqlite3_column_text() or sqlite3_column_blob() with calls to5436** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16()5437** with calls to sqlite3_column_bytes().5438**5439** ^The pointers returned are valid until a type conversion occurs as5440** described above, or until [sqlite3_step()] or [sqlite3_reset()] or5441** [sqlite3_finalize()] is called. ^The memory space used to hold strings5442** and BLOBs is freed automatically. Do not pass the pointers returned5443** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into5444** [sqlite3_free()].5445**5446** As long as the input parameters are correct, these routines will only5447** fail if an out-of-memory error occurs during a format conversion.5448** Only the following subset of interfaces are subject to out-of-memory5449** errors:5450**5451** <ul>5452** <li> sqlite3_column_blob()5453** <li> sqlite3_column_text()5454** <li> sqlite3_column_text16()5455** <li> sqlite3_column_bytes()5456** <li> sqlite3_column_bytes16()5457** </ul>5458**5459** If an out-of-memory error occurs, then the return value from these5460** routines is the same as if the column had contained an SQL NULL value.5461** Valid SQL NULL returns can be distinguished from out-of-memory errors5462** by invoking the [sqlite3_errcode()] immediately after the suspect5463** return value is obtained and before any5464** other SQLite interface is called on the same [database connection].5465*/5466SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);5467SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol);5468SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol);5469SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);5470SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);5471SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol);5472SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);5473SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol);5474SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol);5475SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol);54765477/*5478** CAPI3REF: Destroy A Prepared Statement Object5479** DESTRUCTOR: sqlite3_stmt5480**5481** ^The sqlite3_finalize() function is called to delete a [prepared statement].5482** ^If the most recent evaluation of the statement encountered no errors5483** or if the statement is never been evaluated, then sqlite3_finalize() returns5484** SQLITE_OK. ^If the most recent evaluation of statement S failed, then5485** sqlite3_finalize(S) returns the appropriate [error code] or5486** [extended error code].5487**5488** ^The sqlite3_finalize(S) routine can be called at any point during5489** the life cycle of [prepared statement] S:5490** before statement S is ever evaluated, after5491** one or more calls to [sqlite3_reset()], or after any call5492** to [sqlite3_step()] regardless of whether or not the statement has5493** completed execution.5494**5495** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op.5496**5497** The application must finalize every [prepared statement] in order to avoid5498** resource leaks. It is a grievous error for the application to try to use5499** a prepared statement after it has been finalized. Any use of a prepared5500** statement after it has been finalized can result in undefined and5501** undesirable behavior such as segfaults and heap corruption.5502*/5503SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt);55045505/*5506** CAPI3REF: Reset A Prepared Statement Object5507** METHOD: sqlite3_stmt5508**5509** The sqlite3_reset() function is called to reset a [prepared statement]5510** object back to its initial state, ready to be re-executed.5511** ^Any SQL statement variables that had values bound to them using5512** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values.5513** Use [sqlite3_clear_bindings()] to reset the bindings.5514**5515** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S5516** back to the beginning of its program.5517**5518** ^The return code from [sqlite3_reset(S)] indicates whether or not5519** the previous evaluation of prepared statement S completed successfully.5520** ^If [sqlite3_step(S)] has never before been called on S or if5521** [sqlite3_step(S)] has not been called since the previous call5522** to [sqlite3_reset(S)], then [sqlite3_reset(S)] will return5523** [SQLITE_OK].5524**5525** ^If the most recent call to [sqlite3_step(S)] for the5526** [prepared statement] S indicated an error, then5527** [sqlite3_reset(S)] returns an appropriate [error code].5528** ^The [sqlite3_reset(S)] interface might also return an [error code]5529** if there were no prior errors but the process of resetting5530** the prepared statement caused a new error. ^For example, if an5531** [INSERT] statement with a [RETURNING] clause is only stepped one time,5532** that one call to [sqlite3_step(S)] might return SQLITE_ROW but5533** the overall statement might still fail and the [sqlite3_reset(S)] call5534** might return SQLITE_BUSY if locking constraints prevent the5535** database change from committing. Therefore, it is important that5536** applications check the return code from [sqlite3_reset(S)] even if5537** no prior call to [sqlite3_step(S)] indicated a problem.5538**5539** ^The [sqlite3_reset(S)] interface does not change the values5540** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S.5541*/5542SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);554355445545/*5546** CAPI3REF: Create Or Redefine SQL Functions5547** KEYWORDS: {function creation routines}5548** METHOD: sqlite35549**5550** ^These functions (collectively known as "function creation routines")5551** are used to add SQL functions or aggregates or to redefine the behavior5552** of existing SQL functions or aggregates. The only differences between5553** the three "sqlite3_create_function*" routines are the text encoding5554** expected for the second parameter (the name of the function being5555** created) and the presence or absence of a destructor callback for5556** the application data pointer. Function sqlite3_create_window_function()5557** is similar, but allows the user to supply the extra callback functions5558** needed by [aggregate window functions].5559**5560** ^The first parameter is the [database connection] to which the SQL5561** function is to be added. ^If an application uses more than one database5562** connection then application-defined SQL functions must be added5563** to each database connection separately.5564**5565** ^The second parameter is the name of the SQL function to be created or5566** redefined. ^The length of the name is limited to 255 bytes in a UTF-85567** representation, exclusive of the zero-terminator. ^Note that the name5568** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes.5569** ^Any attempt to create a function with a longer name5570** will result in [SQLITE_MISUSE] being returned.5571**5572** ^The third parameter (nArg)5573** is the number of arguments that the SQL function or5574** aggregate takes. ^If this parameter is -1, then the SQL function or5575** aggregate may take any number of arguments between 0 and the limit5576** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third5577** parameter is less than -1 or greater than 127 then the behavior is5578** undefined.5579**5580** ^The fourth parameter, eTextRep, specifies what5581** [SQLITE_UTF8 | text encoding] this SQL function prefers for5582** its parameters. The application should set this parameter to5583** [SQLITE_UTF16LE] if the function implementation invokes5584** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the5585** implementation invokes [sqlite3_value_text16be()] on an input, or5586** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8]5587** otherwise. ^The same SQL function may be registered multiple times using5588** different preferred text encodings, with different implementations for5589** each encoding.5590** ^When multiple implementations of the same function are available, SQLite5591** will pick the one that involves the least amount of data conversion.5592**5593** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC]5594** to signal that the function will always return the same result given5595** the same inputs within a single SQL statement. Most SQL functions are5596** deterministic. The built-in [random()] SQL function is an example of a5597** function that is not deterministic. The SQLite query planner is able to5598** perform additional optimizations on deterministic functions, so use5599** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.5600**5601** ^The fourth parameter may also optionally include the [SQLITE_DIRECTONLY]5602** flag, which if present prevents the function from being invoked from5603** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions,5604** index expressions, or the WHERE clause of partial indexes.5605**5606** For best security, the [SQLITE_DIRECTONLY] flag is recommended for5607** all application-defined SQL functions that do not need to be5608** used inside of triggers, view, CHECK constraints, or other elements of5609** the database schema. This flags is especially recommended for SQL5610** functions that have side effects or reveal internal application state.5611** Without this flag, an attacker might be able to modify the schema of5612** a database file to include invocations of the function with parameters5613** chosen by the attacker, which the application will then execute when5614** the database file is opened and read.5615**5616** ^(The fifth parameter is an arbitrary pointer. The implementation of the5617** function can gain access to this pointer using [sqlite3_user_data()].)^5618**5619** ^The sixth, seventh and eighth parameters passed to the three5620** "sqlite3_create_function*" functions, xFunc, xStep and xFinal, are5621** pointers to C-language functions that implement the SQL function or5622** aggregate. ^A scalar SQL function requires an implementation of the xFunc5623** callback only; NULL pointers must be passed as the xStep and xFinal5624** parameters. ^An aggregate SQL function requires an implementation of xStep5625** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing5626** SQL function or aggregate, pass NULL pointers for all three function5627** callbacks.5628**5629** ^The sixth, seventh, eighth and ninth parameters (xStep, xFinal, xValue5630** and xInverse) passed to sqlite3_create_window_function are pointers to5631** C-language callbacks that implement the new function. xStep and xFinal5632** must both be non-NULL. xValue and xInverse may either both be NULL, in5633** which case a regular aggregate function is created, or must both be5634** non-NULL, in which case the new function may be used as either an aggregate5635** or aggregate window function. More details regarding the implementation5636** of aggregate window functions are5637** [user-defined window functions|available here].5638**5639** ^(If the final parameter to sqlite3_create_function_v2() or5640** sqlite3_create_window_function() is not NULL, then it is destructor for5641** the application data pointer. The destructor is invoked when the function5642** is deleted, either by being overloaded or when the database connection5643** closes.)^ ^The destructor is also invoked if the call to5644** sqlite3_create_function_v2() fails. ^When the destructor callback is5645** invoked, it is passed a single argument which is a copy of the application5646** data pointer which was the fifth parameter to sqlite3_create_function_v2().5647**5648** ^It is permitted to register multiple implementations of the same5649** functions with the same name but with either differing numbers of5650** arguments or differing preferred text encodings. ^SQLite will use5651** the implementation that most closely matches the way in which the5652** SQL function is used. ^A function implementation with a non-negative5653** nArg parameter is a better match than a function implementation with5654** a negative nArg. ^A function where the preferred text encoding5655** matches the database encoding is a better5656** match than a function where the encoding is different.5657** ^A function where the encoding difference is between UTF16le and UTF16be5658** is a closer match than a function where the encoding difference is5659** between UTF8 and UTF16.5660**5661** ^Built-in functions may be overloaded by new application-defined functions.5662**5663** ^An application-defined function is permitted to call other5664** SQLite interfaces. However, such calls must not5665** close the database connection nor finalize or reset the prepared5666** statement in which the function is running.5667*/5668SQLITE_API int sqlite3_create_function(5669sqlite3 *db,5670const char *zFunctionName,5671int nArg,5672int eTextRep,5673void *pApp,5674void (*xFunc)(sqlite3_context*,int,sqlite3_value**),5675void (*xStep)(sqlite3_context*,int,sqlite3_value**),5676void (*xFinal)(sqlite3_context*)5677);5678SQLITE_API int sqlite3_create_function16(5679sqlite3 *db,5680const void *zFunctionName,5681int nArg,5682int eTextRep,5683void *pApp,5684void (*xFunc)(sqlite3_context*,int,sqlite3_value**),5685void (*xStep)(sqlite3_context*,int,sqlite3_value**),5686void (*xFinal)(sqlite3_context*)5687);5688SQLITE_API int sqlite3_create_function_v2(5689sqlite3 *db,5690const char *zFunctionName,5691int nArg,5692int eTextRep,5693void *pApp,5694void (*xFunc)(sqlite3_context*,int,sqlite3_value**),5695void (*xStep)(sqlite3_context*,int,sqlite3_value**),5696void (*xFinal)(sqlite3_context*),5697void(*xDestroy)(void*)5698);5699SQLITE_API int sqlite3_create_window_function(5700sqlite3 *db,5701const char *zFunctionName,5702int nArg,5703int eTextRep,5704void *pApp,5705void (*xStep)(sqlite3_context*,int,sqlite3_value**),5706void (*xFinal)(sqlite3_context*),5707void (*xValue)(sqlite3_context*),5708void (*xInverse)(sqlite3_context*,int,sqlite3_value**),5709void(*xDestroy)(void*)5710);57115712/*5713** CAPI3REF: Text Encodings5714**5715** These constant define integer codes that represent the various5716** text encodings supported by SQLite.5717*/5718#define SQLITE_UTF8 1 /* IMP: R-37514-35566 */5719#define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */5720#define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */5721#define SQLITE_UTF16 4 /* Use native byte order */5722#define SQLITE_ANY 5 /* Deprecated */5723#define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */57245725/*5726** CAPI3REF: Function Flags5727**5728** These constants may be ORed together with the5729** [SQLITE_UTF8 | preferred text encoding] as the fourth argument5730** to [sqlite3_create_function()], [sqlite3_create_function16()], or5731** [sqlite3_create_function_v2()].5732**5733** <dl>5734** [[SQLITE_DETERMINISTIC]] <dt>SQLITE_DETERMINISTIC</dt><dd>5735** The SQLITE_DETERMINISTIC flag means that the new function always gives5736** the same output when the input parameters are the same.5737** The [abs|abs() function] is deterministic, for example, but5738** [randomblob|randomblob()] is not. Functions must5739** be deterministic in order to be used in certain contexts such as5740** with the WHERE clause of [partial indexes] or in [generated columns].5741** SQLite might also optimize deterministic functions by factoring them5742** out of inner loops.5743** </dd>5744**5745** [[SQLITE_DIRECTONLY]] <dt>SQLITE_DIRECTONLY</dt><dd>5746** The SQLITE_DIRECTONLY flag means that the function may only be invoked5747** from top-level SQL, and cannot be used in VIEWs or TRIGGERs nor in5748** schema structures such as [CHECK constraints], [DEFAULT clauses],5749** [expression indexes], [partial indexes], or [generated columns].5750** <p>5751** The SQLITE_DIRECTONLY flag is recommended for any5752** [application-defined SQL function]5753** that has side-effects or that could potentially leak sensitive information.5754** This will prevent attacks in which an application is tricked5755** into using a database file that has had its schema surreptitiously5756** modified to invoke the application-defined function in ways that are5757** harmful.5758** <p>5759** Some people say it is good practice to set SQLITE_DIRECTONLY on all5760** [application-defined SQL functions], regardless of whether or not they5761** are security sensitive, as doing so prevents those functions from being used5762** inside of the database schema, and thus ensures that the database5763** can be inspected and modified using generic tools (such as the [CLI])5764** that do not have access to the application-defined functions.5765** </dd>5766**5767** [[SQLITE_INNOCUOUS]] <dt>SQLITE_INNOCUOUS</dt><dd>5768** The SQLITE_INNOCUOUS flag means that the function is unlikely5769** to cause problems even if misused. An innocuous function should have5770** no side effects and should not depend on any values other than its5771** input parameters. The [abs|abs() function] is an example of an5772** innocuous function.5773** The [load_extension() SQL function] is not innocuous because of its5774** side effects.5775** <p> SQLITE_INNOCUOUS is similar to SQLITE_DETERMINISTIC, but is not5776** exactly the same. The [random|random() function] is an example of a5777** function that is innocuous but not deterministic.5778** <p>Some heightened security settings5779** ([SQLITE_DBCONFIG_TRUSTED_SCHEMA] and [PRAGMA trusted_schema=OFF])5780** disable the use of SQL functions inside views and triggers and in5781** schema structures such as [CHECK constraints], [DEFAULT clauses],5782** [expression indexes], [partial indexes], and [generated columns] unless5783** the function is tagged with SQLITE_INNOCUOUS. Most built-in functions5784** are innocuous. Developers are advised to avoid using the5785** SQLITE_INNOCUOUS flag for application-defined functions unless the5786** function has been carefully audited and found to be free of potentially5787** security-adverse side-effects and information-leaks.5788** </dd>5789**5790** [[SQLITE_SUBTYPE]] <dt>SQLITE_SUBTYPE</dt><dd>5791** The SQLITE_SUBTYPE flag indicates to SQLite that a function might call5792** [sqlite3_value_subtype()] to inspect the sub-types of its arguments.5793** This flag instructs SQLite to omit some corner-case optimizations that5794** might disrupt the operation of the [sqlite3_value_subtype()] function,5795** causing it to return zero rather than the correct subtype().5796** All SQL functions that invoke [sqlite3_value_subtype()] should have this5797** property. If the SQLITE_SUBTYPE property is omitted, then the return5798** value from [sqlite3_value_subtype()] might sometimes be zero even though5799** a non-zero subtype was specified by the function argument expression.5800**5801** [[SQLITE_RESULT_SUBTYPE]] <dt>SQLITE_RESULT_SUBTYPE</dt><dd>5802** The SQLITE_RESULT_SUBTYPE flag indicates to SQLite that a function might call5803** [sqlite3_result_subtype()] to cause a sub-type to be associated with its5804** result.5805** Every function that invokes [sqlite3_result_subtype()] should have this5806** property. If it does not, then the call to [sqlite3_result_subtype()]5807** might become a no-op if the function is used as term in an5808** [expression index]. On the other hand, SQL functions that never invoke5809** [sqlite3_result_subtype()] should avoid setting this property, as the5810** purpose of this property is to disable certain optimizations that are5811** incompatible with subtypes.5812**5813** [[SQLITE_SELFORDER1]] <dt>SQLITE_SELFORDER1</dt><dd>5814** The SQLITE_SELFORDER1 flag indicates that the function is an aggregate5815** that internally orders the values provided to the first argument. The5816** ordered-set aggregate SQL notation with a single ORDER BY term can be5817** used to invoke this function. If the ordered-set aggregate notation is5818** used on a function that lacks this flag, then an error is raised. Note5819** that the ordered-set aggregate syntax is only available if SQLite is5820** built using the -DSQLITE_ENABLE_ORDERED_SET_AGGREGATES compile-time option.5821** </dd>5822** </dl>5823*/5824#define SQLITE_DETERMINISTIC 0x0000008005825#define SQLITE_DIRECTONLY 0x0000800005826#define SQLITE_SUBTYPE 0x0001000005827#define SQLITE_INNOCUOUS 0x0002000005828#define SQLITE_RESULT_SUBTYPE 0x0010000005829#define SQLITE_SELFORDER1 0x00200000058305831/*5832** CAPI3REF: Deprecated Functions5833** DEPRECATED5834**5835** These functions are [deprecated]. In order to maintain5836** backwards compatibility with older code, these functions continue5837** to be supported. However, new applications should avoid5838** the use of these functions. To encourage programmers to avoid5839** these functions, we will not explain what they do.5840*/5841#ifndef SQLITE_OMIT_DEPRECATED5842SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);5843SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);5844SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);5845SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void);5846SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void);5847SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),5848void*,sqlite3_int64);5849#endif58505851/*5852** CAPI3REF: Obtaining SQL Values5853** METHOD: sqlite3_value5854**5855** <b>Summary:</b>5856** <blockquote><table border=0 cellpadding=0 cellspacing=0>5857** <tr><td><b>sqlite3_value_blob</b><td>→<td>BLOB value5858** <tr><td><b>sqlite3_value_double</b><td>→<td>REAL value5859** <tr><td><b>sqlite3_value_int</b><td>→<td>32-bit INTEGER value5860** <tr><td><b>sqlite3_value_int64</b><td>→<td>64-bit INTEGER value5861** <tr><td><b>sqlite3_value_pointer</b><td>→<td>Pointer value5862** <tr><td><b>sqlite3_value_text</b><td>→<td>UTF-8 TEXT value5863** <tr><td><b>sqlite3_value_text16</b><td>→<td>UTF-16 TEXT value in5864** the native byteorder5865** <tr><td><b>sqlite3_value_text16be</b><td>→<td>UTF-16be TEXT value5866** <tr><td><b>sqlite3_value_text16le</b><td>→<td>UTF-16le TEXT value5867** <tr><td> <td> <td> 5868** <tr><td><b>sqlite3_value_bytes</b><td>→<td>Size of a BLOB5869** or a UTF-8 TEXT in bytes5870** <tr><td><b>sqlite3_value_bytes16 </b>5871** <td>→ <td>Size of UTF-165872** TEXT in bytes5873** <tr><td><b>sqlite3_value_type</b><td>→<td>Default5874** datatype of the value5875** <tr><td><b>sqlite3_value_numeric_type </b>5876** <td>→ <td>Best numeric datatype of the value5877** <tr><td><b>sqlite3_value_nochange </b>5878** <td>→ <td>True if the column is unchanged in an UPDATE5879** against a virtual table.5880** <tr><td><b>sqlite3_value_frombind </b>5881** <td>→ <td>True if value originated from a [bound parameter]5882** </table></blockquote>5883**5884** <b>Details:</b>5885**5886** These routines extract type, size, and content information from5887** [protected sqlite3_value] objects. Protected sqlite3_value objects5888** are used to pass parameter information into the functions that5889** implement [application-defined SQL functions] and [virtual tables].5890**5891** These routines work only with [protected sqlite3_value] objects.5892** Any attempt to use these routines on an [unprotected sqlite3_value]5893** is not threadsafe.5894**5895** ^These routines work just like the corresponding [column access functions]5896** except that these routines take a single [protected sqlite3_value] object5897** pointer instead of a [sqlite3_stmt*] pointer and an integer column number.5898**5899** ^The sqlite3_value_text16() interface extracts a UTF-16 string5900** in the native byte-order of the host machine. ^The5901** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces5902** extract UTF-16 strings as big-endian and little-endian respectively.5903**5904** ^If [sqlite3_value] object V was initialized5905** using [sqlite3_bind_pointer(S,I,P,X,D)] or [sqlite3_result_pointer(C,P,X,D)]5906** and if X and Y are strings that compare equal according to strcmp(X,Y),5907** then sqlite3_value_pointer(V,Y) will return the pointer P. ^Otherwise,5908** sqlite3_value_pointer(V,Y) returns a NULL. The sqlite3_bind_pointer()5909** routine is part of the [pointer passing interface] added for SQLite 3.20.0.5910**5911** ^(The sqlite3_value_type(V) interface returns the5912** [SQLITE_INTEGER | datatype code] for the initial datatype of the5913** [sqlite3_value] object V. The returned value is one of [SQLITE_INTEGER],5914** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL].)^5915** Other interfaces might change the datatype for an sqlite3_value object.5916** For example, if the datatype is initially SQLITE_INTEGER and5917** sqlite3_value_text(V) is called to extract a text value for that5918** integer, then subsequent calls to sqlite3_value_type(V) might return5919** SQLITE_TEXT. Whether or not a persistent internal datatype conversion5920** occurs is undefined and may change from one release of SQLite to the next.5921**5922** ^(The sqlite3_value_numeric_type() interface attempts to apply5923** numeric affinity to the value. This means that an attempt is5924** made to convert the value to an integer or floating point. If5925** such a conversion is possible without loss of information (in other5926** words, if the value is a string that looks like a number)5927** then the conversion is performed. Otherwise no conversion occurs.5928** The [SQLITE_INTEGER | datatype] after conversion is returned.)^5929**5930** ^Within the [xUpdate] method of a [virtual table], the5931** sqlite3_value_nochange(X) interface returns true if and only if5932** the column corresponding to X is unchanged by the UPDATE operation5933** that the xUpdate method call was invoked to implement and if5934** and the prior [xColumn] method call that was invoked to extracted5935** the value for that column returned without setting a result (probably5936** because it queried [sqlite3_vtab_nochange()] and found that the column5937** was unchanging). ^Within an [xUpdate] method, any value for which5938** sqlite3_value_nochange(X) is true will in all other respects appear5939** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other5940** than within an [xUpdate] method call for an UPDATE statement, then5941** the return value is arbitrary and meaningless.5942**5943** ^The sqlite3_value_frombind(X) interface returns non-zero if the5944** value X originated from one of the [sqlite3_bind_int|sqlite3_bind()]5945** interfaces. ^If X comes from an SQL literal value, or a table column,5946** or an expression, then sqlite3_value_frombind(X) returns zero.5947**5948** Please pay particular attention to the fact that the pointer returned5949** from [sqlite3_value_blob()], [sqlite3_value_text()], or5950** [sqlite3_value_text16()] can be invalidated by a subsequent call to5951** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],5952** or [sqlite3_value_text16()].5953**5954** These routines must be called from the same thread as5955** the SQL function that supplied the [sqlite3_value*] parameters.5956**5957** As long as the input parameter is correct, these routines can only5958** fail if an out-of-memory error occurs during a format conversion.5959** Only the following subset of interfaces are subject to out-of-memory5960** errors:5961**5962** <ul>5963** <li> sqlite3_value_blob()5964** <li> sqlite3_value_text()5965** <li> sqlite3_value_text16()5966** <li> sqlite3_value_text16le()5967** <li> sqlite3_value_text16be()5968** <li> sqlite3_value_bytes()5969** <li> sqlite3_value_bytes16()5970** </ul>5971**5972** If an out-of-memory error occurs, then the return value from these5973** routines is the same as if the column had contained an SQL NULL value.5974** Valid SQL NULL returns can be distinguished from out-of-memory errors5975** by invoking the [sqlite3_errcode()] immediately after the suspect5976** return value is obtained and before any5977** other SQLite interface is called on the same [database connection].5978*/5979SQLITE_API const void *sqlite3_value_blob(sqlite3_value*);5980SQLITE_API double sqlite3_value_double(sqlite3_value*);5981SQLITE_API int sqlite3_value_int(sqlite3_value*);5982SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*);5983SQLITE_API void *sqlite3_value_pointer(sqlite3_value*, const char*);5984SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*);5985SQLITE_API const void *sqlite3_value_text16(sqlite3_value*);5986SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*);5987SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*);5988SQLITE_API int sqlite3_value_bytes(sqlite3_value*);5989SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);5990SQLITE_API int sqlite3_value_type(sqlite3_value*);5991SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);5992SQLITE_API int sqlite3_value_nochange(sqlite3_value*);5993SQLITE_API int sqlite3_value_frombind(sqlite3_value*);59945995/*5996** CAPI3REF: Report the internal text encoding state of an sqlite3_value object5997** METHOD: sqlite3_value5998**5999** ^(The sqlite3_value_encoding(X) interface returns one of [SQLITE_UTF8],6000** [SQLITE_UTF16BE], or [SQLITE_UTF16LE] according to the current text encoding6001** of the value X, assuming that X has type TEXT.)^ If sqlite3_value_type(X)6002** returns something other than SQLITE_TEXT, then the return value from6003** sqlite3_value_encoding(X) is meaningless. ^Calls to6004** [sqlite3_value_text(X)], [sqlite3_value_text16(X)], [sqlite3_value_text16be(X)],6005** [sqlite3_value_text16le(X)], [sqlite3_value_bytes(X)], or6006** [sqlite3_value_bytes16(X)] might change the encoding of the value X and6007** thus change the return from subsequent calls to sqlite3_value_encoding(X).6008**6009** This routine is intended for used by applications that test and validate6010** the SQLite implementation. This routine is inquiring about the opaque6011** internal state of an [sqlite3_value] object. Ordinary applications should6012** not need to know what the internal state of an sqlite3_value object is and6013** hence should not need to use this interface.6014*/6015SQLITE_API int sqlite3_value_encoding(sqlite3_value*);60166017/*6018** CAPI3REF: Finding The Subtype Of SQL Values6019** METHOD: sqlite3_value6020**6021** The sqlite3_value_subtype(V) function returns the subtype for6022** an [application-defined SQL function] argument V. The subtype6023** information can be used to pass a limited amount of context from6024** one SQL function to another. Use the [sqlite3_result_subtype()]6025** routine to set the subtype for the return value of an SQL function.6026**6027** Every [application-defined SQL function] that invokes this interface6028** should include the [SQLITE_SUBTYPE] property in the text6029** encoding argument when the function is [sqlite3_create_function|registered].6030** If the [SQLITE_SUBTYPE] property is omitted, then sqlite3_value_subtype()6031** might return zero instead of the upstream subtype in some corner cases.6032*/6033SQLITE_API unsigned int sqlite3_value_subtype(sqlite3_value*);60346035/*6036** CAPI3REF: Copy And Free SQL Values6037** METHOD: sqlite3_value6038**6039** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value]6040** object D and returns a pointer to that copy. ^The [sqlite3_value] returned6041** is a [protected sqlite3_value] object even if the input is not.6042** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a6043** memory allocation fails. ^If V is a [pointer value], then the result6044** of sqlite3_value_dup(V) is a NULL value.6045**6046** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object6047** previously obtained from [sqlite3_value_dup()]. ^If V is a NULL pointer6048** then sqlite3_value_free(V) is a harmless no-op.6049*/6050SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value*);6051SQLITE_API void sqlite3_value_free(sqlite3_value*);60526053/*6054** CAPI3REF: Obtain Aggregate Function Context6055** METHOD: sqlite3_context6056**6057** Implementations of aggregate SQL functions use this6058** routine to allocate memory for storing their state.6059**6060** ^The first time the sqlite3_aggregate_context(C,N) routine is called6061** for a particular aggregate function, SQLite allocates6062** N bytes of memory, zeroes out that memory, and returns a pointer6063** to the new memory. ^On second and subsequent calls to6064** sqlite3_aggregate_context() for the same aggregate function instance,6065** the same buffer is returned. Sqlite3_aggregate_context() is normally6066** called once for each invocation of the xStep callback and then one6067** last time when the xFinal callback is invoked. ^(When no rows match6068** an aggregate query, the xStep() callback of the aggregate function6069** implementation is never called and xFinal() is called exactly once.6070** In those cases, sqlite3_aggregate_context() might be called for the6071** first time from within xFinal().)^6072**6073** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer6074** when first called if N is less than or equal to zero or if a memory6075** allocation error occurs.6076**6077** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is6078** determined by the N parameter on first successful call. Changing the6079** value of N in any subsequent call to sqlite3_aggregate_context() within6080** the same aggregate function instance will not resize the memory6081** allocation.)^ Within the xFinal callback, it is customary to set6082** N=0 in calls to sqlite3_aggregate_context(C,N) so that no6083** pointless memory allocations occur.6084**6085** ^SQLite automatically frees the memory allocated by6086** sqlite3_aggregate_context() when the aggregate query concludes.6087**6088** The first parameter must be a copy of the6089** [sqlite3_context | SQL function context] that is the first parameter6090** to the xStep or xFinal callback routine that implements the aggregate6091** function.6092**6093** This routine must be called from the same thread in which6094** the aggregate SQL function is running.6095*/6096SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes);60976098/*6099** CAPI3REF: User Data For Functions6100** METHOD: sqlite3_context6101**6102** ^The sqlite3_user_data() interface returns a copy of6103** the pointer that was the pUserData parameter (the 5th parameter)6104** of the [sqlite3_create_function()]6105** and [sqlite3_create_function16()] routines that originally6106** registered the application defined function.6107**6108** This routine must be called from the same thread in which6109** the application-defined function is running.6110*/6111SQLITE_API void *sqlite3_user_data(sqlite3_context*);61126113/*6114** CAPI3REF: Database Connection For Functions6115** METHOD: sqlite3_context6116**6117** ^The sqlite3_context_db_handle() interface returns a copy of6118** the pointer to the [database connection] (the 1st parameter)6119** of the [sqlite3_create_function()]6120** and [sqlite3_create_function16()] routines that originally6121** registered the application defined function.6122*/6123SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*);61246125/*6126** CAPI3REF: Function Auxiliary Data6127** METHOD: sqlite3_context6128**6129** These functions may be used by (non-aggregate) SQL functions to6130** associate auxiliary data with argument values. If the same argument6131** value is passed to multiple invocations of the same SQL function during6132** query execution, under some circumstances the associated auxiliary data6133** might be preserved. An example of where this might be useful is in a6134** regular-expression matching function. The compiled version of the regular6135** expression can be stored as auxiliary data associated with the pattern string.6136** Then as long as the pattern string remains the same,6137** the compiled regular expression can be reused on multiple6138** invocations of the same function.6139**6140** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the auxiliary data6141** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument6142** value to the application-defined function. ^N is zero for the left-most6143** function argument. ^If there is no auxiliary data6144** associated with the function argument, the sqlite3_get_auxdata(C,N) interface6145** returns a NULL pointer.6146**6147** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as auxiliary data for the6148** N-th argument of the application-defined function. ^Subsequent6149** calls to sqlite3_get_auxdata(C,N) return P from the most recent6150** sqlite3_set_auxdata(C,N,P,X) call if the auxiliary data is still valid or6151** NULL if the auxiliary data has been discarded.6152** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL,6153** SQLite will invoke the destructor function X with parameter P exactly6154** once, when the auxiliary data is discarded.6155** SQLite is free to discard the auxiliary data at any time, including: <ul>6156** <li> ^(when the corresponding function parameter changes)^, or6157** <li> ^(when [sqlite3_reset()] or [sqlite3_finalize()] is called for the6158** SQL statement)^, or6159** <li> ^(when sqlite3_set_auxdata() is invoked again on the same6160** parameter)^, or6161** <li> ^(during the original sqlite3_set_auxdata() call when a memory6162** allocation error occurs.)^6163** <li> ^(during the original sqlite3_set_auxdata() call if the function6164** is evaluated during query planning instead of during query execution,6165** as sometimes happens with [SQLITE_ENABLE_STAT4].)^ </ul>6166**6167** Note the last two bullets in particular. The destructor X in6168** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the6169** sqlite3_set_auxdata() interface even returns. Hence sqlite3_set_auxdata()6170** should be called near the end of the function implementation and the6171** function implementation should not make any use of P after6172** sqlite3_set_auxdata() has been called. Furthermore, a call to6173** sqlite3_get_auxdata() that occurs immediately after a corresponding call6174** to sqlite3_set_auxdata() might still return NULL if an out-of-memory6175** condition occurred during the sqlite3_set_auxdata() call or if the6176** function is being evaluated during query planning rather than during6177** query execution.6178**6179** ^(In practice, auxiliary data is preserved between function calls for6180** function parameters that are compile-time constants, including literal6181** values and [parameters] and expressions composed from the same.)^6182**6183** The value of the N parameter to these interfaces should be non-negative.6184** Future enhancements may make use of negative N values to define new6185** kinds of function caching behavior.6186**6187** These routines must be called from the same thread in which6188** the SQL function is running.6189**6190** See also: [sqlite3_get_clientdata()] and [sqlite3_set_clientdata()].6191*/6192SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);6193SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*));61946195/*6196** CAPI3REF: Database Connection Client Data6197** METHOD: sqlite36198**6199** These functions are used to associate one or more named pointers6200** with a [database connection].6201** A call to sqlite3_set_clientdata(D,N,P,X) causes the pointer P6202** to be attached to [database connection] D using name N. Subsequent6203** calls to sqlite3_get_clientdata(D,N) will return a copy of pointer P6204** or a NULL pointer if there were no prior calls to6205** sqlite3_set_clientdata() with the same values of D and N.6206** Names are compared using strcmp() and are thus case sensitive.6207**6208** If P and X are both non-NULL, then the destructor X is invoked with6209** argument P on the first of the following occurrences:6210** <ul>6211** <li> An out-of-memory error occurs during the call to6212** sqlite3_set_clientdata() which attempts to register pointer P.6213** <li> A subsequent call to sqlite3_set_clientdata(D,N,P,X) is made6214** with the same D and N parameters.6215** <li> The database connection closes. SQLite does not make any guarantees6216** about the order in which destructors are called, only that all6217** destructors will be called exactly once at some point during the6218** database connection closing process.6219** </ul>6220**6221** SQLite does not do anything with client data other than invoke6222** destructors on the client data at the appropriate time. The intended6223** use for client data is to provide a mechanism for wrapper libraries6224** to store additional information about an SQLite database connection.6225**6226** There is no limit (other than available memory) on the number of different6227** client data pointers (with different names) that can be attached to a6228** single database connection. However, the implementation is optimized6229** for the case of having only one or two different client data names.6230** Applications and wrapper libraries are discouraged from using more than6231** one client data name each.6232**6233** There is no way to enumerate the client data pointers6234** associated with a database connection. The N parameter can be thought6235** of as a secret key such that only code that knows the secret key is able6236** to access the associated data.6237**6238** Security Warning: These interfaces should not be exposed in scripting6239** languages or in other circumstances where it might be possible for an6240** an attacker to invoke them. Any agent that can invoke these interfaces6241** can probably also take control of the process.6242**6243** Database connection client data is only available for SQLite6244** version 3.44.0 ([dateof:3.44.0]) and later.6245**6246** See also: [sqlite3_set_auxdata()] and [sqlite3_get_auxdata()].6247*/6248SQLITE_API void *sqlite3_get_clientdata(sqlite3*,const char*);6249SQLITE_API int sqlite3_set_clientdata(sqlite3*, const char*, void*, void(*)(void*));62506251/*6252** CAPI3REF: Constants Defining Special Destructor Behavior6253**6254** These are special values for the destructor that is passed in as the6255** final argument to routines like [sqlite3_result_blob()]. ^If the destructor6256** argument is SQLITE_STATIC, it means that the content pointer is constant6257** and will never change. It does not need to be destroyed. ^The6258** SQLITE_TRANSIENT value means that the content will likely change in6259** the near future and that SQLite should make its own private copy of6260** the content before returning.6261**6262** The typedef is necessary to work around problems in certain6263** C++ compilers.6264*/6265typedef void (*sqlite3_destructor_type)(void*);6266#define SQLITE_STATIC ((sqlite3_destructor_type)0)6267#define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)62686269/*6270** CAPI3REF: Setting The Result Of An SQL Function6271** METHOD: sqlite3_context6272**6273** These routines are used by the xFunc or xFinal callbacks that6274** implement SQL functions and aggregates. See6275** [sqlite3_create_function()] and [sqlite3_create_function16()]6276** for additional information.6277**6278** These functions work very much like the [parameter binding] family of6279** functions used to bind values to host parameters in prepared statements.6280** Refer to the [SQL parameter] documentation for additional information.6281**6282** ^The sqlite3_result_blob() interface sets the result from6283** an application-defined function to be the BLOB whose content is pointed6284** to by the second parameter and which is N bytes long where N is the6285** third parameter.6286**6287** ^The sqlite3_result_zeroblob(C,N) and sqlite3_result_zeroblob64(C,N)6288** interfaces set the result of the application-defined function to be6289** a BLOB containing all zero bytes and N bytes in size.6290**6291** ^The sqlite3_result_double() interface sets the result from6292** an application-defined function to be a floating point value specified6293** by its 2nd argument.6294**6295** ^The sqlite3_result_error() and sqlite3_result_error16() functions6296** cause the implemented SQL function to throw an exception.6297** ^SQLite uses the string pointed to by the6298** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16()6299** as the text of an error message. ^SQLite interprets the error6300** message string from sqlite3_result_error() as UTF-8. ^SQLite6301** interprets the string from sqlite3_result_error16() as UTF-16 using6302** the same [byte-order determination rules] as [sqlite3_bind_text16()].6303** ^If the third parameter to sqlite3_result_error()6304** or sqlite3_result_error16() is negative then SQLite takes as the error6305** message all text up through the first zero character.6306** ^If the third parameter to sqlite3_result_error() or6307** sqlite3_result_error16() is non-negative then SQLite takes that many6308** bytes (not characters) from the 2nd parameter as the error message.6309** ^The sqlite3_result_error() and sqlite3_result_error16()6310** routines make a private copy of the error message text before6311** they return. Hence, the calling function can deallocate or6312** modify the text after they return without harm.6313** ^The sqlite3_result_error_code() function changes the error code6314** returned by SQLite as a result of an error in a function. ^By default,6315** the error code is SQLITE_ERROR. ^A subsequent call to sqlite3_result_error()6316** or sqlite3_result_error16() resets the error code to SQLITE_ERROR.6317**6318** ^The sqlite3_result_error_toobig() interface causes SQLite to throw an6319** error indicating that a string or BLOB is too long to represent.6320**6321** ^The sqlite3_result_error_nomem() interface causes SQLite to throw an6322** error indicating that a memory allocation failed.6323**6324** ^The sqlite3_result_int() interface sets the return value6325** of the application-defined function to be the 32-bit signed integer6326** value given in the 2nd argument.6327** ^The sqlite3_result_int64() interface sets the return value6328** of the application-defined function to be the 64-bit signed integer6329** value given in the 2nd argument.6330**6331** ^The sqlite3_result_null() interface sets the return value6332** of the application-defined function to be NULL.6333**6334** ^The sqlite3_result_text(), sqlite3_result_text16(),6335** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces6336** set the return value of the application-defined function to be6337** a text string which is represented as UTF-8, UTF-16 native byte order,6338** UTF-16 little endian, or UTF-16 big endian, respectively.6339** ^The sqlite3_result_text64() interface sets the return value of an6340** application-defined function to be a text string in an encoding6341** specified by the fifth (and last) parameter, which must be one6342** of [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE].6343** ^SQLite takes the text result from the application from6344** the 2nd parameter of the sqlite3_result_text* interfaces.6345** ^If the 3rd parameter to any of the sqlite3_result_text* interfaces6346** other than sqlite3_result_text64() is negative, then SQLite computes6347** the string length itself by searching the 2nd parameter for the first6348** zero character.6349** ^If the 3rd parameter to the sqlite3_result_text* interfaces6350** is non-negative, then as many bytes (not characters) of the text6351** pointed to by the 2nd parameter are taken as the application-defined6352** function result. If the 3rd parameter is non-negative, then it6353** must be the byte offset into the string where the NUL terminator would6354** appear if the string where NUL terminated. If any NUL characters occur6355** in the string at a byte offset that is less than the value of the 3rd6356** parameter, then the resulting string will contain embedded NULs and the6357** result of expressions operating on strings with embedded NULs is undefined.6358** ^If the 4th parameter to the sqlite3_result_text* interfaces6359** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that6360** function as the destructor on the text or BLOB result when it has6361** finished using that result.6362** ^If the 4th parameter to the sqlite3_result_text* interfaces or to6363** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite6364** assumes that the text or BLOB result is in constant space and does not6365** copy the content of the parameter nor call a destructor on the content6366** when it has finished using that result.6367** ^If the 4th parameter to the sqlite3_result_text* interfaces6368** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT6369** then SQLite makes a copy of the result into space obtained6370** from [sqlite3_malloc()] before it returns.6371**6372** ^For the sqlite3_result_text16(), sqlite3_result_text16le(), and6373** sqlite3_result_text16be() routines, and for sqlite3_result_text64()6374** when the encoding is not UTF8, if the input UTF16 begins with a6375** byte-order mark (BOM, U+FEFF) then the BOM is removed from the6376** string and the rest of the string is interpreted according to the6377** byte-order specified by the BOM. ^The byte-order specified by6378** the BOM at the beginning of the text overrides the byte-order6379** specified by the interface procedure. ^So, for example, if6380** sqlite3_result_text16le() is invoked with text that begins6381** with bytes 0xfe, 0xff (a big-endian byte-order mark) then the6382** first two bytes of input are skipped and the remaining input6383** is interpreted as UTF16BE text.6384**6385** ^For UTF16 input text to the sqlite3_result_text16(),6386** sqlite3_result_text16be(), sqlite3_result_text16le(), and6387** sqlite3_result_text64() routines, if the text contains invalid6388** UTF16 characters, the invalid characters might be converted6389** into the unicode replacement character, U+FFFD.6390**6391** ^The sqlite3_result_value() interface sets the result of6392** the application-defined function to be a copy of the6393** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The6394** sqlite3_result_value() interface makes a copy of the [sqlite3_value]6395** so that the [sqlite3_value] specified in the parameter may change or6396** be deallocated after sqlite3_result_value() returns without harm.6397** ^A [protected sqlite3_value] object may always be used where an6398** [unprotected sqlite3_value] object is required, so either6399** kind of [sqlite3_value] object can be used with this interface.6400**6401** ^The sqlite3_result_pointer(C,P,T,D) interface sets the result to an6402** SQL NULL value, just like [sqlite3_result_null(C)], except that it6403** also associates the host-language pointer P or type T with that6404** NULL value such that the pointer can be retrieved within an6405** [application-defined SQL function] using [sqlite3_value_pointer()].6406** ^If the D parameter is not NULL, then it is a pointer to a destructor6407** for the P parameter. ^SQLite invokes D with P as its only argument6408** when SQLite is finished with P. The T parameter should be a static6409** string and preferably a string literal. The sqlite3_result_pointer()6410** routine is part of the [pointer passing interface] added for SQLite 3.20.0.6411**6412** If these routines are called from within the different thread6413** than the one containing the application-defined function that received6414** the [sqlite3_context] pointer, the results are undefined.6415*/6416SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));6417SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,6418sqlite3_uint64,void(*)(void*));6419SQLITE_API void sqlite3_result_double(sqlite3_context*, double);6420SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);6421SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);6422SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);6423SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);6424SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int);6425SQLITE_API void sqlite3_result_int(sqlite3_context*, int);6426SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64);6427SQLITE_API void sqlite3_result_null(sqlite3_context*);6428SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*));6429SQLITE_API void sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64,6430void(*)(void*), unsigned char encoding);6431SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*));6432SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));6433SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));6434SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*);6435SQLITE_API void sqlite3_result_pointer(sqlite3_context*, void*,const char*,void(*)(void*));6436SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n);6437SQLITE_API int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n);643864396440/*6441** CAPI3REF: Setting The Subtype Of An SQL Function6442** METHOD: sqlite3_context6443**6444** The sqlite3_result_subtype(C,T) function causes the subtype of6445** the result from the [application-defined SQL function] with6446** [sqlite3_context] C to be the value T. Only the lower 8 bits6447** of the subtype T are preserved in current versions of SQLite;6448** higher order bits are discarded.6449** The number of subtype bytes preserved by SQLite might increase6450** in future releases of SQLite.6451**6452** Every [application-defined SQL function] that invokes this interface6453** should include the [SQLITE_RESULT_SUBTYPE] property in its6454** text encoding argument when the SQL function is6455** [sqlite3_create_function|registered]. If the [SQLITE_RESULT_SUBTYPE]6456** property is omitted from the function that invokes sqlite3_result_subtype(),6457** then in some cases the sqlite3_result_subtype() might fail to set6458** the result subtype.6459**6460** If SQLite is compiled with -DSQLITE_STRICT_SUBTYPE=1, then any6461** SQL function that invokes the sqlite3_result_subtype() interface6462** and that does not have the SQLITE_RESULT_SUBTYPE property will raise6463** an error. Future versions of SQLite might enable -DSQLITE_STRICT_SUBTYPE=16464** by default.6465*/6466SQLITE_API void sqlite3_result_subtype(sqlite3_context*,unsigned int);64676468/*6469** CAPI3REF: Define New Collating Sequences6470** METHOD: sqlite36471**6472** ^These functions add, remove, or modify a [collation] associated6473** with the [database connection] specified as the first argument.6474**6475** ^The name of the collation is a UTF-8 string6476** for sqlite3_create_collation() and sqlite3_create_collation_v2()6477** and a UTF-16 string in native byte order for sqlite3_create_collation16().6478** ^Collation names that compare equal according to [sqlite3_strnicmp()] are6479** considered to be the same name.6480**6481** ^(The third argument (eTextRep) must be one of the constants:6482** <ul>6483** <li> [SQLITE_UTF8],6484** <li> [SQLITE_UTF16LE],6485** <li> [SQLITE_UTF16BE],6486** <li> [SQLITE_UTF16], or6487** <li> [SQLITE_UTF16_ALIGNED].6488** </ul>)^6489** ^The eTextRep argument determines the encoding of strings passed6490** to the collating function callback, xCompare.6491** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep6492** force strings to be UTF16 with native byte order.6493** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin6494** on an even byte address.6495**6496** ^The fourth argument, pArg, is an application data pointer that is passed6497** through as the first argument to the collating function callback.6498**6499** ^The fifth argument, xCompare, is a pointer to the collating function.6500** ^Multiple collating functions can be registered using the same name but6501** with different eTextRep parameters and SQLite will use whichever6502** function requires the least amount of data transformation.6503** ^If the xCompare argument is NULL then the collating function is6504** deleted. ^When all collating functions having the same name are deleted,6505** that collation is no longer usable.6506**6507** ^The collating function callback is invoked with a copy of the pArg6508** application data pointer and with two strings in the encoding specified6509** by the eTextRep argument. The two integer parameters to the collating6510** function callback are the length of the two strings, in bytes. The collating6511** function must return an integer that is negative, zero, or positive6512** if the first string is less than, equal to, or greater than the second,6513** respectively. A collating function must always return the same answer6514** given the same inputs. If two or more collating functions are registered6515** to the same collation name (using different eTextRep values) then all6516** must give an equivalent answer when invoked with equivalent strings.6517** The collating function must obey the following properties for all6518** strings A, B, and C:6519**6520** <ol>6521** <li> If A==B then B==A.6522** <li> If A==B and B==C then A==C.6523** <li> If A<B THEN B>A.6524** <li> If A<B and B<C then A<C.6525** </ol>6526**6527** If a collating function fails any of the above constraints and that6528** collating function is registered and used, then the behavior of SQLite6529** is undefined.6530**6531** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation()6532** with the addition that the xDestroy callback is invoked on pArg when6533** the collating function is deleted.6534** ^Collating functions are deleted when they are overridden by later6535** calls to the collation creation functions or when the6536** [database connection] is closed using [sqlite3_close()].6537**6538** ^The xDestroy callback is <u>not</u> called if the6539** sqlite3_create_collation_v2() function fails. Applications that invoke6540** sqlite3_create_collation_v2() with a non-NULL xDestroy argument should6541** check the return code and dispose of the application data pointer6542** themselves rather than expecting SQLite to deal with it for them.6543** This is different from every other SQLite interface. The inconsistency6544** is unfortunate but cannot be changed without breaking backwards6545** compatibility.6546**6547** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()].6548*/6549SQLITE_API int sqlite3_create_collation(6550sqlite3*,6551const char *zName,6552int eTextRep,6553void *pArg,6554int(*xCompare)(void*,int,const void*,int,const void*)6555);6556SQLITE_API int sqlite3_create_collation_v2(6557sqlite3*,6558const char *zName,6559int eTextRep,6560void *pArg,6561int(*xCompare)(void*,int,const void*,int,const void*),6562void(*xDestroy)(void*)6563);6564SQLITE_API int sqlite3_create_collation16(6565sqlite3*,6566const void *zName,6567int eTextRep,6568void *pArg,6569int(*xCompare)(void*,int,const void*,int,const void*)6570);65716572/*6573** CAPI3REF: Collation Needed Callbacks6574** METHOD: sqlite36575**6576** ^To avoid having to register all collation sequences before a database6577** can be used, a single callback function may be registered with the6578** [database connection] to be invoked whenever an undefined collation6579** sequence is required.6580**6581** ^If the function is registered using the sqlite3_collation_needed() API,6582** then it is passed the names of undefined collation sequences as strings6583** encoded in UTF-8. ^If sqlite3_collation_needed16() is used,6584** the names are passed as UTF-16 in machine native byte order.6585** ^A call to either function replaces the existing collation-needed callback.6586**6587** ^(When the callback is invoked, the first argument passed is a copy6588** of the second argument to sqlite3_collation_needed() or6589** sqlite3_collation_needed16(). The second argument is the database6590** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE],6591** or [SQLITE_UTF16LE], indicating the most desirable form of the collation6592** sequence function required. The fourth parameter is the name of the6593** required collation sequence.)^6594**6595** The callback function should register the desired collation using6596** [sqlite3_create_collation()], [sqlite3_create_collation16()], or6597** [sqlite3_create_collation_v2()].6598*/6599SQLITE_API int sqlite3_collation_needed(6600sqlite3*,6601void*,6602void(*)(void*,sqlite3*,int eTextRep,const char*)6603);6604SQLITE_API int sqlite3_collation_needed16(6605sqlite3*,6606void*,6607void(*)(void*,sqlite3*,int eTextRep,const void*)6608);66096610#ifdef SQLITE_ENABLE_CEROD6611/*6612** Specify the activation key for a CEROD database. Unless6613** activated, none of the CEROD routines will work.6614*/6615SQLITE_API void sqlite3_activate_cerod(6616const char *zPassPhrase /* Activation phrase */6617);6618#endif66196620/*6621** CAPI3REF: Suspend Execution For A Short Time6622**6623** The sqlite3_sleep() function causes the current thread to suspend execution6624** for at least a number of milliseconds specified in its parameter.6625**6626** If the operating system does not support sleep requests with6627** millisecond time resolution, then the time will be rounded up to6628** the nearest second. The number of milliseconds of sleep actually6629** requested from the operating system is returned.6630**6631** ^SQLite implements this interface by calling the xSleep()6632** method of the default [sqlite3_vfs] object. If the xSleep() method6633** of the default VFS is not implemented correctly, or not implemented at6634** all, then the behavior of sqlite3_sleep() may deviate from the description6635** in the previous paragraphs.6636**6637** If a negative argument is passed to sqlite3_sleep() the results vary by6638** VFS and operating system. Some system treat a negative argument as an6639** instruction to sleep forever. Others understand it to mean do not sleep6640** at all. ^In SQLite version 3.42.0 and later, a negative6641** argument passed into sqlite3_sleep() is changed to zero before it is relayed6642** down into the xSleep method of the VFS.6643*/6644SQLITE_API int sqlite3_sleep(int);66456646/*6647** CAPI3REF: Name Of The Folder Holding Temporary Files6648**6649** ^(If this global variable is made to point to a string which is6650** the name of a folder (a.k.a. directory), then all temporary files6651** created by SQLite when using a built-in [sqlite3_vfs | VFS]6652** will be placed in that directory.)^ ^If this variable6653** is a NULL pointer, then SQLite performs a search for an appropriate6654** temporary file directory.6655**6656** Applications are strongly discouraged from using this global variable.6657** It is required to set a temporary folder on Windows Runtime (WinRT).6658** But for all other platforms, it is highly recommended that applications6659** neither read nor write this variable. This global variable is a relic6660** that exists for backwards compatibility of legacy applications and should6661** be avoided in new projects.6662**6663** It is not safe to read or modify this variable in more than one6664** thread at a time. It is not safe to read or modify this variable6665** if a [database connection] is being used at the same time in a separate6666** thread.6667** It is intended that this variable be set once6668** as part of process initialization and before any SQLite interface6669** routines have been called and that this variable remain unchanged6670** thereafter.6671**6672** ^The [temp_store_directory pragma] may modify this variable and cause6673** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore,6674** the [temp_store_directory pragma] always assumes that any string6675** that this variable points to is held in memory obtained from6676** [sqlite3_malloc] and the pragma may attempt to free that memory6677** using [sqlite3_free].6678** Hence, if this variable is modified directly, either it should be6679** made NULL or made to point to memory obtained from [sqlite3_malloc]6680** or else the use of the [temp_store_directory pragma] should be avoided.6681** Except when requested by the [temp_store_directory pragma], SQLite6682** does not free the memory that sqlite3_temp_directory points to. If6683** the application wants that memory to be freed, it must do6684** so itself, taking care to only do so after all [database connection]6685** objects have been destroyed.6686**6687** <b>Note to Windows Runtime users:</b> The temporary directory must be set6688** prior to calling [sqlite3_open] or [sqlite3_open_v2]. Otherwise, various6689** features that require the use of temporary files may fail. Here is an6690** example of how to do this using C++ with the Windows Runtime:6691**6692** <blockquote><pre>6693** LPCWSTR zPath = Windows::Storage::ApplicationData::Current->6694** TemporaryFolder->Path->Data();6695** char zPathBuf[MAX_PATH + 1];6696** memset(zPathBuf, 0, sizeof(zPathBuf));6697** WideCharToMultiByte(CP_UTF8, 0, zPath, -1, zPathBuf, sizeof(zPathBuf),6698** NULL, NULL);6699** sqlite3_temp_directory = sqlite3_mprintf("%s", zPathBuf);6700** </pre></blockquote>6701*/6702SQLITE_API SQLITE_EXTERN char *sqlite3_temp_directory;67036704/*6705** CAPI3REF: Name Of The Folder Holding Database Files6706**6707** ^(If this global variable is made to point to a string which is6708** the name of a folder (a.k.a. directory), then all database files6709** specified with a relative pathname and created or accessed by6710** SQLite when using a built-in windows [sqlite3_vfs | VFS] will be assumed6711** to be relative to that directory.)^ ^If this variable is a NULL6712** pointer, then SQLite assumes that all database files specified6713** with a relative pathname are relative to the current directory6714** for the process. Only the windows VFS makes use of this global6715** variable; it is ignored by the unix VFS.6716**6717** Changing the value of this variable while a database connection is6718** open can result in a corrupt database.6719**6720** It is not safe to read or modify this variable in more than one6721** thread at a time. It is not safe to read or modify this variable6722** if a [database connection] is being used at the same time in a separate6723** thread.6724** It is intended that this variable be set once6725** as part of process initialization and before any SQLite interface6726** routines have been called and that this variable remain unchanged6727** thereafter.6728**6729** ^The [data_store_directory pragma] may modify this variable and cause6730** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore,6731** the [data_store_directory pragma] always assumes that any string6732** that this variable points to is held in memory obtained from6733** [sqlite3_malloc] and the pragma may attempt to free that memory6734** using [sqlite3_free].6735** Hence, if this variable is modified directly, either it should be6736** made NULL or made to point to memory obtained from [sqlite3_malloc]6737** or else the use of the [data_store_directory pragma] should be avoided.6738*/6739SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory;67406741/*6742** CAPI3REF: Win32 Specific Interface6743**6744** These interfaces are available only on Windows. The6745** [sqlite3_win32_set_directory] interface is used to set the value associated6746** with the [sqlite3_temp_directory] or [sqlite3_data_directory] variable, to6747** zValue, depending on the value of the type parameter. The zValue parameter6748** should be NULL to cause the previous value to be freed via [sqlite3_free];6749** a non-NULL value will be copied into memory obtained from [sqlite3_malloc]6750** prior to being used. The [sqlite3_win32_set_directory] interface returns6751** [SQLITE_OK] to indicate success, [SQLITE_ERROR] if the type is unsupported,6752** or [SQLITE_NOMEM] if memory could not be allocated. The value of the6753** [sqlite3_data_directory] variable is intended to act as a replacement for6754** the current directory on the sub-platforms of Win32 where that concept is6755** not present, e.g. WinRT and UWP. The [sqlite3_win32_set_directory8] and6756** [sqlite3_win32_set_directory16] interfaces behave exactly the same as the6757** sqlite3_win32_set_directory interface except the string parameter must be6758** UTF-8 or UTF-16, respectively.6759*/6760SQLITE_API int sqlite3_win32_set_directory(6761unsigned long type, /* Identifier for directory being set or reset */6762void *zValue /* New value for directory being set or reset */6763);6764SQLITE_API int sqlite3_win32_set_directory8(unsigned long type, const char *zValue);6765SQLITE_API int sqlite3_win32_set_directory16(unsigned long type, const void *zValue);67666767/*6768** CAPI3REF: Win32 Directory Types6769**6770** These macros are only available on Windows. They define the allowed values6771** for the type argument to the [sqlite3_win32_set_directory] interface.6772*/6773#define SQLITE_WIN32_DATA_DIRECTORY_TYPE 16774#define SQLITE_WIN32_TEMP_DIRECTORY_TYPE 267756776/*6777** CAPI3REF: Test For Auto-Commit Mode6778** KEYWORDS: {autocommit mode}6779** METHOD: sqlite36780**6781** ^The sqlite3_get_autocommit() interface returns non-zero or6782** zero if the given database connection is or is not in autocommit mode,6783** respectively. ^Autocommit mode is on by default.6784** ^Autocommit mode is disabled by a [BEGIN] statement.6785** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK].6786**6787** If certain kinds of errors occur on a statement within a multi-statement6788** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR],6789** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the6790** transaction might be rolled back automatically. The only way to6791** find out whether SQLite automatically rolled back the transaction after6792** an error is to use this function.6793**6794** If another thread changes the autocommit status of the database6795** connection while this routine is running, then the return value6796** is undefined.6797*/6798SQLITE_API int sqlite3_get_autocommit(sqlite3*);67996800/*6801** CAPI3REF: Find The Database Handle Of A Prepared Statement6802** METHOD: sqlite3_stmt6803**6804** ^The sqlite3_db_handle interface returns the [database connection] handle6805** to which a [prepared statement] belongs. ^The [database connection]6806** returned by sqlite3_db_handle is the same [database connection]6807** that was the first argument6808** to the [sqlite3_prepare_v2()] call (or its variants) that was used to6809** create the statement in the first place.6810*/6811SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);68126813/*6814** CAPI3REF: Return The Schema Name For A Database Connection6815** METHOD: sqlite36816**6817** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name6818** for the N-th database on database connection D, or a NULL pointer of N is6819** out of range. An N value of 0 means the main database file. An N of 1 is6820** the "temp" schema. Larger values of N correspond to various ATTACH-ed6821** databases.6822**6823** Space to hold the string that is returned by sqlite3_db_name() is managed6824** by SQLite itself. The string might be deallocated by any operation that6825** changes the schema, including [ATTACH] or [DETACH] or calls to6826** [sqlite3_serialize()] or [sqlite3_deserialize()], even operations that6827** occur on a different thread. Applications that need to6828** remember the string long-term should make their own copy. Applications that6829** are accessing the same database connection simultaneously on multiple6830** threads should mutex-protect calls to this API and should make their own6831** private copy of the result prior to releasing the mutex.6832*/6833SQLITE_API const char *sqlite3_db_name(sqlite3 *db, int N);68346835/*6836** CAPI3REF: Return The Filename For A Database Connection6837** METHOD: sqlite36838**6839** ^The sqlite3_db_filename(D,N) interface returns a pointer to the filename6840** associated with database N of connection D.6841** ^If there is no attached database N on the database6842** connection D, or if database N is a temporary or in-memory database, then6843** this function will return either a NULL pointer or an empty string.6844**6845** ^The string value returned by this routine is owned and managed by6846** the database connection. ^The value will be valid until the database N6847** is [DETACH]-ed or until the database connection closes.6848**6849** ^The filename returned by this function is the output of the6850** xFullPathname method of the [VFS]. ^In other words, the filename6851** will be an absolute pathname, even if the filename used6852** to open the database originally was a URI or relative pathname.6853**6854** If the filename pointer returned by this routine is not NULL, then it6855** can be used as the filename input parameter to these routines:6856** <ul>6857** <li> [sqlite3_uri_parameter()]6858** <li> [sqlite3_uri_boolean()]6859** <li> [sqlite3_uri_int64()]6860** <li> [sqlite3_filename_database()]6861** <li> [sqlite3_filename_journal()]6862** <li> [sqlite3_filename_wal()]6863** </ul>6864*/6865SQLITE_API sqlite3_filename sqlite3_db_filename(sqlite3 *db, const char *zDbName);68666867/*6868** CAPI3REF: Determine if a database is read-only6869** METHOD: sqlite36870**6871** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N6872** of connection D is read-only, 0 if it is read/write, or -1 if N is not6873** the name of a database on connection D.6874*/6875SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);68766877/*6878** CAPI3REF: Determine the transaction state of a database6879** METHOD: sqlite36880**6881** ^The sqlite3_txn_state(D,S) interface returns the current6882** [transaction state] of schema S in database connection D. ^If S is NULL,6883** then the highest transaction state of any schema on database connection D6884** is returned. Transaction states are (in order of lowest to highest):6885** <ol>6886** <li value="0"> SQLITE_TXN_NONE6887** <li value="1"> SQLITE_TXN_READ6888** <li value="2"> SQLITE_TXN_WRITE6889** </ol>6890** ^If the S argument to sqlite3_txn_state(D,S) is not the name of6891** a valid schema, then -1 is returned.6892*/6893SQLITE_API int sqlite3_txn_state(sqlite3*,const char *zSchema);68946895/*6896** CAPI3REF: Allowed return values from sqlite3_txn_state()6897** KEYWORDS: {transaction state}6898**6899** These constants define the current transaction state of a database file.6900** ^The [sqlite3_txn_state(D,S)] interface returns one of these6901** constants in order to describe the transaction state of schema S6902** in [database connection] D.6903**6904** <dl>6905** [[SQLITE_TXN_NONE]] <dt>SQLITE_TXN_NONE</dt>6906** <dd>The SQLITE_TXN_NONE state means that no transaction is currently6907** pending.</dd>6908**6909** [[SQLITE_TXN_READ]] <dt>SQLITE_TXN_READ</dt>6910** <dd>The SQLITE_TXN_READ state means that the database is currently6911** in a read transaction. Content has been read from the database file6912** but nothing in the database file has changed. The transaction state6913** will advanced to SQLITE_TXN_WRITE if any changes occur and there are6914** no other conflicting concurrent write transactions. The transaction6915** state will revert to SQLITE_TXN_NONE following a [ROLLBACK] or6916** [COMMIT].</dd>6917**6918** [[SQLITE_TXN_WRITE]] <dt>SQLITE_TXN_WRITE</dt>6919** <dd>The SQLITE_TXN_WRITE state means that the database is currently6920** in a write transaction. Content has been written to the database file6921** but has not yet committed. The transaction state will change to6922** to SQLITE_TXN_NONE at the next [ROLLBACK] or [COMMIT].</dd>6923*/6924#define SQLITE_TXN_NONE 06925#define SQLITE_TXN_READ 16926#define SQLITE_TXN_WRITE 269276928/*6929** CAPI3REF: Find the next prepared statement6930** METHOD: sqlite36931**6932** ^This interface returns a pointer to the next [prepared statement] after6933** pStmt associated with the [database connection] pDb. ^If pStmt is NULL6934** then this interface returns a pointer to the first prepared statement6935** associated with the database connection pDb. ^If no prepared statement6936** satisfies the conditions of this routine, it returns NULL.6937**6938** The [database connection] pointer D in a call to6939** [sqlite3_next_stmt(D,S)] must refer to an open database6940** connection and in particular must not be a NULL pointer.6941*/6942SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt);69436944/*6945** CAPI3REF: Commit And Rollback Notification Callbacks6946** METHOD: sqlite36947**6948** ^The sqlite3_commit_hook() interface registers a callback6949** function to be invoked whenever a transaction is [COMMIT | committed].6950** ^Any callback set by a previous call to sqlite3_commit_hook()6951** for the same database connection is overridden.6952** ^The sqlite3_rollback_hook() interface registers a callback6953** function to be invoked whenever a transaction is [ROLLBACK | rolled back].6954** ^Any callback set by a previous call to sqlite3_rollback_hook()6955** for the same database connection is overridden.6956** ^The pArg argument is passed through to the callback.6957** ^If the callback on a commit hook function returns non-zero,6958** then the commit is converted into a rollback.6959**6960** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions6961** return the P argument from the previous call of the same function6962** on the same [database connection] D, or NULL for6963** the first call for each function on D.6964**6965** The commit and rollback hook callbacks are not reentrant.6966** The callback implementation must not do anything that will modify6967** the database connection that invoked the callback. Any actions6968** to modify the database connection must be deferred until after the6969** completion of the [sqlite3_step()] call that triggered the commit6970** or rollback hook in the first place.6971** Note that running any other SQL statements, including SELECT statements,6972** or merely calling [sqlite3_prepare_v2()] and [sqlite3_step()] will modify6973** the database connections for the meaning of "modify" in this paragraph.6974**6975** ^Registering a NULL function disables the callback.6976**6977** ^When the commit hook callback routine returns zero, the [COMMIT]6978** operation is allowed to continue normally. ^If the commit hook6979** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK].6980** ^The rollback hook is invoked on a rollback that results from a commit6981** hook returning non-zero, just as it would be with any other rollback.6982**6983** ^For the purposes of this API, a transaction is said to have been6984** rolled back if an explicit "ROLLBACK" statement is executed, or6985** an error or constraint causes an implicit rollback to occur.6986** ^The rollback callback is not invoked if a transaction is6987** automatically rolled back because the database connection is closed.6988**6989** See also the [sqlite3_update_hook()] interface.6990*/6991SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*);6992SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*);69936994/*6995** CAPI3REF: Autovacuum Compaction Amount Callback6996** METHOD: sqlite36997**6998** ^The sqlite3_autovacuum_pages(D,C,P,X) interface registers a callback6999** function C that is invoked prior to each autovacuum of the database7000** file. ^The callback is passed a copy of the generic data pointer (P),7001** the schema-name of the attached database that is being autovacuumed,7002** the size of the database file in pages, the number of free pages,7003** and the number of bytes per page, respectively. The callback should7004** return the number of free pages that should be removed by the7005** autovacuum. ^If the callback returns zero, then no autovacuum happens.7006** ^If the value returned is greater than or equal to the number of7007** free pages, then a complete autovacuum happens.7008**7009** <p>^If there are multiple ATTACH-ed database files that are being7010** modified as part of a transaction commit, then the autovacuum pages7011** callback is invoked separately for each file.7012**7013** <p><b>The callback is not reentrant.</b> The callback function should7014** not attempt to invoke any other SQLite interface. If it does, bad7015** things may happen, including segmentation faults and corrupt database7016** files. The callback function should be a simple function that7017** does some arithmetic on its input parameters and returns a result.7018**7019** ^The X parameter to sqlite3_autovacuum_pages(D,C,P,X) is an optional7020** destructor for the P parameter. ^If X is not NULL, then X(P) is7021** invoked whenever the database connection closes or when the callback7022** is overwritten by another invocation of sqlite3_autovacuum_pages().7023**7024** <p>^There is only one autovacuum pages callback per database connection.7025** ^Each call to the sqlite3_autovacuum_pages() interface overrides all7026** previous invocations for that database connection. ^If the callback7027** argument (C) to sqlite3_autovacuum_pages(D,C,P,X) is a NULL pointer,7028** then the autovacuum steps callback is canceled. The return value7029** from sqlite3_autovacuum_pages() is normally SQLITE_OK, but might7030** be some other error code if something goes wrong. The current7031** implementation will only return SQLITE_OK or SQLITE_MISUSE, but other7032** return codes might be added in future releases.7033**7034** <p>If no autovacuum pages callback is specified (the usual case) or7035** a NULL pointer is provided for the callback,7036** then the default behavior is to vacuum all free pages. So, in other7037** words, the default behavior is the same as if the callback function7038** were something like this:7039**7040** <blockquote><pre>7041** unsigned int demonstration_autovac_pages_callback(7042** void *pClientData,7043** const char *zSchema,7044** unsigned int nDbPage,7045** unsigned int nFreePage,7046** unsigned int nBytePerPage7047** ){7048** return nFreePage;7049** }7050** </pre></blockquote>7051*/7052SQLITE_API int sqlite3_autovacuum_pages(7053sqlite3 *db,7054unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int),7055void*,7056void(*)(void*)7057);705870597060/*7061** CAPI3REF: Data Change Notification Callbacks7062** METHOD: sqlite37063**7064** ^The sqlite3_update_hook() interface registers a callback function7065** with the [database connection] identified by the first argument7066** to be invoked whenever a row is updated, inserted or deleted in7067** a [rowid table].7068** ^Any callback set by a previous call to this function7069** for the same database connection is overridden.7070**7071** ^The second argument is a pointer to the function to invoke when a7072** row is updated, inserted or deleted in a rowid table.7073** ^The update hook is disabled by invoking sqlite3_update_hook()7074** with a NULL pointer as the second parameter.7075** ^The first argument to the callback is a copy of the third argument7076** to sqlite3_update_hook().7077** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE],7078** or [SQLITE_UPDATE], depending on the operation that caused the callback7079** to be invoked.7080** ^The third and fourth arguments to the callback contain pointers to the7081** database and table name containing the affected row.7082** ^The final callback parameter is the [rowid] of the row.7083** ^In the case of an update, this is the [rowid] after the update takes place.7084**7085** ^(The update hook is not invoked when internal system tables are7086** modified (i.e. sqlite_sequence).)^7087** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.7088**7089** ^In the current implementation, the update hook7090** is not invoked when conflicting rows are deleted because of an7091** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook7092** invoked when rows are deleted using the [truncate optimization].7093** The exceptions defined in this paragraph might change in a future7094** release of SQLite.7095**7096** Whether the update hook is invoked before or after the7097** corresponding change is currently unspecified and may differ7098** depending on the type of change. Do not rely on the order of the7099** hook call with regards to the final result of the operation which7100** triggers the hook.7101**7102** The update hook implementation must not do anything that will modify7103** the database connection that invoked the update hook. Any actions7104** to modify the database connection must be deferred until after the7105** completion of the [sqlite3_step()] call that triggered the update hook.7106** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their7107** database connections for the meaning of "modify" in this paragraph.7108**7109** ^The sqlite3_update_hook(D,C,P) function7110** returns the P argument from the previous call7111** on the same [database connection] D, or NULL for7112** the first call on D.7113**7114** See also the [sqlite3_commit_hook()], [sqlite3_rollback_hook()],7115** and [sqlite3_preupdate_hook()] interfaces.7116*/7117SQLITE_API void *sqlite3_update_hook(7118sqlite3*,7119void(*)(void *,int ,char const *,char const *,sqlite3_int64),7120void*7121);71227123/*7124** CAPI3REF: Enable Or Disable Shared Pager Cache7125**7126** ^(This routine enables or disables the sharing of the database cache7127** and schema data structures between [database connection | connections]7128** to the same database. Sharing is enabled if the argument is true7129** and disabled if the argument is false.)^7130**7131** This interface is omitted if SQLite is compiled with7132** [-DSQLITE_OMIT_SHARED_CACHE]. The [-DSQLITE_OMIT_SHARED_CACHE]7133** compile-time option is recommended because the7134** [use of shared cache mode is discouraged].7135**7136** ^Cache sharing is enabled and disabled for an entire process.7137** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]).7138** In prior versions of SQLite,7139** sharing was enabled or disabled for each thread separately.7140**7141** ^(The cache sharing mode set by this interface effects all subsequent7142** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()].7143** Existing database connections continue to use the sharing mode7144** that was in effect at the time they were opened.)^7145**7146** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled7147** successfully. An [error code] is returned otherwise.)^7148**7149** ^Shared cache is disabled by default. It is recommended that it stay7150** that way. In other words, do not use this routine. This interface7151** continues to be provided for historical compatibility, but its use is7152** discouraged. Any use of shared cache is discouraged. If shared cache7153** must be used, it is recommended that shared cache only be enabled for7154** individual database connections using the [sqlite3_open_v2()] interface7155** with the [SQLITE_OPEN_SHAREDCACHE] flag.7156**7157** Note: This method is disabled on MacOS X 10.7 and iOS version 5.07158** and will always return SQLITE_MISUSE. On those systems,7159** shared cache mode should be enabled per-database connection via7160** [sqlite3_open_v2()] with [SQLITE_OPEN_SHAREDCACHE].7161**7162** This interface is threadsafe on processors where writing a7163** 32-bit integer is atomic.7164**7165** See Also: [SQLite Shared-Cache Mode]7166*/7167SQLITE_API int sqlite3_enable_shared_cache(int);71687169/*7170** CAPI3REF: Attempt To Free Heap Memory7171**7172** ^The sqlite3_release_memory() interface attempts to free N bytes7173** of heap memory by deallocating non-essential memory allocations7174** held by the database library. Memory used to cache database7175** pages to improve performance is an example of non-essential memory.7176** ^sqlite3_release_memory() returns the number of bytes actually freed,7177** which might be more or less than the amount requested.7178** ^The sqlite3_release_memory() routine is a no-op returning zero7179** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT].7180**7181** See also: [sqlite3_db_release_memory()]7182*/7183SQLITE_API int sqlite3_release_memory(int);71847185/*7186** CAPI3REF: Free Memory Used By A Database Connection7187** METHOD: sqlite37188**7189** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap7190** memory as possible from database connection D. Unlike the7191** [sqlite3_release_memory()] interface, this interface is in effect even7192** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is7193** omitted.7194**7195** See also: [sqlite3_release_memory()]7196*/7197SQLITE_API int sqlite3_db_release_memory(sqlite3*);71987199/*7200** CAPI3REF: Impose A Limit On Heap Size7201**7202** These interfaces impose limits on the amount of heap memory that will be7203** by all database connections within a single process.7204**7205** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the7206** soft limit on the amount of heap memory that may be allocated by SQLite.7207** ^SQLite strives to keep heap memory utilization below the soft heap7208** limit by reducing the number of pages held in the page cache7209** as heap memory usages approaches the limit.7210** ^The soft heap limit is "soft" because even though SQLite strives to stay7211** below the limit, it will exceed the limit rather than generate7212** an [SQLITE_NOMEM] error. In other words, the soft heap limit7213** is advisory only.7214**7215** ^The sqlite3_hard_heap_limit64(N) interface sets a hard upper bound of7216** N bytes on the amount of memory that will be allocated. ^The7217** sqlite3_hard_heap_limit64(N) interface is similar to7218** sqlite3_soft_heap_limit64(N) except that memory allocations will fail7219** when the hard heap limit is reached.7220**7221** ^The return value from both sqlite3_soft_heap_limit64() and7222** sqlite3_hard_heap_limit64() is the size of7223** the heap limit prior to the call, or negative in the case of an7224** error. ^If the argument N is negative7225** then no change is made to the heap limit. Hence, the current7226** size of heap limits can be determined by invoking7227** sqlite3_soft_heap_limit64(-1) or sqlite3_hard_heap_limit(-1).7228**7229** ^Setting the heap limits to zero disables the heap limiter mechanism.7230**7231** ^The soft heap limit may not be greater than the hard heap limit.7232** ^If the hard heap limit is enabled and if sqlite3_soft_heap_limit(N)7233** is invoked with a value of N that is greater than the hard heap limit,7234** the soft heap limit is set to the value of the hard heap limit.7235** ^The soft heap limit is automatically enabled whenever the hard heap7236** limit is enabled. ^When sqlite3_hard_heap_limit64(N) is invoked and7237** the soft heap limit is outside the range of 1..N, then the soft heap7238** limit is set to N. ^Invoking sqlite3_soft_heap_limit64(0) when the7239** hard heap limit is enabled makes the soft heap limit equal to the7240** hard heap limit.7241**7242** The memory allocation limits can also be adjusted using7243** [PRAGMA soft_heap_limit] and [PRAGMA hard_heap_limit].7244**7245** ^(The heap limits are not enforced in the current implementation7246** if one or more of following conditions are true:7247**7248** <ul>7249** <li> The limit value is set to zero.7250** <li> Memory accounting is disabled using a combination of the7251** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and7252** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option.7253** <li> An alternative page cache implementation is specified using7254** [sqlite3_config]([SQLITE_CONFIG_PCACHE2],...).7255** <li> The page cache allocates from its own memory pool supplied7256** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than7257** from the heap.7258** </ul>)^7259**7260** The circumstances under which SQLite will enforce the heap limits may7261** changes in future releases of SQLite.7262*/7263SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);7264SQLITE_API sqlite3_int64 sqlite3_hard_heap_limit64(sqlite3_int64 N);72657266/*7267** CAPI3REF: Deprecated Soft Heap Limit Interface7268** DEPRECATED7269**7270** This is a deprecated version of the [sqlite3_soft_heap_limit64()]7271** interface. This routine is provided for historical compatibility7272** only. All new applications should use the7273** [sqlite3_soft_heap_limit64()] interface rather than this one.7274*/7275SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N);727672777278/*7279** CAPI3REF: Extract Metadata About A Column Of A Table7280** METHOD: sqlite37281**7282** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns7283** information about column C of table T in database D7284** on [database connection] X.)^ ^The sqlite3_table_column_metadata()7285** interface returns SQLITE_OK and fills in the non-NULL pointers in7286** the final five arguments with appropriate values if the specified7287** column exists. ^The sqlite3_table_column_metadata() interface returns7288** SQLITE_ERROR if the specified column does not exist.7289** ^If the column-name parameter to sqlite3_table_column_metadata() is a7290** NULL pointer, then this routine simply checks for the existence of the7291** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it7292** does not. If the table name parameter T in a call to7293** sqlite3_table_column_metadata(X,D,T,C,...) is NULL then the result is7294** undefined behavior.7295**7296** ^The column is identified by the second, third and fourth parameters to7297** this function. ^(The second parameter is either the name of the database7298** (i.e. "main", "temp", or an attached database) containing the specified7299** table or NULL.)^ ^If it is NULL, then all attached databases are searched7300** for the table using the same algorithm used by the database engine to7301** resolve unqualified table references.7302**7303** ^The third and fourth parameters to this function are the table and column7304** name of the desired column, respectively.7305**7306** ^Metadata is returned by writing to the memory locations passed as the 5th7307** and subsequent parameters to this function. ^Any of these arguments may be7308** NULL, in which case the corresponding element of metadata is omitted.7309**7310** ^(<blockquote>7311** <table border="1">7312** <tr><th> Parameter <th> Output<br>Type <th> Description7313**7314** <tr><td> 5th <td> const char* <td> Data type7315** <tr><td> 6th <td> const char* <td> Name of default collation sequence7316** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint7317** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY7318** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT]7319** </table>7320** </blockquote>)^7321**7322** ^The memory pointed to by the character pointers returned for the7323** declaration type and collation sequence is valid until the next7324** call to any SQLite API function.7325**7326** ^If the specified table is actually a view, an [error code] is returned.7327**7328** ^If the specified column is "rowid", "oid" or "_rowid_" and the table7329** is not a [WITHOUT ROWID] table and an7330** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output7331** parameters are set for the explicitly declared column. ^(If there is no7332** [INTEGER PRIMARY KEY] column, then the outputs7333** for the [rowid] are set as follows:7334**7335** <pre>7336** data type: "INTEGER"7337** collation sequence: "BINARY"7338** not null: 07339** primary key: 17340** auto increment: 07341** </pre>)^7342**7343** ^This function causes all database schemas to be read from disk and7344** parsed, if that has not already been done, and returns an error if7345** any errors are encountered while loading the schema.7346*/7347SQLITE_API int sqlite3_table_column_metadata(7348sqlite3 *db, /* Connection handle */7349const char *zDbName, /* Database name or NULL */7350const char *zTableName, /* Table name */7351const char *zColumnName, /* Column name */7352char const **pzDataType, /* OUTPUT: Declared data type */7353char const **pzCollSeq, /* OUTPUT: Collation sequence name */7354int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */7355int *pPrimaryKey, /* OUTPUT: True if column part of PK */7356int *pAutoinc /* OUTPUT: True if column is auto-increment */7357);73587359/*7360** CAPI3REF: Load An Extension7361** METHOD: sqlite37362**7363** ^This interface loads an SQLite extension library from the named file.7364**7365** ^The sqlite3_load_extension() interface attempts to load an7366** [SQLite extension] library contained in the file zFile. If7367** the file cannot be loaded directly, attempts are made to load7368** with various operating-system specific extensions added.7369** So for example, if "samplelib" cannot be loaded, then names like7370** "samplelib.so" or "samplelib.dylib" or "samplelib.dll" might7371** be tried also.7372**7373** ^The entry point is zProc.7374** ^(zProc may be 0, in which case SQLite will try to come up with an7375** entry point name on its own. It first tries "sqlite3_extension_init".7376** If that does not work, it constructs a name "sqlite3_X_init" where the7377** X is consists of the lower-case equivalent of all ASCII alphabetic7378** characters in the filename from the last "/" to the first following7379** "." and omitting any initial "lib".)^7380** ^The sqlite3_load_extension() interface returns7381** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong.7382** ^If an error occurs and pzErrMsg is not 0, then the7383** [sqlite3_load_extension()] interface shall attempt to7384** fill *pzErrMsg with error message text stored in memory7385** obtained from [sqlite3_malloc()]. The calling function7386** should free this memory by calling [sqlite3_free()].7387**7388** ^Extension loading must be enabled using7389** [sqlite3_enable_load_extension()] or7390** [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],1,NULL)7391** prior to calling this API,7392** otherwise an error will be returned.7393**7394** <b>Security warning:</b> It is recommended that the7395** [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method be used to enable only this7396** interface. The use of the [sqlite3_enable_load_extension()] interface7397** should be avoided. This will keep the SQL function [load_extension()]7398** disabled and prevent SQL injections from giving attackers7399** access to extension loading capabilities.7400**7401** See also the [load_extension() SQL function].7402*/7403SQLITE_API int sqlite3_load_extension(7404sqlite3 *db, /* Load the extension into this database connection */7405const char *zFile, /* Name of the shared library containing extension */7406const char *zProc, /* Entry point. Derived from zFile if 0 */7407char **pzErrMsg /* Put error message here if not 0 */7408);74097410/*7411** CAPI3REF: Enable Or Disable Extension Loading7412** METHOD: sqlite37413**7414** ^So as not to open security holes in older applications that are7415** unprepared to deal with [extension loading], and as a means of disabling7416** [extension loading] while evaluating user-entered SQL, the following API7417** is provided to turn the [sqlite3_load_extension()] mechanism on and off.7418**7419** ^Extension loading is off by default.7420** ^Call the sqlite3_enable_load_extension() routine with onoff==17421** to turn extension loading on and call it with onoff==0 to turn7422** it back off again.7423**7424** ^This interface enables or disables both the C-API7425** [sqlite3_load_extension()] and the SQL function [load_extension()].7426** ^(Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)7427** to enable or disable only the C-API.)^7428**7429** <b>Security warning:</b> It is recommended that extension loading7430** be enabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method7431** rather than this interface, so the [load_extension()] SQL function7432** remains disabled. This will prevent SQL injections from giving attackers7433** access to extension loading capabilities.7434*/7435SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff);74367437/*7438** CAPI3REF: Automatically Load Statically Linked Extensions7439**7440** ^This interface causes the xEntryPoint() function to be invoked for7441** each new [database connection] that is created. The idea here is that7442** xEntryPoint() is the entry point for a statically linked [SQLite extension]7443** that is to be automatically loaded into all new database connections.7444**7445** ^(Even though the function prototype shows that xEntryPoint() takes7446** no arguments and returns void, SQLite invokes xEntryPoint() with three7447** arguments and expects an integer result as if the signature of the7448** entry point where as follows:7449**7450** <blockquote><pre>7451** int xEntryPoint(7452** sqlite3 *db,7453** const char **pzErrMsg,7454** const struct sqlite3_api_routines *pThunk7455** );7456** </pre></blockquote>)^7457**7458** If the xEntryPoint routine encounters an error, it should make *pzErrMsg7459** point to an appropriate error message (obtained from [sqlite3_mprintf()])7460** and return an appropriate [error code]. ^SQLite ensures that *pzErrMsg7461** is NULL before calling the xEntryPoint(). ^SQLite will invoke7462** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns. ^If any7463** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()],7464** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail.7465**7466** ^Calling sqlite3_auto_extension(X) with an entry point X that is already7467** on the list of automatic extensions is a harmless no-op. ^No entry point7468** will be called more than once for each database connection that is opened.7469**7470** See also: [sqlite3_reset_auto_extension()]7471** and [sqlite3_cancel_auto_extension()]7472*/7473SQLITE_API int sqlite3_auto_extension(void(*xEntryPoint)(void));74747475/*7476** CAPI3REF: Cancel Automatic Extension Loading7477**7478** ^The [sqlite3_cancel_auto_extension(X)] interface unregisters the7479** initialization routine X that was registered using a prior call to7480** [sqlite3_auto_extension(X)]. ^The [sqlite3_cancel_auto_extension(X)]7481** routine returns 1 if initialization routine X was successfully7482** unregistered and it returns 0 if X was not on the list of initialization7483** routines.7484*/7485SQLITE_API int sqlite3_cancel_auto_extension(void(*xEntryPoint)(void));74867487/*7488** CAPI3REF: Reset Automatic Extension Loading7489**7490** ^This interface disables all automatic extensions previously7491** registered using [sqlite3_auto_extension()].7492*/7493SQLITE_API void sqlite3_reset_auto_extension(void);74947495/*7496** Structures used by the virtual table interface7497*/7498typedef struct sqlite3_vtab sqlite3_vtab;7499typedef struct sqlite3_index_info sqlite3_index_info;7500typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor;7501typedef struct sqlite3_module sqlite3_module;75027503/*7504** CAPI3REF: Virtual Table Object7505** KEYWORDS: sqlite3_module {virtual table module}7506**7507** This structure, sometimes called a "virtual table module",7508** defines the implementation of a [virtual table].7509** This structure consists mostly of methods for the module.7510**7511** ^A virtual table module is created by filling in a persistent7512** instance of this structure and passing a pointer to that instance7513** to [sqlite3_create_module()] or [sqlite3_create_module_v2()].7514** ^The registration remains valid until it is replaced by a different7515** module or until the [database connection] closes. The content7516** of this structure must not change while it is registered with7517** any database connection.7518*/7519struct sqlite3_module {7520int iVersion;7521int (*xCreate)(sqlite3*, void *pAux,7522int argc, const char *const*argv,7523sqlite3_vtab **ppVTab, char**);7524int (*xConnect)(sqlite3*, void *pAux,7525int argc, const char *const*argv,7526sqlite3_vtab **ppVTab, char**);7527int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);7528int (*xDisconnect)(sqlite3_vtab *pVTab);7529int (*xDestroy)(sqlite3_vtab *pVTab);7530int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor);7531int (*xClose)(sqlite3_vtab_cursor*);7532int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr,7533int argc, sqlite3_value **argv);7534int (*xNext)(sqlite3_vtab_cursor*);7535int (*xEof)(sqlite3_vtab_cursor*);7536int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int);7537int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid);7538int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *);7539int (*xBegin)(sqlite3_vtab *pVTab);7540int (*xSync)(sqlite3_vtab *pVTab);7541int (*xCommit)(sqlite3_vtab *pVTab);7542int (*xRollback)(sqlite3_vtab *pVTab);7543int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName,7544void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),7545void **ppArg);7546int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);7547/* The methods above are in version 1 of the sqlite_module object. Those7548** below are for version 2 and greater. */7549int (*xSavepoint)(sqlite3_vtab *pVTab, int);7550int (*xRelease)(sqlite3_vtab *pVTab, int);7551int (*xRollbackTo)(sqlite3_vtab *pVTab, int);7552/* The methods above are in versions 1 and 2 of the sqlite_module object.7553** Those below are for version 3 and greater. */7554int (*xShadowName)(const char*);7555/* The methods above are in versions 1 through 3 of the sqlite_module object.7556** Those below are for version 4 and greater. */7557int (*xIntegrity)(sqlite3_vtab *pVTab, const char *zSchema,7558const char *zTabName, int mFlags, char **pzErr);7559};75607561/*7562** CAPI3REF: Virtual Table Indexing Information7563** KEYWORDS: sqlite3_index_info7564**7565** The sqlite3_index_info structure and its substructures is used as part7566** of the [virtual table] interface to7567** pass information into and receive the reply from the [xBestIndex]7568** method of a [virtual table module]. The fields under **Inputs** are the7569** inputs to xBestIndex and are read-only. xBestIndex inserts its7570** results into the **Outputs** fields.7571**7572** ^(The aConstraint[] array records WHERE clause constraints of the form:7573**7574** <blockquote>column OP expr</blockquote>7575**7576** where OP is =, <, <=, >, or >=.)^ ^(The particular operator is7577** stored in aConstraint[].op using one of the7578** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^7579** ^(The index of the column is stored in7580** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the7581** expr on the right-hand side can be evaluated (and thus the constraint7582** is usable) and false if it cannot.)^7583**7584** ^The optimizer automatically inverts terms of the form "expr OP column"7585** and makes other simplifications to the WHERE clause in an attempt to7586** get as many WHERE clause terms into the form shown above as possible.7587** ^The aConstraint[] array only reports WHERE clause terms that are7588** relevant to the particular virtual table being queried.7589**7590** ^Information about the ORDER BY clause is stored in aOrderBy[].7591** ^Each term of aOrderBy records a column of the ORDER BY clause.7592**7593** The colUsed field indicates which columns of the virtual table may be7594** required by the current scan. Virtual table columns are numbered from7595** zero in the order in which they appear within the CREATE TABLE statement7596** passed to sqlite3_declare_vtab(). For the first 63 columns (columns 0-62),7597** the corresponding bit is set within the colUsed mask if the column may be7598** required by SQLite. If the table has at least 64 columns and any column7599** to the right of the first 63 is required, then bit 63 of colUsed is also7600** set. In other words, column iCol may be required if the expression7601** (colUsed & ((sqlite3_uint64)1 << (iCol>=63 ? 63 : iCol))) evaluates to7602** non-zero.7603**7604** The [xBestIndex] method must fill aConstraintUsage[] with information7605** about what parameters to pass to xFilter. ^If argvIndex>0 then7606** the right-hand side of the corresponding aConstraint[] is evaluated7607** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit7608** is true, then the constraint is assumed to be fully handled by the7609** virtual table and might not be checked again by the byte code.)^ ^(The7610** aConstraintUsage[].omit flag is an optimization hint. When the omit flag7611** is left in its default setting of false, the constraint will always be7612** checked separately in byte code. If the omit flag is change to true, then7613** the constraint may or may not be checked in byte code. In other words,7614** when the omit flag is true there is no guarantee that the constraint will7615** not be checked again using byte code.)^7616**7617** ^The idxNum and idxStr values are recorded and passed into the7618** [xFilter] method.7619** ^[sqlite3_free()] is used to free idxStr if and only if7620** needToFreeIdxStr is true.7621**7622** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in7623** the correct order to satisfy the ORDER BY clause so that no separate7624** sorting step is required.7625**7626** ^The estimatedCost value is an estimate of the cost of a particular7627** strategy. A cost of N indicates that the cost of the strategy is similar7628** to a linear scan of an SQLite table with N rows. A cost of log(N)7629** indicates that the expense of the operation is similar to that of a7630** binary search on a unique indexed field of an SQLite table with N rows.7631**7632** ^The estimatedRows value is an estimate of the number of rows that7633** will be returned by the strategy.7634**7635** The xBestIndex method may optionally populate the idxFlags field with a7636** mask of SQLITE_INDEX_SCAN_* flags. One such flag is7637** [SQLITE_INDEX_SCAN_HEX], which if set causes the [EXPLAIN QUERY PLAN]7638** output to show the idxNum has hex instead of as decimal. Another flag is7639** SQLITE_INDEX_SCAN_UNIQUE, which if set indicates that the query plan will7640** return at most one row.7641**7642** Additionally, if xBestIndex sets the SQLITE_INDEX_SCAN_UNIQUE flag, then7643** SQLite also assumes that if a call to the xUpdate() method is made as7644** part of the same statement to delete or update a virtual table row and the7645** implementation returns SQLITE_CONSTRAINT, then there is no need to rollback7646** any database changes. In other words, if the xUpdate() returns7647** SQLITE_CONSTRAINT, the database contents must be exactly as they were7648** before xUpdate was called. By contrast, if SQLITE_INDEX_SCAN_UNIQUE is not7649** set and xUpdate returns SQLITE_CONSTRAINT, any database changes made by7650** the xUpdate method are automatically rolled back by SQLite.7651**7652** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info7653** structure for SQLite [version 3.8.2] ([dateof:3.8.2]).7654** If a virtual table extension is7655** used with an SQLite version earlier than 3.8.2, the results of attempting7656** to read or write the estimatedRows field are undefined (but are likely7657** to include crashing the application). The estimatedRows field should7658** therefore only be used if [sqlite3_libversion_number()] returns a7659** value greater than or equal to 3008002. Similarly, the idxFlags field7660** was added for [version 3.9.0] ([dateof:3.9.0]).7661** It may therefore only be used if7662** sqlite3_libversion_number() returns a value greater than or equal to7663** 3009000.7664*/7665struct sqlite3_index_info {7666/* Inputs */7667int nConstraint; /* Number of entries in aConstraint */7668struct sqlite3_index_constraint {7669int iColumn; /* Column constrained. -1 for ROWID */7670unsigned char op; /* Constraint operator */7671unsigned char usable; /* True if this constraint is usable */7672int iTermOffset; /* Used internally - xBestIndex should ignore */7673} *aConstraint; /* Table of WHERE clause constraints */7674int nOrderBy; /* Number of terms in the ORDER BY clause */7675struct sqlite3_index_orderby {7676int iColumn; /* Column number */7677unsigned char desc; /* True for DESC. False for ASC. */7678} *aOrderBy; /* The ORDER BY clause */7679/* Outputs */7680struct sqlite3_index_constraint_usage {7681int argvIndex; /* if >0, constraint is part of argv to xFilter */7682unsigned char omit; /* Do not code a test for this constraint */7683} *aConstraintUsage;7684int idxNum; /* Number used to identify the index */7685char *idxStr; /* String, possibly obtained from sqlite3_malloc */7686int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */7687int orderByConsumed; /* True if output is already ordered */7688double estimatedCost; /* Estimated cost of using this index */7689/* Fields below are only available in SQLite 3.8.2 and later */7690sqlite3_int64 estimatedRows; /* Estimated number of rows returned */7691/* Fields below are only available in SQLite 3.9.0 and later */7692int idxFlags; /* Mask of SQLITE_INDEX_SCAN_* flags */7693/* Fields below are only available in SQLite 3.10.0 and later */7694sqlite3_uint64 colUsed; /* Input: Mask of columns used by statement */7695};76967697/*7698** CAPI3REF: Virtual Table Scan Flags7699**7700** Virtual table implementations are allowed to set the7701** [sqlite3_index_info].idxFlags field to some combination of7702** these bits.7703*/7704#define SQLITE_INDEX_SCAN_UNIQUE 0x00000001 /* Scan visits at most 1 row */7705#define SQLITE_INDEX_SCAN_HEX 0x00000002 /* Display idxNum as hex */7706/* in EXPLAIN QUERY PLAN */77077708/*7709** CAPI3REF: Virtual Table Constraint Operator Codes7710**7711** These macros define the allowed values for the7712** [sqlite3_index_info].aConstraint[].op field. Each value represents7713** an operator that is part of a constraint term in the WHERE clause of7714** a query that uses a [virtual table].7715**7716** ^The left-hand operand of the operator is given by the corresponding7717** aConstraint[].iColumn field. ^An iColumn of -1 indicates the left-hand7718** operand is the rowid.7719** The SQLITE_INDEX_CONSTRAINT_LIMIT and SQLITE_INDEX_CONSTRAINT_OFFSET7720** operators have no left-hand operand, and so for those operators the7721** corresponding aConstraint[].iColumn is meaningless and should not be7722** used.7723**7724** All operator values from SQLITE_INDEX_CONSTRAINT_FUNCTION through7725** value 255 are reserved to represent functions that are overloaded7726** by the [xFindFunction|xFindFunction method] of the virtual table7727** implementation.7728**7729** The right-hand operands for each constraint might be accessible using7730** the [sqlite3_vtab_rhs_value()] interface. Usually the right-hand7731** operand is only available if it appears as a single constant literal7732** in the input SQL. If the right-hand operand is another column or an7733** expression (even a constant expression) or a parameter, then the7734** sqlite3_vtab_rhs_value() probably will not be able to extract it.7735** ^The SQLITE_INDEX_CONSTRAINT_ISNULL and7736** SQLITE_INDEX_CONSTRAINT_ISNOTNULL operators have no right-hand operand7737** and hence calls to sqlite3_vtab_rhs_value() for those operators will7738** always return SQLITE_NOTFOUND.7739**7740** The collating sequence to be used for comparison can be found using7741** the [sqlite3_vtab_collation()] interface. For most real-world virtual7742** tables, the collating sequence of constraints does not matter (for example7743** because the constraints are numeric) and so the sqlite3_vtab_collation()7744** interface is not commonly needed.7745*/7746#define SQLITE_INDEX_CONSTRAINT_EQ 27747#define SQLITE_INDEX_CONSTRAINT_GT 47748#define SQLITE_INDEX_CONSTRAINT_LE 87749#define SQLITE_INDEX_CONSTRAINT_LT 167750#define SQLITE_INDEX_CONSTRAINT_GE 327751#define SQLITE_INDEX_CONSTRAINT_MATCH 647752#define SQLITE_INDEX_CONSTRAINT_LIKE 657753#define SQLITE_INDEX_CONSTRAINT_GLOB 667754#define SQLITE_INDEX_CONSTRAINT_REGEXP 677755#define SQLITE_INDEX_CONSTRAINT_NE 687756#define SQLITE_INDEX_CONSTRAINT_ISNOT 697757#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 707758#define SQLITE_INDEX_CONSTRAINT_ISNULL 717759#define SQLITE_INDEX_CONSTRAINT_IS 727760#define SQLITE_INDEX_CONSTRAINT_LIMIT 737761#define SQLITE_INDEX_CONSTRAINT_OFFSET 747762#define SQLITE_INDEX_CONSTRAINT_FUNCTION 15077637764/*7765** CAPI3REF: Register A Virtual Table Implementation7766** METHOD: sqlite37767**7768** ^These routines are used to register a new [virtual table module] name.7769** ^Module names must be registered before7770** creating a new [virtual table] using the module and before using a7771** preexisting [virtual table] for the module.7772**7773** ^The module name is registered on the [database connection] specified7774** by the first parameter. ^The name of the module is given by the7775** second parameter. ^The third parameter is a pointer to7776** the implementation of the [virtual table module]. ^The fourth7777** parameter is an arbitrary client data pointer that is passed through7778** into the [xCreate] and [xConnect] methods of the virtual table module7779** when a new virtual table is be being created or reinitialized.7780**7781** ^The sqlite3_create_module_v2() interface has a fifth parameter which7782** is a pointer to a destructor for the pClientData. ^SQLite will7783** invoke the destructor function (if it is not NULL) when SQLite7784** no longer needs the pClientData pointer. ^The destructor will also7785** be invoked if the call to sqlite3_create_module_v2() fails.7786** ^The sqlite3_create_module()7787** interface is equivalent to sqlite3_create_module_v2() with a NULL7788** destructor.7789**7790** ^If the third parameter (the pointer to the sqlite3_module object) is7791** NULL then no new module is created and any existing modules with the7792** same name are dropped.7793**7794** See also: [sqlite3_drop_modules()]7795*/7796SQLITE_API int sqlite3_create_module(7797sqlite3 *db, /* SQLite connection to register module with */7798const char *zName, /* Name of the module */7799const sqlite3_module *p, /* Methods for the module */7800void *pClientData /* Client data for xCreate/xConnect */7801);7802SQLITE_API int sqlite3_create_module_v2(7803sqlite3 *db, /* SQLite connection to register module with */7804const char *zName, /* Name of the module */7805const sqlite3_module *p, /* Methods for the module */7806void *pClientData, /* Client data for xCreate/xConnect */7807void(*xDestroy)(void*) /* Module destructor function */7808);78097810/*7811** CAPI3REF: Remove Unnecessary Virtual Table Implementations7812** METHOD: sqlite37813**7814** ^The sqlite3_drop_modules(D,L) interface removes all virtual7815** table modules from database connection D except those named on list L.7816** The L parameter must be either NULL or a pointer to an array of pointers7817** to strings where the array is terminated by a single NULL pointer.7818** ^If the L parameter is NULL, then all virtual table modules are removed.7819**7820** See also: [sqlite3_create_module()]7821*/7822SQLITE_API int sqlite3_drop_modules(7823sqlite3 *db, /* Remove modules from this connection */7824const char **azKeep /* Except, do not remove the ones named here */7825);78267827/*7828** CAPI3REF: Virtual Table Instance Object7829** KEYWORDS: sqlite3_vtab7830**7831** Every [virtual table module] implementation uses a subclass7832** of this object to describe a particular instance7833** of the [virtual table]. Each subclass will7834** be tailored to the specific needs of the module implementation.7835** The purpose of this superclass is to define certain fields that are7836** common to all module implementations.7837**7838** ^Virtual tables methods can set an error message by assigning a7839** string obtained from [sqlite3_mprintf()] to zErrMsg. The method should7840** take care that any prior string is freed by a call to [sqlite3_free()]7841** prior to assigning a new string to zErrMsg. ^After the error message7842** is delivered up to the client application, the string will be automatically7843** freed by sqlite3_free() and the zErrMsg field will be zeroed.7844*/7845struct sqlite3_vtab {7846const sqlite3_module *pModule; /* The module for this virtual table */7847int nRef; /* Number of open cursors */7848char *zErrMsg; /* Error message from sqlite3_mprintf() */7849/* Virtual table implementations will typically add additional fields */7850};78517852/*7853** CAPI3REF: Virtual Table Cursor Object7854** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor}7855**7856** Every [virtual table module] implementation uses a subclass of the7857** following structure to describe cursors that point into the7858** [virtual table] and are used7859** to loop through the virtual table. Cursors are created using the7860** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed7861** by the [sqlite3_module.xClose | xClose] method. Cursors are used7862** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods7863** of the module. Each module implementation will define7864** the content of a cursor structure to suit its own needs.7865**7866** This superclass exists in order to define fields of the cursor that7867** are common to all implementations.7868*/7869struct sqlite3_vtab_cursor {7870sqlite3_vtab *pVtab; /* Virtual table of this cursor */7871/* Virtual table implementations will typically add additional fields */7872};78737874/*7875** CAPI3REF: Declare The Schema Of A Virtual Table7876**7877** ^The [xCreate] and [xConnect] methods of a7878** [virtual table module] call this interface7879** to declare the format (the names and datatypes of the columns) of7880** the virtual tables they implement.7881*/7882SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL);78837884/*7885** CAPI3REF: Overload A Function For A Virtual Table7886** METHOD: sqlite37887**7888** ^(Virtual tables can provide alternative implementations of functions7889** using the [xFindFunction] method of the [virtual table module].7890** But global versions of those functions7891** must exist in order to be overloaded.)^7892**7893** ^(This API makes sure a global version of a function with a particular7894** name and number of parameters exists. If no such function exists7895** before this API is called, a new function is created.)^ ^The implementation7896** of the new function always causes an exception to be thrown. So7897** the new function is not good for anything by itself. Its only7898** purpose is to be a placeholder function that can be overloaded7899** by a [virtual table].7900*/7901SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);79027903/*7904** CAPI3REF: A Handle To An Open BLOB7905** KEYWORDS: {BLOB handle} {BLOB handles}7906**7907** An instance of this object represents an open BLOB on which7908** [sqlite3_blob_open | incremental BLOB I/O] can be performed.7909** ^Objects of this type are created by [sqlite3_blob_open()]7910** and destroyed by [sqlite3_blob_close()].7911** ^The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces7912** can be used to read or write small subsections of the BLOB.7913** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes.7914*/7915typedef struct sqlite3_blob sqlite3_blob;79167917/*7918** CAPI3REF: Open A BLOB For Incremental I/O7919** METHOD: sqlite37920** CONSTRUCTOR: sqlite3_blob7921**7922** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located7923** in row iRow, column zColumn, table zTable in database zDb;7924** in other words, the same BLOB that would be selected by:7925**7926** <pre>7927** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;7928** </pre>)^7929**7930** ^(Parameter zDb is not the filename that contains the database, but7931** rather the symbolic name of the database. For attached databases, this is7932** the name that appears after the AS keyword in the [ATTACH] statement.7933** For the main database file, the database name is "main". For TEMP7934** tables, the database name is "temp".)^7935**7936** ^If the flags parameter is non-zero, then the BLOB is opened for read7937** and write access. ^If the flags parameter is zero, the BLOB is opened for7938** read-only access.7939**7940** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored7941** in *ppBlob. Otherwise an [error code] is returned and, unless the error7942** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided7943** the API is not misused, it is always safe to call [sqlite3_blob_close()]7944** on *ppBlob after this function it returns.7945**7946** This function fails with SQLITE_ERROR if any of the following are true:7947** <ul>7948** <li> ^(Database zDb does not exist)^,7949** <li> ^(Table zTable does not exist within database zDb)^,7950** <li> ^(Table zTable is a WITHOUT ROWID table)^,7951** <li> ^(Column zColumn does not exist)^,7952** <li> ^(Row iRow is not present in the table)^,7953** <li> ^(The specified column of row iRow contains a value that is not7954** a TEXT or BLOB value)^,7955** <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE7956** constraint and the blob is being opened for read/write access)^,7957** <li> ^([foreign key constraints | Foreign key constraints] are enabled,7958** column zColumn is part of a [child key] definition and the blob is7959** being opened for read/write access)^.7960** </ul>7961**7962** ^Unless it returns SQLITE_MISUSE, this function sets the7963** [database connection] error code and message accessible via7964** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.7965**7966** A BLOB referenced by sqlite3_blob_open() may be read using the7967** [sqlite3_blob_read()] interface and modified by using7968** [sqlite3_blob_write()]. The [BLOB handle] can be moved to a7969** different row of the same table using the [sqlite3_blob_reopen()]7970** interface. However, the column, table, or database of a [BLOB handle]7971** cannot be changed after the [BLOB handle] is opened.7972**7973** ^(If the row that a BLOB handle points to is modified by an7974** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects7975** then the BLOB handle is marked as "expired".7976** This is true if any column of the row is changed, even a column7977** other than the one the BLOB handle is open on.)^7978** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for7979** an expired BLOB handle fail with a return code of [SQLITE_ABORT].7980** ^(Changes written into a BLOB prior to the BLOB expiring are not7981** rolled back by the expiration of the BLOB. Such changes will eventually7982** commit if the transaction continues to completion.)^7983**7984** ^Use the [sqlite3_blob_bytes()] interface to determine the size of7985** the opened blob. ^The size of a blob may not be changed by this7986** interface. Use the [UPDATE] SQL command to change the size of a7987** blob.7988**7989** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces7990** and the built-in [zeroblob] SQL function may be used to create a7991** zero-filled blob to read or write using the incremental-blob interface.7992**7993** To avoid a resource leak, every open [BLOB handle] should eventually7994** be released by a call to [sqlite3_blob_close()].7995**7996** See also: [sqlite3_blob_close()],7997** [sqlite3_blob_reopen()], [sqlite3_blob_read()],7998** [sqlite3_blob_bytes()], [sqlite3_blob_write()].7999*/8000SQLITE_API int sqlite3_blob_open(8001sqlite3*,8002const char *zDb,8003const char *zTable,8004const char *zColumn,8005sqlite3_int64 iRow,8006int flags,8007sqlite3_blob **ppBlob8008);80098010/*8011** CAPI3REF: Move a BLOB Handle to a New Row8012** METHOD: sqlite3_blob8013**8014** ^This function is used to move an existing [BLOB handle] so that it points8015** to a different row of the same database table. ^The new row is identified8016** by the rowid value passed as the second argument. Only the row can be8017** changed. ^The database, table and column on which the blob handle is open8018** remain the same. Moving an existing [BLOB handle] to a new row is8019** faster than closing the existing handle and opening a new one.8020**8021** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] -8022** it must exist and there must be either a blob or text value stored in8023** the nominated column.)^ ^If the new row is not present in the table, or if8024** it does not contain a blob or text value, or if another error occurs, an8025** SQLite error code is returned and the blob handle is considered aborted.8026** ^All subsequent calls to [sqlite3_blob_read()], [sqlite3_blob_write()] or8027** [sqlite3_blob_reopen()] on an aborted blob handle immediately return8028** SQLITE_ABORT. ^Calling [sqlite3_blob_bytes()] on an aborted blob handle8029** always returns zero.8030**8031** ^This function sets the database handle error code and message.8032*/8033SQLITE_API int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);80348035/*8036** CAPI3REF: Close A BLOB Handle8037** DESTRUCTOR: sqlite3_blob8038**8039** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed8040** unconditionally. Even if this routine returns an error code, the8041** handle is still closed.)^8042**8043** ^If the blob handle being closed was opened for read-write access, and if8044** the database is in auto-commit mode and there are no other open read-write8045** blob handles or active write statements, the current transaction is8046** committed. ^If an error occurs while committing the transaction, an error8047** code is returned and the transaction rolled back.8048**8049** Calling this function with an argument that is not a NULL pointer or an8050** open blob handle results in undefined behavior. ^Calling this routine8051** with a null pointer (such as would be returned by a failed call to8052** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function8053** is passed a valid open blob handle, the values returned by the8054** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.8055*/8056SQLITE_API int sqlite3_blob_close(sqlite3_blob *);80578058/*8059** CAPI3REF: Return The Size Of An Open BLOB8060** METHOD: sqlite3_blob8061**8062** ^Returns the size in bytes of the BLOB accessible via the8063** successfully opened [BLOB handle] in its only argument. ^The8064** incremental blob I/O routines can only read or overwriting existing8065** blob content; they cannot change the size of a blob.8066**8067** This routine only works on a [BLOB handle] which has been created8068** by a prior successful call to [sqlite3_blob_open()] and which has not8069** been closed by [sqlite3_blob_close()]. Passing any other pointer in8070** to this routine results in undefined and probably undesirable behavior.8071*/8072SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *);80738074/*8075** CAPI3REF: Read Data From A BLOB Incrementally8076** METHOD: sqlite3_blob8077**8078** ^(This function is used to read data from an open [BLOB handle] into a8079** caller-supplied buffer. N bytes of data are copied into buffer Z8080** from the open BLOB, starting at offset iOffset.)^8081**8082** ^If offset iOffset is less than N bytes from the end of the BLOB,8083** [SQLITE_ERROR] is returned and no data is read. ^If N or iOffset is8084** less than zero, [SQLITE_ERROR] is returned and no data is read.8085** ^The size of the blob (and hence the maximum value of N+iOffset)8086** can be determined using the [sqlite3_blob_bytes()] interface.8087**8088** ^An attempt to read from an expired [BLOB handle] fails with an8089** error code of [SQLITE_ABORT].8090**8091** ^(On success, sqlite3_blob_read() returns SQLITE_OK.8092** Otherwise, an [error code] or an [extended error code] is returned.)^8093**8094** This routine only works on a [BLOB handle] which has been created8095** by a prior successful call to [sqlite3_blob_open()] and which has not8096** been closed by [sqlite3_blob_close()]. Passing any other pointer in8097** to this routine results in undefined and probably undesirable behavior.8098**8099** See also: [sqlite3_blob_write()].8100*/8101SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);81028103/*8104** CAPI3REF: Write Data Into A BLOB Incrementally8105** METHOD: sqlite3_blob8106**8107** ^(This function is used to write data into an open [BLOB handle] from a8108** caller-supplied buffer. N bytes of data are copied from the buffer Z8109** into the open BLOB, starting at offset iOffset.)^8110**8111** ^(On success, sqlite3_blob_write() returns SQLITE_OK.8112** Otherwise, an [error code] or an [extended error code] is returned.)^8113** ^Unless SQLITE_MISUSE is returned, this function sets the8114** [database connection] error code and message accessible via8115** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.8116**8117** ^If the [BLOB handle] passed as the first argument was not opened for8118** writing (the flags parameter to [sqlite3_blob_open()] was zero),8119** this function returns [SQLITE_READONLY].8120**8121** This function may only modify the contents of the BLOB; it is8122** not possible to increase the size of a BLOB using this API.8123** ^If offset iOffset is less than N bytes from the end of the BLOB,8124** [SQLITE_ERROR] is returned and no data is written. The size of the8125** BLOB (and hence the maximum value of N+iOffset) can be determined8126** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less8127** than zero [SQLITE_ERROR] is returned and no data is written.8128**8129** ^An attempt to write to an expired [BLOB handle] fails with an8130** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred8131** before the [BLOB handle] expired are not rolled back by the8132** expiration of the handle, though of course those changes might8133** have been overwritten by the statement that expired the BLOB handle8134** or by other independent statements.8135**8136** This routine only works on a [BLOB handle] which has been created8137** by a prior successful call to [sqlite3_blob_open()] and which has not8138** been closed by [sqlite3_blob_close()]. Passing any other pointer in8139** to this routine results in undefined and probably undesirable behavior.8140**8141** See also: [sqlite3_blob_read()].8142*/8143SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset);81448145/*8146** CAPI3REF: Virtual File System Objects8147**8148** A virtual filesystem (VFS) is an [sqlite3_vfs] object8149** that SQLite uses to interact8150** with the underlying operating system. Most SQLite builds come with a8151** single default VFS that is appropriate for the host computer.8152** New VFSes can be registered and existing VFSes can be unregistered.8153** The following interfaces are provided.8154**8155** ^The sqlite3_vfs_find() interface returns a pointer to a VFS given its name.8156** ^Names are case sensitive.8157** ^Names are zero-terminated UTF-8 strings.8158** ^If there is no match, a NULL pointer is returned.8159** ^If zVfsName is NULL then the default VFS is returned.8160**8161** ^New VFSes are registered with sqlite3_vfs_register().8162** ^Each new VFS becomes the default VFS if the makeDflt flag is set.8163** ^The same VFS can be registered multiple times without injury.8164** ^To make an existing VFS into the default VFS, register it again8165** with the makeDflt flag set. If two different VFSes with the8166** same name are registered, the behavior is undefined. If a8167** VFS is registered with a name that is NULL or an empty string,8168** then the behavior is undefined.8169**8170** ^Unregister a VFS with the sqlite3_vfs_unregister() interface.8171** ^(If the default VFS is unregistered, another VFS is chosen as8172** the default. The choice for the new VFS is arbitrary.)^8173*/8174SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName);8175SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt);8176SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*);81778178/*8179** CAPI3REF: Mutexes8180**8181** The SQLite core uses these routines for thread8182** synchronization. Though they are intended for internal8183** use by SQLite, code that links against SQLite is8184** permitted to use any of these routines.8185**8186** The SQLite source code contains multiple implementations8187** of these mutex routines. An appropriate implementation8188** is selected automatically at compile-time. The following8189** implementations are available in the SQLite core:8190**8191** <ul>8192** <li> SQLITE_MUTEX_PTHREADS8193** <li> SQLITE_MUTEX_W328194** <li> SQLITE_MUTEX_NOOP8195** </ul>8196**8197** The SQLITE_MUTEX_NOOP implementation is a set of routines8198** that does no real locking and is appropriate for use in8199** a single-threaded application. The SQLITE_MUTEX_PTHREADS and8200** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix8201** and Windows.8202**8203** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor8204** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex8205** implementation is included with the library. In this case the8206** application must supply a custom mutex implementation using the8207** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function8208** before calling sqlite3_initialize() or any other public sqlite3_8209** function that calls sqlite3_initialize().8210**8211** ^The sqlite3_mutex_alloc() routine allocates a new8212** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()8213** routine returns NULL if it is unable to allocate the requested8214** mutex. The argument to sqlite3_mutex_alloc() must one of these8215** integer constants:8216**8217** <ul>8218** <li> SQLITE_MUTEX_FAST8219** <li> SQLITE_MUTEX_RECURSIVE8220** <li> SQLITE_MUTEX_STATIC_MAIN8221** <li> SQLITE_MUTEX_STATIC_MEM8222** <li> SQLITE_MUTEX_STATIC_OPEN8223** <li> SQLITE_MUTEX_STATIC_PRNG8224** <li> SQLITE_MUTEX_STATIC_LRU8225** <li> SQLITE_MUTEX_STATIC_PMEM8226** <li> SQLITE_MUTEX_STATIC_APP18227** <li> SQLITE_MUTEX_STATIC_APP28228** <li> SQLITE_MUTEX_STATIC_APP38229** <li> SQLITE_MUTEX_STATIC_VFS18230** <li> SQLITE_MUTEX_STATIC_VFS28231** <li> SQLITE_MUTEX_STATIC_VFS38232** </ul>8233**8234** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)8235** cause sqlite3_mutex_alloc() to create8236** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE8237** is used but not necessarily so when SQLITE_MUTEX_FAST is used.8238** The mutex implementation does not need to make a distinction8239** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does8240** not want to. SQLite will only request a recursive mutex in8241** cases where it really needs one. If a faster non-recursive mutex8242** implementation is available on the host platform, the mutex subsystem8243** might return such a mutex in response to SQLITE_MUTEX_FAST.8244**8245** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other8246** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return8247** a pointer to a static preexisting mutex. ^Nine static mutexes are8248** used by the current version of SQLite. Future versions of SQLite8249** may add additional static mutexes. Static mutexes are for internal8250** use by SQLite only. Applications that use SQLite mutexes should8251** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or8252** SQLITE_MUTEX_RECURSIVE.8253**8254** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST8255** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()8256** returns a different mutex on every call. ^For the static8257** mutex types, the same mutex is returned on every call that has8258** the same type number.8259**8260** ^The sqlite3_mutex_free() routine deallocates a previously8261** allocated dynamic mutex. Attempting to deallocate a static8262** mutex results in undefined behavior.8263**8264** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt8265** to enter a mutex. ^If another thread is already within the mutex,8266** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return8267** SQLITE_BUSY. ^The sqlite3_mutex_try() interface returns [SQLITE_OK]8268** upon successful entry. ^(Mutexes created using8269** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.8270** In such cases, the8271** mutex must be exited an equal number of times before another thread8272** can enter.)^ If the same thread tries to enter any mutex other8273** than an SQLITE_MUTEX_RECURSIVE more than once, the behavior is undefined.8274**8275** ^(Some systems (for example, Windows 95) do not support the operation8276** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try()8277** will always return SQLITE_BUSY. In most cases the SQLite core only uses8278** sqlite3_mutex_try() as an optimization, so this is acceptable8279** behavior. The exceptions are unix builds that set the8280** SQLITE_ENABLE_SETLK_TIMEOUT build option. In that case a working8281** sqlite3_mutex_try() is required.)^8282**8283** ^The sqlite3_mutex_leave() routine exits a mutex that was8284** previously entered by the same thread. The behavior8285** is undefined if the mutex is not currently entered by the8286** calling thread or is not currently allocated.8287**8288** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(),8289** sqlite3_mutex_leave(), or sqlite3_mutex_free() is a NULL pointer,8290** then any of the four routines behaves as a no-op.8291**8292** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()].8293*/8294SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int);8295SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*);8296SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*);8297SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*);8298SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*);82998300/*8301** CAPI3REF: Mutex Methods Object8302**8303** An instance of this structure defines the low-level routines8304** used to allocate and use mutexes.8305**8306** Usually, the default mutex implementations provided by SQLite are8307** sufficient, however the application has the option of substituting a custom8308** implementation for specialized deployments or systems for which SQLite8309** does not provide a suitable implementation. In this case, the application8310** creates and populates an instance of this structure to pass8311** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option.8312** Additionally, an instance of this structure can be used as an8313** output variable when querying the system for the current mutex8314** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.8315**8316** ^The xMutexInit method defined by this structure is invoked as8317** part of system initialization by the sqlite3_initialize() function.8318** ^The xMutexInit routine is called by SQLite exactly once for each8319** effective call to [sqlite3_initialize()].8320**8321** ^The xMutexEnd method defined by this structure is invoked as8322** part of system shutdown by the sqlite3_shutdown() function. The8323** implementation of this method is expected to release all outstanding8324** resources obtained by the mutex methods implementation, especially8325** those obtained by the xMutexInit method. ^The xMutexEnd()8326** interface is invoked exactly once for each call to [sqlite3_shutdown()].8327**8328** ^(The remaining seven methods defined by this structure (xMutexAlloc,8329** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and8330** xMutexNotheld) implement the following interfaces (respectively):8331**8332** <ul>8333** <li> [sqlite3_mutex_alloc()] </li>8334** <li> [sqlite3_mutex_free()] </li>8335** <li> [sqlite3_mutex_enter()] </li>8336** <li> [sqlite3_mutex_try()] </li>8337** <li> [sqlite3_mutex_leave()] </li>8338** <li> [sqlite3_mutex_held()] </li>8339** <li> [sqlite3_mutex_notheld()] </li>8340** </ul>)^8341**8342** The only difference is that the public sqlite3_XXX functions enumerated8343** above silently ignore any invocations that pass a NULL pointer instead8344** of a valid mutex handle. The implementations of the methods defined8345** by this structure are not required to handle this case. The results8346** of passing a NULL pointer instead of a valid mutex handle are undefined8347** (i.e. it is acceptable to provide an implementation that segfaults if8348** it is passed a NULL pointer).8349**8350** The xMutexInit() method must be threadsafe. It must be harmless to8351** invoke xMutexInit() multiple times within the same process and without8352** intervening calls to xMutexEnd(). Second and subsequent calls to8353** xMutexInit() must be no-ops.8354**8355** xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()]8356** and its associates). Similarly, xMutexAlloc() must not use SQLite memory8357** allocation for a static mutex. ^However xMutexAlloc() may use SQLite8358** memory allocation for a fast or recursive mutex.8359**8360** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is8361** called, but only if the prior call to xMutexInit returned SQLITE_OK.8362** If xMutexInit fails in any way, it is expected to clean up after itself8363** prior to returning.8364*/8365typedef struct sqlite3_mutex_methods sqlite3_mutex_methods;8366struct sqlite3_mutex_methods {8367int (*xMutexInit)(void);8368int (*xMutexEnd)(void);8369sqlite3_mutex *(*xMutexAlloc)(int);8370void (*xMutexFree)(sqlite3_mutex *);8371void (*xMutexEnter)(sqlite3_mutex *);8372int (*xMutexTry)(sqlite3_mutex *);8373void (*xMutexLeave)(sqlite3_mutex *);8374int (*xMutexHeld)(sqlite3_mutex *);8375int (*xMutexNotheld)(sqlite3_mutex *);8376};83778378/*8379** CAPI3REF: Mutex Verification Routines8380**8381** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines8382** are intended for use inside assert() statements. The SQLite core8383** never uses these routines except inside an assert() and applications8384** are advised to follow the lead of the core. The SQLite core only8385** provides implementations for these routines when it is compiled8386** with the SQLITE_DEBUG flag. External mutex implementations8387** are only required to provide these routines if SQLITE_DEBUG is8388** defined and if NDEBUG is not defined.8389**8390** These routines should return true if the mutex in their argument8391** is held or not held, respectively, by the calling thread.8392**8393** The implementation is not required to provide versions of these8394** routines that actually work. If the implementation does not provide working8395** versions of these routines, it should at least provide stubs that always8396** return true so that one does not get spurious assertion failures.8397**8398** If the argument to sqlite3_mutex_held() is a NULL pointer then8399** the routine should return 1. This seems counter-intuitive since8400** clearly the mutex cannot be held if it does not exist. But8401** the reason the mutex does not exist is because the build is not8402** using mutexes. And we do not want the assert() containing the8403** call to sqlite3_mutex_held() to fail, so a non-zero return is8404** the appropriate thing to do. The sqlite3_mutex_notheld()8405** interface should also return 1 when given a NULL pointer.8406*/8407#ifndef NDEBUG8408SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*);8409SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*);8410#endif84118412/*8413** CAPI3REF: Mutex Types8414**8415** The [sqlite3_mutex_alloc()] interface takes a single argument8416** which is one of these integer constants.8417**8418** The set of static mutexes may change from one SQLite release to the8419** next. Applications that override the built-in mutex logic must be8420** prepared to accommodate additional static mutexes.8421*/8422#define SQLITE_MUTEX_FAST 08423#define SQLITE_MUTEX_RECURSIVE 18424#define SQLITE_MUTEX_STATIC_MAIN 28425#define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */8426#define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */8427#define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */8428#define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_randomness() */8429#define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */8430#define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */8431#define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */8432#define SQLITE_MUTEX_STATIC_APP1 8 /* For use by application */8433#define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */8434#define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */8435#define SQLITE_MUTEX_STATIC_VFS1 11 /* For use by built-in VFS */8436#define SQLITE_MUTEX_STATIC_VFS2 12 /* For use by extension VFS */8437#define SQLITE_MUTEX_STATIC_VFS3 13 /* For use by application VFS */84388439/* Legacy compatibility: */8440#define SQLITE_MUTEX_STATIC_MASTER 2844184428443/*8444** CAPI3REF: Retrieve the mutex for a database connection8445** METHOD: sqlite38446**8447** ^This interface returns a pointer the [sqlite3_mutex] object that8448** serializes access to the [database connection] given in the argument8449** when the [threading mode] is Serialized.8450** ^If the [threading mode] is Single-thread or Multi-thread then this8451** routine returns a NULL pointer.8452*/8453SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*);84548455/*8456** CAPI3REF: Low-Level Control Of Database Files8457** METHOD: sqlite38458** KEYWORDS: {file control}8459**8460** ^The [sqlite3_file_control()] interface makes a direct call to the8461** xFileControl method for the [sqlite3_io_methods] object associated8462** with a particular database identified by the second argument. ^The8463** name of the database is "main" for the main database or "temp" for the8464** TEMP database, or the name that appears after the AS keyword for8465** databases that are added using the [ATTACH] SQL command.8466** ^A NULL pointer can be used in place of "main" to refer to the8467** main database file.8468** ^The third and fourth parameters to this routine8469** are passed directly through to the second and third parameters of8470** the xFileControl method. ^The return value of the xFileControl8471** method becomes the return value of this routine.8472**8473** A few opcodes for [sqlite3_file_control()] are handled directly8474** by the SQLite core and never invoke the8475** sqlite3_io_methods.xFileControl method.8476** ^The [SQLITE_FCNTL_FILE_POINTER] value for the op parameter causes8477** a pointer to the underlying [sqlite3_file] object to be written into8478** the space pointed to by the 4th parameter. The8479** [SQLITE_FCNTL_JOURNAL_POINTER] works similarly except that it returns8480** the [sqlite3_file] object associated with the journal file instead of8481** the main database. The [SQLITE_FCNTL_VFS_POINTER] opcode returns8482** a pointer to the underlying [sqlite3_vfs] object for the file.8483** The [SQLITE_FCNTL_DATA_VERSION] returns the data version counter8484** from the pager.8485**8486** ^If the second parameter (zDbName) does not match the name of any8487** open database file, then SQLITE_ERROR is returned. ^This error8488** code is not remembered and will not be recalled by [sqlite3_errcode()]8489** or [sqlite3_errmsg()]. The underlying xFileControl method might8490** also return SQLITE_ERROR. There is no way to distinguish between8491** an incorrect zDbName and an SQLITE_ERROR return from the underlying8492** xFileControl method.8493**8494** See also: [file control opcodes]8495*/8496SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*);84978498/*8499** CAPI3REF: Testing Interface8500**8501** ^The sqlite3_test_control() interface is used to read out internal8502** state of SQLite and to inject faults into SQLite for testing8503** purposes. ^The first parameter is an operation code that determines8504** the number, meaning, and operation of all subsequent parameters.8505**8506** This interface is not for use by applications. It exists solely8507** for verifying the correct operation of the SQLite library. Depending8508** on how the SQLite library is compiled, this interface might not exist.8509**8510** The details of the operation codes, their meanings, the parameters8511** they take, and what they do are all subject to change without notice.8512** Unlike most of the SQLite API, this function is not guaranteed to8513** operate consistently from one release to the next.8514*/8515SQLITE_API int sqlite3_test_control(int op, ...);85168517/*8518** CAPI3REF: Testing Interface Operation Codes8519**8520** These constants are the valid operation code parameters used8521** as the first argument to [sqlite3_test_control()].8522**8523** These parameters and their meanings are subject to change8524** without notice. These values are for testing purposes only.8525** Applications should not use any of these parameters or the8526** [sqlite3_test_control()] interface.8527*/8528#define SQLITE_TESTCTRL_FIRST 58529#define SQLITE_TESTCTRL_PRNG_SAVE 58530#define SQLITE_TESTCTRL_PRNG_RESTORE 68531#define SQLITE_TESTCTRL_PRNG_RESET 7 /* NOT USED */8532#define SQLITE_TESTCTRL_FK_NO_ACTION 78533#define SQLITE_TESTCTRL_BITVEC_TEST 88534#define SQLITE_TESTCTRL_FAULT_INSTALL 98535#define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 108536#define SQLITE_TESTCTRL_PENDING_BYTE 118537#define SQLITE_TESTCTRL_ASSERT 128538#define SQLITE_TESTCTRL_ALWAYS 138539#define SQLITE_TESTCTRL_RESERVE 14 /* NOT USED */8540#define SQLITE_TESTCTRL_JSON_SELFCHECK 148541#define SQLITE_TESTCTRL_OPTIMIZATIONS 158542#define SQLITE_TESTCTRL_ISKEYWORD 16 /* NOT USED */8543#define SQLITE_TESTCTRL_GETOPT 168544#define SQLITE_TESTCTRL_SCRATCHMALLOC 17 /* NOT USED */8545#define SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 178546#define SQLITE_TESTCTRL_LOCALTIME_FAULT 188547#define SQLITE_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */8548#define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD 198549#define SQLITE_TESTCTRL_NEVER_CORRUPT 208550#define SQLITE_TESTCTRL_VDBE_COVERAGE 218551#define SQLITE_TESTCTRL_BYTEORDER 228552#define SQLITE_TESTCTRL_ISINIT 238553#define SQLITE_TESTCTRL_SORTER_MMAP 248554#define SQLITE_TESTCTRL_IMPOSTER 258555#define SQLITE_TESTCTRL_PARSER_COVERAGE 268556#define SQLITE_TESTCTRL_RESULT_INTREAL 278557#define SQLITE_TESTCTRL_PRNG_SEED 288558#define SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS 298559#define SQLITE_TESTCTRL_SEEK_COUNT 308560#define SQLITE_TESTCTRL_TRACEFLAGS 318561#define SQLITE_TESTCTRL_TUNE 328562#define SQLITE_TESTCTRL_LOGEST 338563#define SQLITE_TESTCTRL_USELONGDOUBLE 34 /* NOT USED */8564#define SQLITE_TESTCTRL_LAST 34 /* Largest TESTCTRL */85658566/*8567** CAPI3REF: SQL Keyword Checking8568**8569** These routines provide access to the set of SQL language keywords8570** recognized by SQLite. Applications can uses these routines to determine8571** whether or not a specific identifier needs to be escaped (for example,8572** by enclosing in double-quotes) so as not to confuse the parser.8573**8574** The sqlite3_keyword_count() interface returns the number of distinct8575** keywords understood by SQLite.8576**8577** The sqlite3_keyword_name(N,Z,L) interface finds the 0-based N-th keyword and8578** makes *Z point to that keyword expressed as UTF8 and writes the number8579** of bytes in the keyword into *L. The string that *Z points to is not8580** zero-terminated. The sqlite3_keyword_name(N,Z,L) routine returns8581** SQLITE_OK if N is within bounds and SQLITE_ERROR if not. If either Z8582** or L are NULL or invalid pointers then calls to8583** sqlite3_keyword_name(N,Z,L) result in undefined behavior.8584**8585** The sqlite3_keyword_check(Z,L) interface checks to see whether or not8586** the L-byte UTF8 identifier that Z points to is a keyword, returning non-zero8587** if it is and zero if not.8588**8589** The parser used by SQLite is forgiving. It is often possible to use8590** a keyword as an identifier as long as such use does not result in a8591** parsing ambiguity. For example, the statement8592** "CREATE TABLE BEGIN(REPLACE,PRAGMA,END);" is accepted by SQLite, and8593** creates a new table named "BEGIN" with three columns named8594** "REPLACE", "PRAGMA", and "END". Nevertheless, best practice is to avoid8595** using keywords as identifiers. Common techniques used to avoid keyword8596** name collisions include:8597** <ul>8598** <li> Put all identifier names inside double-quotes. This is the official8599** SQL way to escape identifier names.8600** <li> Put identifier names inside [...]. This is not standard SQL,8601** but it is what SQL Server does and so lots of programmers use this8602** technique.8603** <li> Begin every identifier with the letter "Z" as no SQL keywords start8604** with "Z".8605** <li> Include a digit somewhere in every identifier name.8606** </ul>8607**8608** Note that the number of keywords understood by SQLite can depend on8609** compile-time options. For example, "VACUUM" is not a keyword if8610** SQLite is compiled with the [-DSQLITE_OMIT_VACUUM] option. Also,8611** new keywords may be added to future releases of SQLite.8612*/8613SQLITE_API int sqlite3_keyword_count(void);8614SQLITE_API int sqlite3_keyword_name(int,const char**,int*);8615SQLITE_API int sqlite3_keyword_check(const char*,int);86168617/*8618** CAPI3REF: Dynamic String Object8619** KEYWORDS: {dynamic string}8620**8621** An instance of the sqlite3_str object contains a dynamically-sized8622** string under construction.8623**8624** The lifecycle of an sqlite3_str object is as follows:8625** <ol>8626** <li> ^The sqlite3_str object is created using [sqlite3_str_new()].8627** <li> ^Text is appended to the sqlite3_str object using various8628** methods, such as [sqlite3_str_appendf()].8629** <li> ^The sqlite3_str object is destroyed and the string it created8630** is returned using the [sqlite3_str_finish()] interface.8631** </ol>8632*/8633typedef struct sqlite3_str sqlite3_str;86348635/*8636** CAPI3REF: Create A New Dynamic String Object8637** CONSTRUCTOR: sqlite3_str8638**8639** ^The [sqlite3_str_new(D)] interface allocates and initializes8640** a new [sqlite3_str] object. To avoid memory leaks, the object returned by8641** [sqlite3_str_new()] must be freed by a subsequent call to8642** [sqlite3_str_finish(X)].8643**8644** ^The [sqlite3_str_new(D)] interface always returns a pointer to a8645** valid [sqlite3_str] object, though in the event of an out-of-memory8646** error the returned object might be a special singleton that will8647** silently reject new text, always return SQLITE_NOMEM from8648** [sqlite3_str_errcode()], always return 0 for8649** [sqlite3_str_length()], and always return NULL from8650** [sqlite3_str_finish(X)]. It is always safe to use the value8651** returned by [sqlite3_str_new(D)] as the sqlite3_str parameter8652** to any of the other [sqlite3_str] methods.8653**8654** The D parameter to [sqlite3_str_new(D)] may be NULL. If the8655** D parameter in [sqlite3_str_new(D)] is not NULL, then the maximum8656** length of the string contained in the [sqlite3_str] object will be8657** the value set for [sqlite3_limit](D,[SQLITE_LIMIT_LENGTH]) instead8658** of [SQLITE_MAX_LENGTH].8659*/8660SQLITE_API sqlite3_str *sqlite3_str_new(sqlite3*);86618662/*8663** CAPI3REF: Finalize A Dynamic String8664** DESTRUCTOR: sqlite3_str8665**8666** ^The [sqlite3_str_finish(X)] interface destroys the sqlite3_str object X8667** and returns a pointer to a memory buffer obtained from [sqlite3_malloc64()]8668** that contains the constructed string. The calling application should8669** pass the returned value to [sqlite3_free()] to avoid a memory leak.8670** ^The [sqlite3_str_finish(X)] interface may return a NULL pointer if any8671** errors were encountered during construction of the string. ^The8672** [sqlite3_str_finish(X)] interface will also return a NULL pointer if the8673** string in [sqlite3_str] object X is zero bytes long.8674*/8675SQLITE_API char *sqlite3_str_finish(sqlite3_str*);86768677/*8678** CAPI3REF: Add Content To A Dynamic String8679** METHOD: sqlite3_str8680**8681** These interfaces add content to an sqlite3_str object previously obtained8682** from [sqlite3_str_new()].8683**8684** ^The [sqlite3_str_appendf(X,F,...)] and8685** [sqlite3_str_vappendf(X,F,V)] interfaces uses the [built-in printf]8686** functionality of SQLite to append formatted text onto the end of8687** [sqlite3_str] object X.8688**8689** ^The [sqlite3_str_append(X,S,N)] method appends exactly N bytes from string S8690** onto the end of the [sqlite3_str] object X. N must be non-negative.8691** S must contain at least N non-zero bytes of content. To append a8692** zero-terminated string in its entirety, use the [sqlite3_str_appendall()]8693** method instead.8694**8695** ^The [sqlite3_str_appendall(X,S)] method appends the complete content of8696** zero-terminated string S onto the end of [sqlite3_str] object X.8697**8698** ^The [sqlite3_str_appendchar(X,N,C)] method appends N copies of the8699** single-byte character C onto the end of [sqlite3_str] object X.8700** ^This method can be used, for example, to add whitespace indentation.8701**8702** ^The [sqlite3_str_reset(X)] method resets the string under construction8703** inside [sqlite3_str] object X back to zero bytes in length.8704**8705** These methods do not return a result code. ^If an error occurs, that fact8706** is recorded in the [sqlite3_str] object and can be recovered by a8707** subsequent call to [sqlite3_str_errcode(X)].8708*/8709SQLITE_API void sqlite3_str_appendf(sqlite3_str*, const char *zFormat, ...);8710SQLITE_API void sqlite3_str_vappendf(sqlite3_str*, const char *zFormat, va_list);8711SQLITE_API void sqlite3_str_append(sqlite3_str*, const char *zIn, int N);8712SQLITE_API void sqlite3_str_appendall(sqlite3_str*, const char *zIn);8713SQLITE_API void sqlite3_str_appendchar(sqlite3_str*, int N, char C);8714SQLITE_API void sqlite3_str_reset(sqlite3_str*);87158716/*8717** CAPI3REF: Status Of A Dynamic String8718** METHOD: sqlite3_str8719**8720** These interfaces return the current status of an [sqlite3_str] object.8721**8722** ^If any prior errors have occurred while constructing the dynamic string8723** in sqlite3_str X, then the [sqlite3_str_errcode(X)] method will return8724** an appropriate error code. ^The [sqlite3_str_errcode(X)] method returns8725** [SQLITE_NOMEM] following any out-of-memory error, or8726** [SQLITE_TOOBIG] if the size of the dynamic string exceeds8727** [SQLITE_MAX_LENGTH], or [SQLITE_OK] if there have been no errors.8728**8729** ^The [sqlite3_str_length(X)] method returns the current length, in bytes,8730** of the dynamic string under construction in [sqlite3_str] object X.8731** ^The length returned by [sqlite3_str_length(X)] does not include the8732** zero-termination byte.8733**8734** ^The [sqlite3_str_value(X)] method returns a pointer to the current8735** content of the dynamic string under construction in X. The value8736** returned by [sqlite3_str_value(X)] is managed by the sqlite3_str object X8737** and might be freed or altered by any subsequent method on the same8738** [sqlite3_str] object. Applications must not used the pointer returned8739** [sqlite3_str_value(X)] after any subsequent method call on the same8740** object. ^Applications may change the content of the string returned8741** by [sqlite3_str_value(X)] as long as they do not write into any bytes8742** outside the range of 0 to [sqlite3_str_length(X)] and do not read or8743** write any byte after any subsequent sqlite3_str method call.8744*/8745SQLITE_API int sqlite3_str_errcode(sqlite3_str*);8746SQLITE_API int sqlite3_str_length(sqlite3_str*);8747SQLITE_API char *sqlite3_str_value(sqlite3_str*);87488749/*8750** CAPI3REF: SQLite Runtime Status8751**8752** ^These interfaces are used to retrieve runtime status information8753** about the performance of SQLite, and optionally to reset various8754** highwater marks. ^The first argument is an integer code for8755** the specific parameter to measure. ^(Recognized integer codes8756** are of the form [status parameters | SQLITE_STATUS_...].)^8757** ^The current value of the parameter is returned into *pCurrent.8758** ^The highest recorded value is returned in *pHighwater. ^If the8759** resetFlag is true, then the highest record value is reset after8760** *pHighwater is written. ^(Some parameters do not record the highest8761** value. For those parameters8762** nothing is written into *pHighwater and the resetFlag is ignored.)^8763** ^(Other parameters record only the highwater mark and not the current8764** value. For these latter parameters nothing is written into *pCurrent.)^8765**8766** ^The sqlite3_status() and sqlite3_status64() routines return8767** SQLITE_OK on success and a non-zero [error code] on failure.8768**8769** If either the current value or the highwater mark is too large to8770** be represented by a 32-bit integer, then the values returned by8771** sqlite3_status() are undefined.8772**8773** See also: [sqlite3_db_status()]8774*/8775SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);8776SQLITE_API int sqlite3_status64(8777int op,8778sqlite3_int64 *pCurrent,8779sqlite3_int64 *pHighwater,8780int resetFlag8781);878287838784/*8785** CAPI3REF: Status Parameters8786** KEYWORDS: {status parameters}8787**8788** These integer constants designate various run-time status parameters8789** that can be returned by [sqlite3_status()].8790**8791** <dl>8792** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>8793** <dd>This parameter is the current amount of memory checked out8794** using [sqlite3_malloc()], either directly or indirectly. The8795** figure includes calls made to [sqlite3_malloc()] by the application8796** and internal memory usage by the SQLite library. Auxiliary page-cache8797** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in8798** this parameter. The amount returned is the sum of the allocation8799** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^8800**8801** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>8802** <dd>This parameter records the largest memory allocation request8803** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their8804** internal equivalents). Only the value returned in the8805** *pHighwater parameter to [sqlite3_status()] is of interest.8806** The value written into the *pCurrent parameter is undefined.</dd>)^8807**8808** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt>8809** <dd>This parameter records the number of separate memory allocations8810** currently checked out.</dd>)^8811**8812** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt>8813** <dd>This parameter returns the number of pages used out of the8814** [pagecache memory allocator] that was configured using8815** [SQLITE_CONFIG_PAGECACHE]. The8816** value returned is in pages, not in bytes.</dd>)^8817**8818** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]]8819** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt>8820** <dd>This parameter returns the number of bytes of page cache8821** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE]8822** buffer and where forced to overflow to [sqlite3_malloc()]. The8823** returned value includes allocations that overflowed because they8824** where too large (they were larger than the "sz" parameter to8825** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because8826** no space was left in the page cache.</dd>)^8827**8828** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt>8829** <dd>This parameter records the largest memory allocation request8830** handed to the [pagecache memory allocator]. Only the value returned in the8831** *pHighwater parameter to [sqlite3_status()] is of interest.8832** The value written into the *pCurrent parameter is undefined.</dd>)^8833**8834** [[SQLITE_STATUS_SCRATCH_USED]] <dt>SQLITE_STATUS_SCRATCH_USED</dt>8835** <dd>No longer used.</dd>8836**8837** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>8838** <dd>No longer used.</dd>8839**8840** [[SQLITE_STATUS_SCRATCH_SIZE]] <dt>SQLITE_STATUS_SCRATCH_SIZE</dt>8841** <dd>No longer used.</dd>8842**8843** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>8844** <dd>The *pHighwater parameter records the deepest parser stack.8845** The *pCurrent value is undefined. The *pHighwater value is only8846** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^8847** </dl>8848**8849** New status parameters may be added from time to time.8850*/8851#define SQLITE_STATUS_MEMORY_USED 08852#define SQLITE_STATUS_PAGECACHE_USED 18853#define SQLITE_STATUS_PAGECACHE_OVERFLOW 28854#define SQLITE_STATUS_SCRATCH_USED 3 /* NOT USED */8855#define SQLITE_STATUS_SCRATCH_OVERFLOW 4 /* NOT USED */8856#define SQLITE_STATUS_MALLOC_SIZE 58857#define SQLITE_STATUS_PARSER_STACK 68858#define SQLITE_STATUS_PAGECACHE_SIZE 78859#define SQLITE_STATUS_SCRATCH_SIZE 8 /* NOT USED */8860#define SQLITE_STATUS_MALLOC_COUNT 988618862/*8863** CAPI3REF: Database Connection Status8864** METHOD: sqlite38865**8866** ^This interface is used to retrieve runtime status information8867** about a single [database connection]. ^The first argument is the8868** database connection object to be interrogated. ^The second argument8869** is an integer constant, taken from the set of8870** [SQLITE_DBSTATUS options], that8871** determines the parameter to interrogate. The set of8872** [SQLITE_DBSTATUS options] is likely8873** to grow in future releases of SQLite.8874**8875** ^The current value of the requested parameter is written into *pCur8876** and the highest instantaneous value is written into *pHiwtr. ^If8877** the resetFlg is true, then the highest instantaneous value is8878** reset back down to the current value.8879**8880** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a8881** non-zero [error code] on failure.8882**8883** See also: [sqlite3_status()] and [sqlite3_stmt_status()].8884*/8885SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg);88868887/*8888** CAPI3REF: Status Parameters for database connections8889** KEYWORDS: {SQLITE_DBSTATUS options}8890**8891** These constants are the available integer "verbs" that can be passed as8892** the second argument to the [sqlite3_db_status()] interface.8893**8894** New verbs may be added in future releases of SQLite. Existing verbs8895** might be discontinued. Applications should check the return code from8896** [sqlite3_db_status()] to make sure that the call worked.8897** The [sqlite3_db_status()] interface will return a non-zero error code8898** if a discontinued or unsupported verb is invoked.8899**8900** <dl>8901** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt>8902** <dd>This parameter returns the number of lookaside memory slots currently8903** checked out.</dd>)^8904**8905** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt>8906** <dd>This parameter returns the number of malloc attempts that were8907** satisfied using lookaside memory. Only the high-water value is meaningful;8908** the current value is always zero.)^8909**8910** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]]8911** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt>8912** <dd>This parameter returns the number malloc attempts that might have8913** been satisfied using lookaside memory but failed due to the amount of8914** memory requested being larger than the lookaside slot size.8915** Only the high-water value is meaningful;8916** the current value is always zero.)^8917**8918** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]]8919** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt>8920** <dd>This parameter returns the number malloc attempts that might have8921** been satisfied using lookaside memory but failed due to all lookaside8922** memory already being in use.8923** Only the high-water value is meaningful;8924** the current value is always zero.)^8925**8926** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt>8927** <dd>This parameter returns the approximate number of bytes of heap8928** memory used by all pager caches associated with the database connection.)^8929** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0.8930**8931** [[SQLITE_DBSTATUS_CACHE_USED_SHARED]]8932** ^(<dt>SQLITE_DBSTATUS_CACHE_USED_SHARED</dt>8933** <dd>This parameter is similar to DBSTATUS_CACHE_USED, except that if a8934** pager cache is shared between two or more connections the bytes of heap8935** memory used by that pager cache is divided evenly between the attached8936** connections.)^ In other words, if none of the pager caches associated8937** with the database connection are shared, this request returns the same8938** value as DBSTATUS_CACHE_USED. Or, if one or more or the pager caches are8939** shared, the value returned by this call will be smaller than that returned8940** by DBSTATUS_CACHE_USED. ^The highwater mark associated with8941** SQLITE_DBSTATUS_CACHE_USED_SHARED is always 0.8942**8943** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt>8944** <dd>This parameter returns the approximate number of bytes of heap8945** memory used to store the schema for all databases associated8946** with the connection - main, temp, and any [ATTACH]-ed databases.)^8947** ^The full amount of memory used by the schemas is reported, even if the8948** schema memory is shared with other database connections due to8949** [shared cache mode] being enabled.8950** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0.8951**8952** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt>8953** <dd>This parameter returns the approximate number of bytes of heap8954** and lookaside memory used by all prepared statements associated with8955** the database connection.)^8956** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0.8957** </dd>8958**8959** [[SQLITE_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE_DBSTATUS_CACHE_HIT</dt>8960** <dd>This parameter returns the number of pager cache hits that have8961** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_HIT8962** is always 0.8963** </dd>8964**8965** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt>8966** <dd>This parameter returns the number of pager cache misses that have8967** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS8968** is always 0.8969** </dd>8970**8971** [[SQLITE_DBSTATUS_CACHE_WRITE]] ^(<dt>SQLITE_DBSTATUS_CACHE_WRITE</dt>8972** <dd>This parameter returns the number of dirty cache entries that have8973** been written to disk. Specifically, the number of pages written to the8974** wal file in wal mode databases, or the number of pages written to the8975** database file in rollback mode databases. Any pages written as part of8976** transaction rollback or database recovery operations are not included.8977** If an IO or other error occurs while writing a page to disk, the effect8978** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The8979** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0.8980** </dd>8981**8982** [[SQLITE_DBSTATUS_CACHE_SPILL]] ^(<dt>SQLITE_DBSTATUS_CACHE_SPILL</dt>8983** <dd>This parameter returns the number of dirty cache entries that have8984** been written to disk in the middle of a transaction due to the page8985** cache overflowing. Transactions are more efficient if they are written8986** to disk all at once. When pages spill mid-transaction, that introduces8987** additional overhead. This parameter can be used help identify8988** inefficiencies that can be resolved by increasing the cache size.8989** </dd>8990**8991** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt>8992** <dd>This parameter returns zero for the current value if and only if8993** all foreign key constraints (deferred or immediate) have been8994** resolved.)^ ^The highwater mark is always 0.8995** </dd>8996** </dl>8997*/8998#define SQLITE_DBSTATUS_LOOKASIDE_USED 08999#define SQLITE_DBSTATUS_CACHE_USED 19000#define SQLITE_DBSTATUS_SCHEMA_USED 29001#define SQLITE_DBSTATUS_STMT_USED 39002#define SQLITE_DBSTATUS_LOOKASIDE_HIT 49003#define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 59004#define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 69005#define SQLITE_DBSTATUS_CACHE_HIT 79006#define SQLITE_DBSTATUS_CACHE_MISS 89007#define SQLITE_DBSTATUS_CACHE_WRITE 99008#define SQLITE_DBSTATUS_DEFERRED_FKS 109009#define SQLITE_DBSTATUS_CACHE_USED_SHARED 119010#define SQLITE_DBSTATUS_CACHE_SPILL 129011#define SQLITE_DBSTATUS_MAX 12 /* Largest defined DBSTATUS */901290139014/*9015** CAPI3REF: Prepared Statement Status9016** METHOD: sqlite3_stmt9017**9018** ^(Each prepared statement maintains various9019** [SQLITE_STMTSTATUS counters] that measure the number9020** of times it has performed specific operations.)^ These counters can9021** be used to monitor the performance characteristics of the prepared9022** statements. For example, if the number of table steps greatly exceeds9023** the number of table searches or result rows, that would tend to indicate9024** that the prepared statement is using a full table scan rather than9025** an index.9026**9027** ^(This interface is used to retrieve and reset counter values from9028** a [prepared statement]. The first argument is the prepared statement9029** object to be interrogated. The second argument9030** is an integer code for a specific [SQLITE_STMTSTATUS counter]9031** to be interrogated.)^9032** ^The current value of the requested counter is returned.9033** ^If the resetFlg is true, then the counter is reset to zero after this9034** interface call returns.9035**9036** See also: [sqlite3_status()] and [sqlite3_db_status()].9037*/9038SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg);90399040/*9041** CAPI3REF: Status Parameters for prepared statements9042** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters}9043**9044** These preprocessor macros define integer codes that name counter9045** values associated with the [sqlite3_stmt_status()] interface.9046** The meanings of the various counters are as follows:9047**9048** <dl>9049** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt>9050** <dd>^This is the number of times that SQLite has stepped forward in9051** a table as part of a full table scan. Large numbers for this counter9052** may indicate opportunities for performance improvement through9053** careful use of indices.</dd>9054**9055** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt>9056** <dd>^This is the number of sort operations that have occurred.9057** A non-zero value in this counter may indicate an opportunity to9058** improvement performance through careful use of indices.</dd>9059**9060** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt>9061** <dd>^This is the number of rows inserted into transient indices that9062** were created automatically in order to help joins run faster.9063** A non-zero value in this counter may indicate an opportunity to9064** improvement performance by adding permanent indices that do not9065** need to be reinitialized each time the statement is run.</dd>9066**9067** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>9068** <dd>^This is the number of virtual machine operations executed9069** by the prepared statement if that number is less than or equal9070** to 2147483647. The number of virtual machine operations can be9071** used as a proxy for the total work done by the prepared statement.9072** If the number of virtual machine operations exceeds 21474836479073** then the value returned by this statement status code is undefined.9074**9075** [[SQLITE_STMTSTATUS_REPREPARE]] <dt>SQLITE_STMTSTATUS_REPREPARE</dt>9076** <dd>^This is the number of times that the prepare statement has been9077** automatically regenerated due to schema changes or changes to9078** [bound parameters] that might affect the query plan.9079**9080** [[SQLITE_STMTSTATUS_RUN]] <dt>SQLITE_STMTSTATUS_RUN</dt>9081** <dd>^This is the number of times that the prepared statement has9082** been run. A single "run" for the purposes of this counter is one9083** or more calls to [sqlite3_step()] followed by a call to [sqlite3_reset()].9084** The counter is incremented on the first [sqlite3_step()] call of each9085** cycle.9086**9087** [[SQLITE_STMTSTATUS_FILTER_MISS]]9088** [[SQLITE_STMTSTATUS_FILTER HIT]]9089** <dt>SQLITE_STMTSTATUS_FILTER_HIT<br>9090** SQLITE_STMTSTATUS_FILTER_MISS</dt>9091** <dd>^SQLITE_STMTSTATUS_FILTER_HIT is the number of times that a join9092** step was bypassed because a Bloom filter returned not-found. The9093** corresponding SQLITE_STMTSTATUS_FILTER_MISS value is the number of9094** times that the Bloom filter returned a find, and thus the join step9095** had to be processed as normal.9096**9097** [[SQLITE_STMTSTATUS_MEMUSED]] <dt>SQLITE_STMTSTATUS_MEMUSED</dt>9098** <dd>^This is the approximate number of bytes of heap memory9099** used to store the prepared statement. ^This value is not actually9100** a counter, and so the resetFlg parameter to sqlite3_stmt_status()9101** is ignored when the opcode is SQLITE_STMTSTATUS_MEMUSED.9102** </dd>9103** </dl>9104*/9105#define SQLITE_STMTSTATUS_FULLSCAN_STEP 19106#define SQLITE_STMTSTATUS_SORT 29107#define SQLITE_STMTSTATUS_AUTOINDEX 39108#define SQLITE_STMTSTATUS_VM_STEP 49109#define SQLITE_STMTSTATUS_REPREPARE 59110#define SQLITE_STMTSTATUS_RUN 69111#define SQLITE_STMTSTATUS_FILTER_MISS 79112#define SQLITE_STMTSTATUS_FILTER_HIT 89113#define SQLITE_STMTSTATUS_MEMUSED 9991149115/*9116** CAPI3REF: Custom Page Cache Object9117**9118** The sqlite3_pcache type is opaque. It is implemented by9119** the pluggable module. The SQLite core has no knowledge of9120** its size or internal structure and never deals with the9121** sqlite3_pcache object except by holding and passing pointers9122** to the object.9123**9124** See [sqlite3_pcache_methods2] for additional information.9125*/9126typedef struct sqlite3_pcache sqlite3_pcache;91279128/*9129** CAPI3REF: Custom Page Cache Object9130**9131** The sqlite3_pcache_page object represents a single page in the9132** page cache. The page cache will allocate instances of this9133** object. Various methods of the page cache use pointers to instances9134** of this object as parameters or as their return value.9135**9136** See [sqlite3_pcache_methods2] for additional information.9137*/9138typedef struct sqlite3_pcache_page sqlite3_pcache_page;9139struct sqlite3_pcache_page {9140void *pBuf; /* The content of the page */9141void *pExtra; /* Extra information associated with the page */9142};91439144/*9145** CAPI3REF: Application Defined Page Cache.9146** KEYWORDS: {page cache}9147**9148** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE2], ...) interface can9149** register an alternative page cache implementation by passing in an9150** instance of the sqlite3_pcache_methods2 structure.)^9151** In many applications, most of the heap memory allocated by9152** SQLite is used for the page cache.9153** By implementing a9154** custom page cache using this API, an application can better control9155** the amount of memory consumed by SQLite, the way in which9156** that memory is allocated and released, and the policies used to9157** determine exactly which parts of a database file are cached and for9158** how long.9159**9160** The alternative page cache mechanism is an9161** extreme measure that is only needed by the most demanding applications.9162** The built-in page cache is recommended for most uses.9163**9164** ^(The contents of the sqlite3_pcache_methods2 structure are copied to an9165** internal buffer by SQLite within the call to [sqlite3_config]. Hence9166** the application may discard the parameter after the call to9167** [sqlite3_config()] returns.)^9168**9169** [[the xInit() page cache method]]9170** ^(The xInit() method is called once for each effective9171** call to [sqlite3_initialize()])^9172** (usually only once during the lifetime of the process). ^(The xInit()9173** method is passed a copy of the sqlite3_pcache_methods2.pArg value.)^9174** The intent of the xInit() method is to set up global data structures9175** required by the custom page cache implementation.9176** ^(If the xInit() method is NULL, then the9177** built-in default page cache is used instead of the application defined9178** page cache.)^9179**9180** [[the xShutdown() page cache method]]9181** ^The xShutdown() method is called by [sqlite3_shutdown()].9182** It can be used to clean up9183** any outstanding resources before process shutdown, if required.9184** ^The xShutdown() method may be NULL.9185**9186** ^SQLite automatically serializes calls to the xInit method,9187** so the xInit method need not be threadsafe. ^The9188** xShutdown method is only called from [sqlite3_shutdown()] so it does9189** not need to be threadsafe either. All other methods must be threadsafe9190** in multithreaded applications.9191**9192** ^SQLite will never invoke xInit() more than once without an intervening9193** call to xShutdown().9194**9195** [[the xCreate() page cache methods]]9196** ^SQLite invokes the xCreate() method to construct a new cache instance.9197** SQLite will typically create one cache instance for each open database file,9198** though this is not guaranteed. ^The9199** first parameter, szPage, is the size in bytes of the pages that must9200** be allocated by the cache. ^szPage will always a power of two. ^The9201** second parameter szExtra is a number of bytes of extra storage9202** associated with each page cache entry. ^The szExtra parameter will9203** a number less than 250. SQLite will use the9204** extra szExtra bytes on each page to store metadata about the underlying9205** database page on disk. The value passed into szExtra depends9206** on the SQLite version, the target platform, and how SQLite was compiled.9207** ^The third argument to xCreate(), bPurgeable, is true if the cache being9208** created will be used to cache database pages of a file stored on disk, or9209** false if it is used for an in-memory database. The cache implementation9210** does not have to do anything special based with the value of bPurgeable;9211** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will9212** never invoke xUnpin() except to deliberately delete a page.9213** ^In other words, calls to xUnpin() on a cache with bPurgeable set to9214** false will always have the "discard" flag set to true.9215** ^Hence, a cache created with bPurgeable false will9216** never contain any unpinned pages.9217**9218** [[the xCachesize() page cache method]]9219** ^(The xCachesize() method may be called at any time by SQLite to set the9220** suggested maximum cache-size (number of pages stored by) the cache9221** instance passed as the first argument. This is the value configured using9222** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable9223** parameter, the implementation is not required to do anything with this9224** value; it is advisory only.9225**9226** [[the xPagecount() page cache methods]]9227** The xPagecount() method must return the number of pages currently9228** stored in the cache, both pinned and unpinned.9229**9230** [[the xFetch() page cache methods]]9231** The xFetch() method locates a page in the cache and returns a pointer to9232** an sqlite3_pcache_page object associated with that page, or a NULL pointer.9233** The pBuf element of the returned sqlite3_pcache_page object will be a9234** pointer to a buffer of szPage bytes used to store the content of a9235** single database page. The pExtra element of sqlite3_pcache_page will be9236** a pointer to the szExtra bytes of extra storage that SQLite has requested9237** for each entry in the page cache.9238**9239** The page to be fetched is determined by the key. ^The minimum key value9240** is 1. After it has been retrieved using xFetch, the page is considered9241** to be "pinned".9242**9243** If the requested page is already in the page cache, then the page cache9244** implementation must return a pointer to the page buffer with its content9245** intact. If the requested page is not already in the cache, then the9246** cache implementation should use the value of the createFlag9247** parameter to help it determined what action to take:9248**9249** <table border=1 width=85% align=center>9250** <tr><th> createFlag <th> Behavior when page is not already in cache9251** <tr><td> 0 <td> Do not allocate a new page. Return NULL.9252** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so.9253** Otherwise return NULL.9254** <tr><td> 2 <td> Make every effort to allocate a new page. Only return9255** NULL if allocating a new page is effectively impossible.9256** </table>9257**9258** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite9259** will only use a createFlag of 2 after a prior call with a createFlag of 19260** failed.)^ In between the xFetch() calls, SQLite may9261** attempt to unpin one or more cache pages by spilling the content of9262** pinned pages to disk and synching the operating system disk cache.9263**9264** [[the xUnpin() page cache method]]9265** ^xUnpin() is called by SQLite with a pointer to a currently pinned page9266** as its second argument. If the third parameter, discard, is non-zero,9267** then the page must be evicted from the cache.9268** ^If the discard parameter is9269** zero, then the page may be discarded or retained at the discretion of9270** page cache implementation. ^The page cache implementation9271** may choose to evict unpinned pages at any time.9272**9273** The cache must not perform any reference counting. A single9274** call to xUnpin() unpins the page regardless of the number of prior calls9275** to xFetch().9276**9277** [[the xRekey() page cache methods]]9278** The xRekey() method is used to change the key value associated with the9279** page passed as the second argument. If the cache9280** previously contains an entry associated with newKey, it must be9281** discarded. ^Any prior cache entry associated with newKey is guaranteed not9282** to be pinned.9283**9284** When SQLite calls the xTruncate() method, the cache must discard all9285** existing cache entries with page numbers (keys) greater than or equal9286** to the value of the iLimit parameter passed to xTruncate(). If any9287** of these pages are pinned, they are implicitly unpinned, meaning that9288** they can be safely discarded.9289**9290** [[the xDestroy() page cache method]]9291** ^The xDestroy() method is used to delete a cache allocated by xCreate().9292** All resources associated with the specified cache should be freed. ^After9293** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]9294** handle invalid, and will not use it with any other sqlite3_pcache_methods29295** functions.9296**9297** [[the xShrink() page cache method]]9298** ^SQLite invokes the xShrink() method when it wants the page cache to9299** free up as much of heap memory as possible. The page cache implementation9300** is not obligated to free any memory, but well-behaved implementations should9301** do their best.9302*/9303typedef struct sqlite3_pcache_methods2 sqlite3_pcache_methods2;9304struct sqlite3_pcache_methods2 {9305int iVersion;9306void *pArg;9307int (*xInit)(void*);9308void (*xShutdown)(void*);9309sqlite3_pcache *(*xCreate)(int szPage, int szExtra, int bPurgeable);9310void (*xCachesize)(sqlite3_pcache*, int nCachesize);9311int (*xPagecount)(sqlite3_pcache*);9312sqlite3_pcache_page *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);9313void (*xUnpin)(sqlite3_pcache*, sqlite3_pcache_page*, int discard);9314void (*xRekey)(sqlite3_pcache*, sqlite3_pcache_page*,9315unsigned oldKey, unsigned newKey);9316void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);9317void (*xDestroy)(sqlite3_pcache*);9318void (*xShrink)(sqlite3_pcache*);9319};93209321/*9322** This is the obsolete pcache_methods object that has now been replaced9323** by sqlite3_pcache_methods2. This object is not used by SQLite. It is9324** retained in the header file for backwards compatibility only.9325*/9326typedef struct sqlite3_pcache_methods sqlite3_pcache_methods;9327struct sqlite3_pcache_methods {9328void *pArg;9329int (*xInit)(void*);9330void (*xShutdown)(void*);9331sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable);9332void (*xCachesize)(sqlite3_pcache*, int nCachesize);9333int (*xPagecount)(sqlite3_pcache*);9334void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);9335void (*xUnpin)(sqlite3_pcache*, void*, int discard);9336void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey);9337void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);9338void (*xDestroy)(sqlite3_pcache*);9339};934093419342/*9343** CAPI3REF: Online Backup Object9344**9345** The sqlite3_backup object records state information about an ongoing9346** online backup operation. ^The sqlite3_backup object is created by9347** a call to [sqlite3_backup_init()] and is destroyed by a call to9348** [sqlite3_backup_finish()].9349**9350** See Also: [Using the SQLite Online Backup API]9351*/9352typedef struct sqlite3_backup sqlite3_backup;93539354/*9355** CAPI3REF: Online Backup API.9356**9357** The backup API copies the content of one database into another.9358** It is useful either for creating backups of databases or9359** for copying in-memory databases to or from persistent files.9360**9361** See Also: [Using the SQLite Online Backup API]9362**9363** ^SQLite holds a write transaction open on the destination database file9364** for the duration of the backup operation.9365** ^The source database is read-locked only while it is being read;9366** it is not locked continuously for the entire backup operation.9367** ^Thus, the backup may be performed on a live source database without9368** preventing other database connections from9369** reading or writing to the source database while the backup is underway.9370**9371** ^(To perform a backup operation:9372** <ol>9373** <li><b>sqlite3_backup_init()</b> is called once to initialize the9374** backup,9375** <li><b>sqlite3_backup_step()</b> is called one or more times to transfer9376** the data between the two databases, and finally9377** <li><b>sqlite3_backup_finish()</b> is called to release all resources9378** associated with the backup operation.9379** </ol>)^9380** There should be exactly one call to sqlite3_backup_finish() for each9381** successful call to sqlite3_backup_init().9382**9383** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b>9384**9385** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the9386** [database connection] associated with the destination database9387** and the database name, respectively.9388** ^The database name is "main" for the main database, "temp" for the9389** temporary database, or the name specified after the AS keyword in9390** an [ATTACH] statement for an attached database.9391** ^The S and M arguments passed to9392** sqlite3_backup_init(D,N,S,M) identify the [database connection]9393** and database name of the source database, respectively.9394** ^The source and destination [database connections] (parameters S and D)9395** must be different or else sqlite3_backup_init(D,N,S,M) will fail with9396** an error.9397**9398** ^A call to sqlite3_backup_init() will fail, returning NULL, if9399** there is already a read or read-write transaction open on the9400** destination database.9401**9402** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is9403** returned and an error code and error message are stored in the9404** destination [database connection] D.9405** ^The error code and message for the failed call to sqlite3_backup_init()9406** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or9407** [sqlite3_errmsg16()] functions.9408** ^A successful call to sqlite3_backup_init() returns a pointer to an9409** [sqlite3_backup] object.9410** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and9411** sqlite3_backup_finish() functions to perform the specified backup9412** operation.9413**9414** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b>9415**9416** ^Function sqlite3_backup_step(B,N) will copy up to N pages between9417** the source and destination databases specified by [sqlite3_backup] object B.9418** ^If N is negative, all remaining source pages are copied.9419** ^If sqlite3_backup_step(B,N) successfully copies N pages and there9420** are still more pages to be copied, then the function returns [SQLITE_OK].9421** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages9422** from source to destination, then it returns [SQLITE_DONE].9423** ^If an error occurs while running sqlite3_backup_step(B,N),9424** then an [error code] is returned. ^As well as [SQLITE_OK] and9425** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],9426** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an9427** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code.9428**9429** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if9430** <ol>9431** <li> the destination database was opened read-only, or9432** <li> the destination database is using write-ahead-log journaling9433** and the destination and source page sizes differ, or9434** <li> the destination database is an in-memory database and the9435** destination and source page sizes differ.9436** </ol>)^9437**9438** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then9439** the [sqlite3_busy_handler | busy-handler function]9440** is invoked (if one is specified). ^If the9441** busy-handler returns non-zero before the lock is available, then9442** [SQLITE_BUSY] is returned to the caller. ^In this case the call to9443** sqlite3_backup_step() can be retried later. ^If the source9444** [database connection]9445** is being used to write to the source database when sqlite3_backup_step()9446** is called, then [SQLITE_LOCKED] is returned immediately. ^Again, in this9447** case the call to sqlite3_backup_step() can be retried later on. ^(If9448** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or9449** [SQLITE_READONLY] is returned, then9450** there is no point in retrying the call to sqlite3_backup_step(). These9451** errors are considered fatal.)^ The application must accept9452** that the backup operation has failed and pass the backup operation handle9453** to the sqlite3_backup_finish() to release associated resources.9454**9455** ^The first call to sqlite3_backup_step() obtains an exclusive lock9456** on the destination file. ^The exclusive lock is not released until either9457** sqlite3_backup_finish() is called or the backup operation is complete9458** and sqlite3_backup_step() returns [SQLITE_DONE]. ^Every call to9459** sqlite3_backup_step() obtains a [shared lock] on the source database that9460** lasts for the duration of the sqlite3_backup_step() call.9461** ^Because the source database is not locked between calls to9462** sqlite3_backup_step(), the source database may be modified mid-way9463** through the backup process. ^If the source database is modified by an9464** external process or via a database connection other than the one being9465** used by the backup operation, then the backup will be automatically9466** restarted by the next call to sqlite3_backup_step(). ^If the source9467** database is modified by the using the same database connection as is used9468** by the backup operation, then the backup database is automatically9469** updated at the same time.9470**9471** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b>9472**9473** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the9474** application wishes to abandon the backup operation, the application9475** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish().9476** ^The sqlite3_backup_finish() interfaces releases all9477** resources associated with the [sqlite3_backup] object.9478** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any9479** active write-transaction on the destination database is rolled back.9480** The [sqlite3_backup] object is invalid9481** and may not be used following a call to sqlite3_backup_finish().9482**9483** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no9484** sqlite3_backup_step() errors occurred, regardless or whether or not9485** sqlite3_backup_step() completed.9486** ^If an out-of-memory condition or IO error occurred during any prior9487** sqlite3_backup_step() call on the same [sqlite3_backup] object, then9488** sqlite3_backup_finish() returns the corresponding [error code].9489**9490** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()9491** is not a permanent error and does not affect the return value of9492** sqlite3_backup_finish().9493**9494** [[sqlite3_backup_remaining()]] [[sqlite3_backup_pagecount()]]9495** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b>9496**9497** ^The sqlite3_backup_remaining() routine returns the number of pages still9498** to be backed up at the conclusion of the most recent sqlite3_backup_step().9499** ^The sqlite3_backup_pagecount() routine returns the total number of pages9500** in the source database at the conclusion of the most recent9501** sqlite3_backup_step().9502** ^(The values returned by these functions are only updated by9503** sqlite3_backup_step(). If the source database is modified in a way that9504** changes the size of the source database or the number of pages remaining,9505** those changes are not reflected in the output of sqlite3_backup_pagecount()9506** and sqlite3_backup_remaining() until after the next9507** sqlite3_backup_step().)^9508**9509** <b>Concurrent Usage of Database Handles</b>9510**9511** ^The source [database connection] may be used by the application for other9512** purposes while a backup operation is underway or being initialized.9513** ^If SQLite is compiled and configured to support threadsafe database9514** connections, then the source database connection may be used concurrently9515** from within other threads.9516**9517** However, the application must guarantee that the destination9518** [database connection] is not passed to any other API (by any thread) after9519** sqlite3_backup_init() is called and before the corresponding call to9520** sqlite3_backup_finish(). SQLite does not currently check to see9521** if the application incorrectly accesses the destination [database connection]9522** and so no error code is reported, but the operations may malfunction9523** nevertheless. Use of the destination database connection while a9524** backup is in progress might also cause a mutex deadlock.9525**9526** If running in [shared cache mode], the application must9527** guarantee that the shared cache used by the destination database9528** is not accessed while the backup is running. In practice this means9529** that the application must guarantee that the disk file being9530** backed up to is not accessed by any connection within the process,9531** not just the specific connection that was passed to sqlite3_backup_init().9532**9533** The [sqlite3_backup] object itself is partially threadsafe. Multiple9534** threads may safely make multiple concurrent calls to sqlite3_backup_step().9535** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount()9536** APIs are not strictly speaking threadsafe. If they are invoked at the9537** same time as another thread is invoking sqlite3_backup_step() it is9538** possible that they return invalid values.9539**9540** <b>Alternatives To Using The Backup API</b>9541**9542** Other techniques for safely creating a consistent backup of an SQLite9543** database include:9544**9545** <ul>9546** <li> The [VACUUM INTO] command.9547** <li> The [sqlite3_rsync] utility program.9548** </ul>9549*/9550SQLITE_API sqlite3_backup *sqlite3_backup_init(9551sqlite3 *pDest, /* Destination database handle */9552const char *zDestName, /* Destination database name */9553sqlite3 *pSource, /* Source database handle */9554const char *zSourceName /* Source database name */9555);9556SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage);9557SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p);9558SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);9559SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);95609561/*9562** CAPI3REF: Unlock Notification9563** METHOD: sqlite39564**9565** ^When running in shared-cache mode, a database operation may fail with9566** an [SQLITE_LOCKED] error if the required locks on the shared-cache or9567** individual tables within the shared-cache cannot be obtained. See9568** [SQLite Shared-Cache Mode] for a description of shared-cache locking.9569** ^This API may be used to register a callback that SQLite will invoke9570** when the connection currently holding the required lock relinquishes it.9571** ^This API is only available if the library was compiled with the9572** [SQLITE_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined.9573**9574** See Also: [Using the SQLite Unlock Notification Feature].9575**9576** ^Shared-cache locks are released when a database connection concludes9577** its current transaction, either by committing it or rolling it back.9578**9579** ^When a connection (known as the blocked connection) fails to obtain a9580** shared-cache lock and SQLITE_LOCKED is returned to the caller, the9581** identity of the database connection (the blocking connection) that9582** has locked the required resource is stored internally. ^After an9583** application receives an SQLITE_LOCKED error, it may call the9584** sqlite3_unlock_notify() method with the blocked connection handle as9585** the first argument to register for a callback that will be invoked9586** when the blocking connections current transaction is concluded. ^The9587** callback is invoked from within the [sqlite3_step] or [sqlite3_close]9588** call that concludes the blocking connection's transaction.9589**9590** ^(If sqlite3_unlock_notify() is called in a multi-threaded application,9591** there is a chance that the blocking connection will have already9592** concluded its transaction by the time sqlite3_unlock_notify() is invoked.9593** If this happens, then the specified callback is invoked immediately,9594** from within the call to sqlite3_unlock_notify().)^9595**9596** ^If the blocked connection is attempting to obtain a write-lock on a9597** shared-cache table, and more than one other connection currently holds9598** a read-lock on the same table, then SQLite arbitrarily selects one of9599** the other connections to use as the blocking connection.9600**9601** ^(There may be at most one unlock-notify callback registered by a9602** blocked connection. If sqlite3_unlock_notify() is called when the9603** blocked connection already has a registered unlock-notify callback,9604** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is9605** called with a NULL pointer as its second argument, then any existing9606** unlock-notify callback is canceled. ^The blocked connections9607** unlock-notify callback may also be canceled by closing the blocked9608** connection using [sqlite3_close()].9609**9610** The unlock-notify callback is not reentrant. If an application invokes9611** any sqlite3_xxx API functions from within an unlock-notify callback, a9612** crash or deadlock may be the result.9613**9614** ^Unless deadlock is detected (see below), sqlite3_unlock_notify() always9615** returns SQLITE_OK.9616**9617** <b>Callback Invocation Details</b>9618**9619** When an unlock-notify callback is registered, the application provides a9620** single void* pointer that is passed to the callback when it is invoked.9621** However, the signature of the callback function allows SQLite to pass9622** it an array of void* context pointers. The first argument passed to9623** an unlock-notify callback is a pointer to an array of void* pointers,9624** and the second is the number of entries in the array.9625**9626** When a blocking connection's transaction is concluded, there may be9627** more than one blocked connection that has registered for an unlock-notify9628** callback. ^If two or more such blocked connections have specified the9629** same callback function, then instead of invoking the callback function9630** multiple times, it is invoked once with the set of void* context pointers9631** specified by the blocked connections bundled together into an array.9632** This gives the application an opportunity to prioritize any actions9633** related to the set of unblocked database connections.9634**9635** <b>Deadlock Detection</b>9636**9637** Assuming that after registering for an unlock-notify callback a9638** database waits for the callback to be issued before taking any further9639** action (a reasonable assumption), then using this API may cause the9640** application to deadlock. For example, if connection X is waiting for9641** connection Y's transaction to be concluded, and similarly connection9642** Y is waiting on connection X's transaction, then neither connection9643** will proceed and the system may remain deadlocked indefinitely.9644**9645** To avoid this scenario, the sqlite3_unlock_notify() performs deadlock9646** detection. ^If a given call to sqlite3_unlock_notify() would put the9647** system in a deadlocked state, then SQLITE_LOCKED is returned and no9648** unlock-notify callback is registered. The system is said to be in9649** a deadlocked state if connection A has registered for an unlock-notify9650** callback on the conclusion of connection B's transaction, and connection9651** B has itself registered for an unlock-notify callback when connection9652** A's transaction is concluded. ^Indirect deadlock is also detected, so9653** the system is also considered to be deadlocked if connection B has9654** registered for an unlock-notify callback on the conclusion of connection9655** C's transaction, where connection C is waiting on connection A. ^Any9656** number of levels of indirection are allowed.9657**9658** <b>The "DROP TABLE" Exception</b>9659**9660** When a call to [sqlite3_step()] returns SQLITE_LOCKED, it is almost9661** always appropriate to call sqlite3_unlock_notify(). There is however,9662** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement,9663** SQLite checks if there are any currently executing SELECT statements9664** that belong to the same connection. If there are, SQLITE_LOCKED is9665** returned. In this case there is no "blocking connection", so invoking9666** sqlite3_unlock_notify() results in the unlock-notify callback being9667** invoked immediately. If the application then re-attempts the "DROP TABLE"9668** or "DROP INDEX" query, an infinite loop might be the result.9669**9670** One way around this problem is to check the extended error code returned9671** by an sqlite3_step() call. ^(If there is a blocking connection, then the9672** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in9673** the special "DROP TABLE/INDEX" case, the extended error code is just9674** SQLITE_LOCKED.)^9675*/9676SQLITE_API int sqlite3_unlock_notify(9677sqlite3 *pBlocked, /* Waiting connection */9678void (*xNotify)(void **apArg, int nArg), /* Callback function to invoke */9679void *pNotifyArg /* Argument to pass to xNotify */9680);968196829683/*9684** CAPI3REF: String Comparison9685**9686** ^The [sqlite3_stricmp()] and [sqlite3_strnicmp()] APIs allow applications9687** and extensions to compare the contents of two buffers containing UTF-89688** strings in a case-independent fashion, using the same definition of "case9689** independence" that SQLite uses internally when comparing identifiers.9690*/9691SQLITE_API int sqlite3_stricmp(const char *, const char *);9692SQLITE_API int sqlite3_strnicmp(const char *, const char *, int);96939694/*9695** CAPI3REF: String Globbing9696*9697** ^The [sqlite3_strglob(P,X)] interface returns zero if and only if9698** string X matches the [GLOB] pattern P.9699** ^The definition of [GLOB] pattern matching used in9700** [sqlite3_strglob(P,X)] is the same as for the "X GLOB P" operator in the9701** SQL dialect understood by SQLite. ^The [sqlite3_strglob(P,X)] function9702** is case sensitive.9703**9704** Note that this routine returns zero on a match and non-zero if the strings9705** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()].9706**9707** See also: [sqlite3_strlike()].9708*/9709SQLITE_API int sqlite3_strglob(const char *zGlob, const char *zStr);97109711/*9712** CAPI3REF: String LIKE Matching9713*9714** ^The [sqlite3_strlike(P,X,E)] interface returns zero if and only if9715** string X matches the [LIKE] pattern P with escape character E.9716** ^The definition of [LIKE] pattern matching used in9717** [sqlite3_strlike(P,X,E)] is the same as for the "X LIKE P ESCAPE E"9718** operator in the SQL dialect understood by SQLite. ^For "X LIKE P" without9719** the ESCAPE clause, set the E parameter of [sqlite3_strlike(P,X,E)] to 0.9720** ^As with the LIKE operator, the [sqlite3_strlike(P,X,E)] function is case9721** insensitive - equivalent upper and lower case ASCII characters match9722** one another.9723**9724** ^The [sqlite3_strlike(P,X,E)] function matches Unicode characters, though9725** only ASCII characters are case folded.9726**9727** Note that this routine returns zero on a match and non-zero if the strings9728** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()].9729**9730** See also: [sqlite3_strglob()].9731*/9732SQLITE_API int sqlite3_strlike(const char *zGlob, const char *zStr, unsigned int cEsc);97339734/*9735** CAPI3REF: Error Logging Interface9736**9737** ^The [sqlite3_log()] interface writes a message into the [error log]9738** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()].9739** ^If logging is enabled, the zFormat string and subsequent arguments are9740** used with [sqlite3_snprintf()] to generate the final output string.9741**9742** The sqlite3_log() interface is intended for use by extensions such as9743** virtual tables, collating functions, and SQL functions. While there is9744** nothing to prevent an application from calling sqlite3_log(), doing so9745** is considered bad form.9746**9747** The zFormat string must not be NULL.9748**9749** To avoid deadlocks and other threading problems, the sqlite3_log() routine9750** will not use dynamically allocated memory. The log message is stored in9751** a fixed-length buffer on the stack. If the log message is longer than9752** a few hundred characters, it will be truncated to the length of the9753** buffer.9754*/9755SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...);97569757/*9758** CAPI3REF: Write-Ahead Log Commit Hook9759** METHOD: sqlite39760**9761** ^The [sqlite3_wal_hook()] function is used to register a callback that9762** is invoked each time data is committed to a database in wal mode.9763**9764** ^(The callback is invoked by SQLite after the commit has taken place and9765** the associated write-lock on the database released)^, so the implementation9766** may read, write or [checkpoint] the database as required.9767**9768** ^The first parameter passed to the callback function when it is invoked9769** is a copy of the third parameter passed to sqlite3_wal_hook() when9770** registering the callback. ^The second is a copy of the database handle.9771** ^The third parameter is the name of the database that was written to -9772** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter9773** is the number of pages currently in the write-ahead log file,9774** including those that were just committed.9775**9776** The callback function should normally return [SQLITE_OK]. ^If an error9777** code is returned, that error will propagate back up through the9778** SQLite code base to cause the statement that provoked the callback9779** to report an error, though the commit will have still occurred. If the9780** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value9781** that does not correspond to any valid SQLite error code, the results9782** are undefined.9783**9784** A single database handle may have at most a single write-ahead log callback9785** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any9786** previously registered write-ahead log callback. ^The return value is9787** a copy of the third parameter from the previous call, if any, or 0.9788** ^Note that the [sqlite3_wal_autocheckpoint()] interface and the9789** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will9790** overwrite any prior [sqlite3_wal_hook()] settings.9791*/9792SQLITE_API void *sqlite3_wal_hook(9793sqlite3*,9794int(*)(void *,sqlite3*,const char*,int),9795void*9796);97979798/*9799** CAPI3REF: Configure an auto-checkpoint9800** METHOD: sqlite39801**9802** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around9803** [sqlite3_wal_hook()] that causes any database on [database connection] D9804** to automatically [checkpoint]9805** after committing a transaction if there are N or9806** more frames in the [write-ahead log] file. ^Passing zero or9807** a negative value as the nFrame parameter disables automatic9808** checkpoints entirely.9809**9810** ^The callback registered by this function replaces any existing callback9811** registered using [sqlite3_wal_hook()]. ^Likewise, registering a callback9812** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism9813** configured by this function.9814**9815** ^The [wal_autocheckpoint pragma] can be used to invoke this interface9816** from SQL.9817**9818** ^Checkpoints initiated by this mechanism are9819** [sqlite3_wal_checkpoint_v2|PASSIVE].9820**9821** ^Every new [database connection] defaults to having the auto-checkpoint9822** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT]9823** pages. The use of this interface9824** is only necessary if the default setting is found to be suboptimal9825** for a particular application.9826*/9827SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);98289829/*9830** CAPI3REF: Checkpoint a database9831** METHOD: sqlite39832**9833** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to9834** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^9835**9836** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the9837** [write-ahead log] for database X on [database connection] D to be9838** transferred into the database file and for the write-ahead log to9839** be reset. See the [checkpointing] documentation for addition9840** information.9841**9842** This interface used to be the only way to cause a checkpoint to9843** occur. But then the newer and more powerful [sqlite3_wal_checkpoint_v2()]9844** interface was added. This interface is retained for backwards9845** compatibility and as a convenience for applications that need to manually9846** start a callback but which do not need the full power (and corresponding9847** complication) of [sqlite3_wal_checkpoint_v2()].9848*/9849SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);98509851/*9852** CAPI3REF: Checkpoint a database9853** METHOD: sqlite39854**9855** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint9856** operation on database X of [database connection] D in mode M. Status9857** information is written back into integers pointed to by L and C.)^9858** ^(The M parameter must be a valid [checkpoint mode]:)^9859**9860** <dl>9861** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>9862** ^Checkpoint as many frames as possible without waiting for any database9863** readers or writers to finish, then sync the database file if all frames9864** in the log were checkpointed. ^The [busy-handler callback]9865** is never invoked in the SQLITE_CHECKPOINT_PASSIVE mode.9866** ^On the other hand, passive mode might leave the checkpoint unfinished9867** if there are concurrent readers or writers.9868**9869** <dt>SQLITE_CHECKPOINT_FULL<dd>9870** ^This mode blocks (it invokes the9871** [sqlite3_busy_handler|busy-handler callback]) until there is no9872** database writer and all readers are reading from the most recent database9873** snapshot. ^It then checkpoints all frames in the log file and syncs the9874** database file. ^This mode blocks new database writers while it is pending,9875** but new database readers are allowed to continue unimpeded.9876**9877** <dt>SQLITE_CHECKPOINT_RESTART<dd>9878** ^This mode works the same way as SQLITE_CHECKPOINT_FULL with the addition9879** that after checkpointing the log file it blocks (calls the9880** [busy-handler callback])9881** until all readers are reading from the database file only. ^This ensures9882** that the next writer will restart the log file from the beginning.9883** ^Like SQLITE_CHECKPOINT_FULL, this mode blocks new9884** database writer attempts while it is pending, but does not impede readers.9885**9886** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd>9887** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the9888** addition that it also truncates the log file to zero bytes just prior9889** to a successful return.9890** </dl>9891**9892** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in9893** the log file or to -1 if the checkpoint could not run because9894** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not9895** NULL,then *pnCkpt is set to the total number of checkpointed frames in the9896** log file (including any that were already checkpointed before the function9897** was called) or to -1 if the checkpoint could not run due to an error or9898** because the database is not in WAL mode. ^Note that upon successful9899** completion of an SQLITE_CHECKPOINT_TRUNCATE, the log file will have been9900** truncated to zero bytes and so both *pnLog and *pnCkpt will be set to zero.9901**9902** ^All calls obtain an exclusive "checkpoint" lock on the database file. ^If9903** any other process is running a checkpoint operation at the same time, the9904** lock cannot be obtained and SQLITE_BUSY is returned. ^Even if there is a9905** busy-handler configured, it will not be invoked in this case.9906**9907** ^The SQLITE_CHECKPOINT_FULL, RESTART and TRUNCATE modes also obtain the9908** exclusive "writer" lock on the database file. ^If the writer lock cannot be9909** obtained immediately, and a busy-handler is configured, it is invoked and9910** the writer lock retried until either the busy-handler returns 0 or the lock9911** is successfully obtained. ^The busy-handler is also invoked while waiting for9912** database readers as described above. ^If the busy-handler returns 0 before9913** the writer lock is obtained or while waiting for database readers, the9914** checkpoint operation proceeds from that point in the same way as9915** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible9916** without blocking any further. ^SQLITE_BUSY is returned in this case.9917**9918** ^If parameter zDb is NULL or points to a zero length string, then the9919** specified operation is attempted on all WAL databases [attached] to9920** [database connection] db. In this case the9921** values written to output parameters *pnLog and *pnCkpt are undefined. ^If9922** an SQLITE_BUSY error is encountered when processing one or more of the9923** attached WAL databases, the operation is still attempted on any remaining9924** attached databases and SQLITE_BUSY is returned at the end. ^If any other9925** error occurs while processing an attached database, processing is abandoned9926** and the error code is returned to the caller immediately. ^If no error9927** (SQLITE_BUSY or otherwise) is encountered while processing the attached9928** databases, SQLITE_OK is returned.9929**9930** ^If database zDb is the name of an attached database that is not in WAL9931** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. ^If9932** zDb is not NULL (or a zero length string) and is not the name of any9933** attached database, SQLITE_ERROR is returned to the caller.9934**9935** ^Unless it returns SQLITE_MISUSE,9936** the sqlite3_wal_checkpoint_v2() interface9937** sets the error information that is queried by9938** [sqlite3_errcode()] and [sqlite3_errmsg()].9939**9940** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface9941** from SQL.9942*/9943SQLITE_API int sqlite3_wal_checkpoint_v2(9944sqlite3 *db, /* Database handle */9945const char *zDb, /* Name of attached database (or NULL) */9946int eMode, /* SQLITE_CHECKPOINT_* value */9947int *pnLog, /* OUT: Size of WAL log in frames */9948int *pnCkpt /* OUT: Total number of frames checkpointed */9949);99509951/*9952** CAPI3REF: Checkpoint Mode Values9953** KEYWORDS: {checkpoint mode}9954**9955** These constants define all valid values for the "checkpoint mode" passed9956** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface.9957** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the9958** meaning of each of these checkpoint modes.9959*/9960#define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */9961#define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */9962#define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for readers */9963#define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */99649965/*9966** CAPI3REF: Virtual Table Interface Configuration9967**9968** This function may be called by either the [xConnect] or [xCreate] method9969** of a [virtual table] implementation to configure9970** various facets of the virtual table interface.9971**9972** If this interface is invoked outside the context of an xConnect or9973** xCreate virtual table method then the behavior is undefined.9974**9975** In the call sqlite3_vtab_config(D,C,...) the D parameter is the9976** [database connection] in which the virtual table is being created and9977** which is passed in as the first argument to the [xConnect] or [xCreate]9978** method that is invoking sqlite3_vtab_config(). The C parameter is one9979** of the [virtual table configuration options]. The presence and meaning9980** of parameters after C depend on which [virtual table configuration option]9981** is used.9982*/9983SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...);99849985/*9986** CAPI3REF: Virtual Table Configuration Options9987** KEYWORDS: {virtual table configuration options}9988** KEYWORDS: {virtual table configuration option}9989**9990** These macros define the various options to the9991** [sqlite3_vtab_config()] interface that [virtual table] implementations9992** can use to customize and optimize their behavior.9993**9994** <dl>9995** [[SQLITE_VTAB_CONSTRAINT_SUPPORT]]9996** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT</dt>9997** <dd>Calls of the form9998** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,9999** where X is an integer. If X is zero, then the [virtual table] whose10000** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not10001** support constraints. In this configuration (which is the default) if10002** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire10003** statement is rolled back as if [ON CONFLICT | OR ABORT] had been10004** specified as part of the users SQL statement, regardless of the actual10005** ON CONFLICT mode specified.10006**10007** If X is non-zero, then the virtual table implementation guarantees10008** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before10009** any modifications to internal or persistent data structures have been made.10010** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite10011** is able to roll back a statement or database transaction, and abandon10012** or continue processing the current SQL statement as appropriate.10013** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns10014** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode10015** had been ABORT.10016**10017** Virtual table implementations that are required to handle OR REPLACE10018** must do so within the [xUpdate] method. If a call to the10019** [sqlite3_vtab_on_conflict()] function indicates that the current ON10020** CONFLICT policy is REPLACE, the virtual table implementation should10021** silently replace the appropriate rows within the xUpdate callback and10022** return SQLITE_OK. Or, if this is not possible, it may return10023** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT10024** constraint handling.10025** </dd>10026**10027** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt>10028** <dd>Calls of the form10029** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the10030** the [xConnect] or [xCreate] methods of a [virtual table] implementation10031** prohibits that virtual table from being used from within triggers and10032** views.10033** </dd>10034**10035** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>10036** <dd>Calls of the form10037** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the10038** the [xConnect] or [xCreate] methods of a [virtual table] implementation10039** identify that virtual table as being safe to use from within triggers10040** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the10041** virtual table can do no serious harm even if it is controlled by a10042** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS10043** flag unless absolutely necessary.10044** </dd>10045**10046** [[SQLITE_VTAB_USES_ALL_SCHEMAS]]<dt>SQLITE_VTAB_USES_ALL_SCHEMAS</dt>10047** <dd>Calls of the form10048** [sqlite3_vtab_config](db,SQLITE_VTAB_USES_ALL_SCHEMA) from within the10049** the [xConnect] or [xCreate] methods of a [virtual table] implementation10050** instruct the query planner to begin at least a read transaction on10051** all schemas ("main", "temp", and any ATTACH-ed databases) whenever the10052** virtual table is used.10053** </dd>10054** </dl>10055*/10056#define SQLITE_VTAB_CONSTRAINT_SUPPORT 110057#define SQLITE_VTAB_INNOCUOUS 210058#define SQLITE_VTAB_DIRECTONLY 310059#define SQLITE_VTAB_USES_ALL_SCHEMAS 41006010061/*10062** CAPI3REF: Determine The Virtual Table Conflict Policy10063**10064** This function may only be called from within a call to the [xUpdate] method10065** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The10066** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL],10067** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode10068** of the SQL statement that triggered the call to the [xUpdate] method of the10069** [virtual table].10070*/10071SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);1007210073/*10074** CAPI3REF: Determine If Virtual Table Column Access Is For UPDATE10075**10076** If the sqlite3_vtab_nochange(X) routine is called within the [xColumn]10077** method of a [virtual table], then it might return true if the10078** column is being fetched as part of an UPDATE operation during which the10079** column value will not change. The virtual table implementation can use10080** this hint as permission to substitute a return value that is less10081** expensive to compute and that the corresponding10082** [xUpdate] method understands as a "no-change" value.10083**10084** If the [xColumn] method calls sqlite3_vtab_nochange() and finds that10085** the column is not changed by the UPDATE statement, then the xColumn10086** method can optionally return without setting a result, without calling10087** any of the [sqlite3_result_int|sqlite3_result_xxxxx() interfaces].10088** In that case, [sqlite3_value_nochange(X)] will return true for the10089** same column in the [xUpdate] method.10090**10091** The sqlite3_vtab_nochange() routine is an optimization. Virtual table10092** implementations should continue to give a correct answer even if the10093** sqlite3_vtab_nochange() interface were to always return false. In the10094** current implementation, the sqlite3_vtab_nochange() interface does always10095** returns false for the enhanced [UPDATE FROM] statement.10096*/10097SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);1009810099/*10100** CAPI3REF: Determine The Collation For a Virtual Table Constraint10101** METHOD: sqlite3_index_info10102**10103** This function may only be called from within a call to the [xBestIndex]10104** method of a [virtual table]. This function returns a pointer to a string10105** that is the name of the appropriate collation sequence to use for text10106** comparisons on the constraint identified by its arguments.10107**10108** The first argument must be the pointer to the [sqlite3_index_info] object10109** that is the first parameter to the xBestIndex() method. The second argument10110** must be an index into the aConstraint[] array belonging to the10111** sqlite3_index_info structure passed to xBestIndex.10112**10113** Important:10114** The first parameter must be the same pointer that is passed into the10115** xBestMethod() method. The first parameter may not be a pointer to a10116** different [sqlite3_index_info] object, even an exact copy.10117**10118** The return value is computed as follows:10119**10120** <ol>10121** <li><p> If the constraint comes from a WHERE clause expression that contains10122** a [COLLATE operator], then the name of the collation specified by10123** that COLLATE operator is returned.10124** <li><p> If there is no COLLATE operator, but the column that is the subject10125** of the constraint specifies an alternative collating sequence via10126** a [COLLATE clause] on the column definition within the CREATE TABLE10127** statement that was passed into [sqlite3_declare_vtab()], then the10128** name of that alternative collating sequence is returned.10129** <li><p> Otherwise, "BINARY" is returned.10130** </ol>10131*/10132SQLITE_API const char *sqlite3_vtab_collation(sqlite3_index_info*,int);1013310134/*10135** CAPI3REF: Determine if a virtual table query is DISTINCT10136** METHOD: sqlite3_index_info10137**10138** This API may only be used from within an [xBestIndex|xBestIndex method]10139** of a [virtual table] implementation. The result of calling this10140** interface from outside of xBestIndex() is undefined and probably harmful.10141**10142** ^The sqlite3_vtab_distinct() interface returns an integer between 0 and10143** 3. The integer returned by sqlite3_vtab_distinct()10144** gives the virtual table additional information about how the query10145** planner wants the output to be ordered. As long as the virtual table10146** can meet the ordering requirements of the query planner, it may set10147** the "orderByConsumed" flag.10148**10149** <ol><li value="0"><p>10150** ^If the sqlite3_vtab_distinct() interface returns 0, that means10151** that the query planner needs the virtual table to return all rows in the10152** sort order defined by the "nOrderBy" and "aOrderBy" fields of the10153** [sqlite3_index_info] object. This is the default expectation. If the10154** virtual table outputs all rows in sorted order, then it is always safe for10155** the xBestIndex method to set the "orderByConsumed" flag, regardless of10156** the return value from sqlite3_vtab_distinct().10157** <li value="1"><p>10158** ^(If the sqlite3_vtab_distinct() interface returns 1, that means10159** that the query planner does not need the rows to be returned in sorted order10160** as long as all rows with the same values in all columns identified by the10161** "aOrderBy" field are adjacent.)^ This mode is used when the query planner10162** is doing a GROUP BY.10163** <li value="2"><p>10164** ^(If the sqlite3_vtab_distinct() interface returns 2, that means10165** that the query planner does not need the rows returned in any particular10166** order, as long as rows with the same values in all columns identified10167** by "aOrderBy" are adjacent.)^ ^(Furthermore, when two or more rows10168** contain the same values for all columns identified by "colUsed", all but10169** one such row may optionally be omitted from the result.)^10170** The virtual table is not required to omit rows that are duplicates10171** over the "colUsed" columns, but if the virtual table can do that without10172** too much extra effort, it could potentially help the query to run faster.10173** This mode is used for a DISTINCT query.10174** <li value="3"><p>10175** ^(If the sqlite3_vtab_distinct() interface returns 3, that means the10176** virtual table must return rows in the order defined by "aOrderBy" as10177** if the sqlite3_vtab_distinct() interface had returned 0. However if10178** two or more rows in the result have the same values for all columns10179** identified by "colUsed", then all but one such row may optionally be10180** omitted.)^ Like when the return value is 2, the virtual table10181** is not required to omit rows that are duplicates over the "colUsed"10182** columns, but if the virtual table can do that without10183** too much extra effort, it could potentially help the query to run faster.10184** This mode is used for queries10185** that have both DISTINCT and ORDER BY clauses.10186** </ol>10187**10188** <p>The following table summarizes the conditions under which the10189** virtual table is allowed to set the "orderByConsumed" flag based on10190** the value returned by sqlite3_vtab_distinct(). This table is a10191** restatement of the previous four paragraphs:10192**10193** <table border=1 cellspacing=0 cellpadding=10 width="90%">10194** <tr>10195** <td valign="top">sqlite3_vtab_distinct() return value10196** <td valign="top">Rows are returned in aOrderBy order10197** <td valign="top">Rows with the same value in all aOrderBy columns are adjacent10198** <td valign="top">Duplicates over all colUsed columns may be omitted10199** <tr><td>0<td>yes<td>yes<td>no10200** <tr><td>1<td>no<td>yes<td>no10201** <tr><td>2<td>no<td>yes<td>yes10202** <tr><td>3<td>yes<td>yes<td>yes10203** </table>10204**10205** ^For the purposes of comparing virtual table output values to see if the10206** values are same value for sorting purposes, two NULL values are considered10207** to be the same. In other words, the comparison operator is "IS"10208** (or "IS NOT DISTINCT FROM") and not "==".10209**10210** If a virtual table implementation is unable to meet the requirements10211** specified above, then it must not set the "orderByConsumed" flag in the10212** [sqlite3_index_info] object or an incorrect answer may result.10213**10214** ^A virtual table implementation is always free to return rows in any order10215** it wants, as long as the "orderByConsumed" flag is not set. ^When the10216** the "orderByConsumed" flag is unset, the query planner will add extra10217** [bytecode] to ensure that the final results returned by the SQL query are10218** ordered correctly. The use of the "orderByConsumed" flag and the10219** sqlite3_vtab_distinct() interface is merely an optimization. ^Careful10220** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed"10221** flag might help queries against a virtual table to run faster. Being10222** overly aggressive and setting the "orderByConsumed" flag when it is not10223** valid to do so, on the other hand, might cause SQLite to return incorrect10224** results.10225*/10226SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*);1022710228/*10229** CAPI3REF: Identify and handle IN constraints in xBestIndex10230**10231** This interface may only be used from within an10232** [xBestIndex|xBestIndex() method] of a [virtual table] implementation.10233** The result of invoking this interface from any other context is10234** undefined and probably harmful.10235**10236** ^(A constraint on a virtual table of the form10237** "[IN operator|column IN (...)]" is10238** communicated to the xBestIndex method as a10239** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use10240** this constraint, it must set the corresponding10241** aConstraintUsage[].argvIndex to a positive integer. ^(Then, under10242** the usual mode of handling IN operators, SQLite generates [bytecode]10243** that invokes the [xFilter|xFilter() method] once for each value10244** on the right-hand side of the IN operator.)^ Thus the virtual table10245** only sees a single value from the right-hand side of the IN operator10246** at a time.10247**10248** In some cases, however, it would be advantageous for the virtual10249** table to see all values on the right-hand of the IN operator all at10250** once. The sqlite3_vtab_in() interfaces facilitates this in two ways:10251**10252** <ol>10253** <li><p>10254** ^A call to sqlite3_vtab_in(P,N,-1) will return true (non-zero)10255** if and only if the [sqlite3_index_info|P->aConstraint][N] constraint10256** is an [IN operator] that can be processed all at once. ^In other words,10257** sqlite3_vtab_in() with -1 in the third argument is a mechanism10258** by which the virtual table can ask SQLite if all-at-once processing10259** of the IN operator is even possible.10260**10261** <li><p>10262** ^A call to sqlite3_vtab_in(P,N,F) with F==1 or F==0 indicates10263** to SQLite that the virtual table does or does not want to process10264** the IN operator all-at-once, respectively. ^Thus when the third10265** parameter (F) is non-negative, this interface is the mechanism by10266** which the virtual table tells SQLite how it wants to process the10267** IN operator.10268** </ol>10269**10270** ^The sqlite3_vtab_in(P,N,F) interface can be invoked multiple times10271** within the same xBestIndex method call. ^For any given P,N pair,10272** the return value from sqlite3_vtab_in(P,N,F) will always be the same10273** within the same xBestIndex call. ^If the interface returns true10274** (non-zero), that means that the constraint is an IN operator10275** that can be processed all-at-once. ^If the constraint is not an IN10276** operator or cannot be processed all-at-once, then the interface returns10277** false.10278**10279** ^(All-at-once processing of the IN operator is selected if both of the10280** following conditions are met:10281**10282** <ol>10283** <li><p> The P->aConstraintUsage[N].argvIndex value is set to a positive10284** integer. This is how the virtual table tells SQLite that it wants to10285** use the N-th constraint.10286**10287** <li><p> The last call to sqlite3_vtab_in(P,N,F) for which F was10288** non-negative had F>=1.10289** </ol>)^10290**10291** ^If either or both of the conditions above are false, then SQLite uses10292** the traditional one-at-a-time processing strategy for the IN constraint.10293** ^If both conditions are true, then the argvIndex-th parameter to the10294** xFilter method will be an [sqlite3_value] that appears to be NULL,10295** but which can be passed to [sqlite3_vtab_in_first()] and10296** [sqlite3_vtab_in_next()] to find all values on the right-hand side10297** of the IN constraint.10298*/10299SQLITE_API int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle);1030010301/*10302** CAPI3REF: Find all elements on the right-hand side of an IN constraint.10303**10304** These interfaces are only useful from within the10305** [xFilter|xFilter() method] of a [virtual table] implementation.10306** The result of invoking these interfaces from any other context10307** is undefined and probably harmful.10308**10309** The X parameter in a call to sqlite3_vtab_in_first(X,P) or10310** sqlite3_vtab_in_next(X,P) should be one of the parameters to the10311** xFilter method which invokes these routines, and specifically10312** a parameter that was previously selected for all-at-once IN constraint10313** processing use the [sqlite3_vtab_in()] interface in the10314** [xBestIndex|xBestIndex method]. ^(If the X parameter is not10315** an xFilter argument that was selected for all-at-once IN constraint10316** processing, then these routines return [SQLITE_ERROR].)^10317**10318** ^(Use these routines to access all values on the right-hand side10319** of the IN constraint using code like the following:10320**10321** <blockquote><pre>10322** for(rc=sqlite3_vtab_in_first(pList, &pVal);10323** rc==SQLITE_OK && pVal;10324** rc=sqlite3_vtab_in_next(pList, &pVal)10325** ){10326** // do something with pVal10327** }10328** if( rc!=SQLITE_OK ){10329** // an error has occurred10330** }10331** </pre></blockquote>)^10332**10333** ^On success, the sqlite3_vtab_in_first(X,P) and sqlite3_vtab_in_next(X,P)10334** routines return SQLITE_OK and set *P to point to the first or next value10335** on the RHS of the IN constraint. ^If there are no more values on the10336** right hand side of the IN constraint, then *P is set to NULL and these10337** routines return [SQLITE_DONE]. ^The return value might be10338** some other value, such as SQLITE_NOMEM, in the event of a malfunction.10339**10340** The *ppOut values returned by these routines are only valid until the10341** next call to either of these routines or until the end of the xFilter10342** method from which these routines were called. If the virtual table10343** implementation needs to retain the *ppOut values for longer, it must make10344** copies. The *ppOut values are [protected sqlite3_value|protected].10345*/10346SQLITE_API int sqlite3_vtab_in_first(sqlite3_value *pVal, sqlite3_value **ppOut);10347SQLITE_API int sqlite3_vtab_in_next(sqlite3_value *pVal, sqlite3_value **ppOut);1034810349/*10350** CAPI3REF: Constraint values in xBestIndex()10351** METHOD: sqlite3_index_info10352**10353** This API may only be used from within the [xBestIndex|xBestIndex method]10354** of a [virtual table] implementation. The result of calling this interface10355** from outside of an xBestIndex method are undefined and probably harmful.10356**10357** ^When the sqlite3_vtab_rhs_value(P,J,V) interface is invoked from within10358** the [xBestIndex] method of a [virtual table] implementation, with P being10359** a copy of the [sqlite3_index_info] object pointer passed into xBestIndex and10360** J being a 0-based index into P->aConstraint[], then this routine10361** attempts to set *V to the value of the right-hand operand of10362** that constraint if the right-hand operand is known. ^If the10363** right-hand operand is not known, then *V is set to a NULL pointer.10364** ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if10365** and only if *V is set to a value. ^The sqlite3_vtab_rhs_value(P,J,V)10366** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th10367** constraint is not available. ^The sqlite3_vtab_rhs_value() interface10368** can return an result code other than SQLITE_OK or SQLITE_NOTFOUND if10369** something goes wrong.10370**10371** The sqlite3_vtab_rhs_value() interface is usually only successful if10372** the right-hand operand of a constraint is a literal value in the original10373** SQL statement. If the right-hand operand is an expression or a reference10374** to some other column or a [host parameter], then sqlite3_vtab_rhs_value()10375** will probably return [SQLITE_NOTFOUND].10376**10377** ^(Some constraints, such as [SQLITE_INDEX_CONSTRAINT_ISNULL] and10378** [SQLITE_INDEX_CONSTRAINT_ISNOTNULL], have no right-hand operand. For such10379** constraints, sqlite3_vtab_rhs_value() always returns SQLITE_NOTFOUND.)^10380**10381** ^The [sqlite3_value] object returned in *V is a protected sqlite3_value10382** and remains valid for the duration of the xBestIndex method call.10383** ^When xBestIndex returns, the sqlite3_value object returned by10384** sqlite3_vtab_rhs_value() is automatically deallocated.10385**10386** The "_rhs_" in the name of this routine is an abbreviation for10387** "Right-Hand Side".10388*/10389SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal);1039010391/*10392** CAPI3REF: Conflict resolution modes10393** KEYWORDS: {conflict resolution mode}10394**10395** These constants are returned by [sqlite3_vtab_on_conflict()] to10396** inform a [virtual table] implementation what the [ON CONFLICT] mode10397** is for the SQL statement being evaluated.10398**10399** Note that the [SQLITE_IGNORE] constant is also used as a potential10400** return value from the [sqlite3_set_authorizer()] callback and that10401** [SQLITE_ABORT] is also a [result code].10402*/10403#define SQLITE_ROLLBACK 110404/* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */10405#define SQLITE_FAIL 310406/* #define SQLITE_ABORT 4 // Also an error code */10407#define SQLITE_REPLACE 51040810409/*10410** CAPI3REF: Prepared Statement Scan Status Opcodes10411** KEYWORDS: {scanstatus options}10412**10413** The following constants can be used for the T parameter to the10414** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a10415** different metric for sqlite3_stmt_scanstatus() to return.10416**10417** When the value returned to V is a string, space to hold that string is10418** managed by the prepared statement S and will be automatically freed when10419** S is finalized.10420**10421** Not all values are available for all query elements. When a value is10422** not available, the output variable is set to -1 if the value is numeric,10423** or to NULL if it is a string (SQLITE_SCANSTAT_NAME).10424**10425** <dl>10426** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>10427** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be10428** set to the total number of times that the X-th loop has run.</dd>10429**10430** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>10431** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be set10432** to the total number of rows examined by all iterations of the X-th loop.</dd>10433**10434** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>10435** <dd>^The "double" variable pointed to by the V parameter will be set to the10436** query planner's estimate for the average number of rows output from each10437** iteration of the X-th loop. If the query planner's estimates was accurate,10438** then this value will approximate the quotient NVISIT/NLOOP and the10439** product of this value for all prior loops with the same SELECTID will10440** be the NLOOP value for the current loop.10441**10442** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>10443** <dd>^The "const char *" variable pointed to by the V parameter will be set10444** to a zero-terminated UTF-8 string containing the name of the index or table10445** used for the X-th loop.10446**10447** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>10448** <dd>^The "const char *" variable pointed to by the V parameter will be set10449** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]10450** description for the X-th loop.10451**10452** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECTID</dt>10453** <dd>^The "int" variable pointed to by the V parameter will be set to the10454** id for the X-th query plan element. The id value is unique within the10455** statement. The select-id is the same value as is output in the first10456** column of an [EXPLAIN QUERY PLAN] query.10457**10458** [[SQLITE_SCANSTAT_PARENTID]] <dt>SQLITE_SCANSTAT_PARENTID</dt>10459** <dd>The "int" variable pointed to by the V parameter will be set to the10460** the id of the parent of the current query element, if applicable, or10461** to zero if the query element has no parent. This is the same value as10462** returned in the second column of an [EXPLAIN QUERY PLAN] query.10463**10464** [[SQLITE_SCANSTAT_NCYCLE]] <dt>SQLITE_SCANSTAT_NCYCLE</dt>10465** <dd>The sqlite3_int64 output value is set to the number of cycles,10466** according to the processor time-stamp counter, that elapsed while the10467** query element was being processed. This value is not available for10468** all query elements - if it is unavailable the output variable is10469** set to -1.10470** </dl>10471*/10472#define SQLITE_SCANSTAT_NLOOP 010473#define SQLITE_SCANSTAT_NVISIT 110474#define SQLITE_SCANSTAT_EST 210475#define SQLITE_SCANSTAT_NAME 310476#define SQLITE_SCANSTAT_EXPLAIN 410477#define SQLITE_SCANSTAT_SELECTID 510478#define SQLITE_SCANSTAT_PARENTID 610479#define SQLITE_SCANSTAT_NCYCLE 71048010481/*10482** CAPI3REF: Prepared Statement Scan Status10483** METHOD: sqlite3_stmt10484**10485** These interfaces return information about the predicted and measured10486** performance for pStmt. Advanced applications can use this10487** interface to compare the predicted and the measured performance and10488** issue warnings and/or rerun [ANALYZE] if discrepancies are found.10489**10490** Since this interface is expected to be rarely used, it is only10491** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS]10492** compile-time option.10493**10494** The "iScanStatusOp" parameter determines which status information to return.10495** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior10496** of this interface is undefined. ^The requested measurement is written into10497** a variable pointed to by the "pOut" parameter.10498**10499** The "flags" parameter must be passed a mask of flags. At present only10500** one flag is defined - SQLITE_SCANSTAT_COMPLEX. If SQLITE_SCANSTAT_COMPLEX10501** is specified, then status information is available for all elements10502** of a query plan that are reported by "EXPLAIN QUERY PLAN" output. If10503** SQLITE_SCANSTAT_COMPLEX is not specified, then only query plan elements10504** that correspond to query loops (the "SCAN..." and "SEARCH..." elements of10505** the EXPLAIN QUERY PLAN output) are available. Invoking API10506** sqlite3_stmt_scanstatus() is equivalent to calling10507** sqlite3_stmt_scanstatus_v2() with a zeroed flags parameter.10508**10509** Parameter "idx" identifies the specific query element to retrieve statistics10510** for. Query elements are numbered starting from zero. A value of -1 may be10511** to query for statistics regarding the entire query. ^If idx is out of range10512** - less than -1 or greater than or equal to the total number of query10513** elements used to implement the statement - a non-zero value is returned and10514** the variable that pOut points to is unchanged.10515**10516** See also: [sqlite3_stmt_scanstatus_reset()]10517*/10518SQLITE_API int sqlite3_stmt_scanstatus(10519sqlite3_stmt *pStmt, /* Prepared statement for which info desired */10520int idx, /* Index of loop to report on */10521int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */10522void *pOut /* Result written here */10523);10524SQLITE_API int sqlite3_stmt_scanstatus_v2(10525sqlite3_stmt *pStmt, /* Prepared statement for which info desired */10526int idx, /* Index of loop to report on */10527int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */10528int flags, /* Mask of flags defined below */10529void *pOut /* Result written here */10530);1053110532/*10533** CAPI3REF: Prepared Statement Scan Status10534** KEYWORDS: {scan status flags}10535*/10536#define SQLITE_SCANSTAT_COMPLEX 0x00011053710538/*10539** CAPI3REF: Zero Scan-Status Counters10540** METHOD: sqlite3_stmt10541**10542** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.10543**10544** This API is only available if the library is built with pre-processor10545** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.10546*/10547SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);1054810549/*10550** CAPI3REF: Flush caches to disk mid-transaction10551** METHOD: sqlite310552**10553** ^If a write-transaction is open on [database connection] D when the10554** [sqlite3_db_cacheflush(D)] interface invoked, any dirty10555** pages in the pager-cache that are not currently in use are written out10556** to disk. A dirty page may be in use if a database cursor created by an10557** active SQL statement is reading from it, or if it is page 1 of a database10558** file (page 1 is always "in use"). ^The [sqlite3_db_cacheflush(D)]10559** interface flushes caches for all schemas - "main", "temp", and10560** any [attached] databases.10561**10562** ^If this function needs to obtain extra database locks before dirty pages10563** can be flushed to disk, it does so. ^If those locks cannot be obtained10564** immediately and there is a busy-handler callback configured, it is invoked10565** in the usual manner. ^If the required lock still cannot be obtained, then10566** the database is skipped and an attempt made to flush any dirty pages10567** belonging to the next (if any) database. ^If any databases are skipped10568** because locks cannot be obtained, but no other error occurs, this10569** function returns SQLITE_BUSY.10570**10571** ^If any other error occurs while flushing dirty pages to disk (for10572** example an IO error or out-of-memory condition), then processing is10573** abandoned and an SQLite [error code] is returned to the caller immediately.10574**10575** ^Otherwise, if no error occurs, [sqlite3_db_cacheflush()] returns SQLITE_OK.10576**10577** ^This function does not set the database handle error code or message10578** returned by the [sqlite3_errcode()] and [sqlite3_errmsg()] functions.10579*/10580SQLITE_API int sqlite3_db_cacheflush(sqlite3*);1058110582/*10583** CAPI3REF: The pre-update hook.10584** METHOD: sqlite310585**10586** ^These interfaces are only available if SQLite is compiled using the10587** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option.10588**10589** ^The [sqlite3_preupdate_hook()] interface registers a callback function10590** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation10591** on a database table.10592** ^At most one preupdate hook may be registered at a time on a single10593** [database connection]; each call to [sqlite3_preupdate_hook()] overrides10594** the previous setting.10595** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()]10596** with a NULL pointer as the second parameter.10597** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as10598** the first parameter to callbacks.10599**10600** ^The preupdate hook only fires for changes to real database tables; the10601** preupdate hook is not invoked for changes to [virtual tables] or to10602** system tables like sqlite_sequence or sqlite_stat1.10603**10604** ^The second parameter to the preupdate callback is a pointer to10605** the [database connection] that registered the preupdate hook.10606** ^The third parameter to the preupdate callback is one of the constants10607** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the10608** kind of update operation that is about to occur.10609** ^(The fourth parameter to the preupdate callback is the name of the10610** database within the database connection that is being modified. This10611** will be "main" for the main database or "temp" for TEMP tables or10612** the name given after the AS keyword in the [ATTACH] statement for attached10613** databases.)^10614** ^The fifth parameter to the preupdate callback is the name of the10615** table that is being modified.10616**10617** For an UPDATE or DELETE operation on a [rowid table], the sixth10618** parameter passed to the preupdate callback is the initial [rowid] of the10619** row being modified or deleted. For an INSERT operation on a rowid table,10620** or any operation on a WITHOUT ROWID table, the value of the sixth10621** parameter is undefined. For an INSERT or UPDATE on a rowid table the10622** seventh parameter is the final rowid value of the row being inserted10623** or updated. The value of the seventh parameter passed to the callback10624** function is not defined for operations on WITHOUT ROWID tables, or for10625** DELETE operations on rowid tables.10626**10627** ^The sqlite3_preupdate_hook(D,C,P) function returns the P argument from10628** the previous call on the same [database connection] D, or NULL for10629** the first call on D.10630**10631** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],10632** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces10633** provide additional information about a preupdate event. These routines10634** may only be called from within a preupdate callback. Invoking any of10635** these routines from outside of a preupdate callback or with a10636** [database connection] pointer that is different from the one supplied10637** to the preupdate callback results in undefined and probably undesirable10638** behavior.10639**10640** ^The [sqlite3_preupdate_count(D)] interface returns the number of columns10641** in the row that is being inserted, updated, or deleted.10642**10643** ^The [sqlite3_preupdate_old(D,N,P)] interface writes into P a pointer to10644** a [protected sqlite3_value] that contains the value of the Nth column of10645** the table row before it is updated. The N parameter must be between 010646** and one less than the number of columns or the behavior will be10647** undefined. This must only be used within SQLITE_UPDATE and SQLITE_DELETE10648** preupdate callbacks; if it is used by an SQLITE_INSERT callback then the10649** behavior is undefined. The [sqlite3_value] that P points to10650** will be destroyed when the preupdate callback returns.10651**10652** ^The [sqlite3_preupdate_new(D,N,P)] interface writes into P a pointer to10653** a [protected sqlite3_value] that contains the value of the Nth column of10654** the table row after it is updated. The N parameter must be between 010655** and one less than the number of columns or the behavior will be10656** undefined. This must only be used within SQLITE_INSERT and SQLITE_UPDATE10657** preupdate callbacks; if it is used by an SQLITE_DELETE callback then the10658** behavior is undefined. The [sqlite3_value] that P points to10659** will be destroyed when the preupdate callback returns.10660**10661** ^The [sqlite3_preupdate_depth(D)] interface returns 0 if the preupdate10662** callback was invoked as a result of a direct insert, update, or delete10663** operation; or 1 for inserts, updates, or deletes invoked by top-level10664** triggers; or 2 for changes resulting from triggers called by top-level10665** triggers; and so forth.10666**10667** When the [sqlite3_blob_write()] API is used to update a blob column,10668** the pre-update hook is invoked with SQLITE_DELETE. This is because the10669** in this case the new values are not available. In this case, when a10670** callback made with op==SQLITE_DELETE is actually a write using the10671** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns10672** the index of the column being written. In other cases, where the10673** pre-update hook is being invoked for some other reason, including a10674** regular DELETE, sqlite3_preupdate_blobwrite() returns -1.10675**10676** See also: [sqlite3_update_hook()]10677*/10678#if defined(SQLITE_ENABLE_PREUPDATE_HOOK)10679SQLITE_API void *sqlite3_preupdate_hook(10680sqlite3 *db,10681void(*xPreUpdate)(10682void *pCtx, /* Copy of third arg to preupdate_hook() */10683sqlite3 *db, /* Database handle */10684int op, /* SQLITE_UPDATE, DELETE or INSERT */10685char const *zDb, /* Database name */10686char const *zName, /* Table name */10687sqlite3_int64 iKey1, /* Rowid of row about to be deleted/updated */10688sqlite3_int64 iKey2 /* New rowid value (for a rowid UPDATE) */10689),10690void*10691);10692SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);10693SQLITE_API int sqlite3_preupdate_count(sqlite3 *);10694SQLITE_API int sqlite3_preupdate_depth(sqlite3 *);10695SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);10696SQLITE_API int sqlite3_preupdate_blobwrite(sqlite3 *);10697#endif1069810699/*10700** CAPI3REF: Low-level system error code10701** METHOD: sqlite310702**10703** ^Attempt to return the underlying operating system error code or error10704** number that caused the most recent I/O error or failure to open a file.10705** The return value is OS-dependent. For example, on unix systems, after10706** [sqlite3_open_v2()] returns [SQLITE_CANTOPEN], this interface could be10707** called to get back the underlying "errno" that caused the problem, such10708** as ENOSPC, EAUTH, EISDIR, and so forth.10709*/10710SQLITE_API int sqlite3_system_errno(sqlite3*);1071110712/*10713** CAPI3REF: Database Snapshot10714** KEYWORDS: {snapshot} {sqlite3_snapshot}10715**10716** An instance of the snapshot object records the state of a [WAL mode]10717** database for some specific point in history.10718**10719** In [WAL mode], multiple [database connections] that are open on the10720** same database file can each be reading a different historical version10721** of the database file. When a [database connection] begins a read10722** transaction, that connection sees an unchanging copy of the database10723** as it existed for the point in time when the transaction first started.10724** Subsequent changes to the database from other connections are not seen10725** by the reader until a new read transaction is started.10726**10727** The sqlite3_snapshot object records state information about an historical10728** version of the database file so that it is possible to later open a new read10729** transaction that sees that historical version of the database rather than10730** the most recent version.10731*/10732typedef struct sqlite3_snapshot {10733unsigned char hidden[48];10734} sqlite3_snapshot;1073510736/*10737** CAPI3REF: Record A Database Snapshot10738** CONSTRUCTOR: sqlite3_snapshot10739**10740** ^The [sqlite3_snapshot_get(D,S,P)] interface attempts to make a10741** new [sqlite3_snapshot] object that records the current state of10742** schema S in database connection D. ^On success, the10743** [sqlite3_snapshot_get(D,S,P)] interface writes a pointer to the newly10744** created [sqlite3_snapshot] object into *P and returns SQLITE_OK.10745** If there is not already a read-transaction open on schema S when10746** this function is called, one is opened automatically.10747**10748** If a read-transaction is opened by this function, then it is guaranteed10749** that the returned snapshot object may not be invalidated by a database10750** writer or checkpointer until after the read-transaction is closed. This10751** is not guaranteed if a read-transaction is already open when this10752** function is called. In that case, any subsequent write or checkpoint10753** operation on the database may invalidate the returned snapshot handle,10754** even while the read-transaction remains open.10755**10756** The following must be true for this function to succeed. If any of10757** the following statements are false when sqlite3_snapshot_get() is10758** called, SQLITE_ERROR is returned. The final value of *P is undefined10759** in this case.10760**10761** <ul>10762** <li> The database handle must not be in [autocommit mode].10763**10764** <li> Schema S of [database connection] D must be a [WAL mode] database.10765**10766** <li> There must not be a write transaction open on schema S of database10767** connection D.10768**10769** <li> One or more transactions must have been written to the current wal10770** file since it was created on disk (by any connection). This means10771** that a snapshot cannot be taken on a wal mode database with no wal10772** file immediately after it is first opened. At least one transaction10773** must be written to it first.10774** </ul>10775**10776** This function may also return SQLITE_NOMEM. If it is called with the10777** database handle in autocommit mode but fails for some other reason,10778** whether or not a read transaction is opened on schema S is undefined.10779**10780** The [sqlite3_snapshot] object returned from a successful call to10781** [sqlite3_snapshot_get()] must be freed using [sqlite3_snapshot_free()]10782** to avoid a memory leak.10783**10784** The [sqlite3_snapshot_get()] interface is only available when the10785** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.10786*/10787SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_get(10788sqlite3 *db,10789const char *zSchema,10790sqlite3_snapshot **ppSnapshot10791);1079210793/*10794** CAPI3REF: Start a read transaction on an historical snapshot10795** METHOD: sqlite3_snapshot10796**10797** ^The [sqlite3_snapshot_open(D,S,P)] interface either starts a new read10798** transaction or upgrades an existing one for schema S of10799** [database connection] D such that the read transaction refers to10800** historical [snapshot] P, rather than the most recent change to the10801** database. ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK10802** on success or an appropriate [error code] if it fails.10803**10804** ^In order to succeed, the database connection must not be in10805** [autocommit mode] when [sqlite3_snapshot_open(D,S,P)] is called. If there10806** is already a read transaction open on schema S, then the database handle10807** must have no active statements (SELECT statements that have been passed10808** to sqlite3_step() but not sqlite3_reset() or sqlite3_finalize()).10809** SQLITE_ERROR is returned if either of these conditions is violated, or10810** if schema S does not exist, or if the snapshot object is invalid.10811**10812** ^A call to sqlite3_snapshot_open() will fail to open if the specified10813** snapshot has been overwritten by a [checkpoint]. In this case10814** SQLITE_ERROR_SNAPSHOT is returned.10815**10816** If there is already a read transaction open when this function is10817** invoked, then the same read transaction remains open (on the same10818** database snapshot) if SQLITE_ERROR, SQLITE_BUSY or SQLITE_ERROR_SNAPSHOT10819** is returned. If another error code - for example SQLITE_PROTOCOL or an10820** SQLITE_IOERR error code - is returned, then the final state of the10821** read transaction is undefined. If SQLITE_OK is returned, then the10822** read transaction is now open on database snapshot P.10823**10824** ^(A call to [sqlite3_snapshot_open(D,S,P)] will fail if the10825** database connection D does not know that the database file for10826** schema S is in [WAL mode]. A database connection might not know10827** that the database file is in [WAL mode] if there has been no prior10828** I/O on that database connection, or if the database entered [WAL mode]10829** after the most recent I/O on the database connection.)^10830** (Hint: Run "[PRAGMA application_id]" against a newly opened10831** database connection in order to make it ready to use snapshots.)10832**10833** The [sqlite3_snapshot_open()] interface is only available when the10834** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.10835*/10836SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_open(10837sqlite3 *db,10838const char *zSchema,10839sqlite3_snapshot *pSnapshot10840);1084110842/*10843** CAPI3REF: Destroy a snapshot10844** DESTRUCTOR: sqlite3_snapshot10845**10846** ^The [sqlite3_snapshot_free(P)] interface destroys [sqlite3_snapshot] P.10847** The application must eventually free every [sqlite3_snapshot] object10848** using this routine to avoid a memory leak.10849**10850** The [sqlite3_snapshot_free()] interface is only available when the10851** [SQLITE_ENABLE_SNAPSHOT] compile-time option is used.10852*/10853SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_snapshot_free(sqlite3_snapshot*);1085410855/*10856** CAPI3REF: Compare the ages of two snapshot handles.10857** METHOD: sqlite3_snapshot10858**10859** The sqlite3_snapshot_cmp(P1, P2) interface is used to compare the ages10860** of two valid snapshot handles.10861**10862** If the two snapshot handles are not associated with the same database10863** file, the result of the comparison is undefined.10864**10865** Additionally, the result of the comparison is only valid if both of the10866** snapshot handles were obtained by calling sqlite3_snapshot_get() since the10867** last time the wal file was deleted. The wal file is deleted when the10868** database is changed back to rollback mode or when the number of database10869** clients drops to zero. If either snapshot handle was obtained before the10870** wal file was last deleted, the value returned by this function10871** is undefined.10872**10873** Otherwise, this API returns a negative value if P1 refers to an older10874** snapshot than P2, zero if the two handles refer to the same database10875** snapshot, and a positive value if P1 is a newer snapshot than P2.10876**10877** This interface is only available if SQLite is compiled with the10878** [SQLITE_ENABLE_SNAPSHOT] option.10879*/10880SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp(10881sqlite3_snapshot *p1,10882sqlite3_snapshot *p210883);1088410885/*10886** CAPI3REF: Recover snapshots from a wal file10887** METHOD: sqlite3_snapshot10888**10889** If a [WAL file] remains on disk after all database connections close10890** (either through the use of the [SQLITE_FCNTL_PERSIST_WAL] [file control]10891** or because the last process to have the database opened exited without10892** calling [sqlite3_close()]) and a new connection is subsequently opened10893** on that database and [WAL file], the [sqlite3_snapshot_open()] interface10894** will only be able to open the last transaction added to the WAL file10895** even though the WAL file contains other valid transactions.10896**10897** This function attempts to scan the WAL file associated with database zDb10898** of database handle db and make all valid snapshots available to10899** sqlite3_snapshot_open(). It is an error if there is already a read10900** transaction open on the database, or if the database is not a WAL mode10901** database.10902**10903** SQLITE_OK is returned if successful, or an SQLite error code otherwise.10904**10905** This interface is only available if SQLite is compiled with the10906** [SQLITE_ENABLE_SNAPSHOT] option.10907*/10908SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb);1090910910/*10911** CAPI3REF: Serialize a database10912**10913** The sqlite3_serialize(D,S,P,F) interface returns a pointer to10914** memory that is a serialization of the S database on10915** [database connection] D. If S is a NULL pointer, the main database is used.10916** If P is not a NULL pointer, then the size of the database in bytes10917** is written into *P.10918**10919** For an ordinary on-disk database file, the serialization is just a10920** copy of the disk file. For an in-memory database or a "TEMP" database,10921** the serialization is the same sequence of bytes which would be written10922** to disk if that database where backed up to disk.10923**10924** The usual case is that sqlite3_serialize() copies the serialization of10925** the database into memory obtained from [sqlite3_malloc64()] and returns10926** a pointer to that memory. The caller is responsible for freeing the10927** returned value to avoid a memory leak. However, if the F argument10928** contains the SQLITE_SERIALIZE_NOCOPY bit, then no memory allocations10929** are made, and the sqlite3_serialize() function will return a pointer10930** to the contiguous memory representation of the database that SQLite10931** is currently using for that database, or NULL if the no such contiguous10932** memory representation of the database exists. A contiguous memory10933** representation of the database will usually only exist if there has10934** been a prior call to [sqlite3_deserialize(D,S,...)] with the same10935** values of D and S.10936** The size of the database is written into *P even if the10937** SQLITE_SERIALIZE_NOCOPY bit is set but no contiguous copy10938** of the database exists.10939**10940** After the call, if the SQLITE_SERIALIZE_NOCOPY bit had been set,10941** the returned buffer content will remain accessible and unchanged10942** until either the next write operation on the connection or when10943** the connection is closed, and applications must not modify the10944** buffer. If the bit had been clear, the returned buffer will not10945** be accessed by SQLite after the call.10946**10947** A call to sqlite3_serialize(D,S,P,F) might return NULL even if the10948** SQLITE_SERIALIZE_NOCOPY bit is omitted from argument F if a memory10949** allocation error occurs.10950**10951** This interface is omitted if SQLite is compiled with the10952** [SQLITE_OMIT_DESERIALIZE] option.10953*/10954SQLITE_API unsigned char *sqlite3_serialize(10955sqlite3 *db, /* The database connection */10956const char *zSchema, /* Which DB to serialize. ex: "main", "temp", ... */10957sqlite3_int64 *piSize, /* Write size of the DB here, if not NULL */10958unsigned int mFlags /* Zero or more SQLITE_SERIALIZE_* flags */10959);1096010961/*10962** CAPI3REF: Flags for sqlite3_serialize10963**10964** Zero or more of the following constants can be OR-ed together for10965** the F argument to [sqlite3_serialize(D,S,P,F)].10966**10967** SQLITE_SERIALIZE_NOCOPY means that [sqlite3_serialize()] will return10968** a pointer to contiguous in-memory database that it is currently using,10969** without making a copy of the database. If SQLite is not currently using10970** a contiguous in-memory database, then this option causes10971** [sqlite3_serialize()] to return a NULL pointer. SQLite will only be10972** using a contiguous in-memory database if it has been initialized by a10973** prior call to [sqlite3_deserialize()].10974*/10975#define SQLITE_SERIALIZE_NOCOPY 0x001 /* Do no memory allocations */1097610977/*10978** CAPI3REF: Deserialize a database10979**10980** The sqlite3_deserialize(D,S,P,N,M,F) interface causes the10981** [database connection] D to disconnect from database S and then10982** reopen S as an in-memory database based on the serialization contained10983** in P. The serialized database P is N bytes in size. M is the size of10984** the buffer P, which might be larger than N. If M is larger than N, and10985** the SQLITE_DESERIALIZE_READONLY bit is not set in F, then SQLite is10986** permitted to add content to the in-memory database as long as the total10987** size does not exceed M bytes.10988**10989** If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will10990** invoke sqlite3_free() on the serialization buffer when the database10991** connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then10992** SQLite will try to increase the buffer size using sqlite3_realloc64()10993** if writes on the database cause it to grow larger than M bytes.10994**10995** Applications must not modify the buffer P or invalidate it before10996** the database connection D is closed.10997**10998** The sqlite3_deserialize() interface will fail with SQLITE_BUSY if the10999** database is currently in a read transaction or is involved in a backup11000** operation.11001**11002** It is not possible to deserialized into the TEMP database. If the11003** S argument to sqlite3_deserialize(D,S,P,N,M,F) is "temp" then the11004** function returns SQLITE_ERROR.11005**11006** The deserialized database should not be in [WAL mode]. If the database11007** is in WAL mode, then any attempt to use the database file will result11008** in an [SQLITE_CANTOPEN] error. The application can set the11009** [file format version numbers] (bytes 18 and 19) of the input database P11010** to 0x01 prior to invoking sqlite3_deserialize(D,S,P,N,M,F) to force the11011** database file into rollback mode and work around this limitation.11012**11013** If sqlite3_deserialize(D,S,P,N,M,F) fails for any reason and if the11014** SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then11015** [sqlite3_free()] is invoked on argument P prior to returning.11016**11017** This interface is omitted if SQLite is compiled with the11018** [SQLITE_OMIT_DESERIALIZE] option.11019*/11020SQLITE_API int sqlite3_deserialize(11021sqlite3 *db, /* The database connection */11022const char *zSchema, /* Which DB to reopen with the deserialization */11023unsigned char *pData, /* The serialized database content */11024sqlite3_int64 szDb, /* Number bytes in the deserialization */11025sqlite3_int64 szBuf, /* Total size of buffer pData[] */11026unsigned mFlags /* Zero or more SQLITE_DESERIALIZE_* flags */11027);1102811029/*11030** CAPI3REF: Flags for sqlite3_deserialize()11031**11032** The following are allowed values for 6th argument (the F argument) to11033** the [sqlite3_deserialize(D,S,P,N,M,F)] interface.11034**11035** The SQLITE_DESERIALIZE_FREEONCLOSE means that the database serialization11036** in the P argument is held in memory obtained from [sqlite3_malloc64()]11037** and that SQLite should take ownership of this memory and automatically11038** free it when it has finished using it. Without this flag, the caller11039** is responsible for freeing any dynamically allocated memory.11040**11041** The SQLITE_DESERIALIZE_RESIZEABLE flag means that SQLite is allowed to11042** grow the size of the database using calls to [sqlite3_realloc64()]. This11043** flag should only be used if SQLITE_DESERIALIZE_FREEONCLOSE is also used.11044** Without this flag, the deserialized database cannot increase in size beyond11045** the number of bytes specified by the M parameter.11046**11047** The SQLITE_DESERIALIZE_READONLY flag means that the deserialized database11048** should be treated as read-only.11049*/11050#define SQLITE_DESERIALIZE_FREEONCLOSE 1 /* Call sqlite3_free() on close */11051#define SQLITE_DESERIALIZE_RESIZEABLE 2 /* Resize using sqlite3_realloc64() */11052#define SQLITE_DESERIALIZE_READONLY 4 /* Database is read-only */1105311054/*11055** Undo the hack that converts floating point types to integer for11056** builds on processors without floating point support.11057*/11058#ifdef SQLITE_OMIT_FLOATING_POINT11059# undef double11060#endif1106111062#if defined(__wasi__)11063# undef SQLITE_WASI11064# define SQLITE_WASI 111065# ifndef SQLITE_OMIT_LOAD_EXTENSION11066# define SQLITE_OMIT_LOAD_EXTENSION11067# endif11068# ifndef SQLITE_THREADSAFE11069# define SQLITE_THREADSAFE 011070# endif11071#endif1107211073#ifdef __cplusplus11074} /* End of the 'extern "C"' block */11075#endif11076/* #endif for SQLITE3_H will be added by mksqlite3.tcl */1107711078/******** Begin file sqlite3rtree.h *********/11079/*11080** 2010 August 3011081**11082** The author disclaims copyright to this source code. In place of11083** a legal notice, here is a blessing:11084**11085** May you do good and not evil.11086** May you find forgiveness for yourself and forgive others.11087** May you share freely, never taking more than you give.11088**11089*************************************************************************11090*/1109111092#ifndef _SQLITE3RTREE_H_11093#define _SQLITE3RTREE_H_110941109511096#ifdef __cplusplus11097extern "C" {11098#endif1109911100typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry;11101typedef struct sqlite3_rtree_query_info sqlite3_rtree_query_info;1110211103/* The double-precision datatype used by RTree depends on the11104** SQLITE_RTREE_INT_ONLY compile-time option.11105*/11106#ifdef SQLITE_RTREE_INT_ONLY11107typedef sqlite3_int64 sqlite3_rtree_dbl;11108#else11109typedef double sqlite3_rtree_dbl;11110#endif1111111112/*11113** Register a geometry callback named zGeom that can be used as part of an11114** R-Tree geometry query as follows:11115**11116** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...)11117*/11118SQLITE_API int sqlite3_rtree_geometry_callback(11119sqlite3 *db,11120const char *zGeom,11121int (*xGeom)(sqlite3_rtree_geometry*, int, sqlite3_rtree_dbl*,int*),11122void *pContext11123);111241112511126/*11127** A pointer to a structure of the following type is passed as the first11128** argument to callbacks registered using rtree_geometry_callback().11129*/11130struct sqlite3_rtree_geometry {11131void *pContext; /* Copy of pContext passed to s_r_g_c() */11132int nParam; /* Size of array aParam[] */11133sqlite3_rtree_dbl *aParam; /* Parameters passed to SQL geom function */11134void *pUser; /* Callback implementation user data */11135void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */11136};1113711138/*11139** Register a 2nd-generation geometry callback named zScore that can be11140** used as part of an R-Tree geometry query as follows:11141**11142** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zQueryFunc(... params ...)11143*/11144SQLITE_API int sqlite3_rtree_query_callback(11145sqlite3 *db,11146const char *zQueryFunc,11147int (*xQueryFunc)(sqlite3_rtree_query_info*),11148void *pContext,11149void (*xDestructor)(void*)11150);111511115211153/*11154** A pointer to a structure of the following type is passed as the11155** argument to scored geometry callback registered using11156** sqlite3_rtree_query_callback().11157**11158** Note that the first 5 fields of this structure are identical to11159** sqlite3_rtree_geometry. This structure is a subclass of11160** sqlite3_rtree_geometry.11161*/11162struct sqlite3_rtree_query_info {11163void *pContext; /* pContext from when function registered */11164int nParam; /* Number of function parameters */11165sqlite3_rtree_dbl *aParam; /* value of function parameters */11166void *pUser; /* callback can use this, if desired */11167void (*xDelUser)(void*); /* function to free pUser */11168sqlite3_rtree_dbl *aCoord; /* Coordinates of node or entry to check */11169unsigned int *anQueue; /* Number of pending entries in the queue */11170int nCoord; /* Number of coordinates */11171int iLevel; /* Level of current node or entry */11172int mxLevel; /* The largest iLevel value in the tree */11173sqlite3_int64 iRowid; /* Rowid for current entry */11174sqlite3_rtree_dbl rParentScore; /* Score of parent node */11175int eParentWithin; /* Visibility of parent node */11176int eWithin; /* OUT: Visibility */11177sqlite3_rtree_dbl rScore; /* OUT: Write the score here */11178/* The following fields are only available in 3.8.11 and later */11179sqlite3_value **apSqlParam; /* Original SQL values of parameters */11180};1118111182/*11183** Allowed values for sqlite3_rtree_query.eWithin and .eParentWithin.11184*/11185#define NOT_WITHIN 0 /* Object completely outside of query region */11186#define PARTLY_WITHIN 1 /* Object partially overlaps query region */11187#define FULLY_WITHIN 2 /* Object fully contained within query region */111881118911190#ifdef __cplusplus11191} /* end of the 'extern "C"' block */11192#endif1119311194#endif /* ifndef _SQLITE3RTREE_H_ */1119511196/******** End of sqlite3rtree.h *********/11197/******** Begin file sqlite3session.h *********/1119811199#if !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION)11200#define __SQLITESESSION_H_ 11120111202/*11203** Make sure we can call this stuff from C++.11204*/11205#ifdef __cplusplus11206extern "C" {11207#endif112081120911210/*11211** CAPI3REF: Session Object Handle11212**11213** An instance of this object is a [session] that can be used to11214** record changes to a database.11215*/11216typedef struct sqlite3_session sqlite3_session;1121711218/*11219** CAPI3REF: Changeset Iterator Handle11220**11221** An instance of this object acts as a cursor for iterating11222** over the elements of a [changeset] or [patchset].11223*/11224typedef struct sqlite3_changeset_iter sqlite3_changeset_iter;1122511226/*11227** CAPI3REF: Create A New Session Object11228** CONSTRUCTOR: sqlite3_session11229**11230** Create a new session object attached to database handle db. If successful,11231** a pointer to the new object is written to *ppSession and SQLITE_OK is11232** returned. If an error occurs, *ppSession is set to NULL and an SQLite11233** error code (e.g. SQLITE_NOMEM) is returned.11234**11235** It is possible to create multiple session objects attached to a single11236** database handle.11237**11238** Session objects created using this function should be deleted using the11239** [sqlite3session_delete()] function before the database handle that they11240** are attached to is itself closed. If the database handle is closed before11241** the session object is deleted, then the results of calling any session11242** module function, including [sqlite3session_delete()] on the session object11243** are undefined.11244**11245** Because the session module uses the [sqlite3_preupdate_hook()] API, it11246** is not possible for an application to register a pre-update hook on a11247** database handle that has one or more session objects attached. Nor is11248** it possible to create a session object attached to a database handle for11249** which a pre-update hook is already defined. The results of attempting11250** either of these things are undefined.11251**11252** The session object will be used to create changesets for tables in11253** database zDb, where zDb is either "main", or "temp", or the name of an11254** attached database. It is not an error if database zDb is not attached11255** to the database when the session object is created.11256*/11257SQLITE_API int sqlite3session_create(11258sqlite3 *db, /* Database handle */11259const char *zDb, /* Name of db (e.g. "main") */11260sqlite3_session **ppSession /* OUT: New session object */11261);1126211263/*11264** CAPI3REF: Delete A Session Object11265** DESTRUCTOR: sqlite3_session11266**11267** Delete a session object previously allocated using11268** [sqlite3session_create()]. Once a session object has been deleted, the11269** results of attempting to use pSession with any other session module11270** function are undefined.11271**11272** Session objects must be deleted before the database handle to which they11273** are attached is closed. Refer to the documentation for11274** [sqlite3session_create()] for details.11275*/11276SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);1127711278/*11279** CAPI3REF: Configure a Session Object11280** METHOD: sqlite3_session11281**11282** This method is used to configure a session object after it has been11283** created. At present the only valid values for the second parameter are11284** [SQLITE_SESSION_OBJCONFIG_SIZE] and [SQLITE_SESSION_OBJCONFIG_ROWID].11285**11286*/11287SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);1128811289/*11290** CAPI3REF: Options for sqlite3session_object_config11291**11292** The following values may passed as the the 2nd parameter to11293** sqlite3session_object_config().11294**11295** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>11296** This option is used to set, clear or query the flag that enables11297** the [sqlite3session_changeset_size()] API. Because it imposes some11298** computational overhead, this API is disabled by default. Argument11299** pArg must point to a value of type (int). If the value is initially11300** 0, then the sqlite3session_changeset_size() API is disabled. If it11301** is greater than 0, then the same API is enabled. Or, if the initial11302** value is less than zero, no change is made. In all cases the (int)11303** variable is set to 1 if the sqlite3session_changeset_size() API is11304** enabled following the current call, or 0 otherwise.11305**11306** It is an error (SQLITE_MISUSE) to attempt to modify this setting after11307** the first table has been attached to the session object.11308**11309** <dt>SQLITE_SESSION_OBJCONFIG_ROWID <dd>11310** This option is used to set, clear or query the flag that enables11311** collection of data for tables with no explicit PRIMARY KEY.11312**11313** Normally, tables with no explicit PRIMARY KEY are simply ignored11314** by the sessions module. However, if this flag is set, it behaves11315** as if such tables have a column "_rowid_ INTEGER PRIMARY KEY" inserted11316** as their leftmost columns.11317**11318** It is an error (SQLITE_MISUSE) to attempt to modify this setting after11319** the first table has been attached to the session object.11320*/11321#define SQLITE_SESSION_OBJCONFIG_SIZE 111322#define SQLITE_SESSION_OBJCONFIG_ROWID 21132311324/*11325** CAPI3REF: Enable Or Disable A Session Object11326** METHOD: sqlite3_session11327**11328** Enable or disable the recording of changes by a session object. When11329** enabled, a session object records changes made to the database. When11330** disabled - it does not. A newly created session object is enabled.11331** Refer to the documentation for [sqlite3session_changeset()] for further11332** details regarding how enabling and disabling a session object affects11333** the eventual changesets.11334**11335** Passing zero to this function disables the session. Passing a value11336** greater than zero enables it. Passing a value less than zero is a11337** no-op, and may be used to query the current state of the session.11338**11339** The return value indicates the final state of the session object: 0 if11340** the session is disabled, or 1 if it is enabled.11341*/11342SQLITE_API int sqlite3session_enable(sqlite3_session *pSession, int bEnable);1134311344/*11345** CAPI3REF: Set Or Clear the Indirect Change Flag11346** METHOD: sqlite3_session11347**11348** Each change recorded by a session object is marked as either direct or11349** indirect. A change is marked as indirect if either:11350**11351** <ul>11352** <li> The session object "indirect" flag is set when the change is11353** made, or11354** <li> The change is made by an SQL trigger or foreign key action11355** instead of directly as a result of a users SQL statement.11356** </ul>11357**11358** If a single row is affected by more than one operation within a session,11359** then the change is considered indirect if all operations meet the criteria11360** for an indirect change above, or direct otherwise.11361**11362** This function is used to set, clear or query the session object indirect11363** flag. If the second argument passed to this function is zero, then the11364** indirect flag is cleared. If it is greater than zero, the indirect flag11365** is set. Passing a value less than zero does not modify the current value11366** of the indirect flag, and may be used to query the current state of the11367** indirect flag for the specified session object.11368**11369** The return value indicates the final state of the indirect flag: 0 if11370** it is clear, or 1 if it is set.11371*/11372SQLITE_API int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);1137311374/*11375** CAPI3REF: Attach A Table To A Session Object11376** METHOD: sqlite3_session11377**11378** If argument zTab is not NULL, then it is the name of a table to attach11379** to the session object passed as the first argument. All subsequent changes11380** made to the table while the session object is enabled will be recorded. See11381** documentation for [sqlite3session_changeset()] for further details.11382**11383** Or, if argument zTab is NULL, then changes are recorded for all tables11384** in the database. If additional tables are added to the database (by11385** executing "CREATE TABLE" statements) after this call is made, changes for11386** the new tables are also recorded.11387**11388** Changes can only be recorded for tables that have a PRIMARY KEY explicitly11389** defined as part of their CREATE TABLE statement. It does not matter if the11390** PRIMARY KEY is an "INTEGER PRIMARY KEY" (rowid alias) or not. The PRIMARY11391** KEY may consist of a single column, or may be a composite key.11392**11393** It is not an error if the named table does not exist in the database. Nor11394** is it an error if the named table does not have a PRIMARY KEY. However,11395** no changes will be recorded in either of these scenarios.11396**11397** Changes are not recorded for individual rows that have NULL values stored11398** in one or more of their PRIMARY KEY columns.11399**11400** SQLITE_OK is returned if the call completes without error. Or, if an error11401** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.11402**11403** <h3>Special sqlite_stat1 Handling</h3>11404**11405** As of SQLite version 3.22.0, the "sqlite_stat1" table is an exception to11406** some of the rules above. In SQLite, the schema of sqlite_stat1 is:11407** <pre>11408** CREATE TABLE sqlite_stat1(tbl,idx,stat)11409** </pre>11410**11411** Even though sqlite_stat1 does not have a PRIMARY KEY, changes are11412** recorded for it as if the PRIMARY KEY is (tbl,idx). Additionally, changes11413** are recorded for rows for which (idx IS NULL) is true. However, for such11414** rows a zero-length blob (SQL value X'') is stored in the changeset or11415** patchset instead of a NULL value. This allows such changesets to be11416** manipulated by legacy implementations of sqlite3changeset_invert(),11417** concat() and similar.11418**11419** The sqlite3changeset_apply() function automatically converts the11420** zero-length blob back to a NULL value when updating the sqlite_stat111421** table. However, if the application calls sqlite3changeset_new(),11422** sqlite3changeset_old() or sqlite3changeset_conflict on a changeset11423** iterator directly (including on a changeset iterator passed to a11424** conflict-handler callback) then the X'' value is returned. The application11425** must translate X'' to NULL itself if required.11426**11427** Legacy (older than 3.22.0) versions of the sessions module cannot capture11428** changes made to the sqlite_stat1 table. Legacy versions of the11429** sqlite3changeset_apply() function silently ignore any modifications to the11430** sqlite_stat1 table that are part of a changeset or patchset.11431*/11432SQLITE_API int sqlite3session_attach(11433sqlite3_session *pSession, /* Session object */11434const char *zTab /* Table name */11435);1143611437/*11438** CAPI3REF: Set a table filter on a Session Object.11439** METHOD: sqlite3_session11440**11441** The second argument (xFilter) is the "filter callback". For changes to rows11442** in tables that are not attached to the Session object, the filter is called11443** to determine whether changes to the table's rows should be tracked or not.11444** If xFilter returns 0, changes are not tracked. Note that once a table is11445** attached, xFilter will not be called again.11446*/11447SQLITE_API void sqlite3session_table_filter(11448sqlite3_session *pSession, /* Session object */11449int(*xFilter)(11450void *pCtx, /* Copy of third arg to _filter_table() */11451const char *zTab /* Table name */11452),11453void *pCtx /* First argument passed to xFilter */11454);1145511456/*11457** CAPI3REF: Generate A Changeset From A Session Object11458** METHOD: sqlite3_session11459**11460** Obtain a changeset containing changes to the tables attached to the11461** session object passed as the first argument. If successful,11462** set *ppChangeset to point to a buffer containing the changeset11463** and *pnChangeset to the size of the changeset in bytes before returning11464** SQLITE_OK. If an error occurs, set both *ppChangeset and *pnChangeset to11465** zero and return an SQLite error code.11466**11467** A changeset consists of zero or more INSERT, UPDATE and/or DELETE changes,11468** each representing a change to a single row of an attached table. An INSERT11469** change contains the values of each field of a new database row. A DELETE11470** contains the original values of each field of a deleted database row. An11471** UPDATE change contains the original values of each field of an updated11472** database row along with the updated values for each updated non-primary-key11473** column. It is not possible for an UPDATE change to represent a change that11474** modifies the values of primary key columns. If such a change is made, it11475** is represented in a changeset as a DELETE followed by an INSERT.11476**11477** Changes are not recorded for rows that have NULL values stored in one or11478** more of their PRIMARY KEY columns. If such a row is inserted or deleted,11479** no corresponding change is present in the changesets returned by this11480** function. If an existing row with one or more NULL values stored in11481** PRIMARY KEY columns is updated so that all PRIMARY KEY columns are non-NULL,11482** only an INSERT is appears in the changeset. Similarly, if an existing row11483** with non-NULL PRIMARY KEY values is updated so that one or more of its11484** PRIMARY KEY columns are set to NULL, the resulting changeset contains a11485** DELETE change only.11486**11487** The contents of a changeset may be traversed using an iterator created11488** using the [sqlite3changeset_start()] API. A changeset may be applied to11489** a database with a compatible schema using the [sqlite3changeset_apply()]11490** API.11491**11492** Within a changeset generated by this function, all changes related to a11493** single table are grouped together. In other words, when iterating through11494** a changeset or when applying a changeset to a database, all changes related11495** to a single table are processed before moving on to the next table. Tables11496** are sorted in the same order in which they were attached (or auto-attached)11497** to the sqlite3_session object. The order in which the changes related to11498** a single table are stored is undefined.11499**11500** Following a successful call to this function, it is the responsibility of11501** the caller to eventually free the buffer that *ppChangeset points to using11502** [sqlite3_free()].11503**11504** <h3>Changeset Generation</h3>11505**11506** Once a table has been attached to a session object, the session object11507** records the primary key values of all new rows inserted into the table.11508** It also records the original primary key and other column values of any11509** deleted or updated rows. For each unique primary key value, data is only11510** recorded once - the first time a row with said primary key is inserted,11511** updated or deleted in the lifetime of the session.11512**11513** There is one exception to the previous paragraph: when a row is inserted,11514** updated or deleted, if one or more of its primary key columns contain a11515** NULL value, no record of the change is made.11516**11517** The session object therefore accumulates two types of records - those11518** that consist of primary key values only (created when the user inserts11519** a new record) and those that consist of the primary key values and the11520** original values of other table columns (created when the users deletes11521** or updates a record).11522**11523** When this function is called, the requested changeset is created using11524** both the accumulated records and the current contents of the database11525** file. Specifically:11526**11527** <ul>11528** <li> For each record generated by an insert, the database is queried11529** for a row with a matching primary key. If one is found, an INSERT11530** change is added to the changeset. If no such row is found, no change11531** is added to the changeset.11532**11533** <li> For each record generated by an update or delete, the database is11534** queried for a row with a matching primary key. If such a row is11535** found and one or more of the non-primary key fields have been11536** modified from their original values, an UPDATE change is added to11537** the changeset. Or, if no such row is found in the table, a DELETE11538** change is added to the changeset. If there is a row with a matching11539** primary key in the database, but all fields contain their original11540** values, no change is added to the changeset.11541** </ul>11542**11543** This means, amongst other things, that if a row is inserted and then later11544** deleted while a session object is active, neither the insert nor the delete11545** will be present in the changeset. Or if a row is deleted and then later a11546** row with the same primary key values inserted while a session object is11547** active, the resulting changeset will contain an UPDATE change instead of11548** a DELETE and an INSERT.11549**11550** When a session object is disabled (see the [sqlite3session_enable()] API),11551** it does not accumulate records when rows are inserted, updated or deleted.11552** This may appear to have some counter-intuitive effects if a single row11553** is written to more than once during a session. For example, if a row11554** is inserted while a session object is enabled, then later deleted while11555** the same session object is disabled, no INSERT record will appear in the11556** changeset, even though the delete took place while the session was disabled.11557** Or, if one field of a row is updated while a session is enabled, and11558** then another field of the same row is updated while the session is disabled,11559** the resulting changeset will contain an UPDATE change that updates both11560** fields.11561*/11562SQLITE_API int sqlite3session_changeset(11563sqlite3_session *pSession, /* Session object */11564int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */11565void **ppChangeset /* OUT: Buffer containing changeset */11566);1156711568/*11569** CAPI3REF: Return An Upper-limit For The Size Of The Changeset11570** METHOD: sqlite3_session11571**11572** By default, this function always returns 0. For it to return11573** a useful result, the sqlite3_session object must have been configured11574** to enable this API using sqlite3session_object_config() with the11575** SQLITE_SESSION_OBJCONFIG_SIZE verb.11576**11577** When enabled, this function returns an upper limit, in bytes, for the size11578** of the changeset that might be produced if sqlite3session_changeset() were11579** called. The final changeset size might be equal to or smaller than the11580** size in bytes returned by this function.11581*/11582SQLITE_API sqlite3_int64 sqlite3session_changeset_size(sqlite3_session *pSession);1158311584/*11585** CAPI3REF: Load The Difference Between Tables Into A Session11586** METHOD: sqlite3_session11587**11588** If it is not already attached to the session object passed as the first11589** argument, this function attaches table zTbl in the same manner as the11590** [sqlite3session_attach()] function. If zTbl does not exist, or if it11591** does not have a primary key, this function is a no-op (but does not return11592** an error).11593**11594** Argument zFromDb must be the name of a database ("main", "temp" etc.)11595** attached to the same database handle as the session object that contains11596** a table compatible with the table attached to the session by this function.11597** A table is considered compatible if it:11598**11599** <ul>11600** <li> Has the same name,11601** <li> Has the same set of columns declared in the same order, and11602** <li> Has the same PRIMARY KEY definition.11603** </ul>11604**11605** If the tables are not compatible, SQLITE_SCHEMA is returned. If the tables11606** are compatible but do not have any PRIMARY KEY columns, it is not an error11607** but no changes are added to the session object. As with other session11608** APIs, tables without PRIMARY KEYs are simply ignored.11609**11610** This function adds a set of changes to the session object that could be11611** used to update the table in database zFrom (call this the "from-table")11612** so that its content is the same as the table attached to the session11613** object (call this the "to-table"). Specifically:11614**11615** <ul>11616** <li> For each row (primary key) that exists in the to-table but not in11617** the from-table, an INSERT record is added to the session object.11618**11619** <li> For each row (primary key) that exists in the to-table but not in11620** the from-table, a DELETE record is added to the session object.11621**11622** <li> For each row (primary key) that exists in both tables, but features11623** different non-PK values in each, an UPDATE record is added to the11624** session.11625** </ul>11626**11627** To clarify, if this function is called and then a changeset constructed11628** using [sqlite3session_changeset()], then after applying that changeset to11629** database zFrom the contents of the two compatible tables would be11630** identical.11631**11632** Unless the call to this function is a no-op as described above, it is an11633** error if database zFrom does not exist or does not contain the required11634** compatible table.11635**11636** If the operation is successful, SQLITE_OK is returned. Otherwise, an SQLite11637** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg11638** may be set to point to a buffer containing an English language error11639** message. It is the responsibility of the caller to free this buffer using11640** sqlite3_free().11641*/11642SQLITE_API int sqlite3session_diff(11643sqlite3_session *pSession,11644const char *zFromDb,11645const char *zTbl,11646char **pzErrMsg11647);116481164911650/*11651** CAPI3REF: Generate A Patchset From A Session Object11652** METHOD: sqlite3_session11653**11654** The differences between a patchset and a changeset are that:11655**11656** <ul>11657** <li> DELETE records consist of the primary key fields only. The11658** original values of other fields are omitted.11659** <li> The original values of any modified fields are omitted from11660** UPDATE records.11661** </ul>11662**11663** A patchset blob may be used with up to date versions of all11664** sqlite3changeset_xxx API functions except for sqlite3changeset_invert(),11665** which returns SQLITE_CORRUPT if it is passed a patchset. Similarly,11666** attempting to use a patchset blob with old versions of the11667** sqlite3changeset_xxx APIs also provokes an SQLITE_CORRUPT error.11668**11669** Because the non-primary key "old.*" fields are omitted, no11670** SQLITE_CHANGESET_DATA conflicts can be detected or reported if a patchset11671** is passed to the sqlite3changeset_apply() API. Other conflict types work11672** in the same way as for changesets.11673**11674** Changes within a patchset are ordered in the same way as for changesets11675** generated by the sqlite3session_changeset() function (i.e. all changes for11676** a single table are grouped together, tables appear in the order in which11677** they were attached to the session object).11678*/11679SQLITE_API int sqlite3session_patchset(11680sqlite3_session *pSession, /* Session object */11681int *pnPatchset, /* OUT: Size of buffer at *ppPatchset */11682void **ppPatchset /* OUT: Buffer containing patchset */11683);1168411685/*11686** CAPI3REF: Test if a changeset has recorded any changes.11687**11688** Return non-zero if no changes to attached tables have been recorded by11689** the session object passed as the first argument. Otherwise, if one or11690** more changes have been recorded, return zero.11691**11692** Even if this function returns zero, it is possible that calling11693** [sqlite3session_changeset()] on the session handle may still return a11694** changeset that contains no changes. This can happen when a row in11695** an attached table is modified and then later on the original values11696** are restored. However, if this function returns non-zero, then it is11697** guaranteed that a call to sqlite3session_changeset() will return a11698** changeset containing zero changes.11699*/11700SQLITE_API int sqlite3session_isempty(sqlite3_session *pSession);1170111702/*11703** CAPI3REF: Query for the amount of heap memory used by a session object.11704**11705** This API returns the total amount of heap memory in bytes currently11706** used by the session object passed as the only argument.11707*/11708SQLITE_API sqlite3_int64 sqlite3session_memory_used(sqlite3_session *pSession);1170911710/*11711** CAPI3REF: Create An Iterator To Traverse A Changeset11712** CONSTRUCTOR: sqlite3_changeset_iter11713**11714** Create an iterator used to iterate through the contents of a changeset.11715** If successful, *pp is set to point to the iterator handle and SQLITE_OK11716** is returned. Otherwise, if an error occurs, *pp is set to zero and an11717** SQLite error code is returned.11718**11719** The following functions can be used to advance and query a changeset11720** iterator created by this function:11721**11722** <ul>11723** <li> [sqlite3changeset_next()]11724** <li> [sqlite3changeset_op()]11725** <li> [sqlite3changeset_new()]11726** <li> [sqlite3changeset_old()]11727** </ul>11728**11729** It is the responsibility of the caller to eventually destroy the iterator11730** by passing it to [sqlite3changeset_finalize()]. The buffer containing the11731** changeset (pChangeset) must remain valid until after the iterator is11732** destroyed.11733**11734** Assuming the changeset blob was created by one of the11735** [sqlite3session_changeset()], [sqlite3changeset_concat()] or11736** [sqlite3changeset_invert()] functions, all changes within the changeset11737** that apply to a single table are grouped together. This means that when11738** an application iterates through a changeset using an iterator created by11739** this function, all changes that relate to a single table are visited11740** consecutively. There is no chance that the iterator will visit a change11741** the applies to table X, then one for table Y, and then later on visit11742** another change for table X.11743**11744** The behavior of sqlite3changeset_start_v2() and its streaming equivalent11745** may be modified by passing a combination of11746** [SQLITE_CHANGESETSTART_INVERT | supported flags] as the 4th parameter.11747**11748** Note that the sqlite3changeset_start_v2() API is still <b>experimental</b>11749** and therefore subject to change.11750*/11751SQLITE_API int sqlite3changeset_start(11752sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */11753int nChangeset, /* Size of changeset blob in bytes */11754void *pChangeset /* Pointer to blob containing changeset */11755);11756SQLITE_API int sqlite3changeset_start_v2(11757sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */11758int nChangeset, /* Size of changeset blob in bytes */11759void *pChangeset, /* Pointer to blob containing changeset */11760int flags /* SESSION_CHANGESETSTART_* flags */11761);1176211763/*11764** CAPI3REF: Flags for sqlite3changeset_start_v211765**11766** The following flags may passed via the 4th parameter to11767** [sqlite3changeset_start_v2] and [sqlite3changeset_start_v2_strm]:11768**11769** <dt>SQLITE_CHANGESETSTART_INVERT <dd>11770** Invert the changeset while iterating through it. This is equivalent to11771** inverting a changeset using sqlite3changeset_invert() before applying it.11772** It is an error to specify this flag with a patchset.11773*/11774#define SQLITE_CHANGESETSTART_INVERT 0x0002117751177611777/*11778** CAPI3REF: Advance A Changeset Iterator11779** METHOD: sqlite3_changeset_iter11780**11781** This function may only be used with iterators created by the function11782** [sqlite3changeset_start()]. If it is called on an iterator passed to11783** a conflict-handler callback by [sqlite3changeset_apply()], SQLITE_MISUSE11784** is returned and the call has no effect.11785**11786** Immediately after an iterator is created by sqlite3changeset_start(), it11787** does not point to any change in the changeset. Assuming the changeset11788** is not empty, the first call to this function advances the iterator to11789** point to the first change in the changeset. Each subsequent call advances11790** the iterator to point to the next change in the changeset (if any). If11791** no error occurs and the iterator points to a valid change after a call11792** to sqlite3changeset_next() has advanced it, SQLITE_ROW is returned.11793** Otherwise, if all changes in the changeset have already been visited,11794** SQLITE_DONE is returned.11795**11796** If an error occurs, an SQLite error code is returned. Possible error11797** codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or11798** SQLITE_NOMEM.11799*/11800SQLITE_API int sqlite3changeset_next(sqlite3_changeset_iter *pIter);1180111802/*11803** CAPI3REF: Obtain The Current Operation From A Changeset Iterator11804** METHOD: sqlite3_changeset_iter11805**11806** The pIter argument passed to this function may either be an iterator11807** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator11808** created by [sqlite3changeset_start()]. In the latter case, the most recent11809** call to [sqlite3changeset_next()] must have returned [SQLITE_ROW]. If this11810** is not the case, this function returns [SQLITE_MISUSE].11811**11812** Arguments pOp, pnCol and pzTab may not be NULL. Upon return, three11813** outputs are set through these pointers:11814**11815** *pOp is set to one of [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE],11816** depending on the type of change that the iterator currently points to;11817**11818** *pnCol is set to the number of columns in the table affected by the change; and11819**11820** *pzTab is set to point to a nul-terminated utf-8 encoded string containing11821** the name of the table affected by the current change. The buffer remains11822** valid until either sqlite3changeset_next() is called on the iterator11823** or until the conflict-handler function returns.11824**11825** If pbIndirect is not NULL, then *pbIndirect is set to true (1) if the change11826** is an indirect change, or false (0) otherwise. See the documentation for11827** [sqlite3session_indirect()] for a description of direct and indirect11828** changes.11829**11830** If no error occurs, SQLITE_OK is returned. If an error does occur, an11831** SQLite error code is returned. The values of the output variables may not11832** be trusted in this case.11833*/11834SQLITE_API int sqlite3changeset_op(11835sqlite3_changeset_iter *pIter, /* Iterator object */11836const char **pzTab, /* OUT: Pointer to table name */11837int *pnCol, /* OUT: Number of columns in table */11838int *pOp, /* OUT: SQLITE_INSERT, DELETE or UPDATE */11839int *pbIndirect /* OUT: True for an 'indirect' change */11840);1184111842/*11843** CAPI3REF: Obtain The Primary Key Definition Of A Table11844** METHOD: sqlite3_changeset_iter11845**11846** For each modified table, a changeset includes the following:11847**11848** <ul>11849** <li> The number of columns in the table, and11850** <li> Which of those columns make up the tables PRIMARY KEY.11851** </ul>11852**11853** This function is used to find which columns comprise the PRIMARY KEY of11854** the table modified by the change that iterator pIter currently points to.11855** If successful, *pabPK is set to point to an array of nCol entries, where11856** nCol is the number of columns in the table. Elements of *pabPK are set to11857** 0x01 if the corresponding column is part of the tables primary key, or11858** 0x00 if it is not.11859**11860** If argument pnCol is not NULL, then *pnCol is set to the number of columns11861** in the table.11862**11863** If this function is called when the iterator does not point to a valid11864** entry, SQLITE_MISUSE is returned and the output variables zeroed. Otherwise,11865** SQLITE_OK is returned and the output variables populated as described11866** above.11867*/11868SQLITE_API int sqlite3changeset_pk(11869sqlite3_changeset_iter *pIter, /* Iterator object */11870unsigned char **pabPK, /* OUT: Array of boolean - true for PK cols */11871int *pnCol /* OUT: Number of entries in output array */11872);1187311874/*11875** CAPI3REF: Obtain old.* Values From A Changeset Iterator11876** METHOD: sqlite3_changeset_iter11877**11878** The pIter argument passed to this function may either be an iterator11879** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator11880** created by [sqlite3changeset_start()]. In the latter case, the most recent11881** call to [sqlite3changeset_next()] must have returned SQLITE_ROW.11882** Furthermore, it may only be called if the type of change that the iterator11883** currently points to is either [SQLITE_DELETE] or [SQLITE_UPDATE]. Otherwise,11884** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL.11885**11886** Argument iVal must be greater than or equal to 0, and less than the number11887** of columns in the table affected by the current change. Otherwise,11888** [SQLITE_RANGE] is returned and *ppValue is set to NULL.11889**11890** If successful, this function sets *ppValue to point to a protected11891** sqlite3_value object containing the iVal'th value from the vector of11892** original row values stored as part of the UPDATE or DELETE change and11893** returns SQLITE_OK. The name of the function comes from the fact that this11894** is similar to the "old.*" columns available to update or delete triggers.11895**11896** If some other error occurs (e.g. an OOM condition), an SQLite error code11897** is returned and *ppValue is set to NULL.11898*/11899SQLITE_API int sqlite3changeset_old(11900sqlite3_changeset_iter *pIter, /* Changeset iterator */11901int iVal, /* Column number */11902sqlite3_value **ppValue /* OUT: Old value (or NULL pointer) */11903);1190411905/*11906** CAPI3REF: Obtain new.* Values From A Changeset Iterator11907** METHOD: sqlite3_changeset_iter11908**11909** The pIter argument passed to this function may either be an iterator11910** passed to a conflict-handler by [sqlite3changeset_apply()], or an iterator11911** created by [sqlite3changeset_start()]. In the latter case, the most recent11912** call to [sqlite3changeset_next()] must have returned SQLITE_ROW.11913** Furthermore, it may only be called if the type of change that the iterator11914** currently points to is either [SQLITE_UPDATE] or [SQLITE_INSERT]. Otherwise,11915** this function returns [SQLITE_MISUSE] and sets *ppValue to NULL.11916**11917** Argument iVal must be greater than or equal to 0, and less than the number11918** of columns in the table affected by the current change. Otherwise,11919** [SQLITE_RANGE] is returned and *ppValue is set to NULL.11920**11921** If successful, this function sets *ppValue to point to a protected11922** sqlite3_value object containing the iVal'th value from the vector of11923** new row values stored as part of the UPDATE or INSERT change and11924** returns SQLITE_OK. If the change is an UPDATE and does not include11925** a new value for the requested column, *ppValue is set to NULL and11926** SQLITE_OK returned. The name of the function comes from the fact that11927** this is similar to the "new.*" columns available to update or delete11928** triggers.11929**11930** If some other error occurs (e.g. an OOM condition), an SQLite error code11931** is returned and *ppValue is set to NULL.11932*/11933SQLITE_API int sqlite3changeset_new(11934sqlite3_changeset_iter *pIter, /* Changeset iterator */11935int iVal, /* Column number */11936sqlite3_value **ppValue /* OUT: New value (or NULL pointer) */11937);1193811939/*11940** CAPI3REF: Obtain Conflicting Row Values From A Changeset Iterator11941** METHOD: sqlite3_changeset_iter11942**11943** This function should only be used with iterator objects passed to a11944** conflict-handler callback by [sqlite3changeset_apply()] with either11945** [SQLITE_CHANGESET_DATA] or [SQLITE_CHANGESET_CONFLICT]. If this function11946** is called on any other iterator, [SQLITE_MISUSE] is returned and *ppValue11947** is set to NULL.11948**11949** Argument iVal must be greater than or equal to 0, and less than the number11950** of columns in the table affected by the current change. Otherwise,11951** [SQLITE_RANGE] is returned and *ppValue is set to NULL.11952**11953** If successful, this function sets *ppValue to point to a protected11954** sqlite3_value object containing the iVal'th value from the11955** "conflicting row" associated with the current conflict-handler callback11956** and returns SQLITE_OK.11957**11958** If some other error occurs (e.g. an OOM condition), an SQLite error code11959** is returned and *ppValue is set to NULL.11960*/11961SQLITE_API int sqlite3changeset_conflict(11962sqlite3_changeset_iter *pIter, /* Changeset iterator */11963int iVal, /* Column number */11964sqlite3_value **ppValue /* OUT: Value from conflicting row */11965);1196611967/*11968** CAPI3REF: Determine The Number Of Foreign Key Constraint Violations11969** METHOD: sqlite3_changeset_iter11970**11971** This function may only be called with an iterator passed to an11972** SQLITE_CHANGESET_FOREIGN_KEY conflict handler callback. In this case11973** it sets the output variable to the total number of known foreign key11974** violations in the destination database and returns SQLITE_OK.11975**11976** In all other cases this function returns SQLITE_MISUSE.11977*/11978SQLITE_API int sqlite3changeset_fk_conflicts(11979sqlite3_changeset_iter *pIter, /* Changeset iterator */11980int *pnOut /* OUT: Number of FK violations */11981);119821198311984/*11985** CAPI3REF: Finalize A Changeset Iterator11986** METHOD: sqlite3_changeset_iter11987**11988** This function is used to finalize an iterator allocated with11989** [sqlite3changeset_start()].11990**11991** This function should only be called on iterators created using the11992** [sqlite3changeset_start()] function. If an application calls this11993** function with an iterator passed to a conflict-handler by11994** [sqlite3changeset_apply()], [SQLITE_MISUSE] is immediately returned and the11995** call has no effect.11996**11997** If an error was encountered within a call to an sqlite3changeset_xxx()11998** function (for example an [SQLITE_CORRUPT] in [sqlite3changeset_next()] or an11999** [SQLITE_NOMEM] in [sqlite3changeset_new()]) then an error code corresponding12000** to that error is returned by this function. Otherwise, SQLITE_OK is12001** returned. This is to allow the following pattern (pseudo-code):12002**12003** <pre>12004** sqlite3changeset_start();12005** while( SQLITE_ROW==sqlite3changeset_next() ){12006** // Do something with change.12007** }12008** rc = sqlite3changeset_finalize();12009** if( rc!=SQLITE_OK ){12010** // An error has occurred12011** }12012** </pre>12013*/12014SQLITE_API int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);1201512016/*12017** CAPI3REF: Invert A Changeset12018**12019** This function is used to "invert" a changeset object. Applying an inverted12020** changeset to a database reverses the effects of applying the uninverted12021** changeset. Specifically:12022**12023** <ul>12024** <li> Each DELETE change is changed to an INSERT, and12025** <li> Each INSERT change is changed to a DELETE, and12026** <li> For each UPDATE change, the old.* and new.* values are exchanged.12027** </ul>12028**12029** This function does not change the order in which changes appear within12030** the changeset. It merely reverses the sense of each individual change.12031**12032** If successful, a pointer to a buffer containing the inverted changeset12033** is stored in *ppOut, the size of the same buffer is stored in *pnOut, and12034** SQLITE_OK is returned. If an error occurs, both *pnOut and *ppOut are12035** zeroed and an SQLite error code returned.12036**12037** It is the responsibility of the caller to eventually call sqlite3_free()12038** on the *ppOut pointer to free the buffer allocation following a successful12039** call to this function.12040**12041** WARNING/TODO: This function currently assumes that the input is a valid12042** changeset. If it is not, the results are undefined.12043*/12044SQLITE_API int sqlite3changeset_invert(12045int nIn, const void *pIn, /* Input changeset */12046int *pnOut, void **ppOut /* OUT: Inverse of input */12047);1204812049/*12050** CAPI3REF: Concatenate Two Changeset Objects12051**12052** This function is used to concatenate two changesets, A and B, into a12053** single changeset. The result is a changeset equivalent to applying12054** changeset A followed by changeset B.12055**12056** This function combines the two input changesets using an12057** sqlite3_changegroup object. Calling it produces similar results as the12058** following code fragment:12059**12060** <pre>12061** sqlite3_changegroup *pGrp;12062** rc = sqlite3_changegroup_new(&pGrp);12063** if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nA, pA);12064** if( rc==SQLITE_OK ) rc = sqlite3changegroup_add(pGrp, nB, pB);12065** if( rc==SQLITE_OK ){12066** rc = sqlite3changegroup_output(pGrp, pnOut, ppOut);12067** }else{12068** *ppOut = 0;12069** *pnOut = 0;12070** }12071** </pre>12072**12073** Refer to the sqlite3_changegroup documentation below for details.12074*/12075SQLITE_API int sqlite3changeset_concat(12076int nA, /* Number of bytes in buffer pA */12077void *pA, /* Pointer to buffer containing changeset A */12078int nB, /* Number of bytes in buffer pB */12079void *pB, /* Pointer to buffer containing changeset B */12080int *pnOut, /* OUT: Number of bytes in output changeset */12081void **ppOut /* OUT: Buffer containing output changeset */12082);1208312084/*12085** CAPI3REF: Changegroup Handle12086**12087** A changegroup is an object used to combine two or more12088** [changesets] or [patchsets]12089*/12090typedef struct sqlite3_changegroup sqlite3_changegroup;1209112092/*12093** CAPI3REF: Create A New Changegroup Object12094** CONSTRUCTOR: sqlite3_changegroup12095**12096** An sqlite3_changegroup object is used to combine two or more changesets12097** (or patchsets) into a single changeset (or patchset). A single changegroup12098** object may combine changesets or patchsets, but not both. The output is12099** always in the same format as the input.12100**12101** If successful, this function returns SQLITE_OK and populates (*pp) with12102** a pointer to a new sqlite3_changegroup object before returning. The caller12103** should eventually free the returned object using a call to12104** sqlite3changegroup_delete(). If an error occurs, an SQLite error code12105** (i.e. SQLITE_NOMEM) is returned and *pp is set to NULL.12106**12107** The usual usage pattern for an sqlite3_changegroup object is as follows:12108**12109** <ul>12110** <li> It is created using a call to sqlite3changegroup_new().12111**12112** <li> Zero or more changesets (or patchsets) are added to the object12113** by calling sqlite3changegroup_add().12114**12115** <li> The result of combining all input changesets together is obtained12116** by the application via a call to sqlite3changegroup_output().12117**12118** <li> The object is deleted using a call to sqlite3changegroup_delete().12119** </ul>12120**12121** Any number of calls to add() and output() may be made between the calls to12122** new() and delete(), and in any order.12123**12124** As well as the regular sqlite3changegroup_add() and12125** sqlite3changegroup_output() functions, also available are the streaming12126** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm().12127*/12128SQLITE_API int sqlite3changegroup_new(sqlite3_changegroup **pp);1212912130/*12131** CAPI3REF: Add a Schema to a Changegroup12132** METHOD: sqlite3_changegroup_schema12133**12134** This method may be used to optionally enforce the rule that the changesets12135** added to the changegroup handle must match the schema of database zDb12136** ("main", "temp", or the name of an attached database). If12137** sqlite3changegroup_add() is called to add a changeset that is not compatible12138** with the configured schema, SQLITE_SCHEMA is returned and the changegroup12139** object is left in an undefined state.12140**12141** A changeset schema is considered compatible with the database schema in12142** the same way as for sqlite3changeset_apply(). Specifically, for each12143** table in the changeset, there exists a database table with:12144**12145** <ul>12146** <li> The name identified by the changeset, and12147** <li> at least as many columns as recorded in the changeset, and12148** <li> the primary key columns in the same position as recorded in12149** the changeset.12150** </ul>12151**12152** The output of the changegroup object always has the same schema as the12153** database nominated using this function. In cases where changesets passed12154** to sqlite3changegroup_add() have fewer columns than the corresponding table12155** in the database schema, these are filled in using the default column12156** values from the database schema. This makes it possible to combined12157** changesets that have different numbers of columns for a single table12158** within a changegroup, provided that they are otherwise compatible.12159*/12160SQLITE_API int sqlite3changegroup_schema(sqlite3_changegroup*, sqlite3*, const char *zDb);1216112162/*12163** CAPI3REF: Add A Changeset To A Changegroup12164** METHOD: sqlite3_changegroup12165**12166** Add all changes within the changeset (or patchset) in buffer pData (size12167** nData bytes) to the changegroup.12168**12169** If the buffer contains a patchset, then all prior calls to this function12170** on the same changegroup object must also have specified patchsets. Or, if12171** the buffer contains a changeset, so must have the earlier calls to this12172** function. Otherwise, SQLITE_ERROR is returned and no changes are added12173** to the changegroup.12174**12175** Rows within the changeset and changegroup are identified by the values in12176** their PRIMARY KEY columns. A change in the changeset is considered to12177** apply to the same row as a change already present in the changegroup if12178** the two rows have the same primary key.12179**12180** Changes to rows that do not already appear in the changegroup are12181** simply copied into it. Or, if both the new changeset and the changegroup12182** contain changes that apply to a single row, the final contents of the12183** changegroup depends on the type of each change, as follows:12184**12185** <table border=1 style="margin-left:8ex;margin-right:8ex">12186** <tr><th style="white-space:pre">Existing Change </th>12187** <th style="white-space:pre">New Change </th>12188** <th>Output Change12189** <tr><td>INSERT <td>INSERT <td>12190** The new change is ignored. This case does not occur if the new12191** changeset was recorded immediately after the changesets already12192** added to the changegroup.12193** <tr><td>INSERT <td>UPDATE <td>12194** The INSERT change remains in the changegroup. The values in the12195** INSERT change are modified as if the row was inserted by the12196** existing change and then updated according to the new change.12197** <tr><td>INSERT <td>DELETE <td>12198** The existing INSERT is removed from the changegroup. The DELETE is12199** not added.12200** <tr><td>UPDATE <td>INSERT <td>12201** The new change is ignored. This case does not occur if the new12202** changeset was recorded immediately after the changesets already12203** added to the changegroup.12204** <tr><td>UPDATE <td>UPDATE <td>12205** The existing UPDATE remains within the changegroup. It is amended12206** so that the accompanying values are as if the row was updated once12207** by the existing change and then again by the new change.12208** <tr><td>UPDATE <td>DELETE <td>12209** The existing UPDATE is replaced by the new DELETE within the12210** changegroup.12211** <tr><td>DELETE <td>INSERT <td>12212** If one or more of the column values in the row inserted by the12213** new change differ from those in the row deleted by the existing12214** change, the existing DELETE is replaced by an UPDATE within the12215** changegroup. Otherwise, if the inserted row is exactly the same12216** as the deleted row, the existing DELETE is simply discarded.12217** <tr><td>DELETE <td>UPDATE <td>12218** The new change is ignored. This case does not occur if the new12219** changeset was recorded immediately after the changesets already12220** added to the changegroup.12221** <tr><td>DELETE <td>DELETE <td>12222** The new change is ignored. This case does not occur if the new12223** changeset was recorded immediately after the changesets already12224** added to the changegroup.12225** </table>12226**12227** If the new changeset contains changes to a table that is already present12228** in the changegroup, then the number of columns and the position of the12229** primary key columns for the table must be consistent. If this is not the12230** case, this function fails with SQLITE_SCHEMA. Except, if the changegroup12231** object has been configured with a database schema using the12232** sqlite3changegroup_schema() API, then it is possible to combine changesets12233** with different numbers of columns for a single table, provided that12234** they are otherwise compatible.12235**12236** If the input changeset appears to be corrupt and the corruption is12237** detected, SQLITE_CORRUPT is returned. Or, if an out-of-memory condition12238** occurs during processing, this function returns SQLITE_NOMEM.12239**12240** In all cases, if an error occurs the state of the final contents of the12241** changegroup is undefined. If no error occurs, SQLITE_OK is returned.12242*/12243SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);1224412245/*12246** CAPI3REF: Add A Single Change To A Changegroup12247** METHOD: sqlite3_changegroup12248**12249** This function adds the single change currently indicated by the iterator12250** passed as the second argument to the changegroup object. The rules for12251** adding the change are just as described for [sqlite3changegroup_add()].12252**12253** If the change is successfully added to the changegroup, SQLITE_OK is12254** returned. Otherwise, an SQLite error code is returned.12255**12256** The iterator must point to a valid entry when this function is called.12257** If it does not, SQLITE_ERROR is returned and no change is added to the12258** changegroup. Additionally, the iterator must not have been opened with12259** the SQLITE_CHANGESETAPPLY_INVERT flag. In this case SQLITE_ERROR is also12260** returned.12261*/12262SQLITE_API int sqlite3changegroup_add_change(12263sqlite3_changegroup*,12264sqlite3_changeset_iter*12265);12266122671226812269/*12270** CAPI3REF: Obtain A Composite Changeset From A Changegroup12271** METHOD: sqlite3_changegroup12272**12273** Obtain a buffer containing a changeset (or patchset) representing the12274** current contents of the changegroup. If the inputs to the changegroup12275** were themselves changesets, the output is a changeset. Or, if the12276** inputs were patchsets, the output is also a patchset.12277**12278** As with the output of the sqlite3session_changeset() and12279** sqlite3session_patchset() functions, all changes related to a single12280** table are grouped together in the output of this function. Tables appear12281** in the same order as for the very first changeset added to the changegroup.12282** If the second or subsequent changesets added to the changegroup contain12283** changes for tables that do not appear in the first changeset, they are12284** appended onto the end of the output changeset, again in the order in12285** which they are first encountered.12286**12287** If an error occurs, an SQLite error code is returned and the output12288** variables (*pnData) and (*ppData) are set to 0. Otherwise, SQLITE_OK12289** is returned and the output variables are set to the size of and a12290** pointer to the output buffer, respectively. In this case it is the12291** responsibility of the caller to eventually free the buffer using a12292** call to sqlite3_free().12293*/12294SQLITE_API int sqlite3changegroup_output(12295sqlite3_changegroup*,12296int *pnData, /* OUT: Size of output buffer in bytes */12297void **ppData /* OUT: Pointer to output buffer */12298);1229912300/*12301** CAPI3REF: Delete A Changegroup Object12302** DESTRUCTOR: sqlite3_changegroup12303*/12304SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*);1230512306/*12307** CAPI3REF: Apply A Changeset To A Database12308**12309** Apply a changeset or patchset to a database. These functions attempt to12310** update the "main" database attached to handle db with the changes found in12311** the changeset passed via the second and third arguments.12312**12313** The fourth argument (xFilter) passed to these functions is the "filter12314** callback". If it is not NULL, then for each table affected by at least one12315** change in the changeset, the filter callback is invoked with12316** the table name as the second argument, and a copy of the context pointer12317** passed as the sixth argument as the first. If the "filter callback"12318** returns zero, then no attempt is made to apply any changes to the table.12319** Otherwise, if the return value is non-zero or the xFilter argument to12320** is NULL, all changes related to the table are attempted.12321**12322** For each table that is not excluded by the filter callback, this function12323** tests that the target database contains a compatible table. A table is12324** considered compatible if all of the following are true:12325**12326** <ul>12327** <li> The table has the same name as the name recorded in the12328** changeset, and12329** <li> The table has at least as many columns as recorded in the12330** changeset, and12331** <li> The table has primary key columns in the same position as12332** recorded in the changeset.12333** </ul>12334**12335** If there is no compatible table, it is not an error, but none of the12336** changes associated with the table are applied. A warning message is issued12337** via the sqlite3_log() mechanism with the error code SQLITE_SCHEMA. At most12338** one such warning is issued for each table in the changeset.12339**12340** For each change for which there is a compatible table, an attempt is made12341** to modify the table contents according to the UPDATE, INSERT or DELETE12342** change. If a change cannot be applied cleanly, the conflict handler12343** function passed as the fifth argument to sqlite3changeset_apply() may be12344** invoked. A description of exactly when the conflict handler is invoked for12345** each type of change is below.12346**12347** Unlike the xFilter argument, xConflict may not be passed NULL. The results12348** of passing anything other than a valid function pointer as the xConflict12349** argument are undefined.12350**12351** Each time the conflict handler function is invoked, it must return one12352** of [SQLITE_CHANGESET_OMIT], [SQLITE_CHANGESET_ABORT] or12353** [SQLITE_CHANGESET_REPLACE]. SQLITE_CHANGESET_REPLACE may only be returned12354** if the second argument passed to the conflict handler is either12355** SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If the conflict-handler12356** returns an illegal value, any changes already made are rolled back and12357** the call to sqlite3changeset_apply() returns SQLITE_MISUSE. Different12358** actions are taken by sqlite3changeset_apply() depending on the value12359** returned by each invocation of the conflict-handler function. Refer to12360** the documentation for the three12361** [SQLITE_CHANGESET_OMIT|available return values] for details.12362**12363** <dl>12364** <dt>DELETE Changes<dd>12365** For each DELETE change, the function checks if the target database12366** contains a row with the same primary key value (or values) as the12367** original row values stored in the changeset. If it does, and the values12368** stored in all non-primary key columns also match the values stored in12369** the changeset the row is deleted from the target database.12370**12371** If a row with matching primary key values is found, but one or more of12372** the non-primary key fields contains a value different from the original12373** row value stored in the changeset, the conflict-handler function is12374** invoked with [SQLITE_CHANGESET_DATA] as the second argument. If the12375** database table has more columns than are recorded in the changeset,12376** only the values of those non-primary key fields are compared against12377** the current database contents - any trailing database table columns12378** are ignored.12379**12380** If no row with matching primary key values is found in the database,12381** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]12382** passed as the second argument.12383**12384** If the DELETE operation is attempted, but SQLite returns SQLITE_CONSTRAINT12385** (which can only happen if a foreign key constraint is violated), the12386** conflict-handler function is invoked with [SQLITE_CHANGESET_CONSTRAINT]12387** passed as the second argument. This includes the case where the DELETE12388** operation is attempted because an earlier call to the conflict handler12389** function returned [SQLITE_CHANGESET_REPLACE].12390**12391** <dt>INSERT Changes<dd>12392** For each INSERT change, an attempt is made to insert the new row into12393** the database. If the changeset row contains fewer fields than the12394** database table, the trailing fields are populated with their default12395** values.12396**12397** If the attempt to insert the row fails because the database already12398** contains a row with the same primary key values, the conflict handler12399** function is invoked with the second argument set to12400** [SQLITE_CHANGESET_CONFLICT].12401**12402** If the attempt to insert the row fails because of some other constraint12403** violation (e.g. NOT NULL or UNIQUE), the conflict handler function is12404** invoked with the second argument set to [SQLITE_CHANGESET_CONSTRAINT].12405** This includes the case where the INSERT operation is re-attempted because12406** an earlier call to the conflict handler function returned12407** [SQLITE_CHANGESET_REPLACE].12408**12409** <dt>UPDATE Changes<dd>12410** For each UPDATE change, the function checks if the target database12411** contains a row with the same primary key value (or values) as the12412** original row values stored in the changeset. If it does, and the values12413** stored in all modified non-primary key columns also match the values12414** stored in the changeset the row is updated within the target database.12415**12416** If a row with matching primary key values is found, but one or more of12417** the modified non-primary key fields contains a value different from an12418** original row value stored in the changeset, the conflict-handler function12419** is invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since12420** UPDATE changes only contain values for non-primary key fields that are12421** to be modified, only those fields need to match the original values to12422** avoid the SQLITE_CHANGESET_DATA conflict-handler callback.12423**12424** If no row with matching primary key values is found in the database,12425** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]12426** passed as the second argument.12427**12428** If the UPDATE operation is attempted, but SQLite returns12429** SQLITE_CONSTRAINT, the conflict-handler function is invoked with12430** [SQLITE_CHANGESET_CONSTRAINT] passed as the second argument.12431** This includes the case where the UPDATE operation is attempted after12432** an earlier call to the conflict handler function returned12433** [SQLITE_CHANGESET_REPLACE].12434** </dl>12435**12436** It is safe to execute SQL statements, including those that write to the12437** table that the callback related to, from within the xConflict callback.12438** This can be used to further customize the application's conflict12439** resolution strategy.12440**12441** All changes made by these functions are enclosed in a savepoint transaction.12442** If any other error (aside from a constraint failure when attempting to12443** write to the target database) occurs, then the savepoint transaction is12444** rolled back, restoring the target database to its original state, and an12445** SQLite error code returned.12446**12447** If the output parameters (ppRebase) and (pnRebase) are non-NULL and12448** the input is a changeset (not a patchset), then sqlite3changeset_apply_v2()12449** may set (*ppRebase) to point to a "rebase" that may be used with the12450** sqlite3_rebaser APIs buffer before returning. In this case (*pnRebase)12451** is set to the size of the buffer in bytes. It is the responsibility of the12452** caller to eventually free any such buffer using sqlite3_free(). The buffer12453** is only allocated and populated if one or more conflicts were encountered12454** while applying the patchset. See comments surrounding the sqlite3_rebaser12455** APIs for further details.12456**12457** The behavior of sqlite3changeset_apply_v2() and its streaming equivalent12458** may be modified by passing a combination of12459** [SQLITE_CHANGESETAPPLY_NOSAVEPOINT | supported flags] as the 9th parameter.12460**12461** Note that the sqlite3changeset_apply_v2() API is still <b>experimental</b>12462** and therefore subject to change.12463*/12464SQLITE_API int sqlite3changeset_apply(12465sqlite3 *db, /* Apply change to "main" db of this handle */12466int nChangeset, /* Size of changeset in bytes */12467void *pChangeset, /* Changeset blob */12468int(*xFilter)(12469void *pCtx, /* Copy of sixth arg to _apply() */12470const char *zTab /* Table name */12471),12472int(*xConflict)(12473void *pCtx, /* Copy of sixth arg to _apply() */12474int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */12475sqlite3_changeset_iter *p /* Handle describing change and conflict */12476),12477void *pCtx /* First argument passed to xConflict */12478);12479SQLITE_API int sqlite3changeset_apply_v2(12480sqlite3 *db, /* Apply change to "main" db of this handle */12481int nChangeset, /* Size of changeset in bytes */12482void *pChangeset, /* Changeset blob */12483int(*xFilter)(12484void *pCtx, /* Copy of sixth arg to _apply() */12485const char *zTab /* Table name */12486),12487int(*xConflict)(12488void *pCtx, /* Copy of sixth arg to _apply() */12489int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */12490sqlite3_changeset_iter *p /* Handle describing change and conflict */12491),12492void *pCtx, /* First argument passed to xConflict */12493void **ppRebase, int *pnRebase, /* OUT: Rebase data */12494int flags /* SESSION_CHANGESETAPPLY_* flags */12495);1249612497/*12498** CAPI3REF: Flags for sqlite3changeset_apply_v212499**12500** The following flags may passed via the 9th parameter to12501** [sqlite3changeset_apply_v2] and [sqlite3changeset_apply_v2_strm]:12502**12503** <dl>12504** <dt>SQLITE_CHANGESETAPPLY_NOSAVEPOINT <dd>12505** Usually, the sessions module encloses all operations performed by12506** a single call to apply_v2() or apply_v2_strm() in a [SAVEPOINT]. The12507** SAVEPOINT is committed if the changeset or patchset is successfully12508** applied, or rolled back if an error occurs. Specifying this flag12509** causes the sessions module to omit this savepoint. In this case, if the12510** caller has an open transaction or savepoint when apply_v2() is called,12511** it may revert the partially applied changeset by rolling it back.12512**12513** <dt>SQLITE_CHANGESETAPPLY_INVERT <dd>12514** Invert the changeset before applying it. This is equivalent to inverting12515** a changeset using sqlite3changeset_invert() before applying it. It is12516** an error to specify this flag with a patchset.12517**12518** <dt>SQLITE_CHANGESETAPPLY_IGNORENOOP <dd>12519** Do not invoke the conflict handler callback for any changes that12520** would not actually modify the database even if they were applied.12521** Specifically, this means that the conflict handler is not invoked12522** for:12523** <ul>12524** <li>a delete change if the row being deleted cannot be found,12525** <li>an update change if the modified fields are already set to12526** their new values in the conflicting row, or12527** <li>an insert change if all fields of the conflicting row match12528** the row being inserted.12529** </ul>12530**12531** <dt>SQLITE_CHANGESETAPPLY_FKNOACTION <dd>12532** If this flag it set, then all foreign key constraints in the target12533** database behave as if they were declared with "ON UPDATE NO ACTION ON12534** DELETE NO ACTION", even if they are actually CASCADE, RESTRICT, SET NULL12535** or SET DEFAULT.12536*/12537#define SQLITE_CHANGESETAPPLY_NOSAVEPOINT 0x000112538#define SQLITE_CHANGESETAPPLY_INVERT 0x000212539#define SQLITE_CHANGESETAPPLY_IGNORENOOP 0x000412540#define SQLITE_CHANGESETAPPLY_FKNOACTION 0x00081254112542/*12543** CAPI3REF: Constants Passed To The Conflict Handler12544**12545** Values that may be passed as the second argument to a conflict-handler.12546**12547** <dl>12548** <dt>SQLITE_CHANGESET_DATA<dd>12549** The conflict handler is invoked with CHANGESET_DATA as the second argument12550** when processing a DELETE or UPDATE change if a row with the required12551** PRIMARY KEY fields is present in the database, but one or more other12552** (non primary-key) fields modified by the update do not contain the12553** expected "before" values.12554**12555** The conflicting row, in this case, is the database row with the matching12556** primary key.12557**12558** <dt>SQLITE_CHANGESET_NOTFOUND<dd>12559** The conflict handler is invoked with CHANGESET_NOTFOUND as the second12560** argument when processing a DELETE or UPDATE change if a row with the12561** required PRIMARY KEY fields is not present in the database.12562**12563** There is no conflicting row in this case. The results of invoking the12564** sqlite3changeset_conflict() API are undefined.12565**12566** <dt>SQLITE_CHANGESET_CONFLICT<dd>12567** CHANGESET_CONFLICT is passed as the second argument to the conflict12568** handler while processing an INSERT change if the operation would result12569** in duplicate primary key values.12570**12571** The conflicting row in this case is the database row with the matching12572** primary key.12573**12574** <dt>SQLITE_CHANGESET_FOREIGN_KEY<dd>12575** If foreign key handling is enabled, and applying a changeset leaves the12576** database in a state containing foreign key violations, the conflict12577** handler is invoked with CHANGESET_FOREIGN_KEY as the second argument12578** exactly once before the changeset is committed. If the conflict handler12579** returns CHANGESET_OMIT, the changes, including those that caused the12580** foreign key constraint violation, are committed. Or, if it returns12581** CHANGESET_ABORT, the changeset is rolled back.12582**12583** No current or conflicting row information is provided. The only function12584** it is possible to call on the supplied sqlite3_changeset_iter handle12585** is sqlite3changeset_fk_conflicts().12586**12587** <dt>SQLITE_CHANGESET_CONSTRAINT<dd>12588** If any other constraint violation occurs while applying a change (i.e.12589** a UNIQUE, CHECK or NOT NULL constraint), the conflict handler is12590** invoked with CHANGESET_CONSTRAINT as the second argument.12591**12592** There is no conflicting row in this case. The results of invoking the12593** sqlite3changeset_conflict() API are undefined.12594**12595** </dl>12596*/12597#define SQLITE_CHANGESET_DATA 112598#define SQLITE_CHANGESET_NOTFOUND 212599#define SQLITE_CHANGESET_CONFLICT 312600#define SQLITE_CHANGESET_CONSTRAINT 412601#define SQLITE_CHANGESET_FOREIGN_KEY 51260212603/*12604** CAPI3REF: Constants Returned By The Conflict Handler12605**12606** A conflict handler callback must return one of the following three values.12607**12608** <dl>12609** <dt>SQLITE_CHANGESET_OMIT<dd>12610** If a conflict handler returns this value no special action is taken. The12611** change that caused the conflict is not applied. The session module12612** continues to the next change in the changeset.12613**12614** <dt>SQLITE_CHANGESET_REPLACE<dd>12615** This value may only be returned if the second argument to the conflict12616** handler was SQLITE_CHANGESET_DATA or SQLITE_CHANGESET_CONFLICT. If this12617** is not the case, any changes applied so far are rolled back and the12618** call to sqlite3changeset_apply() returns SQLITE_MISUSE.12619**12620** If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_DATA conflict12621** handler, then the conflicting row is either updated or deleted, depending12622** on the type of change.12623**12624** If CHANGESET_REPLACE is returned by an SQLITE_CHANGESET_CONFLICT conflict12625** handler, then the conflicting row is removed from the database and a12626** second attempt to apply the change is made. If this second attempt fails,12627** the original row is restored to the database before continuing.12628**12629** <dt>SQLITE_CHANGESET_ABORT<dd>12630** If this value is returned, any changes applied so far are rolled back12631** and the call to sqlite3changeset_apply() returns SQLITE_ABORT.12632** </dl>12633*/12634#define SQLITE_CHANGESET_OMIT 012635#define SQLITE_CHANGESET_REPLACE 112636#define SQLITE_CHANGESET_ABORT 21263712638/*12639** CAPI3REF: Rebasing changesets12640** EXPERIMENTAL12641**12642** Suppose there is a site hosting a database in state S0. And that12643** modifications are made that move that database to state S1 and a12644** changeset recorded (the "local" changeset). Then, a changeset based12645** on S0 is received from another site (the "remote" changeset) and12646** applied to the database. The database is then in state12647** (S1+"remote"), where the exact state depends on any conflict12648** resolution decisions (OMIT or REPLACE) made while applying "remote".12649** Rebasing a changeset is to update it to take those conflict12650** resolution decisions into account, so that the same conflicts12651** do not have to be resolved elsewhere in the network.12652**12653** For example, if both the local and remote changesets contain an12654** INSERT of the same key on "CREATE TABLE t1(a PRIMARY KEY, b)":12655**12656** local: INSERT INTO t1 VALUES(1, 'v1');12657** remote: INSERT INTO t1 VALUES(1, 'v2');12658**12659** and the conflict resolution is REPLACE, then the INSERT change is12660** removed from the local changeset (it was overridden). Or, if the12661** conflict resolution was "OMIT", then the local changeset is modified12662** to instead contain:12663**12664** UPDATE t1 SET b = 'v2' WHERE a=1;12665**12666** Changes within the local changeset are rebased as follows:12667**12668** <dl>12669** <dt>Local INSERT<dd>12670** This may only conflict with a remote INSERT. If the conflict12671** resolution was OMIT, then add an UPDATE change to the rebased12672** changeset. Or, if the conflict resolution was REPLACE, add12673** nothing to the rebased changeset.12674**12675** <dt>Local DELETE<dd>12676** This may conflict with a remote UPDATE or DELETE. In both cases the12677** only possible resolution is OMIT. If the remote operation was a12678** DELETE, then add no change to the rebased changeset. If the remote12679** operation was an UPDATE, then the old.* fields of change are updated12680** to reflect the new.* values in the UPDATE.12681**12682** <dt>Local UPDATE<dd>12683** This may conflict with a remote UPDATE or DELETE. If it conflicts12684** with a DELETE, and the conflict resolution was OMIT, then the update12685** is changed into an INSERT. Any undefined values in the new.* record12686** from the update change are filled in using the old.* values from12687** the conflicting DELETE. Or, if the conflict resolution was REPLACE,12688** the UPDATE change is simply omitted from the rebased changeset.12689**12690** If conflict is with a remote UPDATE and the resolution is OMIT, then12691** the old.* values are rebased using the new.* values in the remote12692** change. Or, if the resolution is REPLACE, then the change is copied12693** into the rebased changeset with updates to columns also updated by12694** the conflicting remote UPDATE removed. If this means no columns would12695** be updated, the change is omitted.12696** </dl>12697**12698** A local change may be rebased against multiple remote changes12699** simultaneously. If a single key is modified by multiple remote12700** changesets, they are combined as follows before the local changeset12701** is rebased:12702**12703** <ul>12704** <li> If there has been one or more REPLACE resolutions on a12705** key, it is rebased according to a REPLACE.12706**12707** <li> If there have been no REPLACE resolutions on a key, then12708** the local changeset is rebased according to the most recent12709** of the OMIT resolutions.12710** </ul>12711**12712** Note that conflict resolutions from multiple remote changesets are12713** combined on a per-field basis, not per-row. This means that in the12714** case of multiple remote UPDATE operations, some fields of a single12715** local change may be rebased for REPLACE while others are rebased for12716** OMIT.12717**12718** In order to rebase a local changeset, the remote changeset must first12719** be applied to the local database using sqlite3changeset_apply_v2() and12720** the buffer of rebase information captured. Then:12721**12722** <ol>12723** <li> An sqlite3_rebaser object is created by calling12724** sqlite3rebaser_create().12725** <li> The new object is configured with the rebase buffer obtained from12726** sqlite3changeset_apply_v2() by calling sqlite3rebaser_configure().12727** If the local changeset is to be rebased against multiple remote12728** changesets, then sqlite3rebaser_configure() should be called12729** multiple times, in the same order that the multiple12730** sqlite3changeset_apply_v2() calls were made.12731** <li> Each local changeset is rebased by calling sqlite3rebaser_rebase().12732** <li> The sqlite3_rebaser object is deleted by calling12733** sqlite3rebaser_delete().12734** </ol>12735*/12736typedef struct sqlite3_rebaser sqlite3_rebaser;1273712738/*12739** CAPI3REF: Create a changeset rebaser object.12740** EXPERIMENTAL12741**12742** Allocate a new changeset rebaser object. If successful, set (*ppNew) to12743** point to the new object and return SQLITE_OK. Otherwise, if an error12744** occurs, return an SQLite error code (e.g. SQLITE_NOMEM) and set (*ppNew)12745** to NULL.12746*/12747SQLITE_API int sqlite3rebaser_create(sqlite3_rebaser **ppNew);1274812749/*12750** CAPI3REF: Configure a changeset rebaser object.12751** EXPERIMENTAL12752**12753** Configure the changeset rebaser object to rebase changesets according12754** to the conflict resolutions described by buffer pRebase (size nRebase12755** bytes), which must have been obtained from a previous call to12756** sqlite3changeset_apply_v2().12757*/12758SQLITE_API int sqlite3rebaser_configure(12759sqlite3_rebaser*,12760int nRebase, const void *pRebase12761);1276212763/*12764** CAPI3REF: Rebase a changeset12765** EXPERIMENTAL12766**12767** Argument pIn must point to a buffer containing a changeset nIn bytes12768** in size. This function allocates and populates a buffer with a copy12769** of the changeset rebased according to the configuration of the12770** rebaser object passed as the first argument. If successful, (*ppOut)12771** is set to point to the new buffer containing the rebased changeset and12772** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the12773** responsibility of the caller to eventually free the new buffer using12774** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut)12775** are set to zero and an SQLite error code returned.12776*/12777SQLITE_API int sqlite3rebaser_rebase(12778sqlite3_rebaser*,12779int nIn, const void *pIn,12780int *pnOut, void **ppOut12781);1278212783/*12784** CAPI3REF: Delete a changeset rebaser object.12785** EXPERIMENTAL12786**12787** Delete the changeset rebaser object and all associated resources. There12788** should be one call to this function for each successful invocation12789** of sqlite3rebaser_create().12790*/12791SQLITE_API void sqlite3rebaser_delete(sqlite3_rebaser *p);1279212793/*12794** CAPI3REF: Streaming Versions of API functions.12795**12796** The six streaming API xxx_strm() functions serve similar purposes to the12797** corresponding non-streaming API functions:12798**12799** <table border=1 style="margin-left:8ex;margin-right:8ex">12800** <tr><th>Streaming function<th>Non-streaming equivalent</th>12801** <tr><td>sqlite3changeset_apply_strm<td>[sqlite3changeset_apply]12802** <tr><td>sqlite3changeset_apply_strm_v2<td>[sqlite3changeset_apply_v2]12803** <tr><td>sqlite3changeset_concat_strm<td>[sqlite3changeset_concat]12804** <tr><td>sqlite3changeset_invert_strm<td>[sqlite3changeset_invert]12805** <tr><td>sqlite3changeset_start_strm<td>[sqlite3changeset_start]12806** <tr><td>sqlite3session_changeset_strm<td>[sqlite3session_changeset]12807** <tr><td>sqlite3session_patchset_strm<td>[sqlite3session_patchset]12808** </table>12809**12810** Non-streaming functions that accept changesets (or patchsets) as input12811** require that the entire changeset be stored in a single buffer in memory.12812** Similarly, those that return a changeset or patchset do so by returning12813** a pointer to a single large buffer allocated using sqlite3_malloc().12814** Normally this is convenient. However, if an application running in a12815** low-memory environment is required to handle very large changesets, the12816** large contiguous memory allocations required can become onerous.12817**12818** In order to avoid this problem, instead of a single large buffer, input12819** is passed to a streaming API functions by way of a callback function that12820** the sessions module invokes to incrementally request input data as it is12821** required. In all cases, a pair of API function parameters such as12822**12823** <pre>12824** int nChangeset,12825** void *pChangeset,12826** </pre>12827**12828** Is replaced by:12829**12830** <pre>12831** int (*xInput)(void *pIn, void *pData, int *pnData),12832** void *pIn,12833** </pre>12834**12835** Each time the xInput callback is invoked by the sessions module, the first12836** argument passed is a copy of the supplied pIn context pointer. The second12837** argument, pData, points to a buffer (*pnData) bytes in size. Assuming no12838** error occurs the xInput method should copy up to (*pnData) bytes of data12839** into the buffer and set (*pnData) to the actual number of bytes copied12840** before returning SQLITE_OK. If the input is completely exhausted, (*pnData)12841** should be set to zero to indicate this. Or, if an error occurs, an SQLite12842** error code should be returned. In all cases, if an xInput callback returns12843** an error, all processing is abandoned and the streaming API function12844** returns a copy of the error code to the caller.12845**12846** In the case of sqlite3changeset_start_strm(), the xInput callback may be12847** invoked by the sessions module at any point during the lifetime of the12848** iterator. If such an xInput callback returns an error, the iterator enters12849** an error state, whereby all subsequent calls to iterator functions12850** immediately fail with the same error code as returned by xInput.12851**12852** Similarly, streaming API functions that return changesets (or patchsets)12853** return them in chunks by way of a callback function instead of via a12854** pointer to a single large buffer. In this case, a pair of parameters such12855** as:12856**12857** <pre>12858** int *pnChangeset,12859** void **ppChangeset,12860** </pre>12861**12862** Is replaced by:12863**12864** <pre>12865** int (*xOutput)(void *pOut, const void *pData, int nData),12866** void *pOut12867** </pre>12868**12869** The xOutput callback is invoked zero or more times to return data to12870** the application. The first parameter passed to each call is a copy of the12871** pOut pointer supplied by the application. The second parameter, pData,12872** points to a buffer nData bytes in size containing the chunk of output12873** data being returned. If the xOutput callback successfully processes the12874** supplied data, it should return SQLITE_OK to indicate success. Otherwise,12875** it should return some other SQLite error code. In this case processing12876** is immediately abandoned and the streaming API function returns a copy12877** of the xOutput error code to the application.12878**12879** The sessions module never invokes an xOutput callback with the third12880** parameter set to a value less than or equal to zero. Other than this,12881** no guarantees are made as to the size of the chunks of data returned.12882*/12883SQLITE_API int sqlite3changeset_apply_strm(12884sqlite3 *db, /* Apply change to "main" db of this handle */12885int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */12886void *pIn, /* First arg for xInput */12887int(*xFilter)(12888void *pCtx, /* Copy of sixth arg to _apply() */12889const char *zTab /* Table name */12890),12891int(*xConflict)(12892void *pCtx, /* Copy of sixth arg to _apply() */12893int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */12894sqlite3_changeset_iter *p /* Handle describing change and conflict */12895),12896void *pCtx /* First argument passed to xConflict */12897);12898SQLITE_API int sqlite3changeset_apply_v2_strm(12899sqlite3 *db, /* Apply change to "main" db of this handle */12900int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */12901void *pIn, /* First arg for xInput */12902int(*xFilter)(12903void *pCtx, /* Copy of sixth arg to _apply() */12904const char *zTab /* Table name */12905),12906int(*xConflict)(12907void *pCtx, /* Copy of sixth arg to _apply() */12908int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */12909sqlite3_changeset_iter *p /* Handle describing change and conflict */12910),12911void *pCtx, /* First argument passed to xConflict */12912void **ppRebase, int *pnRebase,12913int flags12914);12915SQLITE_API int sqlite3changeset_concat_strm(12916int (*xInputA)(void *pIn, void *pData, int *pnData),12917void *pInA,12918int (*xInputB)(void *pIn, void *pData, int *pnData),12919void *pInB,12920int (*xOutput)(void *pOut, const void *pData, int nData),12921void *pOut12922);12923SQLITE_API int sqlite3changeset_invert_strm(12924int (*xInput)(void *pIn, void *pData, int *pnData),12925void *pIn,12926int (*xOutput)(void *pOut, const void *pData, int nData),12927void *pOut12928);12929SQLITE_API int sqlite3changeset_start_strm(12930sqlite3_changeset_iter **pp,12931int (*xInput)(void *pIn, void *pData, int *pnData),12932void *pIn12933);12934SQLITE_API int sqlite3changeset_start_v2_strm(12935sqlite3_changeset_iter **pp,12936int (*xInput)(void *pIn, void *pData, int *pnData),12937void *pIn,12938int flags12939);12940SQLITE_API int sqlite3session_changeset_strm(12941sqlite3_session *pSession,12942int (*xOutput)(void *pOut, const void *pData, int nData),12943void *pOut12944);12945SQLITE_API int sqlite3session_patchset_strm(12946sqlite3_session *pSession,12947int (*xOutput)(void *pOut, const void *pData, int nData),12948void *pOut12949);12950SQLITE_API int sqlite3changegroup_add_strm(sqlite3_changegroup*,12951int (*xInput)(void *pIn, void *pData, int *pnData),12952void *pIn12953);12954SQLITE_API int sqlite3changegroup_output_strm(sqlite3_changegroup*,12955int (*xOutput)(void *pOut, const void *pData, int nData),12956void *pOut12957);12958SQLITE_API int sqlite3rebaser_rebase_strm(12959sqlite3_rebaser *pRebaser,12960int (*xInput)(void *pIn, void *pData, int *pnData),12961void *pIn,12962int (*xOutput)(void *pOut, const void *pData, int nData),12963void *pOut12964);1296512966/*12967** CAPI3REF: Configure global parameters12968**12969** The sqlite3session_config() interface is used to make global configuration12970** changes to the sessions module in order to tune it to the specific needs12971** of the application.12972**12973** The sqlite3session_config() interface is not threadsafe. If it is invoked12974** while any other thread is inside any other sessions method then the12975** results are undefined. Furthermore, if it is invoked after any sessions12976** related objects have been created, the results are also undefined.12977**12978** The first argument to the sqlite3session_config() function must be one12979** of the SQLITE_SESSION_CONFIG_XXX constants defined below. The12980** interpretation of the (void*) value passed as the second parameter and12981** the effect of calling this function depends on the value of the first12982** parameter.12983**12984** <dl>12985** <dt>SQLITE_SESSION_CONFIG_STRMSIZE<dd>12986** By default, the sessions module streaming interfaces attempt to input12987** and output data in approximately 1 KiB chunks. This operand may be used12988** to set and query the value of this configuration setting. The pointer12989** passed as the second argument must point to a value of type (int).12990** If this value is greater than 0, it is used as the new streaming data12991** chunk size for both input and output. Before returning, the (int) value12992** pointed to by pArg is set to the final value of the streaming interface12993** chunk size.12994** </dl>12995**12996** This function returns SQLITE_OK if successful, or an SQLite error code12997** otherwise.12998*/12999SQLITE_API int sqlite3session_config(int op, void *pArg);1300013001/*13002** CAPI3REF: Values for sqlite3session_config().13003*/13004#define SQLITE_SESSION_CONFIG_STRMSIZE 11300513006/*13007** Make sure we can call this stuff from C++.13008*/13009#ifdef __cplusplus13010}13011#endif1301213013#endif /* !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION) */1301413015/******** End of sqlite3session.h *********/13016/******** Begin file fts5.h *********/13017/*13018** 2014 May 3113019**13020** The author disclaims copyright to this source code. In place of13021** a legal notice, here is a blessing:13022**13023** May you do good and not evil.13024** May you find forgiveness for yourself and forgive others.13025** May you share freely, never taking more than you give.13026**13027******************************************************************************13028**13029** Interfaces to extend FTS5. Using the interfaces defined in this file,13030** FTS5 may be extended with:13031**13032** * custom tokenizers, and13033** * custom auxiliary functions.13034*/130351303613037#ifndef _FTS5_H13038#define _FTS5_H130391304013041#ifdef __cplusplus13042extern "C" {13043#endif1304413045/*************************************************************************13046** CUSTOM AUXILIARY FUNCTIONS13047**13048** Virtual table implementations may overload SQL functions by implementing13049** the sqlite3_module.xFindFunction() method.13050*/1305113052typedef struct Fts5ExtensionApi Fts5ExtensionApi;13053typedef struct Fts5Context Fts5Context;13054typedef struct Fts5PhraseIter Fts5PhraseIter;1305513056typedef void (*fts5_extension_function)(13057const Fts5ExtensionApi *pApi, /* API offered by current FTS version */13058Fts5Context *pFts, /* First arg to pass to pApi functions */13059sqlite3_context *pCtx, /* Context for returning result/error */13060int nVal, /* Number of values in apVal[] array */13061sqlite3_value **apVal /* Array of trailing arguments */13062);1306313064struct Fts5PhraseIter {13065const unsigned char *a;13066const unsigned char *b;13067};1306813069/*13070** EXTENSION API FUNCTIONS13071**13072** xUserData(pFts):13073** Return a copy of the pUserData pointer passed to the xCreateFunction()13074** API when the extension function was registered.13075**13076** xColumnTotalSize(pFts, iCol, pnToken):13077** If parameter iCol is less than zero, set output variable *pnToken13078** to the total number of tokens in the FTS5 table. Or, if iCol is13079** non-negative but less than the number of columns in the table, return13080** the total number of tokens in column iCol, considering all rows in13081** the FTS5 table.13082**13083** If parameter iCol is greater than or equal to the number of columns13084** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.13085** an OOM condition or IO error), an appropriate SQLite error code is13086** returned.13087**13088** xColumnCount(pFts):13089** Return the number of columns in the table.13090**13091** xColumnSize(pFts, iCol, pnToken):13092** If parameter iCol is less than zero, set output variable *pnToken13093** to the total number of tokens in the current row. Or, if iCol is13094** non-negative but less than the number of columns in the table, set13095** *pnToken to the number of tokens in column iCol of the current row.13096**13097** If parameter iCol is greater than or equal to the number of columns13098** in the table, SQLITE_RANGE is returned. Or, if an error occurs (e.g.13099** an OOM condition or IO error), an appropriate SQLite error code is13100** returned.13101**13102** This function may be quite inefficient if used with an FTS5 table13103** created with the "columnsize=0" option.13104**13105** xColumnText:13106** If parameter iCol is less than zero, or greater than or equal to the13107** number of columns in the table, SQLITE_RANGE is returned.13108**13109** Otherwise, this function attempts to retrieve the text of column iCol of13110** the current document. If successful, (*pz) is set to point to a buffer13111** containing the text in utf-8 encoding, (*pn) is set to the size in bytes13112** (not characters) of the buffer and SQLITE_OK is returned. Otherwise,13113** if an error occurs, an SQLite error code is returned and the final values13114** of (*pz) and (*pn) are undefined.13115**13116** xPhraseCount:13117** Returns the number of phrases in the current query expression.13118**13119** xPhraseSize:13120** If parameter iCol is less than zero, or greater than or equal to the13121** number of phrases in the current query, as returned by xPhraseCount,13122** 0 is returned. Otherwise, this function returns the number of tokens in13123** phrase iPhrase of the query. Phrases are numbered starting from zero.13124**13125** xInstCount:13126** Set *pnInst to the total number of occurrences of all phrases within13127** the query within the current row. Return SQLITE_OK if successful, or13128** an error code (i.e. SQLITE_NOMEM) if an error occurs.13129**13130** This API can be quite slow if used with an FTS5 table created with the13131** "detail=none" or "detail=column" option. If the FTS5 table is created13132** with either "detail=none" or "detail=column" and "content=" option13133** (i.e. if it is a contentless table), then this API always returns 0.13134**13135** xInst:13136** Query for the details of phrase match iIdx within the current row.13137** Phrase matches are numbered starting from zero, so the iIdx argument13138** should be greater than or equal to zero and smaller than the value13139** output by xInstCount(). If iIdx is less than zero or greater than13140** or equal to the value returned by xInstCount(), SQLITE_RANGE is returned.13141**13142** Otherwise, output parameter *piPhrase is set to the phrase number, *piCol13143** to the column in which it occurs and *piOff the token offset of the13144** first token of the phrase. SQLITE_OK is returned if successful, or an13145** error code (i.e. SQLITE_NOMEM) if an error occurs.13146**13147** This API can be quite slow if used with an FTS5 table created with the13148** "detail=none" or "detail=column" option.13149**13150** xRowid:13151** Returns the rowid of the current row.13152**13153** xTokenize:13154** Tokenize text using the tokenizer belonging to the FTS5 table.13155**13156** xQueryPhrase(pFts5, iPhrase, pUserData, xCallback):13157** This API function is used to query the FTS table for phrase iPhrase13158** of the current query. Specifically, a query equivalent to:13159**13160** ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid13161**13162** with $p set to a phrase equivalent to the phrase iPhrase of the13163** current query is executed. Any column filter that applies to13164** phrase iPhrase of the current query is included in $p. For each13165** row visited, the callback function passed as the fourth argument13166** is invoked. The context and API objects passed to the callback13167** function may be used to access the properties of each matched row.13168** Invoking Api.xUserData() returns a copy of the pointer passed as13169** the third argument to pUserData.13170**13171** If parameter iPhrase is less than zero, or greater than or equal to13172** the number of phrases in the query, as returned by xPhraseCount(),13173** this function returns SQLITE_RANGE.13174**13175** If the callback function returns any value other than SQLITE_OK, the13176** query is abandoned and the xQueryPhrase function returns immediately.13177** If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK.13178** Otherwise, the error code is propagated upwards.13179**13180** If the query runs to completion without incident, SQLITE_OK is returned.13181** Or, if some error occurs before the query completes or is aborted by13182** the callback, an SQLite error code is returned.13183**13184**13185** xSetAuxdata(pFts5, pAux, xDelete)13186**13187** Save the pointer passed as the second argument as the extension function's13188** "auxiliary data". The pointer may then be retrieved by the current or any13189** future invocation of the same fts5 extension function made as part of13190** the same MATCH query using the xGetAuxdata() API.13191**13192** Each extension function is allocated a single auxiliary data slot for13193** each FTS query (MATCH expression). If the extension function is invoked13194** more than once for a single FTS query, then all invocations share a13195** single auxiliary data context.13196**13197** If there is already an auxiliary data pointer when this function is13198** invoked, then it is replaced by the new pointer. If an xDelete callback13199** was specified along with the original pointer, it is invoked at this13200** point.13201**13202** The xDelete callback, if one is specified, is also invoked on the13203** auxiliary data pointer after the FTS5 query has finished.13204**13205** If an error (e.g. an OOM condition) occurs within this function,13206** the auxiliary data is set to NULL and an error code returned. If the13207** xDelete parameter was not NULL, it is invoked on the auxiliary data13208** pointer before returning.13209**13210**13211** xGetAuxdata(pFts5, bClear)13212**13213** Returns the current auxiliary data pointer for the fts5 extension13214** function. See the xSetAuxdata() method for details.13215**13216** If the bClear argument is non-zero, then the auxiliary data is cleared13217** (set to NULL) before this function returns. In this case the xDelete,13218** if any, is not invoked.13219**13220**13221** xRowCount(pFts5, pnRow)13222**13223** This function is used to retrieve the total number of rows in the table.13224** In other words, the same value that would be returned by:13225**13226** SELECT count(*) FROM ftstable;13227**13228** xPhraseFirst()13229** This function is used, along with type Fts5PhraseIter and the xPhraseNext13230** method, to iterate through all instances of a single query phrase within13231** the current row. This is the same information as is accessible via the13232** xInstCount/xInst APIs. While the xInstCount/xInst APIs are more convenient13233** to use, this API may be faster under some circumstances. To iterate13234** through instances of phrase iPhrase, use the following code:13235**13236** Fts5PhraseIter iter;13237** int iCol, iOff;13238** for(pApi->xPhraseFirst(pFts, iPhrase, &iter, &iCol, &iOff);13239** iCol>=0;13240** pApi->xPhraseNext(pFts, &iter, &iCol, &iOff)13241** ){13242** // An instance of phrase iPhrase at offset iOff of column iCol13243** }13244**13245** The Fts5PhraseIter structure is defined above. Applications should not13246** modify this structure directly - it should only be used as shown above13247** with the xPhraseFirst() and xPhraseNext() API methods (and by13248** xPhraseFirstColumn() and xPhraseNextColumn() as illustrated below).13249**13250** This API can be quite slow if used with an FTS5 table created with the13251** "detail=none" or "detail=column" option. If the FTS5 table is created13252** with either "detail=none" or "detail=column" and "content=" option13253** (i.e. if it is a contentless table), then this API always iterates13254** through an empty set (all calls to xPhraseFirst() set iCol to -1).13255**13256** In all cases, matches are visited in (column ASC, offset ASC) order.13257** i.e. all those in column 0, sorted by offset, followed by those in13258** column 1, etc.13259**13260** xPhraseNext()13261** See xPhraseFirst above.13262**13263** xPhraseFirstColumn()13264** This function and xPhraseNextColumn() are similar to the xPhraseFirst()13265** and xPhraseNext() APIs described above. The difference is that instead13266** of iterating through all instances of a phrase in the current row, these13267** APIs are used to iterate through the set of columns in the current row13268** that contain one or more instances of a specified phrase. For example:13269**13270** Fts5PhraseIter iter;13271** int iCol;13272** for(pApi->xPhraseFirstColumn(pFts, iPhrase, &iter, &iCol);13273** iCol>=0;13274** pApi->xPhraseNextColumn(pFts, &iter, &iCol)13275** ){13276** // Column iCol contains at least one instance of phrase iPhrase13277** }13278**13279** This API can be quite slow if used with an FTS5 table created with the13280** "detail=none" option. If the FTS5 table is created with either13281** "detail=none" "content=" option (i.e. if it is a contentless table),13282** then this API always iterates through an empty set (all calls to13283** xPhraseFirstColumn() set iCol to -1).13284**13285** The information accessed using this API and its companion13286** xPhraseFirstColumn() may also be obtained using xPhraseFirst/xPhraseNext13287** (or xInst/xInstCount). The chief advantage of this API is that it is13288** significantly more efficient than those alternatives when used with13289** "detail=column" tables.13290**13291** xPhraseNextColumn()13292** See xPhraseFirstColumn above.13293**13294** xQueryToken(pFts5, iPhrase, iToken, ppToken, pnToken)13295** This is used to access token iToken of phrase iPhrase of the current13296** query. Before returning, output parameter *ppToken is set to point13297** to a buffer containing the requested token, and *pnToken to the13298** size of this buffer in bytes.13299**13300** If iPhrase or iToken are less than zero, or if iPhrase is greater than13301** or equal to the number of phrases in the query as reported by13302** xPhraseCount(), or if iToken is equal to or greater than the number of13303** tokens in the phrase, SQLITE_RANGE is returned and *ppToken and *pnToken13304are both zeroed.13305**13306** The output text is not a copy of the query text that specified the13307** token. It is the output of the tokenizer module. For tokendata=113308** tables, this includes any embedded 0x00 and trailing data.13309**13310** xInstToken(pFts5, iIdx, iToken, ppToken, pnToken)13311** This is used to access token iToken of phrase hit iIdx within the13312** current row. If iIdx is less than zero or greater than or equal to the13313** value returned by xInstCount(), SQLITE_RANGE is returned. Otherwise,13314** output variable (*ppToken) is set to point to a buffer containing the13315** matching document token, and (*pnToken) to the size of that buffer in13316** bytes.13317**13318** The output text is not a copy of the document text that was tokenized.13319** It is the output of the tokenizer module. For tokendata=1 tables, this13320** includes any embedded 0x00 and trailing data.13321**13322** This API may be slow in some cases if the token identified by parameters13323** iIdx and iToken matched a prefix token in the query. In most cases, the13324** first call to this API for each prefix token in the query is forced13325** to scan the portion of the full-text index that matches the prefix13326** token to collect the extra data required by this API. If the prefix13327** token matches a large number of token instances in the document set,13328** this may be a performance problem.13329**13330** If the user knows in advance that a query may use this API for a13331** prefix token, FTS5 may be configured to collect all required data as part13332** of the initial querying of the full-text index, avoiding the second scan13333** entirely. This also causes prefix queries that do not use this API to13334** run more slowly and use more memory. FTS5 may be configured in this way13335** either on a per-table basis using the [FTS5 insttoken | 'insttoken']13336** option, or on a per-query basis using the13337** [fts5_insttoken | fts5_insttoken()] user function.13338**13339** This API can be quite slow if used with an FTS5 table created with the13340** "detail=none" or "detail=column" option.13341**13342** xColumnLocale(pFts5, iIdx, pzLocale, pnLocale)13343** If parameter iCol is less than zero, or greater than or equal to the13344** number of columns in the table, SQLITE_RANGE is returned.13345**13346** Otherwise, this function attempts to retrieve the locale associated13347** with column iCol of the current row. Usually, there is no associated13348** locale, and output parameters (*pzLocale) and (*pnLocale) are set13349** to NULL and 0, respectively. However, if the fts5_locale() function13350** was used to associate a locale with the value when it was inserted13351** into the fts5 table, then (*pzLocale) is set to point to a nul-terminated13352** buffer containing the name of the locale in utf-8 encoding. (*pnLocale)13353** is set to the size in bytes of the buffer, not including the13354** nul-terminator.13355**13356** If successful, SQLITE_OK is returned. Or, if an error occurs, an13357** SQLite error code is returned. The final value of the output parameters13358** is undefined in this case.13359**13360** xTokenize_v2:13361** Tokenize text using the tokenizer belonging to the FTS5 table. This13362** API is the same as the xTokenize() API, except that it allows a tokenizer13363** locale to be specified.13364*/13365struct Fts5ExtensionApi {13366int iVersion; /* Currently always set to 4 */1336713368void *(*xUserData)(Fts5Context*);1336913370int (*xColumnCount)(Fts5Context*);13371int (*xRowCount)(Fts5Context*, sqlite3_int64 *pnRow);13372int (*xColumnTotalSize)(Fts5Context*, int iCol, sqlite3_int64 *pnToken);1337313374int (*xTokenize)(Fts5Context*,13375const char *pText, int nText, /* Text to tokenize */13376void *pCtx, /* Context passed to xToken() */13377int (*xToken)(void*, int, const char*, int, int, int) /* Callback */13378);1337913380int (*xPhraseCount)(Fts5Context*);13381int (*xPhraseSize)(Fts5Context*, int iPhrase);1338213383int (*xInstCount)(Fts5Context*, int *pnInst);13384int (*xInst)(Fts5Context*, int iIdx, int *piPhrase, int *piCol, int *piOff);1338513386sqlite3_int64 (*xRowid)(Fts5Context*);13387int (*xColumnText)(Fts5Context*, int iCol, const char **pz, int *pn);13388int (*xColumnSize)(Fts5Context*, int iCol, int *pnToken);1338913390int (*xQueryPhrase)(Fts5Context*, int iPhrase, void *pUserData,13391int(*)(const Fts5ExtensionApi*,Fts5Context*,void*)13392);13393int (*xSetAuxdata)(Fts5Context*, void *pAux, void(*xDelete)(void*));13394void *(*xGetAuxdata)(Fts5Context*, int bClear);1339513396int (*xPhraseFirst)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*, int*);13397void (*xPhraseNext)(Fts5Context*, Fts5PhraseIter*, int *piCol, int *piOff);1339813399int (*xPhraseFirstColumn)(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*);13400void (*xPhraseNextColumn)(Fts5Context*, Fts5PhraseIter*, int *piCol);1340113402/* Below this point are iVersion>=3 only */13403int (*xQueryToken)(Fts5Context*,13404int iPhrase, int iToken,13405const char **ppToken, int *pnToken13406);13407int (*xInstToken)(Fts5Context*, int iIdx, int iToken, const char**, int*);1340813409/* Below this point are iVersion>=4 only */13410int (*xColumnLocale)(Fts5Context*, int iCol, const char **pz, int *pn);13411int (*xTokenize_v2)(Fts5Context*,13412const char *pText, int nText, /* Text to tokenize */13413const char *pLocale, int nLocale, /* Locale to pass to tokenizer */13414void *pCtx, /* Context passed to xToken() */13415int (*xToken)(void*, int, const char*, int, int, int) /* Callback */13416);13417};1341813419/*13420** CUSTOM AUXILIARY FUNCTIONS13421*************************************************************************/1342213423/*************************************************************************13424** CUSTOM TOKENIZERS13425**13426** Applications may also register custom tokenizer types. A tokenizer13427** is registered by providing fts5 with a populated instance of the13428** following structure. All structure methods must be defined, setting13429** any member of the fts5_tokenizer struct to NULL leads to undefined13430** behaviour. The structure methods are expected to function as follows:13431**13432** xCreate:13433** This function is used to allocate and initialize a tokenizer instance.13434** A tokenizer instance is required to actually tokenize text.13435**13436** The first argument passed to this function is a copy of the (void*)13437** pointer provided by the application when the fts5_tokenizer_v2 object13438** was registered with FTS5 (the third argument to xCreateTokenizer()).13439** The second and third arguments are an array of nul-terminated strings13440** containing the tokenizer arguments, if any, specified following the13441** tokenizer name as part of the CREATE VIRTUAL TABLE statement used13442** to create the FTS5 table.13443**13444** The final argument is an output variable. If successful, (*ppOut)13445** should be set to point to the new tokenizer handle and SQLITE_OK13446** returned. If an error occurs, some value other than SQLITE_OK should13447** be returned. In this case, fts5 assumes that the final value of *ppOut13448** is undefined.13449**13450** xDelete:13451** This function is invoked to delete a tokenizer handle previously13452** allocated using xCreate(). Fts5 guarantees that this function will13453** be invoked exactly once for each successful call to xCreate().13454**13455** xTokenize:13456** This function is expected to tokenize the nText byte string indicated13457** by argument pText. pText may or may not be nul-terminated. The first13458** argument passed to this function is a pointer to an Fts5Tokenizer object13459** returned by an earlier call to xCreate().13460**13461** The third argument indicates the reason that FTS5 is requesting13462** tokenization of the supplied text. This is always one of the following13463** four values:13464**13465** <ul><li> <b>FTS5_TOKENIZE_DOCUMENT</b> - A document is being inserted into13466** or removed from the FTS table. The tokenizer is being invoked to13467** determine the set of tokens to add to (or delete from) the13468** FTS index.13469**13470** <li> <b>FTS5_TOKENIZE_QUERY</b> - A MATCH query is being executed13471** against the FTS index. The tokenizer is being called to tokenize13472** a bareword or quoted string specified as part of the query.13473**13474** <li> <b>(FTS5_TOKENIZE_QUERY | FTS5_TOKENIZE_PREFIX)</b> - Same as13475** FTS5_TOKENIZE_QUERY, except that the bareword or quoted string is13476** followed by a "*" character, indicating that the last token13477** returned by the tokenizer will be treated as a token prefix.13478**13479** <li> <b>FTS5_TOKENIZE_AUX</b> - The tokenizer is being invoked to13480** satisfy an fts5_api.xTokenize() request made by an auxiliary13481** function. Or an fts5_api.xColumnSize() request made by the same13482** on a columnsize=0 database.13483** </ul>13484**13485** The sixth and seventh arguments passed to xTokenize() - pLocale and13486** nLocale - are a pointer to a buffer containing the locale to use for13487** tokenization (e.g. "en_US") and its size in bytes, respectively. The13488** pLocale buffer is not nul-terminated. pLocale may be passed NULL (in13489** which case nLocale is always 0) to indicate that the tokenizer should13490** use its default locale.13491**13492** For each token in the input string, the supplied callback xToken() must13493** be invoked. The first argument to it should be a copy of the pointer13494** passed as the second argument to xTokenize(). The third and fourth13495** arguments are a pointer to a buffer containing the token text, and the13496** size of the token in bytes. The 4th and 5th arguments are the byte offsets13497** of the first byte of and first byte immediately following the text from13498** which the token is derived within the input.13499**13500** The second argument passed to the xToken() callback ("tflags") should13501** normally be set to 0. The exception is if the tokenizer supports13502** synonyms. In this case see the discussion below for details.13503**13504** FTS5 assumes the xToken() callback is invoked for each token in the13505** order that they occur within the input text.13506**13507** If an xToken() callback returns any value other than SQLITE_OK, then13508** the tokenization should be abandoned and the xTokenize() method should13509** immediately return a copy of the xToken() return value. Or, if the13510** input buffer is exhausted, xTokenize() should return SQLITE_OK. Finally,13511** if an error occurs with the xTokenize() implementation itself, it13512** may abandon the tokenization and return any error code other than13513** SQLITE_OK or SQLITE_DONE.13514**13515** If the tokenizer is registered using an fts5_tokenizer_v2 object,13516** then the xTokenize() method has two additional arguments - pLocale13517** and nLocale. These specify the locale that the tokenizer should use13518** for the current request. If pLocale and nLocale are both 0, then the13519** tokenizer should use its default locale. Otherwise, pLocale points to13520** an nLocale byte buffer containing the name of the locale to use as utf-813521** text. pLocale is not nul-terminated.13522**13523** FTS5_TOKENIZER13524**13525** There is also an fts5_tokenizer object. This is an older, deprecated,13526** version of fts5_tokenizer_v2. It is similar except that:13527**13528** <ul>13529** <li> There is no "iVersion" field, and13530** <li> The xTokenize() method does not take a locale argument.13531** </ul>13532**13533** Legacy fts5_tokenizer tokenizers must be registered using the13534** legacy xCreateTokenizer() function, instead of xCreateTokenizer_v2().13535**13536** Tokenizer implementations registered using either API may be retrieved13537** using both xFindTokenizer() and xFindTokenizer_v2().13538**13539** SYNONYM SUPPORT13540**13541** Custom tokenizers may also support synonyms. Consider a case in which a13542** user wishes to query for a phrase such as "first place". Using the13543** built-in tokenizers, the FTS5 query 'first + place' will match instances13544** of "first place" within the document set, but not alternative forms13545** such as "1st place". In some applications, it would be better to match13546** all instances of "first place" or "1st place" regardless of which form13547** the user specified in the MATCH query text.13548**13549** There are several ways to approach this in FTS5:13550**13551** <ol><li> By mapping all synonyms to a single token. In this case, using13552** the above example, this means that the tokenizer returns the13553** same token for inputs "first" and "1st". Say that token is in13554** fact "first", so that when the user inserts the document "I won13555** 1st place" entries are added to the index for tokens "i", "won",13556** "first" and "place". If the user then queries for '1st + place',13557** the tokenizer substitutes "first" for "1st" and the query works13558** as expected.13559**13560** <li> By querying the index for all synonyms of each query term13561** separately. In this case, when tokenizing query text, the13562** tokenizer may provide multiple synonyms for a single term13563** within the document. FTS5 then queries the index for each13564** synonym individually. For example, faced with the query:13565**13566** <codeblock>13567** ... MATCH 'first place'</codeblock>13568**13569** the tokenizer offers both "1st" and "first" as synonyms for the13570** first token in the MATCH query and FTS5 effectively runs a query13571** similar to:13572**13573** <codeblock>13574** ... MATCH '(first OR 1st) place'</codeblock>13575**13576** except that, for the purposes of auxiliary functions, the query13577** still appears to contain just two phrases - "(first OR 1st)"13578** being treated as a single phrase.13579**13580** <li> By adding multiple synonyms for a single term to the FTS index.13581** Using this method, when tokenizing document text, the tokenizer13582** provides multiple synonyms for each token. So that when a13583** document such as "I won first place" is tokenized, entries are13584** added to the FTS index for "i", "won", "first", "1st" and13585** "place".13586**13587** This way, even if the tokenizer does not provide synonyms13588** when tokenizing query text (it should not - to do so would be13589** inefficient), it doesn't matter if the user queries for13590** 'first + place' or '1st + place', as there are entries in the13591** FTS index corresponding to both forms of the first token.13592** </ol>13593**13594** Whether it is parsing document or query text, any call to xToken that13595** specifies a <i>tflags</i> argument with the FTS5_TOKEN_COLOCATED bit13596** is considered to supply a synonym for the previous token. For example,13597** when parsing the document "I won first place", a tokenizer that supports13598** synonyms would call xToken() 5 times, as follows:13599**13600** <codeblock>13601** xToken(pCtx, 0, "i", 1, 0, 1);13602** xToken(pCtx, 0, "won", 3, 2, 5);13603** xToken(pCtx, 0, "first", 5, 6, 11);13604** xToken(pCtx, FTS5_TOKEN_COLOCATED, "1st", 3, 6, 11);13605** xToken(pCtx, 0, "place", 5, 12, 17);13606**</codeblock>13607**13608** It is an error to specify the FTS5_TOKEN_COLOCATED flag the first time13609** xToken() is called. Multiple synonyms may be specified for a single token13610** by making multiple calls to xToken(FTS5_TOKEN_COLOCATED) in sequence.13611** There is no limit to the number of synonyms that may be provided for a13612** single token.13613**13614** In many cases, method (1) above is the best approach. It does not add13615** extra data to the FTS index or require FTS5 to query for multiple terms,13616** so it is efficient in terms of disk space and query speed. However, it13617** does not support prefix queries very well. If, as suggested above, the13618** token "first" is substituted for "1st" by the tokenizer, then the query:13619**13620** <codeblock>13621** ... MATCH '1s*'</codeblock>13622**13623** will not match documents that contain the token "1st" (as the tokenizer13624** will probably not map "1s" to any prefix of "first").13625**13626** For full prefix support, method (3) may be preferred. In this case,13627** because the index contains entries for both "first" and "1st", prefix13628** queries such as 'fi*' or '1s*' will match correctly. However, because13629** extra entries are added to the FTS index, this method uses more space13630** within the database.13631**13632** Method (2) offers a midpoint between (1) and (3). Using this method,13633** a query such as '1s*' will match documents that contain the literal13634** token "1st", but not "first" (assuming the tokenizer is not able to13635** provide synonyms for prefixes). However, a non-prefix query like '1st'13636** will match against "1st" and "first". This method does not require13637** extra disk space, as no extra entries are added to the FTS index.13638** On the other hand, it may require more CPU cycles to run MATCH queries,13639** as separate queries of the FTS index are required for each synonym.13640**13641** When using methods (2) or (3), it is important that the tokenizer only13642** provide synonyms when tokenizing document text (method (3)) or query13643** text (method (2)), not both. Doing so will not cause any errors, but is13644** inefficient.13645*/13646typedef struct Fts5Tokenizer Fts5Tokenizer;13647typedef struct fts5_tokenizer_v2 fts5_tokenizer_v2;13648struct fts5_tokenizer_v2 {13649int iVersion; /* Currently always 2 */1365013651int (*xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut);13652void (*xDelete)(Fts5Tokenizer*);13653int (*xTokenize)(Fts5Tokenizer*,13654void *pCtx,13655int flags, /* Mask of FTS5_TOKENIZE_* flags */13656const char *pText, int nText,13657const char *pLocale, int nLocale,13658int (*xToken)(13659void *pCtx, /* Copy of 2nd argument to xTokenize() */13660int tflags, /* Mask of FTS5_TOKEN_* flags */13661const char *pToken, /* Pointer to buffer containing token */13662int nToken, /* Size of token in bytes */13663int iStart, /* Byte offset of token within input text */13664int iEnd /* Byte offset of end of token within input text */13665)13666);13667};1366813669/*13670** New code should use the fts5_tokenizer_v2 type to define tokenizer13671** implementations. The following type is included for legacy applications13672** that still use it.13673*/13674typedef struct fts5_tokenizer fts5_tokenizer;13675struct fts5_tokenizer {13676int (*xCreate)(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut);13677void (*xDelete)(Fts5Tokenizer*);13678int (*xTokenize)(Fts5Tokenizer*,13679void *pCtx,13680int flags, /* Mask of FTS5_TOKENIZE_* flags */13681const char *pText, int nText,13682int (*xToken)(13683void *pCtx, /* Copy of 2nd argument to xTokenize() */13684int tflags, /* Mask of FTS5_TOKEN_* flags */13685const char *pToken, /* Pointer to buffer containing token */13686int nToken, /* Size of token in bytes */13687int iStart, /* Byte offset of token within input text */13688int iEnd /* Byte offset of end of token within input text */13689)13690);13691};136921369313694/* Flags that may be passed as the third argument to xTokenize() */13695#define FTS5_TOKENIZE_QUERY 0x000113696#define FTS5_TOKENIZE_PREFIX 0x000213697#define FTS5_TOKENIZE_DOCUMENT 0x000413698#define FTS5_TOKENIZE_AUX 0x00081369913700/* Flags that may be passed by the tokenizer implementation back to FTS513701** as the third argument to the supplied xToken callback. */13702#define FTS5_TOKEN_COLOCATED 0x0001 /* Same position as prev. token */1370313704/*13705** END OF CUSTOM TOKENIZERS13706*************************************************************************/1370713708/*************************************************************************13709** FTS5 EXTENSION REGISTRATION API13710*/13711typedef struct fts5_api fts5_api;13712struct fts5_api {13713int iVersion; /* Currently always set to 3 */1371413715/* Create a new tokenizer */13716int (*xCreateTokenizer)(13717fts5_api *pApi,13718const char *zName,13719void *pUserData,13720fts5_tokenizer *pTokenizer,13721void (*xDestroy)(void*)13722);1372313724/* Find an existing tokenizer */13725int (*xFindTokenizer)(13726fts5_api *pApi,13727const char *zName,13728void **ppUserData,13729fts5_tokenizer *pTokenizer13730);1373113732/* Create a new auxiliary function */13733int (*xCreateFunction)(13734fts5_api *pApi,13735const char *zName,13736void *pUserData,13737fts5_extension_function xFunction,13738void (*xDestroy)(void*)13739);1374013741/* APIs below this point are only available if iVersion>=3 */1374213743/* Create a new tokenizer */13744int (*xCreateTokenizer_v2)(13745fts5_api *pApi,13746const char *zName,13747void *pUserData,13748fts5_tokenizer_v2 *pTokenizer,13749void (*xDestroy)(void*)13750);1375113752/* Find an existing tokenizer */13753int (*xFindTokenizer_v2)(13754fts5_api *pApi,13755const char *zName,13756void **ppUserData,13757fts5_tokenizer_v2 **ppTokenizer13758);13759};1376013761/*13762** END OF REGISTRATION API13763*************************************************************************/1376413765#ifdef __cplusplus13766} /* end of the 'extern "C"' block */13767#endif1376813769#endif /* _FTS5_H */1377013771/******** End of fts5.h *********/13772#endif /* SQLITE3_H */137731377413775