111be35a1SLionel Sambuc /* 211be35a1SLionel Sambuc ** 2001 September 15 311be35a1SLionel Sambuc ** 411be35a1SLionel Sambuc ** The author disclaims copyright to this source code. In place of 511be35a1SLionel Sambuc ** a legal notice, here is a blessing: 611be35a1SLionel Sambuc ** 711be35a1SLionel Sambuc ** May you do good and not evil. 811be35a1SLionel Sambuc ** May you find forgiveness for yourself and forgive others. 911be35a1SLionel Sambuc ** May you share freely, never taking more than you give. 1011be35a1SLionel Sambuc ** 1111be35a1SLionel Sambuc ************************************************************************* 1211be35a1SLionel Sambuc ** This header file defines the interface that the SQLite library 1311be35a1SLionel Sambuc ** presents to client programs. If a C-function, structure, datatype, 1411be35a1SLionel Sambuc ** or constant definition does not appear in this file, then it is 1511be35a1SLionel Sambuc ** not a published API of SQLite, is subject to change without 1611be35a1SLionel Sambuc ** notice, and should not be referenced by programs that use SQLite. 1711be35a1SLionel Sambuc ** 1811be35a1SLionel Sambuc ** Some of the definitions that are in this file are marked as 1911be35a1SLionel Sambuc ** "experimental". Experimental interfaces are normally new 2011be35a1SLionel Sambuc ** features recently added to SQLite. We do not anticipate changes 2111be35a1SLionel Sambuc ** to experimental interfaces but reserve the right to make minor changes 2211be35a1SLionel Sambuc ** if experience from use "in the wild" suggest such changes are prudent. 2311be35a1SLionel Sambuc ** 2411be35a1SLionel Sambuc ** The official C-language API documentation for SQLite is derived 2511be35a1SLionel Sambuc ** from comments in this file. This file is the authoritative source 2611be35a1SLionel Sambuc ** on how SQLite interfaces are suppose to operate. 2711be35a1SLionel Sambuc ** 2811be35a1SLionel Sambuc ** The name of this file under configuration management is "sqlite.h.in". 2911be35a1SLionel Sambuc ** The makefile makes some minor changes to this file (such as inserting 3011be35a1SLionel Sambuc ** the version number) and changes its name to "sqlite3.h" as 3111be35a1SLionel Sambuc ** part of the build process. 3211be35a1SLionel Sambuc */ 3311be35a1SLionel Sambuc #ifndef _SQLITE3_H_ 3411be35a1SLionel Sambuc #define _SQLITE3_H_ 3511be35a1SLionel Sambuc #include <stdarg.h> /* Needed for the definition of va_list */ 3611be35a1SLionel Sambuc 3711be35a1SLionel Sambuc /* 3811be35a1SLionel Sambuc ** Make sure we can call this stuff from C++. 3911be35a1SLionel Sambuc */ 4011be35a1SLionel Sambuc #ifdef __cplusplus 4111be35a1SLionel Sambuc extern "C" { 4211be35a1SLionel Sambuc #endif 4311be35a1SLionel Sambuc 4411be35a1SLionel Sambuc 4511be35a1SLionel Sambuc /* 4611be35a1SLionel Sambuc ** Add the ability to override 'extern' 4711be35a1SLionel Sambuc */ 4811be35a1SLionel Sambuc #ifndef SQLITE_EXTERN 4911be35a1SLionel Sambuc # define SQLITE_EXTERN extern 5011be35a1SLionel Sambuc #endif 5111be35a1SLionel Sambuc 5211be35a1SLionel Sambuc #ifndef SQLITE_API 5311be35a1SLionel Sambuc # define SQLITE_API 5411be35a1SLionel Sambuc #endif 5511be35a1SLionel Sambuc 5611be35a1SLionel Sambuc 5711be35a1SLionel Sambuc /* 5811be35a1SLionel Sambuc ** These no-op macros are used in front of interfaces to mark those 5911be35a1SLionel Sambuc ** interfaces as either deprecated or experimental. New applications 6011be35a1SLionel Sambuc ** should not use deprecated interfaces - they are support for backwards 6111be35a1SLionel Sambuc ** compatibility only. Application writers should be aware that 6211be35a1SLionel Sambuc ** experimental interfaces are subject to change in point releases. 6311be35a1SLionel Sambuc ** 6411be35a1SLionel Sambuc ** These macros used to resolve to various kinds of compiler magic that 6511be35a1SLionel Sambuc ** would generate warning messages when they were used. But that 6611be35a1SLionel Sambuc ** compiler magic ended up generating such a flurry of bug reports 6711be35a1SLionel Sambuc ** that we have taken it all out and gone back to using simple 6811be35a1SLionel Sambuc ** noop macros. 6911be35a1SLionel Sambuc */ 7011be35a1SLionel Sambuc #define SQLITE_DEPRECATED 7111be35a1SLionel Sambuc #define SQLITE_EXPERIMENTAL 7211be35a1SLionel Sambuc 7311be35a1SLionel Sambuc /* 7411be35a1SLionel Sambuc ** Ensure these symbols were not defined by some previous header file. 7511be35a1SLionel Sambuc */ 7611be35a1SLionel Sambuc #ifdef SQLITE_VERSION 7711be35a1SLionel Sambuc # undef SQLITE_VERSION 7811be35a1SLionel Sambuc #endif 7911be35a1SLionel Sambuc #ifdef SQLITE_VERSION_NUMBER 8011be35a1SLionel Sambuc # undef SQLITE_VERSION_NUMBER 8111be35a1SLionel Sambuc #endif 8211be35a1SLionel Sambuc 8311be35a1SLionel Sambuc /* 8411be35a1SLionel Sambuc ** CAPI3REF: Compile-Time Library Version Numbers 8511be35a1SLionel Sambuc ** 8611be35a1SLionel Sambuc ** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header 8711be35a1SLionel Sambuc ** evaluates to a string literal that is the SQLite version in the 8811be35a1SLionel Sambuc ** format "X.Y.Z" where X is the major version number (always 3 for 8911be35a1SLionel Sambuc ** SQLite3) and Y is the minor version number and Z is the release number.)^ 9011be35a1SLionel Sambuc ** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer 9111be35a1SLionel Sambuc ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same 9211be35a1SLionel Sambuc ** numbers used in [SQLITE_VERSION].)^ 9311be35a1SLionel Sambuc ** The SQLITE_VERSION_NUMBER for any given release of SQLite will also 9411be35a1SLionel Sambuc ** be larger than the release from which it is derived. Either Y will 9511be35a1SLionel Sambuc ** be held constant and Z will be incremented or else Y will be incremented 9611be35a1SLionel Sambuc ** and Z will be reset to zero. 9711be35a1SLionel Sambuc ** 9811be35a1SLionel Sambuc ** Since version 3.6.18, SQLite source code has been stored in the 9911be35a1SLionel Sambuc ** <a href="http://www.fossil-scm.org/">Fossil configuration management 10011be35a1SLionel Sambuc ** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to 10111be35a1SLionel Sambuc ** a string which identifies a particular check-in of SQLite 10211be35a1SLionel Sambuc ** within its configuration management system. ^The SQLITE_SOURCE_ID 10311be35a1SLionel Sambuc ** string contains the date and time of the check-in (UTC) and an SHA1 10411be35a1SLionel Sambuc ** hash of the entire source tree. 10511be35a1SLionel Sambuc ** 10611be35a1SLionel Sambuc ** See also: [sqlite3_libversion()], 10711be35a1SLionel Sambuc ** [sqlite3_libversion_number()], [sqlite3_sourceid()], 10811be35a1SLionel Sambuc ** [sqlite_version()] and [sqlite_source_id()]. 10911be35a1SLionel Sambuc */ 110*0a6a1f1dSLionel Sambuc #define SQLITE_VERSION "3.8.3.1" 111*0a6a1f1dSLionel Sambuc #define SQLITE_VERSION_NUMBER 3008003 112*0a6a1f1dSLionel Sambuc #define SQLITE_SOURCE_ID "2014-02-11 14:52:19 ea3317a4803d71d88183b29f1d3086f46d68a00e" 11311be35a1SLionel Sambuc 11411be35a1SLionel Sambuc /* 11511be35a1SLionel Sambuc ** CAPI3REF: Run-Time Library Version Numbers 11611be35a1SLionel Sambuc ** KEYWORDS: sqlite3_version, sqlite3_sourceid 11711be35a1SLionel Sambuc ** 11811be35a1SLionel Sambuc ** These interfaces provide the same information as the [SQLITE_VERSION], 11911be35a1SLionel Sambuc ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros 12011be35a1SLionel Sambuc ** but are associated with the library instead of the header file. ^(Cautious 12111be35a1SLionel Sambuc ** programmers might include assert() statements in their application to 12211be35a1SLionel Sambuc ** verify that values returned by these interfaces match the macros in 12311be35a1SLionel Sambuc ** the header, and thus insure that the application is 12411be35a1SLionel Sambuc ** compiled with matching library and header files. 12511be35a1SLionel Sambuc ** 12611be35a1SLionel Sambuc ** <blockquote><pre> 12711be35a1SLionel Sambuc ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER ); 12811be35a1SLionel Sambuc ** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 ); 12911be35a1SLionel Sambuc ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 ); 13011be35a1SLionel Sambuc ** </pre></blockquote>)^ 13111be35a1SLionel Sambuc ** 13211be35a1SLionel Sambuc ** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION] 13311be35a1SLionel Sambuc ** macro. ^The sqlite3_libversion() function returns a pointer to the 13411be35a1SLionel Sambuc ** to the sqlite3_version[] string constant. The sqlite3_libversion() 13511be35a1SLionel Sambuc ** function is provided for use in DLLs since DLL users usually do not have 13611be35a1SLionel Sambuc ** direct access to string constants within the DLL. ^The 13711be35a1SLionel Sambuc ** sqlite3_libversion_number() function returns an integer equal to 13811be35a1SLionel Sambuc ** [SQLITE_VERSION_NUMBER]. ^The sqlite3_sourceid() function returns 13911be35a1SLionel Sambuc ** a pointer to a string constant whose value is the same as the 14011be35a1SLionel Sambuc ** [SQLITE_SOURCE_ID] C preprocessor macro. 14111be35a1SLionel Sambuc ** 14211be35a1SLionel Sambuc ** See also: [sqlite_version()] and [sqlite_source_id()]. 14311be35a1SLionel Sambuc */ 14411be35a1SLionel Sambuc SQLITE_API SQLITE_EXTERN const char sqlite3_version[]; 14511be35a1SLionel Sambuc SQLITE_API const char *sqlite3_libversion(void); 14611be35a1SLionel Sambuc SQLITE_API const char *sqlite3_sourceid(void); 14711be35a1SLionel Sambuc SQLITE_API int sqlite3_libversion_number(void); 14811be35a1SLionel Sambuc 14911be35a1SLionel Sambuc /* 15011be35a1SLionel Sambuc ** CAPI3REF: Run-Time Library Compilation Options Diagnostics 15111be35a1SLionel Sambuc ** 15211be35a1SLionel Sambuc ** ^The sqlite3_compileoption_used() function returns 0 or 1 15311be35a1SLionel Sambuc ** indicating whether the specified option was defined at 15411be35a1SLionel Sambuc ** compile time. ^The SQLITE_ prefix may be omitted from the 15511be35a1SLionel Sambuc ** option name passed to sqlite3_compileoption_used(). 15611be35a1SLionel Sambuc ** 15711be35a1SLionel Sambuc ** ^The sqlite3_compileoption_get() function allows iterating 15811be35a1SLionel Sambuc ** over the list of options that were defined at compile time by 15911be35a1SLionel Sambuc ** returning the N-th compile time option string. ^If N is out of range, 16011be35a1SLionel Sambuc ** sqlite3_compileoption_get() returns a NULL pointer. ^The SQLITE_ 16111be35a1SLionel Sambuc ** prefix is omitted from any strings returned by 16211be35a1SLionel Sambuc ** sqlite3_compileoption_get(). 16311be35a1SLionel Sambuc ** 16411be35a1SLionel Sambuc ** ^Support for the diagnostic functions sqlite3_compileoption_used() 16511be35a1SLionel Sambuc ** and sqlite3_compileoption_get() may be omitted by specifying the 16611be35a1SLionel Sambuc ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time. 16711be35a1SLionel Sambuc ** 16811be35a1SLionel Sambuc ** See also: SQL functions [sqlite_compileoption_used()] and 16911be35a1SLionel Sambuc ** [sqlite_compileoption_get()] and the [compile_options pragma]. 17011be35a1SLionel Sambuc */ 17111be35a1SLionel Sambuc #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS 17211be35a1SLionel Sambuc SQLITE_API int sqlite3_compileoption_used(const char *zOptName); 17311be35a1SLionel Sambuc SQLITE_API const char *sqlite3_compileoption_get(int N); 17411be35a1SLionel Sambuc #endif 17511be35a1SLionel Sambuc 17611be35a1SLionel Sambuc /* 17711be35a1SLionel Sambuc ** CAPI3REF: Test To See If The Library Is Threadsafe 17811be35a1SLionel Sambuc ** 17911be35a1SLionel Sambuc ** ^The sqlite3_threadsafe() function returns zero if and only if 18011be35a1SLionel Sambuc ** SQLite was compiled with mutexing code omitted due to the 18111be35a1SLionel Sambuc ** [SQLITE_THREADSAFE] compile-time option being set to 0. 18211be35a1SLionel Sambuc ** 18311be35a1SLionel Sambuc ** SQLite can be compiled with or without mutexes. When 18411be35a1SLionel Sambuc ** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes 18511be35a1SLionel Sambuc ** are enabled and SQLite is threadsafe. When the 18611be35a1SLionel Sambuc ** [SQLITE_THREADSAFE] macro is 0, 18711be35a1SLionel Sambuc ** the mutexes are omitted. Without the mutexes, it is not safe 18811be35a1SLionel Sambuc ** to use SQLite concurrently from more than one thread. 18911be35a1SLionel Sambuc ** 19011be35a1SLionel Sambuc ** Enabling mutexes incurs a measurable performance penalty. 19111be35a1SLionel Sambuc ** So if speed is of utmost importance, it makes sense to disable 19211be35a1SLionel Sambuc ** the mutexes. But for maximum safety, mutexes should be enabled. 19311be35a1SLionel Sambuc ** ^The default behavior is for mutexes to be enabled. 19411be35a1SLionel Sambuc ** 19511be35a1SLionel Sambuc ** This interface can be used by an application to make sure that the 19611be35a1SLionel Sambuc ** version of SQLite that it is linking against was compiled with 19711be35a1SLionel Sambuc ** the desired setting of the [SQLITE_THREADSAFE] macro. 19811be35a1SLionel Sambuc ** 19911be35a1SLionel Sambuc ** This interface only reports on the compile-time mutex setting 20011be35a1SLionel Sambuc ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with 20111be35a1SLionel Sambuc ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but 20211be35a1SLionel Sambuc ** can be fully or partially disabled using a call to [sqlite3_config()] 20311be35a1SLionel Sambuc ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD], 20411be35a1SLionel Sambuc ** or [SQLITE_CONFIG_MUTEX]. ^(The return value of the 20511be35a1SLionel Sambuc ** sqlite3_threadsafe() function shows only the compile-time setting of 20611be35a1SLionel Sambuc ** thread safety, not any run-time changes to that setting made by 20711be35a1SLionel Sambuc ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe() 20811be35a1SLionel Sambuc ** is unchanged by calls to sqlite3_config().)^ 20911be35a1SLionel Sambuc ** 21011be35a1SLionel Sambuc ** See the [threading mode] documentation for additional information. 21111be35a1SLionel Sambuc */ 21211be35a1SLionel Sambuc SQLITE_API int sqlite3_threadsafe(void); 21311be35a1SLionel Sambuc 21411be35a1SLionel Sambuc /* 21511be35a1SLionel Sambuc ** CAPI3REF: Database Connection Handle 21611be35a1SLionel Sambuc ** KEYWORDS: {database connection} {database connections} 21711be35a1SLionel Sambuc ** 21811be35a1SLionel Sambuc ** Each open SQLite database is represented by a pointer to an instance of 21911be35a1SLionel Sambuc ** the opaque structure named "sqlite3". It is useful to think of an sqlite3 22011be35a1SLionel Sambuc ** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and 22111be35a1SLionel Sambuc ** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()] 222*0a6a1f1dSLionel Sambuc ** and [sqlite3_close_v2()] are its destructors. There are many other 223*0a6a1f1dSLionel Sambuc ** interfaces (such as 22411be35a1SLionel Sambuc ** [sqlite3_prepare_v2()], [sqlite3_create_function()], and 22511be35a1SLionel Sambuc ** [sqlite3_busy_timeout()] to name but three) that are methods on an 22611be35a1SLionel Sambuc ** sqlite3 object. 22711be35a1SLionel Sambuc */ 22811be35a1SLionel Sambuc typedef struct sqlite3 sqlite3; 22911be35a1SLionel Sambuc 23011be35a1SLionel Sambuc /* 23111be35a1SLionel Sambuc ** CAPI3REF: 64-Bit Integer Types 23211be35a1SLionel Sambuc ** KEYWORDS: sqlite_int64 sqlite_uint64 23311be35a1SLionel Sambuc ** 23411be35a1SLionel Sambuc ** Because there is no cross-platform way to specify 64-bit integer types 23511be35a1SLionel Sambuc ** SQLite includes typedefs for 64-bit signed and unsigned integers. 23611be35a1SLionel Sambuc ** 23711be35a1SLionel Sambuc ** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions. 23811be35a1SLionel Sambuc ** The sqlite_int64 and sqlite_uint64 types are supported for backwards 23911be35a1SLionel Sambuc ** compatibility only. 24011be35a1SLionel Sambuc ** 24111be35a1SLionel Sambuc ** ^The sqlite3_int64 and sqlite_int64 types can store integer values 24211be35a1SLionel Sambuc ** between -9223372036854775808 and +9223372036854775807 inclusive. ^The 24311be35a1SLionel Sambuc ** sqlite3_uint64 and sqlite_uint64 types can store integer values 24411be35a1SLionel Sambuc ** between 0 and +18446744073709551615 inclusive. 24511be35a1SLionel Sambuc */ 24611be35a1SLionel Sambuc #ifdef SQLITE_INT64_TYPE 24711be35a1SLionel Sambuc typedef SQLITE_INT64_TYPE sqlite_int64; 24811be35a1SLionel Sambuc typedef unsigned SQLITE_INT64_TYPE sqlite_uint64; 24911be35a1SLionel Sambuc #elif defined(_MSC_VER) || defined(__BORLANDC__) 25011be35a1SLionel Sambuc typedef __int64 sqlite_int64; 25111be35a1SLionel Sambuc typedef unsigned __int64 sqlite_uint64; 25211be35a1SLionel Sambuc #else 25311be35a1SLionel Sambuc typedef long long int sqlite_int64; 25411be35a1SLionel Sambuc typedef unsigned long long int sqlite_uint64; 25511be35a1SLionel Sambuc #endif 25611be35a1SLionel Sambuc typedef sqlite_int64 sqlite3_int64; 25711be35a1SLionel Sambuc typedef sqlite_uint64 sqlite3_uint64; 25811be35a1SLionel Sambuc 25911be35a1SLionel Sambuc /* 26011be35a1SLionel Sambuc ** If compiling for a processor that lacks floating point support, 26111be35a1SLionel Sambuc ** substitute integer for floating-point. 26211be35a1SLionel Sambuc */ 26311be35a1SLionel Sambuc #ifdef SQLITE_OMIT_FLOATING_POINT 26411be35a1SLionel Sambuc # define double sqlite3_int64 26511be35a1SLionel Sambuc #endif 26611be35a1SLionel Sambuc 26711be35a1SLionel Sambuc /* 26811be35a1SLionel Sambuc ** CAPI3REF: Closing A Database Connection 26911be35a1SLionel Sambuc ** 270*0a6a1f1dSLionel Sambuc ** ^The sqlite3_close() and sqlite3_close_v2() routines are destructors 271*0a6a1f1dSLionel Sambuc ** for the [sqlite3] object. 272*0a6a1f1dSLionel Sambuc ** ^Calls to sqlite3_close() and sqlite3_close_v2() return SQLITE_OK if 273*0a6a1f1dSLionel Sambuc ** the [sqlite3] object is successfully destroyed and all associated 274*0a6a1f1dSLionel Sambuc ** resources are deallocated. 27511be35a1SLionel Sambuc ** 276*0a6a1f1dSLionel Sambuc ** ^If the database connection is associated with unfinalized prepared 277*0a6a1f1dSLionel Sambuc ** statements or unfinished sqlite3_backup objects then sqlite3_close() 278*0a6a1f1dSLionel Sambuc ** will leave the database connection open and return [SQLITE_BUSY]. 279*0a6a1f1dSLionel Sambuc ** ^If sqlite3_close_v2() is called with unfinalized prepared statements 280*0a6a1f1dSLionel Sambuc ** and unfinished sqlite3_backups, then the database connection becomes 281*0a6a1f1dSLionel Sambuc ** an unusable "zombie" which will automatically be deallocated when the 282*0a6a1f1dSLionel Sambuc ** last prepared statement is finalized or the last sqlite3_backup is 283*0a6a1f1dSLionel Sambuc ** finished. The sqlite3_close_v2() interface is intended for use with 284*0a6a1f1dSLionel Sambuc ** host languages that are garbage collected, and where the order in which 285*0a6a1f1dSLionel Sambuc ** destructors are called is arbitrary. 28611be35a1SLionel Sambuc ** 287*0a6a1f1dSLionel Sambuc ** Applications should [sqlite3_finalize | finalize] all [prepared statements], 288*0a6a1f1dSLionel Sambuc ** [sqlite3_blob_close | close] all [BLOB handles], and 289*0a6a1f1dSLionel Sambuc ** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated 290*0a6a1f1dSLionel Sambuc ** with the [sqlite3] object prior to attempting to close the object. ^If 291*0a6a1f1dSLionel Sambuc ** sqlite3_close_v2() is called on a [database connection] that still has 292*0a6a1f1dSLionel Sambuc ** outstanding [prepared statements], [BLOB handles], and/or 293*0a6a1f1dSLionel Sambuc ** [sqlite3_backup] objects then it returns SQLITE_OK but the deallocation 294*0a6a1f1dSLionel Sambuc ** of resources is deferred until all [prepared statements], [BLOB handles], 295*0a6a1f1dSLionel Sambuc ** and [sqlite3_backup] objects are also destroyed. 296*0a6a1f1dSLionel Sambuc ** 297*0a6a1f1dSLionel Sambuc ** ^If an [sqlite3] object is destroyed while a transaction is open, 29811be35a1SLionel Sambuc ** the transaction is automatically rolled back. 29911be35a1SLionel Sambuc ** 300*0a6a1f1dSLionel Sambuc ** The C parameter to [sqlite3_close(C)] and [sqlite3_close_v2(C)] 301*0a6a1f1dSLionel Sambuc ** must be either a NULL 30211be35a1SLionel Sambuc ** pointer or an [sqlite3] object pointer obtained 30311be35a1SLionel Sambuc ** from [sqlite3_open()], [sqlite3_open16()], or 30411be35a1SLionel Sambuc ** [sqlite3_open_v2()], and not previously closed. 305*0a6a1f1dSLionel Sambuc ** ^Calling sqlite3_close() or sqlite3_close_v2() with a NULL pointer 306*0a6a1f1dSLionel Sambuc ** argument is a harmless no-op. 30711be35a1SLionel Sambuc */ 30811be35a1SLionel Sambuc SQLITE_API int sqlite3_close(sqlite3*); 309*0a6a1f1dSLionel Sambuc SQLITE_API int sqlite3_close_v2(sqlite3*); 31011be35a1SLionel Sambuc 31111be35a1SLionel Sambuc /* 31211be35a1SLionel Sambuc ** The type for a callback function. 31311be35a1SLionel Sambuc ** This is legacy and deprecated. It is included for historical 31411be35a1SLionel Sambuc ** compatibility and is not documented. 31511be35a1SLionel Sambuc */ 31611be35a1SLionel Sambuc typedef int (*sqlite3_callback)(void*,int,char**, char**); 31711be35a1SLionel Sambuc 31811be35a1SLionel Sambuc /* 31911be35a1SLionel Sambuc ** CAPI3REF: One-Step Query Execution Interface 32011be35a1SLionel Sambuc ** 32111be35a1SLionel Sambuc ** The sqlite3_exec() interface is a convenience wrapper around 32211be35a1SLionel Sambuc ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()], 32311be35a1SLionel Sambuc ** that allows an application to run multiple statements of SQL 32411be35a1SLionel Sambuc ** without having to use a lot of C code. 32511be35a1SLionel Sambuc ** 32611be35a1SLionel Sambuc ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded, 32711be35a1SLionel Sambuc ** semicolon-separate SQL statements passed into its 2nd argument, 32811be35a1SLionel Sambuc ** in the context of the [database connection] passed in as its 1st 32911be35a1SLionel Sambuc ** argument. ^If the callback function of the 3rd argument to 33011be35a1SLionel Sambuc ** sqlite3_exec() is not NULL, then it is invoked for each result row 33111be35a1SLionel Sambuc ** coming out of the evaluated SQL statements. ^The 4th argument to 33211be35a1SLionel Sambuc ** sqlite3_exec() is relayed through to the 1st argument of each 33311be35a1SLionel Sambuc ** callback invocation. ^If the callback pointer to sqlite3_exec() 33411be35a1SLionel Sambuc ** is NULL, then no callback is ever invoked and result rows are 33511be35a1SLionel Sambuc ** ignored. 33611be35a1SLionel Sambuc ** 33711be35a1SLionel Sambuc ** ^If an error occurs while evaluating the SQL statements passed into 33811be35a1SLionel Sambuc ** sqlite3_exec(), then execution of the current statement stops and 33911be35a1SLionel Sambuc ** subsequent statements are skipped. ^If the 5th parameter to sqlite3_exec() 34011be35a1SLionel Sambuc ** is not NULL then any error message is written into memory obtained 34111be35a1SLionel Sambuc ** from [sqlite3_malloc()] and passed back through the 5th parameter. 34211be35a1SLionel Sambuc ** To avoid memory leaks, the application should invoke [sqlite3_free()] 34311be35a1SLionel Sambuc ** on error message strings returned through the 5th parameter of 34411be35a1SLionel Sambuc ** of sqlite3_exec() after the error message string is no longer needed. 34511be35a1SLionel Sambuc ** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors 34611be35a1SLionel Sambuc ** occur, then sqlite3_exec() sets the pointer in its 5th parameter to 34711be35a1SLionel Sambuc ** NULL before returning. 34811be35a1SLionel Sambuc ** 34911be35a1SLionel Sambuc ** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec() 35011be35a1SLionel Sambuc ** routine returns SQLITE_ABORT without invoking the callback again and 35111be35a1SLionel Sambuc ** without running any subsequent SQL statements. 35211be35a1SLionel Sambuc ** 35311be35a1SLionel Sambuc ** ^The 2nd argument to the sqlite3_exec() callback function is the 35411be35a1SLionel Sambuc ** number of columns in the result. ^The 3rd argument to the sqlite3_exec() 35511be35a1SLionel Sambuc ** callback is an array of pointers to strings obtained as if from 35611be35a1SLionel Sambuc ** [sqlite3_column_text()], one for each column. ^If an element of a 35711be35a1SLionel Sambuc ** result row is NULL then the corresponding string pointer for the 35811be35a1SLionel Sambuc ** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the 35911be35a1SLionel Sambuc ** sqlite3_exec() callback is an array of pointers to strings where each 36011be35a1SLionel Sambuc ** entry represents the name of corresponding result column as obtained 36111be35a1SLionel Sambuc ** from [sqlite3_column_name()]. 36211be35a1SLionel Sambuc ** 36311be35a1SLionel Sambuc ** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer 36411be35a1SLionel Sambuc ** to an empty string, or a pointer that contains only whitespace and/or 36511be35a1SLionel Sambuc ** SQL comments, then no SQL statements are evaluated and the database 36611be35a1SLionel Sambuc ** is not changed. 36711be35a1SLionel Sambuc ** 36811be35a1SLionel Sambuc ** Restrictions: 36911be35a1SLionel Sambuc ** 37011be35a1SLionel Sambuc ** <ul> 37111be35a1SLionel Sambuc ** <li> The application must insure that the 1st parameter to sqlite3_exec() 37211be35a1SLionel Sambuc ** is a valid and open [database connection]. 373*0a6a1f1dSLionel Sambuc ** <li> The application must not close the [database connection] specified by 37411be35a1SLionel Sambuc ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running. 37511be35a1SLionel Sambuc ** <li> The application must not modify the SQL statement text passed into 37611be35a1SLionel Sambuc ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running. 37711be35a1SLionel Sambuc ** </ul> 37811be35a1SLionel Sambuc */ 37911be35a1SLionel Sambuc SQLITE_API int sqlite3_exec( 38011be35a1SLionel Sambuc sqlite3*, /* An open database */ 38111be35a1SLionel Sambuc const char *sql, /* SQL to be evaluated */ 38211be35a1SLionel Sambuc int (*callback)(void*,int,char**,char**), /* Callback function */ 38311be35a1SLionel Sambuc void *, /* 1st argument to callback */ 38411be35a1SLionel Sambuc char **errmsg /* Error msg written here */ 38511be35a1SLionel Sambuc ); 38611be35a1SLionel Sambuc 38711be35a1SLionel Sambuc /* 38811be35a1SLionel Sambuc ** CAPI3REF: Result Codes 38911be35a1SLionel Sambuc ** KEYWORDS: SQLITE_OK {error code} {error codes} 39011be35a1SLionel Sambuc ** KEYWORDS: {result code} {result codes} 39111be35a1SLionel Sambuc ** 39211be35a1SLionel Sambuc ** Many SQLite functions return an integer result code from the set shown 39311be35a1SLionel Sambuc ** here in order to indicate success or failure. 39411be35a1SLionel Sambuc ** 39511be35a1SLionel Sambuc ** New error codes may be added in future versions of SQLite. 39611be35a1SLionel Sambuc ** 39711be35a1SLionel Sambuc ** See also: [SQLITE_IOERR_READ | extended result codes], 39811be35a1SLionel Sambuc ** [sqlite3_vtab_on_conflict()] [SQLITE_ROLLBACK | result codes]. 39911be35a1SLionel Sambuc */ 40011be35a1SLionel Sambuc #define SQLITE_OK 0 /* Successful result */ 40111be35a1SLionel Sambuc /* beginning-of-error-codes */ 40211be35a1SLionel Sambuc #define SQLITE_ERROR 1 /* SQL error or missing database */ 40311be35a1SLionel Sambuc #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ 40411be35a1SLionel Sambuc #define SQLITE_PERM 3 /* Access permission denied */ 40511be35a1SLionel Sambuc #define SQLITE_ABORT 4 /* Callback routine requested an abort */ 40611be35a1SLionel Sambuc #define SQLITE_BUSY 5 /* The database file is locked */ 40711be35a1SLionel Sambuc #define SQLITE_LOCKED 6 /* A table in the database is locked */ 40811be35a1SLionel Sambuc #define SQLITE_NOMEM 7 /* A malloc() failed */ 40911be35a1SLionel Sambuc #define SQLITE_READONLY 8 /* Attempt to write a readonly database */ 41011be35a1SLionel Sambuc #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/ 41111be35a1SLionel Sambuc #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */ 41211be35a1SLionel Sambuc #define SQLITE_CORRUPT 11 /* The database disk image is malformed */ 41311be35a1SLionel Sambuc #define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */ 41411be35a1SLionel Sambuc #define SQLITE_FULL 13 /* Insertion failed because database is full */ 41511be35a1SLionel Sambuc #define SQLITE_CANTOPEN 14 /* Unable to open the database file */ 41611be35a1SLionel Sambuc #define SQLITE_PROTOCOL 15 /* Database lock protocol error */ 41711be35a1SLionel Sambuc #define SQLITE_EMPTY 16 /* Database is empty */ 41811be35a1SLionel Sambuc #define SQLITE_SCHEMA 17 /* The database schema changed */ 41911be35a1SLionel Sambuc #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */ 42011be35a1SLionel Sambuc #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */ 42111be35a1SLionel Sambuc #define SQLITE_MISMATCH 20 /* Data type mismatch */ 42211be35a1SLionel Sambuc #define SQLITE_MISUSE 21 /* Library used incorrectly */ 42311be35a1SLionel Sambuc #define SQLITE_NOLFS 22 /* Uses OS features not supported on host */ 42411be35a1SLionel Sambuc #define SQLITE_AUTH 23 /* Authorization denied */ 42511be35a1SLionel Sambuc #define SQLITE_FORMAT 24 /* Auxiliary database format error */ 42611be35a1SLionel Sambuc #define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */ 42711be35a1SLionel Sambuc #define SQLITE_NOTADB 26 /* File opened that is not a database file */ 428*0a6a1f1dSLionel Sambuc #define SQLITE_NOTICE 27 /* Notifications from sqlite3_log() */ 429*0a6a1f1dSLionel Sambuc #define SQLITE_WARNING 28 /* Warnings from sqlite3_log() */ 43011be35a1SLionel Sambuc #define SQLITE_ROW 100 /* sqlite3_step() has another row ready */ 43111be35a1SLionel Sambuc #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */ 43211be35a1SLionel Sambuc /* end-of-error-codes */ 43311be35a1SLionel Sambuc 43411be35a1SLionel Sambuc /* 43511be35a1SLionel Sambuc ** CAPI3REF: Extended Result Codes 43611be35a1SLionel Sambuc ** KEYWORDS: {extended error code} {extended error codes} 43711be35a1SLionel Sambuc ** KEYWORDS: {extended result code} {extended result codes} 43811be35a1SLionel Sambuc ** 43911be35a1SLionel Sambuc ** In its default configuration, SQLite API routines return one of 26 integer 44011be35a1SLionel Sambuc ** [SQLITE_OK | result codes]. However, experience has shown that many of 44111be35a1SLionel Sambuc ** these result codes are too coarse-grained. They do not provide as 44211be35a1SLionel Sambuc ** much information about problems as programmers might like. In an effort to 44311be35a1SLionel Sambuc ** address this, newer versions of SQLite (version 3.3.8 and later) include 44411be35a1SLionel Sambuc ** support for additional result codes that provide more detailed information 44511be35a1SLionel Sambuc ** about errors. The extended result codes are enabled or disabled 44611be35a1SLionel Sambuc ** on a per database connection basis using the 44711be35a1SLionel Sambuc ** [sqlite3_extended_result_codes()] API. 44811be35a1SLionel Sambuc ** 44911be35a1SLionel Sambuc ** Some of the available extended result codes are listed here. 450*0a6a1f1dSLionel Sambuc ** One may expect the number of extended result codes will increase 45111be35a1SLionel Sambuc ** over time. Software that uses extended result codes should expect 45211be35a1SLionel Sambuc ** to see new result codes in future releases of SQLite. 45311be35a1SLionel Sambuc ** 45411be35a1SLionel Sambuc ** The SQLITE_OK result code will never be extended. It will always 45511be35a1SLionel Sambuc ** be exactly zero. 45611be35a1SLionel Sambuc */ 45711be35a1SLionel Sambuc #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) 45811be35a1SLionel Sambuc #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) 45911be35a1SLionel Sambuc #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) 46011be35a1SLionel Sambuc #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) 46111be35a1SLionel Sambuc #define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8)) 46211be35a1SLionel Sambuc #define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8)) 46311be35a1SLionel Sambuc #define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8)) 46411be35a1SLionel Sambuc #define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8)) 46511be35a1SLionel Sambuc #define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8)) 46611be35a1SLionel Sambuc #define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8)) 46711be35a1SLionel Sambuc #define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8)) 46811be35a1SLionel Sambuc #define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8)) 46911be35a1SLionel Sambuc #define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8)) 47011be35a1SLionel Sambuc #define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8)) 47111be35a1SLionel Sambuc #define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8)) 47211be35a1SLionel Sambuc #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8)) 47311be35a1SLionel Sambuc #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8)) 47411be35a1SLionel Sambuc #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) 47511be35a1SLionel Sambuc #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) 47611be35a1SLionel Sambuc #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) 47711be35a1SLionel Sambuc #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) 47811be35a1SLionel Sambuc #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) 479*0a6a1f1dSLionel Sambuc #define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8)) 480*0a6a1f1dSLionel Sambuc #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8)) 481*0a6a1f1dSLionel Sambuc #define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8)) 482*0a6a1f1dSLionel Sambuc #define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8)) 48311be35a1SLionel Sambuc #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) 48411be35a1SLionel Sambuc #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) 485*0a6a1f1dSLionel Sambuc #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8)) 48611be35a1SLionel Sambuc #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) 487*0a6a1f1dSLionel Sambuc #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) 488*0a6a1f1dSLionel Sambuc #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) 489*0a6a1f1dSLionel Sambuc #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) 49011be35a1SLionel Sambuc #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) 49111be35a1SLionel Sambuc #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) 49211be35a1SLionel Sambuc #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) 493*0a6a1f1dSLionel Sambuc #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) 494*0a6a1f1dSLionel Sambuc #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8)) 495*0a6a1f1dSLionel Sambuc #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) 496*0a6a1f1dSLionel Sambuc #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) 497*0a6a1f1dSLionel Sambuc #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8)) 498*0a6a1f1dSLionel Sambuc #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) 499*0a6a1f1dSLionel Sambuc #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) 500*0a6a1f1dSLionel Sambuc #define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8)) 501*0a6a1f1dSLionel Sambuc #define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8)) 502*0a6a1f1dSLionel Sambuc #define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8)) 503*0a6a1f1dSLionel Sambuc #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8)) 504*0a6a1f1dSLionel Sambuc #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8)) 505*0a6a1f1dSLionel Sambuc #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8)) 506*0a6a1f1dSLionel Sambuc #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8)) 507*0a6a1f1dSLionel Sambuc #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8)) 508*0a6a1f1dSLionel Sambuc #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8)) 50911be35a1SLionel Sambuc 51011be35a1SLionel Sambuc /* 51111be35a1SLionel Sambuc ** CAPI3REF: Flags For File Open Operations 51211be35a1SLionel Sambuc ** 51311be35a1SLionel Sambuc ** These bit values are intended for use in the 51411be35a1SLionel Sambuc ** 3rd parameter to the [sqlite3_open_v2()] interface and 51511be35a1SLionel Sambuc ** in the 4th parameter to the [sqlite3_vfs.xOpen] method. 51611be35a1SLionel Sambuc */ 51711be35a1SLionel Sambuc #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ 51811be35a1SLionel Sambuc #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ 51911be35a1SLionel Sambuc #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ 52011be35a1SLionel Sambuc #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ 52111be35a1SLionel Sambuc #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */ 52211be35a1SLionel Sambuc #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */ 52311be35a1SLionel Sambuc #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */ 524*0a6a1f1dSLionel Sambuc #define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */ 52511be35a1SLionel Sambuc #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */ 52611be35a1SLionel Sambuc #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ 52711be35a1SLionel Sambuc #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ 52811be35a1SLionel Sambuc #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ 52911be35a1SLionel Sambuc #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ 53011be35a1SLionel Sambuc #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */ 53111be35a1SLionel Sambuc #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */ 53211be35a1SLionel Sambuc #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */ 53311be35a1SLionel Sambuc #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */ 53411be35a1SLionel Sambuc #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ 53511be35a1SLionel Sambuc #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ 53611be35a1SLionel Sambuc #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */ 53711be35a1SLionel Sambuc 53811be35a1SLionel Sambuc /* Reserved: 0x00F00000 */ 53911be35a1SLionel Sambuc 54011be35a1SLionel Sambuc /* 54111be35a1SLionel Sambuc ** CAPI3REF: Device Characteristics 54211be35a1SLionel Sambuc ** 54311be35a1SLionel Sambuc ** The xDeviceCharacteristics method of the [sqlite3_io_methods] 544*0a6a1f1dSLionel Sambuc ** object returns an integer which is a vector of these 54511be35a1SLionel Sambuc ** bit values expressing I/O characteristics of the mass storage 54611be35a1SLionel Sambuc ** device that holds the file that the [sqlite3_io_methods] 54711be35a1SLionel Sambuc ** refers to. 54811be35a1SLionel Sambuc ** 54911be35a1SLionel Sambuc ** The SQLITE_IOCAP_ATOMIC property means that all writes of 55011be35a1SLionel Sambuc ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values 55111be35a1SLionel Sambuc ** mean that writes of blocks that are nnn bytes in size and 55211be35a1SLionel Sambuc ** are aligned to an address which is an integer multiple of 55311be35a1SLionel Sambuc ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means 55411be35a1SLionel Sambuc ** that when data is appended to a file, the data is appended 55511be35a1SLionel Sambuc ** first then the size of the file is extended, never the other 55611be35a1SLionel Sambuc ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that 55711be35a1SLionel Sambuc ** information is written to disk in the same order as calls 55811be35a1SLionel Sambuc ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that 55911be35a1SLionel Sambuc ** after reboot following a crash or power loss, the only bytes in a 56011be35a1SLionel Sambuc ** file that were written at the application level might have changed 56111be35a1SLionel Sambuc ** and that adjacent bytes, even bytes within the same sector are 562*0a6a1f1dSLionel Sambuc ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 563*0a6a1f1dSLionel Sambuc ** flag indicate that a file cannot be deleted when open. 56411be35a1SLionel Sambuc */ 56511be35a1SLionel Sambuc #define SQLITE_IOCAP_ATOMIC 0x00000001 56611be35a1SLionel Sambuc #define SQLITE_IOCAP_ATOMIC512 0x00000002 56711be35a1SLionel Sambuc #define SQLITE_IOCAP_ATOMIC1K 0x00000004 56811be35a1SLionel Sambuc #define SQLITE_IOCAP_ATOMIC2K 0x00000008 56911be35a1SLionel Sambuc #define SQLITE_IOCAP_ATOMIC4K 0x00000010 57011be35a1SLionel Sambuc #define SQLITE_IOCAP_ATOMIC8K 0x00000020 57111be35a1SLionel Sambuc #define SQLITE_IOCAP_ATOMIC16K 0x00000040 57211be35a1SLionel Sambuc #define SQLITE_IOCAP_ATOMIC32K 0x00000080 57311be35a1SLionel Sambuc #define SQLITE_IOCAP_ATOMIC64K 0x00000100 57411be35a1SLionel Sambuc #define SQLITE_IOCAP_SAFE_APPEND 0x00000200 57511be35a1SLionel Sambuc #define SQLITE_IOCAP_SEQUENTIAL 0x00000400 57611be35a1SLionel Sambuc #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800 57711be35a1SLionel Sambuc #define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000 57811be35a1SLionel Sambuc 57911be35a1SLionel Sambuc /* 58011be35a1SLionel Sambuc ** CAPI3REF: File Locking Levels 58111be35a1SLionel Sambuc ** 58211be35a1SLionel Sambuc ** SQLite uses one of these integer values as the second 58311be35a1SLionel Sambuc ** argument to calls it makes to the xLock() and xUnlock() methods 58411be35a1SLionel Sambuc ** of an [sqlite3_io_methods] object. 58511be35a1SLionel Sambuc */ 58611be35a1SLionel Sambuc #define SQLITE_LOCK_NONE 0 58711be35a1SLionel Sambuc #define SQLITE_LOCK_SHARED 1 58811be35a1SLionel Sambuc #define SQLITE_LOCK_RESERVED 2 58911be35a1SLionel Sambuc #define SQLITE_LOCK_PENDING 3 59011be35a1SLionel Sambuc #define SQLITE_LOCK_EXCLUSIVE 4 59111be35a1SLionel Sambuc 59211be35a1SLionel Sambuc /* 59311be35a1SLionel Sambuc ** CAPI3REF: Synchronization Type Flags 59411be35a1SLionel Sambuc ** 59511be35a1SLionel Sambuc ** When SQLite invokes the xSync() method of an 59611be35a1SLionel Sambuc ** [sqlite3_io_methods] object it uses a combination of 59711be35a1SLionel Sambuc ** these integer values as the second argument. 59811be35a1SLionel Sambuc ** 59911be35a1SLionel Sambuc ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the 60011be35a1SLionel Sambuc ** sync operation only needs to flush data to mass storage. Inode 60111be35a1SLionel Sambuc ** information need not be flushed. If the lower four bits of the flag 60211be35a1SLionel Sambuc ** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics. 60311be35a1SLionel Sambuc ** If the lower four bits equal SQLITE_SYNC_FULL, that means 60411be35a1SLionel Sambuc ** to use Mac OS X style fullsync instead of fsync(). 60511be35a1SLionel Sambuc ** 60611be35a1SLionel Sambuc ** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags 60711be35a1SLionel Sambuc ** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL 60811be35a1SLionel Sambuc ** settings. The [synchronous pragma] determines when calls to the 60911be35a1SLionel Sambuc ** xSync VFS method occur and applies uniformly across all platforms. 61011be35a1SLionel Sambuc ** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how 61111be35a1SLionel Sambuc ** energetic or rigorous or forceful the sync operations are and 61211be35a1SLionel Sambuc ** only make a difference on Mac OSX for the default SQLite code. 61311be35a1SLionel Sambuc ** (Third-party VFS implementations might also make the distinction 61411be35a1SLionel Sambuc ** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the 61511be35a1SLionel Sambuc ** operating systems natively supported by SQLite, only Mac OSX 61611be35a1SLionel Sambuc ** cares about the difference.) 61711be35a1SLionel Sambuc */ 61811be35a1SLionel Sambuc #define SQLITE_SYNC_NORMAL 0x00002 61911be35a1SLionel Sambuc #define SQLITE_SYNC_FULL 0x00003 62011be35a1SLionel Sambuc #define SQLITE_SYNC_DATAONLY 0x00010 62111be35a1SLionel Sambuc 62211be35a1SLionel Sambuc /* 62311be35a1SLionel Sambuc ** CAPI3REF: OS Interface Open File Handle 62411be35a1SLionel Sambuc ** 62511be35a1SLionel Sambuc ** An [sqlite3_file] object represents an open file in the 62611be35a1SLionel Sambuc ** [sqlite3_vfs | OS interface layer]. Individual OS interface 62711be35a1SLionel Sambuc ** implementations will 62811be35a1SLionel Sambuc ** want to subclass this object by appending additional fields 62911be35a1SLionel Sambuc ** for their own use. The pMethods entry is a pointer to an 63011be35a1SLionel Sambuc ** [sqlite3_io_methods] object that defines methods for performing 63111be35a1SLionel Sambuc ** I/O operations on the open file. 63211be35a1SLionel Sambuc */ 63311be35a1SLionel Sambuc typedef struct sqlite3_file sqlite3_file; 63411be35a1SLionel Sambuc struct sqlite3_file { 63511be35a1SLionel Sambuc const struct sqlite3_io_methods *pMethods; /* Methods for an open file */ 63611be35a1SLionel Sambuc }; 63711be35a1SLionel Sambuc 63811be35a1SLionel Sambuc /* 63911be35a1SLionel Sambuc ** CAPI3REF: OS Interface File Virtual Methods Object 64011be35a1SLionel Sambuc ** 64111be35a1SLionel Sambuc ** Every file opened by the [sqlite3_vfs.xOpen] method populates an 64211be35a1SLionel Sambuc ** [sqlite3_file] object (or, more commonly, a subclass of the 64311be35a1SLionel Sambuc ** [sqlite3_file] object) with a pointer to an instance of this object. 64411be35a1SLionel Sambuc ** This object defines the methods used to perform various operations 64511be35a1SLionel Sambuc ** against the open file represented by the [sqlite3_file] object. 64611be35a1SLionel Sambuc ** 64711be35a1SLionel Sambuc ** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element 64811be35a1SLionel Sambuc ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method 64911be35a1SLionel Sambuc ** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The 65011be35a1SLionel Sambuc ** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen] 65111be35a1SLionel Sambuc ** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element 65211be35a1SLionel Sambuc ** to NULL. 65311be35a1SLionel Sambuc ** 65411be35a1SLionel Sambuc ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or 65511be35a1SLionel Sambuc ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync(). 65611be35a1SLionel Sambuc ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY] 65711be35a1SLionel Sambuc ** flag may be ORed in to indicate that only the data of the file 65811be35a1SLionel Sambuc ** and not its inode needs to be synced. 65911be35a1SLionel Sambuc ** 66011be35a1SLionel Sambuc ** The integer values to xLock() and xUnlock() are one of 66111be35a1SLionel Sambuc ** <ul> 66211be35a1SLionel Sambuc ** <li> [SQLITE_LOCK_NONE], 66311be35a1SLionel Sambuc ** <li> [SQLITE_LOCK_SHARED], 66411be35a1SLionel Sambuc ** <li> [SQLITE_LOCK_RESERVED], 66511be35a1SLionel Sambuc ** <li> [SQLITE_LOCK_PENDING], or 66611be35a1SLionel Sambuc ** <li> [SQLITE_LOCK_EXCLUSIVE]. 66711be35a1SLionel Sambuc ** </ul> 66811be35a1SLionel Sambuc ** xLock() increases the lock. xUnlock() decreases the lock. 66911be35a1SLionel Sambuc ** The xCheckReservedLock() method checks whether any database connection, 67011be35a1SLionel Sambuc ** either in this process or in some other process, is holding a RESERVED, 67111be35a1SLionel Sambuc ** PENDING, or EXCLUSIVE lock on the file. It returns true 67211be35a1SLionel Sambuc ** if such a lock exists and false otherwise. 67311be35a1SLionel Sambuc ** 67411be35a1SLionel Sambuc ** The xFileControl() method is a generic interface that allows custom 67511be35a1SLionel Sambuc ** VFS implementations to directly control an open file using the 67611be35a1SLionel Sambuc ** [sqlite3_file_control()] interface. The second "op" argument is an 67711be35a1SLionel Sambuc ** integer opcode. The third argument is a generic pointer intended to 67811be35a1SLionel Sambuc ** point to a structure that may contain arguments or space in which to 67911be35a1SLionel Sambuc ** write return values. Potential uses for xFileControl() might be 68011be35a1SLionel Sambuc ** functions to enable blocking locks with timeouts, to change the 68111be35a1SLionel Sambuc ** locking strategy (for example to use dot-file locks), to inquire 68211be35a1SLionel Sambuc ** about the status of a lock, or to break stale locks. The SQLite 68311be35a1SLionel Sambuc ** core reserves all opcodes less than 100 for its own use. 68411be35a1SLionel Sambuc ** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available. 68511be35a1SLionel Sambuc ** Applications that define a custom xFileControl method should use opcodes 68611be35a1SLionel Sambuc ** greater than 100 to avoid conflicts. VFS implementations should 68711be35a1SLionel Sambuc ** return [SQLITE_NOTFOUND] for file control opcodes that they do not 68811be35a1SLionel Sambuc ** recognize. 68911be35a1SLionel Sambuc ** 69011be35a1SLionel Sambuc ** The xSectorSize() method returns the sector size of the 69111be35a1SLionel Sambuc ** device that underlies the file. The sector size is the 69211be35a1SLionel Sambuc ** minimum write that can be performed without disturbing 69311be35a1SLionel Sambuc ** other bytes in the file. The xDeviceCharacteristics() 69411be35a1SLionel Sambuc ** method returns a bit vector describing behaviors of the 69511be35a1SLionel Sambuc ** underlying device: 69611be35a1SLionel Sambuc ** 69711be35a1SLionel Sambuc ** <ul> 69811be35a1SLionel Sambuc ** <li> [SQLITE_IOCAP_ATOMIC] 69911be35a1SLionel Sambuc ** <li> [SQLITE_IOCAP_ATOMIC512] 70011be35a1SLionel Sambuc ** <li> [SQLITE_IOCAP_ATOMIC1K] 70111be35a1SLionel Sambuc ** <li> [SQLITE_IOCAP_ATOMIC2K] 70211be35a1SLionel Sambuc ** <li> [SQLITE_IOCAP_ATOMIC4K] 70311be35a1SLionel Sambuc ** <li> [SQLITE_IOCAP_ATOMIC8K] 70411be35a1SLionel Sambuc ** <li> [SQLITE_IOCAP_ATOMIC16K] 70511be35a1SLionel Sambuc ** <li> [SQLITE_IOCAP_ATOMIC32K] 70611be35a1SLionel Sambuc ** <li> [SQLITE_IOCAP_ATOMIC64K] 70711be35a1SLionel Sambuc ** <li> [SQLITE_IOCAP_SAFE_APPEND] 70811be35a1SLionel Sambuc ** <li> [SQLITE_IOCAP_SEQUENTIAL] 70911be35a1SLionel Sambuc ** </ul> 71011be35a1SLionel Sambuc ** 71111be35a1SLionel Sambuc ** The SQLITE_IOCAP_ATOMIC property means that all writes of 71211be35a1SLionel Sambuc ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values 71311be35a1SLionel Sambuc ** mean that writes of blocks that are nnn bytes in size and 71411be35a1SLionel Sambuc ** are aligned to an address which is an integer multiple of 71511be35a1SLionel Sambuc ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means 71611be35a1SLionel Sambuc ** that when data is appended to a file, the data is appended 71711be35a1SLionel Sambuc ** first then the size of the file is extended, never the other 71811be35a1SLionel Sambuc ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that 71911be35a1SLionel Sambuc ** information is written to disk in the same order as calls 72011be35a1SLionel Sambuc ** to xWrite(). 72111be35a1SLionel Sambuc ** 72211be35a1SLionel Sambuc ** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill 72311be35a1SLionel Sambuc ** in the unread portions of the buffer with zeros. A VFS that 72411be35a1SLionel Sambuc ** fails to zero-fill short reads might seem to work. However, 72511be35a1SLionel Sambuc ** failure to zero-fill short reads will eventually lead to 72611be35a1SLionel Sambuc ** database corruption. 72711be35a1SLionel Sambuc */ 72811be35a1SLionel Sambuc typedef struct sqlite3_io_methods sqlite3_io_methods; 72911be35a1SLionel Sambuc struct sqlite3_io_methods { 73011be35a1SLionel Sambuc int iVersion; 73111be35a1SLionel Sambuc int (*xClose)(sqlite3_file*); 73211be35a1SLionel Sambuc int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); 73311be35a1SLionel Sambuc int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst); 73411be35a1SLionel Sambuc int (*xTruncate)(sqlite3_file*, sqlite3_int64 size); 73511be35a1SLionel Sambuc int (*xSync)(sqlite3_file*, int flags); 73611be35a1SLionel Sambuc int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize); 73711be35a1SLionel Sambuc int (*xLock)(sqlite3_file*, int); 73811be35a1SLionel Sambuc int (*xUnlock)(sqlite3_file*, int); 73911be35a1SLionel Sambuc int (*xCheckReservedLock)(sqlite3_file*, int *pResOut); 74011be35a1SLionel Sambuc int (*xFileControl)(sqlite3_file*, int op, void *pArg); 74111be35a1SLionel Sambuc int (*xSectorSize)(sqlite3_file*); 74211be35a1SLionel Sambuc int (*xDeviceCharacteristics)(sqlite3_file*); 74311be35a1SLionel Sambuc /* Methods above are valid for version 1 */ 74411be35a1SLionel Sambuc int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**); 74511be35a1SLionel Sambuc int (*xShmLock)(sqlite3_file*, int offset, int n, int flags); 74611be35a1SLionel Sambuc void (*xShmBarrier)(sqlite3_file*); 74711be35a1SLionel Sambuc int (*xShmUnmap)(sqlite3_file*, int deleteFlag); 74811be35a1SLionel Sambuc /* Methods above are valid for version 2 */ 749*0a6a1f1dSLionel Sambuc int (*xFetch)(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp); 750*0a6a1f1dSLionel Sambuc int (*xUnfetch)(sqlite3_file*, sqlite3_int64 iOfst, void *p); 751*0a6a1f1dSLionel Sambuc /* Methods above are valid for version 3 */ 75211be35a1SLionel Sambuc /* Additional methods may be added in future releases */ 75311be35a1SLionel Sambuc }; 75411be35a1SLionel Sambuc 75511be35a1SLionel Sambuc /* 75611be35a1SLionel Sambuc ** CAPI3REF: Standard File Control Opcodes 75711be35a1SLionel Sambuc ** 75811be35a1SLionel Sambuc ** These integer constants are opcodes for the xFileControl method 75911be35a1SLionel Sambuc ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()] 76011be35a1SLionel Sambuc ** interface. 76111be35a1SLionel Sambuc ** 76211be35a1SLionel Sambuc ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This 76311be35a1SLionel Sambuc ** opcode causes the xFileControl method to write the current state of 76411be35a1SLionel Sambuc ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED], 76511be35a1SLionel Sambuc ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE]) 76611be35a1SLionel Sambuc ** into an integer that the pArg argument points to. This capability 76711be35a1SLionel Sambuc ** is used during testing and only needs to be supported when SQLITE_TEST 76811be35a1SLionel Sambuc ** is defined. 769*0a6a1f1dSLionel Sambuc ** <ul> 770*0a6a1f1dSLionel Sambuc ** <li>[[SQLITE_FCNTL_SIZE_HINT]] 77111be35a1SLionel Sambuc ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS 77211be35a1SLionel Sambuc ** layer a hint of how large the database file will grow to be during the 77311be35a1SLionel Sambuc ** current transaction. This hint is not guaranteed to be accurate but it 77411be35a1SLionel Sambuc ** is often close. The underlying VFS might choose to preallocate database 77511be35a1SLionel Sambuc ** file space based on this hint in order to help writes to the database 77611be35a1SLionel Sambuc ** file run faster. 77711be35a1SLionel Sambuc ** 778*0a6a1f1dSLionel Sambuc ** <li>[[SQLITE_FCNTL_CHUNK_SIZE]] 77911be35a1SLionel Sambuc ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS 78011be35a1SLionel Sambuc ** extends and truncates the database file in chunks of a size specified 78111be35a1SLionel Sambuc ** by the user. The fourth argument to [sqlite3_file_control()] should 78211be35a1SLionel Sambuc ** point to an integer (type int) containing the new chunk-size to use 78311be35a1SLionel Sambuc ** for the nominated database. Allocating database file space in large 78411be35a1SLionel Sambuc ** chunks (say 1MB at a time), may reduce file-system fragmentation and 78511be35a1SLionel Sambuc ** improve performance on some systems. 78611be35a1SLionel Sambuc ** 787*0a6a1f1dSLionel Sambuc ** <li>[[SQLITE_FCNTL_FILE_POINTER]] 78811be35a1SLionel Sambuc ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer 78911be35a1SLionel Sambuc ** to the [sqlite3_file] object associated with a particular database 79011be35a1SLionel Sambuc ** connection. See the [sqlite3_file_control()] documentation for 79111be35a1SLionel Sambuc ** additional information. 79211be35a1SLionel Sambuc ** 793*0a6a1f1dSLionel Sambuc ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]] 794*0a6a1f1dSLionel Sambuc ** No longer in use. 79511be35a1SLionel Sambuc ** 796*0a6a1f1dSLionel Sambuc ** <li>[[SQLITE_FCNTL_SYNC]] 797*0a6a1f1dSLionel Sambuc ** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and 798*0a6a1f1dSLionel Sambuc ** sent to the VFS immediately before the xSync method is invoked on a 799*0a6a1f1dSLionel Sambuc ** database file descriptor. Or, if the xSync method is not invoked 800*0a6a1f1dSLionel Sambuc ** because the user has configured SQLite with 801*0a6a1f1dSLionel Sambuc ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place 802*0a6a1f1dSLionel Sambuc ** of the xSync method. In most cases, the pointer argument passed with 803*0a6a1f1dSLionel Sambuc ** this file-control is NULL. However, if the database file is being synced 804*0a6a1f1dSLionel Sambuc ** as part of a multi-database commit, the argument points to a nul-terminated 805*0a6a1f1dSLionel Sambuc ** string containing the transactions master-journal file name. VFSes that 806*0a6a1f1dSLionel Sambuc ** do not need this signal should silently ignore this opcode. Applications 807*0a6a1f1dSLionel Sambuc ** should not call [sqlite3_file_control()] with this opcode as doing so may 808*0a6a1f1dSLionel Sambuc ** disrupt the operation of the specialized VFSes that do require it. 809*0a6a1f1dSLionel Sambuc ** 810*0a6a1f1dSLionel Sambuc ** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]] 811*0a6a1f1dSLionel Sambuc ** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite 812*0a6a1f1dSLionel Sambuc ** and sent to the VFS after a transaction has been committed immediately 813*0a6a1f1dSLionel Sambuc ** but before the database is unlocked. VFSes that do not need this signal 814*0a6a1f1dSLionel Sambuc ** should silently ignore this opcode. Applications should not call 815*0a6a1f1dSLionel Sambuc ** [sqlite3_file_control()] with this opcode as doing so may disrupt the 816*0a6a1f1dSLionel Sambuc ** operation of the specialized VFSes that do require it. 817*0a6a1f1dSLionel Sambuc ** 818*0a6a1f1dSLionel Sambuc ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]] 81911be35a1SLionel Sambuc ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic 82011be35a1SLionel Sambuc ** retry counts and intervals for certain disk I/O operations for the 82111be35a1SLionel Sambuc ** windows [VFS] in order to provide robustness in the presence of 82211be35a1SLionel Sambuc ** anti-virus programs. By default, the windows VFS will retry file read, 82311be35a1SLionel Sambuc ** file write, and file delete operations up to 10 times, with a delay 82411be35a1SLionel Sambuc ** of 25 milliseconds before the first retry and with the delay increasing 82511be35a1SLionel Sambuc ** by an additional 25 milliseconds with each subsequent retry. This 82611be35a1SLionel Sambuc ** opcode allows these two values (10 retries and 25 milliseconds of delay) 82711be35a1SLionel Sambuc ** to be adjusted. The values are changed for all database connections 82811be35a1SLionel Sambuc ** within the same process. The argument is a pointer to an array of two 82911be35a1SLionel Sambuc ** integers where the first integer i the new retry count and the second 83011be35a1SLionel Sambuc ** integer is the delay. If either integer is negative, then the setting 83111be35a1SLionel Sambuc ** is not changed but instead the prior value of that setting is written 83211be35a1SLionel Sambuc ** into the array entry, allowing the current retry settings to be 83311be35a1SLionel Sambuc ** interrogated. The zDbName parameter is ignored. 83411be35a1SLionel Sambuc ** 835*0a6a1f1dSLionel Sambuc ** <li>[[SQLITE_FCNTL_PERSIST_WAL]] 83611be35a1SLionel Sambuc ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the 837*0a6a1f1dSLionel Sambuc ** persistent [WAL | Write Ahead Log] setting. By default, the auxiliary 83811be35a1SLionel Sambuc ** write ahead log and shared memory files used for transaction control 83911be35a1SLionel Sambuc ** are automatically deleted when the latest connection to the database 84011be35a1SLionel Sambuc ** closes. Setting persistent WAL mode causes those files to persist after 84111be35a1SLionel Sambuc ** close. Persisting the files is useful when other processes that do not 84211be35a1SLionel Sambuc ** have write permission on the directory containing the database file want 84311be35a1SLionel Sambuc ** to read the database file, as the WAL and shared memory files must exist 84411be35a1SLionel Sambuc ** in order for the database to be readable. The fourth parameter to 84511be35a1SLionel Sambuc ** [sqlite3_file_control()] for this opcode should be a pointer to an integer. 84611be35a1SLionel Sambuc ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent 84711be35a1SLionel Sambuc ** WAL mode. If the integer is -1, then it is overwritten with the current 84811be35a1SLionel Sambuc ** WAL persistence setting. 84911be35a1SLionel Sambuc ** 850*0a6a1f1dSLionel Sambuc ** <li>[[SQLITE_FCNTL_POWERSAFE_OVERWRITE]] 85111be35a1SLionel Sambuc ** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the 85211be35a1SLionel Sambuc ** persistent "powersafe-overwrite" or "PSOW" setting. The PSOW setting 85311be35a1SLionel Sambuc ** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the 85411be35a1SLionel Sambuc ** xDeviceCharacteristics methods. The fourth parameter to 85511be35a1SLionel Sambuc ** [sqlite3_file_control()] for this opcode should be a pointer to an integer. 85611be35a1SLionel Sambuc ** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage 85711be35a1SLionel Sambuc ** mode. If the integer is -1, then it is overwritten with the current 85811be35a1SLionel Sambuc ** zero-damage mode setting. 85911be35a1SLionel Sambuc ** 860*0a6a1f1dSLionel Sambuc ** <li>[[SQLITE_FCNTL_OVERWRITE]] 86111be35a1SLionel Sambuc ** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening 86211be35a1SLionel Sambuc ** a write transaction to indicate that, unless it is rolled back for some 86311be35a1SLionel Sambuc ** reason, the entire database file will be overwritten by the current 86411be35a1SLionel Sambuc ** transaction. This is used by VACUUM operations. 86511be35a1SLionel Sambuc ** 866*0a6a1f1dSLionel Sambuc ** <li>[[SQLITE_FCNTL_VFSNAME]] 86711be35a1SLionel Sambuc ** ^The [SQLITE_FCNTL_VFSNAME] opcode can be used to obtain the names of 86811be35a1SLionel Sambuc ** all [VFSes] in the VFS stack. The names are of all VFS shims and the 86911be35a1SLionel Sambuc ** final bottom-level VFS are written into memory obtained from 87011be35a1SLionel Sambuc ** [sqlite3_malloc()] and the result is stored in the char* variable 87111be35a1SLionel Sambuc ** that the fourth parameter of [sqlite3_file_control()] points to. 87211be35a1SLionel Sambuc ** The caller is responsible for freeing the memory when done. As with 87311be35a1SLionel Sambuc ** all file-control actions, there is no guarantee that this will actually 87411be35a1SLionel Sambuc ** do anything. Callers should initialize the char* variable to a NULL 87511be35a1SLionel Sambuc ** pointer in case this file-control is not implemented. This file-control 87611be35a1SLionel Sambuc ** is intended for diagnostic use only. 877*0a6a1f1dSLionel Sambuc ** 878*0a6a1f1dSLionel Sambuc ** <li>[[SQLITE_FCNTL_PRAGMA]] 879*0a6a1f1dSLionel Sambuc ** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA] 880*0a6a1f1dSLionel Sambuc ** file control is sent to the open [sqlite3_file] object corresponding 881*0a6a1f1dSLionel Sambuc ** to the database file to which the pragma statement refers. ^The argument 882*0a6a1f1dSLionel Sambuc ** to the [SQLITE_FCNTL_PRAGMA] file control is an array of 883*0a6a1f1dSLionel Sambuc ** pointers to strings (char**) in which the second element of the array 884*0a6a1f1dSLionel Sambuc ** is the name of the pragma and the third element is the argument to the 885*0a6a1f1dSLionel Sambuc ** pragma or NULL if the pragma has no argument. ^The handler for an 886*0a6a1f1dSLionel Sambuc ** [SQLITE_FCNTL_PRAGMA] file control can optionally make the first element 887*0a6a1f1dSLionel Sambuc ** of the char** argument point to a string obtained from [sqlite3_mprintf()] 888*0a6a1f1dSLionel Sambuc ** or the equivalent and that string will become the result of the pragma or 889*0a6a1f1dSLionel Sambuc ** the error message if the pragma fails. ^If the 890*0a6a1f1dSLionel Sambuc ** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal 891*0a6a1f1dSLionel Sambuc ** [PRAGMA] processing continues. ^If the [SQLITE_FCNTL_PRAGMA] 892*0a6a1f1dSLionel Sambuc ** file control returns [SQLITE_OK], then the parser assumes that the 893*0a6a1f1dSLionel Sambuc ** VFS has handled the PRAGMA itself and the parser generates a no-op 894*0a6a1f1dSLionel Sambuc ** prepared statement. ^If the [SQLITE_FCNTL_PRAGMA] file control returns 895*0a6a1f1dSLionel Sambuc ** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means 896*0a6a1f1dSLionel Sambuc ** that the VFS encountered an error while handling the [PRAGMA] and the 897*0a6a1f1dSLionel Sambuc ** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA] 898*0a6a1f1dSLionel Sambuc ** file control occurs at the beginning of pragma statement analysis and so 899*0a6a1f1dSLionel Sambuc ** it is able to override built-in [PRAGMA] statements. 900*0a6a1f1dSLionel Sambuc ** 901*0a6a1f1dSLionel Sambuc ** <li>[[SQLITE_FCNTL_BUSYHANDLER]] 902*0a6a1f1dSLionel Sambuc ** ^The [SQLITE_FCNTL_BUSYHANDLER] 903*0a6a1f1dSLionel Sambuc ** file-control may be invoked by SQLite on the database file handle 904*0a6a1f1dSLionel Sambuc ** shortly after it is opened in order to provide a custom VFS with access 905*0a6a1f1dSLionel Sambuc ** to the connections busy-handler callback. The argument is of type (void **) 906*0a6a1f1dSLionel Sambuc ** - an array of two (void *) values. The first (void *) actually points 907*0a6a1f1dSLionel Sambuc ** to a function of type (int (*)(void *)). In order to invoke the connections 908*0a6a1f1dSLionel Sambuc ** busy-handler, this function should be invoked with the second (void *) in 909*0a6a1f1dSLionel Sambuc ** the array as the only argument. If it returns non-zero, then the operation 910*0a6a1f1dSLionel Sambuc ** should be retried. If it returns zero, the custom VFS should abandon the 911*0a6a1f1dSLionel Sambuc ** current operation. 912*0a6a1f1dSLionel Sambuc ** 913*0a6a1f1dSLionel Sambuc ** <li>[[SQLITE_FCNTL_TEMPFILENAME]] 914*0a6a1f1dSLionel Sambuc ** ^Application can invoke the [SQLITE_FCNTL_TEMPFILENAME] file-control 915*0a6a1f1dSLionel Sambuc ** to have SQLite generate a 916*0a6a1f1dSLionel Sambuc ** temporary filename using the same algorithm that is followed to generate 917*0a6a1f1dSLionel Sambuc ** temporary filenames for TEMP tables and other internal uses. The 918*0a6a1f1dSLionel Sambuc ** argument should be a char** which will be filled with the filename 919*0a6a1f1dSLionel Sambuc ** written into memory obtained from [sqlite3_malloc()]. The caller should 920*0a6a1f1dSLionel Sambuc ** invoke [sqlite3_free()] on the result to avoid a memory leak. 921*0a6a1f1dSLionel Sambuc ** 922*0a6a1f1dSLionel Sambuc ** <li>[[SQLITE_FCNTL_MMAP_SIZE]] 923*0a6a1f1dSLionel Sambuc ** The [SQLITE_FCNTL_MMAP_SIZE] file control is used to query or set the 924*0a6a1f1dSLionel Sambuc ** maximum number of bytes that will be used for memory-mapped I/O. 925*0a6a1f1dSLionel Sambuc ** The argument is a pointer to a value of type sqlite3_int64 that 926*0a6a1f1dSLionel Sambuc ** is an advisory maximum number of bytes in the file to memory map. The 927*0a6a1f1dSLionel Sambuc ** pointer is overwritten with the old value. The limit is not changed if 928*0a6a1f1dSLionel Sambuc ** the value originally pointed to is negative, and so the current limit 929*0a6a1f1dSLionel Sambuc ** can be queried by passing in a pointer to a negative number. This 930*0a6a1f1dSLionel Sambuc ** file-control is used internally to implement [PRAGMA mmap_size]. 931*0a6a1f1dSLionel Sambuc ** 932*0a6a1f1dSLionel Sambuc ** <li>[[SQLITE_FCNTL_TRACE]] 933*0a6a1f1dSLionel Sambuc ** The [SQLITE_FCNTL_TRACE] file control provides advisory information 934*0a6a1f1dSLionel Sambuc ** to the VFS about what the higher layers of the SQLite stack are doing. 935*0a6a1f1dSLionel Sambuc ** This file control is used by some VFS activity tracing [shims]. 936*0a6a1f1dSLionel Sambuc ** The argument is a zero-terminated string. Higher layers in the 937*0a6a1f1dSLionel Sambuc ** SQLite stack may generate instances of this file control if 938*0a6a1f1dSLionel Sambuc ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled. 939*0a6a1f1dSLionel Sambuc ** 940*0a6a1f1dSLionel Sambuc ** <li>[[SQLITE_FCNTL_HAS_MOVED]] 941*0a6a1f1dSLionel Sambuc ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a 942*0a6a1f1dSLionel Sambuc ** pointer to an integer and it writes a boolean into that integer depending 943*0a6a1f1dSLionel Sambuc ** on whether or not the file has been renamed, moved, or deleted since it 944*0a6a1f1dSLionel Sambuc ** was first opened. 945*0a6a1f1dSLionel Sambuc ** 946*0a6a1f1dSLionel Sambuc ** </ul> 94711be35a1SLionel Sambuc */ 94811be35a1SLionel Sambuc #define SQLITE_FCNTL_LOCKSTATE 1 94911be35a1SLionel Sambuc #define SQLITE_GET_LOCKPROXYFILE 2 95011be35a1SLionel Sambuc #define SQLITE_SET_LOCKPROXYFILE 3 95111be35a1SLionel Sambuc #define SQLITE_LAST_ERRNO 4 95211be35a1SLionel Sambuc #define SQLITE_FCNTL_SIZE_HINT 5 95311be35a1SLionel Sambuc #define SQLITE_FCNTL_CHUNK_SIZE 6 95411be35a1SLionel Sambuc #define SQLITE_FCNTL_FILE_POINTER 7 95511be35a1SLionel Sambuc #define SQLITE_FCNTL_SYNC_OMITTED 8 95611be35a1SLionel Sambuc #define SQLITE_FCNTL_WIN32_AV_RETRY 9 95711be35a1SLionel Sambuc #define SQLITE_FCNTL_PERSIST_WAL 10 95811be35a1SLionel Sambuc #define SQLITE_FCNTL_OVERWRITE 11 95911be35a1SLionel Sambuc #define SQLITE_FCNTL_VFSNAME 12 96011be35a1SLionel Sambuc #define SQLITE_FCNTL_POWERSAFE_OVERWRITE 13 961*0a6a1f1dSLionel Sambuc #define SQLITE_FCNTL_PRAGMA 14 962*0a6a1f1dSLionel Sambuc #define SQLITE_FCNTL_BUSYHANDLER 15 963*0a6a1f1dSLionel Sambuc #define SQLITE_FCNTL_TEMPFILENAME 16 964*0a6a1f1dSLionel Sambuc #define SQLITE_FCNTL_MMAP_SIZE 18 965*0a6a1f1dSLionel Sambuc #define SQLITE_FCNTL_TRACE 19 966*0a6a1f1dSLionel Sambuc #define SQLITE_FCNTL_HAS_MOVED 20 967*0a6a1f1dSLionel Sambuc #define SQLITE_FCNTL_SYNC 21 968*0a6a1f1dSLionel Sambuc #define SQLITE_FCNTL_COMMIT_PHASETWO 22 96911be35a1SLionel Sambuc 97011be35a1SLionel Sambuc /* 97111be35a1SLionel Sambuc ** CAPI3REF: Mutex Handle 97211be35a1SLionel Sambuc ** 97311be35a1SLionel Sambuc ** The mutex module within SQLite defines [sqlite3_mutex] to be an 97411be35a1SLionel Sambuc ** abstract type for a mutex object. The SQLite core never looks 97511be35a1SLionel Sambuc ** at the internal representation of an [sqlite3_mutex]. It only 97611be35a1SLionel Sambuc ** deals with pointers to the [sqlite3_mutex] object. 97711be35a1SLionel Sambuc ** 97811be35a1SLionel Sambuc ** Mutexes are created using [sqlite3_mutex_alloc()]. 97911be35a1SLionel Sambuc */ 98011be35a1SLionel Sambuc typedef struct sqlite3_mutex sqlite3_mutex; 98111be35a1SLionel Sambuc 98211be35a1SLionel Sambuc /* 98311be35a1SLionel Sambuc ** CAPI3REF: OS Interface Object 98411be35a1SLionel Sambuc ** 98511be35a1SLionel Sambuc ** An instance of the sqlite3_vfs object defines the interface between 98611be35a1SLionel Sambuc ** the SQLite core and the underlying operating system. The "vfs" 98711be35a1SLionel Sambuc ** in the name of the object stands for "virtual file system". See 98811be35a1SLionel Sambuc ** the [VFS | VFS documentation] for further information. 98911be35a1SLionel Sambuc ** 99011be35a1SLionel Sambuc ** The value of the iVersion field is initially 1 but may be larger in 99111be35a1SLionel Sambuc ** future versions of SQLite. Additional fields may be appended to this 99211be35a1SLionel Sambuc ** object when the iVersion value is increased. Note that the structure 99311be35a1SLionel Sambuc ** of the sqlite3_vfs object changes in the transaction between 99411be35a1SLionel Sambuc ** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not 99511be35a1SLionel Sambuc ** modified. 99611be35a1SLionel Sambuc ** 99711be35a1SLionel Sambuc ** The szOsFile field is the size of the subclassed [sqlite3_file] 99811be35a1SLionel Sambuc ** structure used by this VFS. mxPathname is the maximum length of 99911be35a1SLionel Sambuc ** a pathname in this VFS. 100011be35a1SLionel Sambuc ** 100111be35a1SLionel Sambuc ** Registered sqlite3_vfs objects are kept on a linked list formed by 100211be35a1SLionel Sambuc ** the pNext pointer. The [sqlite3_vfs_register()] 100311be35a1SLionel Sambuc ** and [sqlite3_vfs_unregister()] interfaces manage this list 100411be35a1SLionel Sambuc ** in a thread-safe way. The [sqlite3_vfs_find()] interface 100511be35a1SLionel Sambuc ** searches the list. Neither the application code nor the VFS 100611be35a1SLionel Sambuc ** implementation should use the pNext pointer. 100711be35a1SLionel Sambuc ** 100811be35a1SLionel Sambuc ** The pNext field is the only field in the sqlite3_vfs 100911be35a1SLionel Sambuc ** structure that SQLite will ever modify. SQLite will only access 101011be35a1SLionel Sambuc ** or modify this field while holding a particular static mutex. 101111be35a1SLionel Sambuc ** The application should never modify anything within the sqlite3_vfs 101211be35a1SLionel Sambuc ** object once the object has been registered. 101311be35a1SLionel Sambuc ** 101411be35a1SLionel Sambuc ** The zName field holds the name of the VFS module. The name must 101511be35a1SLionel Sambuc ** be unique across all VFS modules. 101611be35a1SLionel Sambuc ** 101711be35a1SLionel Sambuc ** [[sqlite3_vfs.xOpen]] 101811be35a1SLionel Sambuc ** ^SQLite guarantees that the zFilename parameter to xOpen 101911be35a1SLionel Sambuc ** is either a NULL pointer or string obtained 102011be35a1SLionel Sambuc ** from xFullPathname() with an optional suffix added. 102111be35a1SLionel Sambuc ** ^If a suffix is added to the zFilename parameter, it will 102211be35a1SLionel Sambuc ** consist of a single "-" character followed by no more than 102311be35a1SLionel Sambuc ** 11 alphanumeric and/or "-" characters. 102411be35a1SLionel Sambuc ** ^SQLite further guarantees that 102511be35a1SLionel Sambuc ** the string will be valid and unchanged until xClose() is 102611be35a1SLionel Sambuc ** called. Because of the previous sentence, 102711be35a1SLionel Sambuc ** the [sqlite3_file] can safely store a pointer to the 102811be35a1SLionel Sambuc ** filename if it needs to remember the filename for some reason. 102911be35a1SLionel Sambuc ** If the zFilename parameter to xOpen is a NULL pointer then xOpen 103011be35a1SLionel Sambuc ** must invent its own temporary name for the file. ^Whenever the 103111be35a1SLionel Sambuc ** xFilename parameter is NULL it will also be the case that the 103211be35a1SLionel Sambuc ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE]. 103311be35a1SLionel Sambuc ** 103411be35a1SLionel Sambuc ** The flags argument to xOpen() includes all bits set in 103511be35a1SLionel Sambuc ** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()] 103611be35a1SLionel Sambuc ** or [sqlite3_open16()] is used, then flags includes at least 103711be35a1SLionel Sambuc ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]. 103811be35a1SLionel Sambuc ** If xOpen() opens a file read-only then it sets *pOutFlags to 103911be35a1SLionel Sambuc ** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set. 104011be35a1SLionel Sambuc ** 104111be35a1SLionel Sambuc ** ^(SQLite will also add one of the following flags to the xOpen() 104211be35a1SLionel Sambuc ** call, depending on the object being opened: 104311be35a1SLionel Sambuc ** 104411be35a1SLionel Sambuc ** <ul> 104511be35a1SLionel Sambuc ** <li> [SQLITE_OPEN_MAIN_DB] 104611be35a1SLionel Sambuc ** <li> [SQLITE_OPEN_MAIN_JOURNAL] 104711be35a1SLionel Sambuc ** <li> [SQLITE_OPEN_TEMP_DB] 104811be35a1SLionel Sambuc ** <li> [SQLITE_OPEN_TEMP_JOURNAL] 104911be35a1SLionel Sambuc ** <li> [SQLITE_OPEN_TRANSIENT_DB] 105011be35a1SLionel Sambuc ** <li> [SQLITE_OPEN_SUBJOURNAL] 105111be35a1SLionel Sambuc ** <li> [SQLITE_OPEN_MASTER_JOURNAL] 105211be35a1SLionel Sambuc ** <li> [SQLITE_OPEN_WAL] 105311be35a1SLionel Sambuc ** </ul>)^ 105411be35a1SLionel Sambuc ** 105511be35a1SLionel Sambuc ** The file I/O implementation can use the object type flags to 105611be35a1SLionel Sambuc ** change the way it deals with files. For example, an application 105711be35a1SLionel Sambuc ** that does not care about crash recovery or rollback might make 105811be35a1SLionel Sambuc ** the open of a journal file a no-op. Writes to this journal would 105911be35a1SLionel Sambuc ** also be no-ops, and any attempt to read the journal would return 106011be35a1SLionel Sambuc ** SQLITE_IOERR. Or the implementation might recognize that a database 106111be35a1SLionel Sambuc ** file will be doing page-aligned sector reads and writes in a random 106211be35a1SLionel Sambuc ** order and set up its I/O subsystem accordingly. 106311be35a1SLionel Sambuc ** 106411be35a1SLionel Sambuc ** SQLite might also add one of the following flags to the xOpen method: 106511be35a1SLionel Sambuc ** 106611be35a1SLionel Sambuc ** <ul> 106711be35a1SLionel Sambuc ** <li> [SQLITE_OPEN_DELETEONCLOSE] 106811be35a1SLionel Sambuc ** <li> [SQLITE_OPEN_EXCLUSIVE] 106911be35a1SLionel Sambuc ** </ul> 107011be35a1SLionel Sambuc ** 107111be35a1SLionel Sambuc ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be 107211be35a1SLionel Sambuc ** deleted when it is closed. ^The [SQLITE_OPEN_DELETEONCLOSE] 107311be35a1SLionel Sambuc ** will be set for TEMP databases and their journals, transient 107411be35a1SLionel Sambuc ** databases, and subjournals. 107511be35a1SLionel Sambuc ** 107611be35a1SLionel Sambuc ** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction 107711be35a1SLionel Sambuc ** with the [SQLITE_OPEN_CREATE] flag, which are both directly 107811be35a1SLionel Sambuc ** analogous to the O_EXCL and O_CREAT flags of the POSIX open() 107911be35a1SLionel Sambuc ** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the 108011be35a1SLionel Sambuc ** SQLITE_OPEN_CREATE, is used to indicate that file should always 108111be35a1SLionel Sambuc ** be created, and that it is an error if it already exists. 108211be35a1SLionel Sambuc ** It is <i>not</i> used to indicate the file should be opened 108311be35a1SLionel Sambuc ** for exclusive access. 108411be35a1SLionel Sambuc ** 108511be35a1SLionel Sambuc ** ^At least szOsFile bytes of memory are allocated by SQLite 108611be35a1SLionel Sambuc ** to hold the [sqlite3_file] structure passed as the third 108711be35a1SLionel Sambuc ** argument to xOpen. The xOpen method does not have to 108811be35a1SLionel Sambuc ** allocate the structure; it should just fill it in. Note that 108911be35a1SLionel Sambuc ** the xOpen method must set the sqlite3_file.pMethods to either 109011be35a1SLionel Sambuc ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do 109111be35a1SLionel Sambuc ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods 109211be35a1SLionel Sambuc ** element will be valid after xOpen returns regardless of the success 109311be35a1SLionel Sambuc ** or failure of the xOpen call. 109411be35a1SLionel Sambuc ** 109511be35a1SLionel Sambuc ** [[sqlite3_vfs.xAccess]] 109611be35a1SLionel Sambuc ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS] 109711be35a1SLionel Sambuc ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to 109811be35a1SLionel Sambuc ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ] 109911be35a1SLionel Sambuc ** to test whether a file is at least readable. The file can be a 110011be35a1SLionel Sambuc ** directory. 110111be35a1SLionel Sambuc ** 110211be35a1SLionel Sambuc ** ^SQLite will always allocate at least mxPathname+1 bytes for the 110311be35a1SLionel Sambuc ** output buffer xFullPathname. The exact size of the output buffer 110411be35a1SLionel Sambuc ** is also passed as a parameter to both methods. If the output buffer 110511be35a1SLionel Sambuc ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is 110611be35a1SLionel Sambuc ** handled as a fatal error by SQLite, vfs implementations should endeavor 110711be35a1SLionel Sambuc ** to prevent this by setting mxPathname to a sufficiently large value. 110811be35a1SLionel Sambuc ** 110911be35a1SLionel Sambuc ** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64() 111011be35a1SLionel Sambuc ** interfaces are not strictly a part of the filesystem, but they are 111111be35a1SLionel Sambuc ** included in the VFS structure for completeness. 111211be35a1SLionel Sambuc ** The xRandomness() function attempts to return nBytes bytes 111311be35a1SLionel Sambuc ** of good-quality randomness into zOut. The return value is 111411be35a1SLionel Sambuc ** the actual number of bytes of randomness obtained. 111511be35a1SLionel Sambuc ** The xSleep() method causes the calling thread to sleep for at 111611be35a1SLionel Sambuc ** least the number of microseconds given. ^The xCurrentTime() 111711be35a1SLionel Sambuc ** method returns a Julian Day Number for the current date and time as 111811be35a1SLionel Sambuc ** a floating point value. 111911be35a1SLionel Sambuc ** ^The xCurrentTimeInt64() method returns, as an integer, the Julian 112011be35a1SLionel Sambuc ** Day Number multiplied by 86400000 (the number of milliseconds in 112111be35a1SLionel Sambuc ** a 24-hour day). 112211be35a1SLionel Sambuc ** ^SQLite will use the xCurrentTimeInt64() method to get the current 112311be35a1SLionel Sambuc ** date and time if that method is available (if iVersion is 2 or 112411be35a1SLionel Sambuc ** greater and the function pointer is not NULL) and will fall back 112511be35a1SLionel Sambuc ** to xCurrentTime() if xCurrentTimeInt64() is unavailable. 112611be35a1SLionel Sambuc ** 112711be35a1SLionel Sambuc ** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces 112811be35a1SLionel Sambuc ** are not used by the SQLite core. These optional interfaces are provided 112911be35a1SLionel Sambuc ** by some VFSes to facilitate testing of the VFS code. By overriding 113011be35a1SLionel Sambuc ** system calls with functions under its control, a test program can 113111be35a1SLionel Sambuc ** simulate faults and error conditions that would otherwise be difficult 113211be35a1SLionel Sambuc ** or impossible to induce. The set of system calls that can be overridden 113311be35a1SLionel Sambuc ** varies from one VFS to another, and from one version of the same VFS to the 113411be35a1SLionel Sambuc ** next. Applications that use these interfaces must be prepared for any 113511be35a1SLionel Sambuc ** or all of these interfaces to be NULL or for their behavior to change 113611be35a1SLionel Sambuc ** from one release to the next. Applications must not attempt to access 113711be35a1SLionel Sambuc ** any of these methods if the iVersion of the VFS is less than 3. 113811be35a1SLionel Sambuc */ 113911be35a1SLionel Sambuc typedef struct sqlite3_vfs sqlite3_vfs; 114011be35a1SLionel Sambuc typedef void (*sqlite3_syscall_ptr)(void); 114111be35a1SLionel Sambuc struct sqlite3_vfs { 114211be35a1SLionel Sambuc int iVersion; /* Structure version number (currently 3) */ 114311be35a1SLionel Sambuc int szOsFile; /* Size of subclassed sqlite3_file */ 114411be35a1SLionel Sambuc int mxPathname; /* Maximum file pathname length */ 114511be35a1SLionel Sambuc sqlite3_vfs *pNext; /* Next registered VFS */ 114611be35a1SLionel Sambuc const char *zName; /* Name of this virtual file system */ 114711be35a1SLionel Sambuc void *pAppData; /* Pointer to application-specific data */ 114811be35a1SLionel Sambuc int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*, 114911be35a1SLionel Sambuc int flags, int *pOutFlags); 115011be35a1SLionel Sambuc int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir); 115111be35a1SLionel Sambuc int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut); 115211be35a1SLionel Sambuc int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut); 115311be35a1SLionel Sambuc void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename); 115411be35a1SLionel Sambuc void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg); 115511be35a1SLionel Sambuc void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void); 115611be35a1SLionel Sambuc void (*xDlClose)(sqlite3_vfs*, void*); 115711be35a1SLionel Sambuc int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut); 115811be35a1SLionel Sambuc int (*xSleep)(sqlite3_vfs*, int microseconds); 115911be35a1SLionel Sambuc int (*xCurrentTime)(sqlite3_vfs*, double*); 116011be35a1SLionel Sambuc int (*xGetLastError)(sqlite3_vfs*, int, char *); 116111be35a1SLionel Sambuc /* 116211be35a1SLionel Sambuc ** The methods above are in version 1 of the sqlite_vfs object 116311be35a1SLionel Sambuc ** definition. Those that follow are added in version 2 or later 116411be35a1SLionel Sambuc */ 116511be35a1SLionel Sambuc int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*); 116611be35a1SLionel Sambuc /* 116711be35a1SLionel Sambuc ** The methods above are in versions 1 and 2 of the sqlite_vfs object. 116811be35a1SLionel Sambuc ** Those below are for version 3 and greater. 116911be35a1SLionel Sambuc */ 117011be35a1SLionel Sambuc int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr); 117111be35a1SLionel Sambuc sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName); 117211be35a1SLionel Sambuc const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName); 117311be35a1SLionel Sambuc /* 117411be35a1SLionel Sambuc ** The methods above are in versions 1 through 3 of the sqlite_vfs object. 117511be35a1SLionel Sambuc ** New fields may be appended in figure versions. The iVersion 117611be35a1SLionel Sambuc ** value will increment whenever this happens. 117711be35a1SLionel Sambuc */ 117811be35a1SLionel Sambuc }; 117911be35a1SLionel Sambuc 118011be35a1SLionel Sambuc /* 118111be35a1SLionel Sambuc ** CAPI3REF: Flags for the xAccess VFS method 118211be35a1SLionel Sambuc ** 118311be35a1SLionel Sambuc ** These integer constants can be used as the third parameter to 118411be35a1SLionel Sambuc ** the xAccess method of an [sqlite3_vfs] object. They determine 118511be35a1SLionel Sambuc ** what kind of permissions the xAccess method is looking for. 118611be35a1SLionel Sambuc ** With SQLITE_ACCESS_EXISTS, the xAccess method 118711be35a1SLionel Sambuc ** simply checks whether the file exists. 118811be35a1SLionel Sambuc ** With SQLITE_ACCESS_READWRITE, the xAccess method 118911be35a1SLionel Sambuc ** checks whether the named directory is both readable and writable 119011be35a1SLionel Sambuc ** (in other words, if files can be added, removed, and renamed within 119111be35a1SLionel Sambuc ** the directory). 119211be35a1SLionel Sambuc ** The SQLITE_ACCESS_READWRITE constant is currently used only by the 119311be35a1SLionel Sambuc ** [temp_store_directory pragma], though this could change in a future 119411be35a1SLionel Sambuc ** release of SQLite. 119511be35a1SLionel Sambuc ** With SQLITE_ACCESS_READ, the xAccess method 119611be35a1SLionel Sambuc ** checks whether the file is readable. The SQLITE_ACCESS_READ constant is 119711be35a1SLionel Sambuc ** currently unused, though it might be used in a future release of 119811be35a1SLionel Sambuc ** SQLite. 119911be35a1SLionel Sambuc */ 120011be35a1SLionel Sambuc #define SQLITE_ACCESS_EXISTS 0 120111be35a1SLionel Sambuc #define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */ 120211be35a1SLionel Sambuc #define SQLITE_ACCESS_READ 2 /* Unused */ 120311be35a1SLionel Sambuc 120411be35a1SLionel Sambuc /* 120511be35a1SLionel Sambuc ** CAPI3REF: Flags for the xShmLock VFS method 120611be35a1SLionel Sambuc ** 120711be35a1SLionel Sambuc ** These integer constants define the various locking operations 120811be35a1SLionel Sambuc ** allowed by the xShmLock method of [sqlite3_io_methods]. The 120911be35a1SLionel Sambuc ** following are the only legal combinations of flags to the 121011be35a1SLionel Sambuc ** xShmLock method: 121111be35a1SLionel Sambuc ** 121211be35a1SLionel Sambuc ** <ul> 121311be35a1SLionel Sambuc ** <li> SQLITE_SHM_LOCK | SQLITE_SHM_SHARED 121411be35a1SLionel Sambuc ** <li> SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE 121511be35a1SLionel Sambuc ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED 121611be35a1SLionel Sambuc ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE 121711be35a1SLionel Sambuc ** </ul> 121811be35a1SLionel Sambuc ** 121911be35a1SLionel Sambuc ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as 122011be35a1SLionel Sambuc ** was given no the corresponding lock. 122111be35a1SLionel Sambuc ** 122211be35a1SLionel Sambuc ** The xShmLock method can transition between unlocked and SHARED or 122311be35a1SLionel Sambuc ** between unlocked and EXCLUSIVE. It cannot transition between SHARED 122411be35a1SLionel Sambuc ** and EXCLUSIVE. 122511be35a1SLionel Sambuc */ 122611be35a1SLionel Sambuc #define SQLITE_SHM_UNLOCK 1 122711be35a1SLionel Sambuc #define SQLITE_SHM_LOCK 2 122811be35a1SLionel Sambuc #define SQLITE_SHM_SHARED 4 122911be35a1SLionel Sambuc #define SQLITE_SHM_EXCLUSIVE 8 123011be35a1SLionel Sambuc 123111be35a1SLionel Sambuc /* 123211be35a1SLionel Sambuc ** CAPI3REF: Maximum xShmLock index 123311be35a1SLionel Sambuc ** 123411be35a1SLionel Sambuc ** The xShmLock method on [sqlite3_io_methods] may use values 123511be35a1SLionel Sambuc ** between 0 and this upper bound as its "offset" argument. 123611be35a1SLionel Sambuc ** The SQLite core will never attempt to acquire or release a 123711be35a1SLionel Sambuc ** lock outside of this range 123811be35a1SLionel Sambuc */ 123911be35a1SLionel Sambuc #define SQLITE_SHM_NLOCK 8 124011be35a1SLionel Sambuc 124111be35a1SLionel Sambuc 124211be35a1SLionel Sambuc /* 124311be35a1SLionel Sambuc ** CAPI3REF: Initialize The SQLite Library 124411be35a1SLionel Sambuc ** 124511be35a1SLionel Sambuc ** ^The sqlite3_initialize() routine initializes the 124611be35a1SLionel Sambuc ** SQLite library. ^The sqlite3_shutdown() routine 124711be35a1SLionel Sambuc ** deallocates any resources that were allocated by sqlite3_initialize(). 124811be35a1SLionel Sambuc ** These routines are designed to aid in process initialization and 124911be35a1SLionel Sambuc ** shutdown on embedded systems. Workstation applications using 125011be35a1SLionel Sambuc ** SQLite normally do not need to invoke either of these routines. 125111be35a1SLionel Sambuc ** 125211be35a1SLionel Sambuc ** A call to sqlite3_initialize() is an "effective" call if it is 125311be35a1SLionel Sambuc ** the first time sqlite3_initialize() is invoked during the lifetime of 125411be35a1SLionel Sambuc ** the process, or if it is the first time sqlite3_initialize() is invoked 125511be35a1SLionel Sambuc ** following a call to sqlite3_shutdown(). ^(Only an effective call 125611be35a1SLionel Sambuc ** of sqlite3_initialize() does any initialization. All other calls 125711be35a1SLionel Sambuc ** are harmless no-ops.)^ 125811be35a1SLionel Sambuc ** 125911be35a1SLionel Sambuc ** A call to sqlite3_shutdown() is an "effective" call if it is the first 126011be35a1SLionel Sambuc ** call to sqlite3_shutdown() since the last sqlite3_initialize(). ^(Only 126111be35a1SLionel Sambuc ** an effective call to sqlite3_shutdown() does any deinitialization. 126211be35a1SLionel Sambuc ** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^ 126311be35a1SLionel Sambuc ** 126411be35a1SLionel Sambuc ** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown() 126511be35a1SLionel Sambuc ** is not. The sqlite3_shutdown() interface must only be called from a 126611be35a1SLionel Sambuc ** single thread. All open [database connections] must be closed and all 126711be35a1SLionel Sambuc ** other SQLite resources must be deallocated prior to invoking 126811be35a1SLionel Sambuc ** sqlite3_shutdown(). 126911be35a1SLionel Sambuc ** 127011be35a1SLionel Sambuc ** Among other things, ^sqlite3_initialize() will invoke 127111be35a1SLionel Sambuc ** sqlite3_os_init(). Similarly, ^sqlite3_shutdown() 127211be35a1SLionel Sambuc ** will invoke sqlite3_os_end(). 127311be35a1SLionel Sambuc ** 127411be35a1SLionel Sambuc ** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success. 127511be35a1SLionel Sambuc ** ^If for some reason, sqlite3_initialize() is unable to initialize 127611be35a1SLionel Sambuc ** the library (perhaps it is unable to allocate a needed resource such 127711be35a1SLionel Sambuc ** as a mutex) it returns an [error code] other than [SQLITE_OK]. 127811be35a1SLionel Sambuc ** 127911be35a1SLionel Sambuc ** ^The sqlite3_initialize() routine is called internally by many other 128011be35a1SLionel Sambuc ** SQLite interfaces so that an application usually does not need to 128111be35a1SLionel Sambuc ** invoke sqlite3_initialize() directly. For example, [sqlite3_open()] 128211be35a1SLionel Sambuc ** calls sqlite3_initialize() so the SQLite library will be automatically 128311be35a1SLionel Sambuc ** initialized when [sqlite3_open()] is called if it has not be initialized 128411be35a1SLionel Sambuc ** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT] 128511be35a1SLionel Sambuc ** compile-time option, then the automatic calls to sqlite3_initialize() 128611be35a1SLionel Sambuc ** are omitted and the application must call sqlite3_initialize() directly 128711be35a1SLionel Sambuc ** prior to using any other SQLite interface. For maximum portability, 128811be35a1SLionel Sambuc ** it is recommended that applications always invoke sqlite3_initialize() 128911be35a1SLionel Sambuc ** directly prior to using any other SQLite interface. Future releases 129011be35a1SLionel Sambuc ** of SQLite may require this. In other words, the behavior exhibited 129111be35a1SLionel Sambuc ** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the 129211be35a1SLionel Sambuc ** default behavior in some future release of SQLite. 129311be35a1SLionel Sambuc ** 129411be35a1SLionel Sambuc ** The sqlite3_os_init() routine does operating-system specific 129511be35a1SLionel Sambuc ** initialization of the SQLite library. The sqlite3_os_end() 129611be35a1SLionel Sambuc ** routine undoes the effect of sqlite3_os_init(). Typical tasks 129711be35a1SLionel Sambuc ** performed by these routines include allocation or deallocation 129811be35a1SLionel Sambuc ** of static resources, initialization of global variables, 129911be35a1SLionel Sambuc ** setting up a default [sqlite3_vfs] module, or setting up 130011be35a1SLionel Sambuc ** a default configuration using [sqlite3_config()]. 130111be35a1SLionel Sambuc ** 130211be35a1SLionel Sambuc ** The application should never invoke either sqlite3_os_init() 130311be35a1SLionel Sambuc ** or sqlite3_os_end() directly. The application should only invoke 130411be35a1SLionel Sambuc ** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init() 130511be35a1SLionel Sambuc ** interface is called automatically by sqlite3_initialize() and 130611be35a1SLionel Sambuc ** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate 130711be35a1SLionel Sambuc ** implementations for sqlite3_os_init() and sqlite3_os_end() 130811be35a1SLionel Sambuc ** are built into SQLite when it is compiled for Unix, Windows, or OS/2. 130911be35a1SLionel Sambuc ** When [custom builds | built for other platforms] 131011be35a1SLionel Sambuc ** (using the [SQLITE_OS_OTHER=1] compile-time 131111be35a1SLionel Sambuc ** option) the application must supply a suitable implementation for 131211be35a1SLionel Sambuc ** sqlite3_os_init() and sqlite3_os_end(). An application-supplied 131311be35a1SLionel Sambuc ** implementation of sqlite3_os_init() or sqlite3_os_end() 131411be35a1SLionel Sambuc ** must return [SQLITE_OK] on success and some other [error code] upon 131511be35a1SLionel Sambuc ** failure. 131611be35a1SLionel Sambuc */ 131711be35a1SLionel Sambuc SQLITE_API int sqlite3_initialize(void); 131811be35a1SLionel Sambuc SQLITE_API int sqlite3_shutdown(void); 131911be35a1SLionel Sambuc SQLITE_API int sqlite3_os_init(void); 132011be35a1SLionel Sambuc SQLITE_API int sqlite3_os_end(void); 132111be35a1SLionel Sambuc 132211be35a1SLionel Sambuc /* 132311be35a1SLionel Sambuc ** CAPI3REF: Configuring The SQLite Library 132411be35a1SLionel Sambuc ** 132511be35a1SLionel Sambuc ** The sqlite3_config() interface is used to make global configuration 132611be35a1SLionel Sambuc ** changes to SQLite in order to tune SQLite to the specific needs of 132711be35a1SLionel Sambuc ** the application. The default configuration is recommended for most 132811be35a1SLionel Sambuc ** applications and so this routine is usually not necessary. It is 132911be35a1SLionel Sambuc ** provided to support rare applications with unusual needs. 133011be35a1SLionel Sambuc ** 133111be35a1SLionel Sambuc ** The sqlite3_config() interface is not threadsafe. The application 133211be35a1SLionel Sambuc ** must insure that no other SQLite interfaces are invoked by other 133311be35a1SLionel Sambuc ** threads while sqlite3_config() is running. Furthermore, sqlite3_config() 133411be35a1SLionel Sambuc ** may only be invoked prior to library initialization using 133511be35a1SLionel Sambuc ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. 133611be35a1SLionel Sambuc ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before 133711be35a1SLionel Sambuc ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE. 133811be35a1SLionel Sambuc ** Note, however, that ^sqlite3_config() can be called as part of the 133911be35a1SLionel Sambuc ** implementation of an application-defined [sqlite3_os_init()]. 134011be35a1SLionel Sambuc ** 134111be35a1SLionel Sambuc ** The first argument to sqlite3_config() is an integer 134211be35a1SLionel Sambuc ** [configuration option] that determines 134311be35a1SLionel Sambuc ** what property of SQLite is to be configured. Subsequent arguments 134411be35a1SLionel Sambuc ** vary depending on the [configuration option] 134511be35a1SLionel Sambuc ** in the first argument. 134611be35a1SLionel Sambuc ** 134711be35a1SLionel Sambuc ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. 134811be35a1SLionel Sambuc ** ^If the option is unknown or SQLite is unable to set the option 134911be35a1SLionel Sambuc ** then this routine returns a non-zero [error code]. 135011be35a1SLionel Sambuc */ 135111be35a1SLionel Sambuc SQLITE_API int sqlite3_config(int, ...); 135211be35a1SLionel Sambuc 135311be35a1SLionel Sambuc /* 135411be35a1SLionel Sambuc ** CAPI3REF: Configure database connections 135511be35a1SLionel Sambuc ** 135611be35a1SLionel Sambuc ** The sqlite3_db_config() interface is used to make configuration 135711be35a1SLionel Sambuc ** changes to a [database connection]. The interface is similar to 135811be35a1SLionel Sambuc ** [sqlite3_config()] except that the changes apply to a single 135911be35a1SLionel Sambuc ** [database connection] (specified in the first argument). 136011be35a1SLionel Sambuc ** 136111be35a1SLionel Sambuc ** The second argument to sqlite3_db_config(D,V,...) is the 136211be35a1SLionel Sambuc ** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code 136311be35a1SLionel Sambuc ** that indicates what aspect of the [database connection] is being configured. 136411be35a1SLionel Sambuc ** Subsequent arguments vary depending on the configuration verb. 136511be35a1SLionel Sambuc ** 136611be35a1SLionel Sambuc ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if 136711be35a1SLionel Sambuc ** the call is considered successful. 136811be35a1SLionel Sambuc */ 136911be35a1SLionel Sambuc SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...); 137011be35a1SLionel Sambuc 137111be35a1SLionel Sambuc /* 137211be35a1SLionel Sambuc ** CAPI3REF: Memory Allocation Routines 137311be35a1SLionel Sambuc ** 137411be35a1SLionel Sambuc ** An instance of this object defines the interface between SQLite 137511be35a1SLionel Sambuc ** and low-level memory allocation routines. 137611be35a1SLionel Sambuc ** 137711be35a1SLionel Sambuc ** This object is used in only one place in the SQLite interface. 137811be35a1SLionel Sambuc ** A pointer to an instance of this object is the argument to 137911be35a1SLionel Sambuc ** [sqlite3_config()] when the configuration option is 138011be35a1SLionel Sambuc ** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC]. 138111be35a1SLionel Sambuc ** By creating an instance of this object 138211be35a1SLionel Sambuc ** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC]) 138311be35a1SLionel Sambuc ** during configuration, an application can specify an alternative 138411be35a1SLionel Sambuc ** memory allocation subsystem for SQLite to use for all of its 138511be35a1SLionel Sambuc ** dynamic memory needs. 138611be35a1SLionel Sambuc ** 138711be35a1SLionel Sambuc ** Note that SQLite comes with several [built-in memory allocators] 138811be35a1SLionel Sambuc ** that are perfectly adequate for the overwhelming majority of applications 138911be35a1SLionel Sambuc ** and that this object is only useful to a tiny minority of applications 139011be35a1SLionel Sambuc ** with specialized memory allocation requirements. This object is 139111be35a1SLionel Sambuc ** also used during testing of SQLite in order to specify an alternative 139211be35a1SLionel Sambuc ** memory allocator that simulates memory out-of-memory conditions in 139311be35a1SLionel Sambuc ** order to verify that SQLite recovers gracefully from such 139411be35a1SLionel Sambuc ** conditions. 139511be35a1SLionel Sambuc ** 139611be35a1SLionel Sambuc ** The xMalloc, xRealloc, and xFree methods must work like the 139711be35a1SLionel Sambuc ** malloc(), realloc() and free() functions from the standard C library. 139811be35a1SLionel Sambuc ** ^SQLite guarantees that the second argument to 139911be35a1SLionel Sambuc ** xRealloc is always a value returned by a prior call to xRoundup. 140011be35a1SLionel Sambuc ** 140111be35a1SLionel Sambuc ** xSize should return the allocated size of a memory allocation 140211be35a1SLionel Sambuc ** previously obtained from xMalloc or xRealloc. The allocated size 140311be35a1SLionel Sambuc ** is always at least as big as the requested size but may be larger. 140411be35a1SLionel Sambuc ** 140511be35a1SLionel Sambuc ** The xRoundup method returns what would be the allocated size of 140611be35a1SLionel Sambuc ** a memory allocation given a particular requested size. Most memory 140711be35a1SLionel Sambuc ** allocators round up memory allocations at least to the next multiple 140811be35a1SLionel Sambuc ** of 8. Some allocators round up to a larger multiple or to a power of 2. 140911be35a1SLionel Sambuc ** Every memory allocation request coming in through [sqlite3_malloc()] 141011be35a1SLionel Sambuc ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0, 141111be35a1SLionel Sambuc ** that causes the corresponding memory allocation to fail. 141211be35a1SLionel Sambuc ** 1413*0a6a1f1dSLionel Sambuc ** The xInit method initializes the memory allocator. For example, 141411be35a1SLionel Sambuc ** it might allocate any require mutexes or initialize internal data 141511be35a1SLionel Sambuc ** structures. The xShutdown method is invoked (indirectly) by 141611be35a1SLionel Sambuc ** [sqlite3_shutdown()] and should deallocate any resources acquired 141711be35a1SLionel Sambuc ** by xInit. The pAppData pointer is used as the only parameter to 141811be35a1SLionel Sambuc ** xInit and xShutdown. 141911be35a1SLionel Sambuc ** 142011be35a1SLionel Sambuc ** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes 142111be35a1SLionel Sambuc ** the xInit method, so the xInit method need not be threadsafe. The 142211be35a1SLionel Sambuc ** xShutdown method is only called from [sqlite3_shutdown()] so it does 142311be35a1SLionel Sambuc ** not need to be threadsafe either. For all other methods, SQLite 142411be35a1SLionel Sambuc ** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the 142511be35a1SLionel Sambuc ** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which 142611be35a1SLionel Sambuc ** it is by default) and so the methods are automatically serialized. 142711be35a1SLionel Sambuc ** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other 142811be35a1SLionel Sambuc ** methods must be threadsafe or else make their own arrangements for 142911be35a1SLionel Sambuc ** serialization. 143011be35a1SLionel Sambuc ** 143111be35a1SLionel Sambuc ** SQLite will never invoke xInit() more than once without an intervening 143211be35a1SLionel Sambuc ** call to xShutdown(). 143311be35a1SLionel Sambuc */ 143411be35a1SLionel Sambuc typedef struct sqlite3_mem_methods sqlite3_mem_methods; 143511be35a1SLionel Sambuc struct sqlite3_mem_methods { 143611be35a1SLionel Sambuc void *(*xMalloc)(int); /* Memory allocation function */ 143711be35a1SLionel Sambuc void (*xFree)(void*); /* Free a prior allocation */ 143811be35a1SLionel Sambuc void *(*xRealloc)(void*,int); /* Resize an allocation */ 143911be35a1SLionel Sambuc int (*xSize)(void*); /* Return the size of an allocation */ 144011be35a1SLionel Sambuc int (*xRoundup)(int); /* Round up request size to allocation size */ 144111be35a1SLionel Sambuc int (*xInit)(void*); /* Initialize the memory allocator */ 144211be35a1SLionel Sambuc void (*xShutdown)(void*); /* Deinitialize the memory allocator */ 144311be35a1SLionel Sambuc void *pAppData; /* Argument to xInit() and xShutdown() */ 144411be35a1SLionel Sambuc }; 144511be35a1SLionel Sambuc 144611be35a1SLionel Sambuc /* 144711be35a1SLionel Sambuc ** CAPI3REF: Configuration Options 144811be35a1SLionel Sambuc ** KEYWORDS: {configuration option} 144911be35a1SLionel Sambuc ** 145011be35a1SLionel Sambuc ** These constants are the available integer configuration options that 145111be35a1SLionel Sambuc ** can be passed as the first argument to the [sqlite3_config()] interface. 145211be35a1SLionel Sambuc ** 145311be35a1SLionel Sambuc ** New configuration options may be added in future releases of SQLite. 145411be35a1SLionel Sambuc ** Existing configuration options might be discontinued. Applications 145511be35a1SLionel Sambuc ** should check the return code from [sqlite3_config()] to make sure that 145611be35a1SLionel Sambuc ** the call worked. The [sqlite3_config()] interface will return a 145711be35a1SLionel Sambuc ** non-zero [error code] if a discontinued or unsupported configuration option 145811be35a1SLionel Sambuc ** is invoked. 145911be35a1SLionel Sambuc ** 146011be35a1SLionel Sambuc ** <dl> 146111be35a1SLionel Sambuc ** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt> 146211be35a1SLionel Sambuc ** <dd>There are no arguments to this option. ^This option sets the 146311be35a1SLionel Sambuc ** [threading mode] to Single-thread. In other words, it disables 146411be35a1SLionel Sambuc ** all mutexing and puts SQLite into a mode where it can only be used 146511be35a1SLionel Sambuc ** by a single thread. ^If SQLite is compiled with 146611be35a1SLionel Sambuc ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 146711be35a1SLionel Sambuc ** it is not possible to change the [threading mode] from its default 146811be35a1SLionel Sambuc ** value of Single-thread and so [sqlite3_config()] will return 146911be35a1SLionel Sambuc ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD 147011be35a1SLionel Sambuc ** configuration option.</dd> 147111be35a1SLionel Sambuc ** 147211be35a1SLionel Sambuc ** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt> 147311be35a1SLionel Sambuc ** <dd>There are no arguments to this option. ^This option sets the 147411be35a1SLionel Sambuc ** [threading mode] to Multi-thread. In other words, it disables 147511be35a1SLionel Sambuc ** mutexing on [database connection] and [prepared statement] objects. 147611be35a1SLionel Sambuc ** The application is responsible for serializing access to 147711be35a1SLionel Sambuc ** [database connections] and [prepared statements]. But other mutexes 147811be35a1SLionel Sambuc ** are enabled so that SQLite will be safe to use in a multi-threaded 147911be35a1SLionel Sambuc ** environment as long as no two threads attempt to use the same 148011be35a1SLionel Sambuc ** [database connection] at the same time. ^If SQLite is compiled with 148111be35a1SLionel Sambuc ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 148211be35a1SLionel Sambuc ** it is not possible to set the Multi-thread [threading mode] and 148311be35a1SLionel Sambuc ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the 148411be35a1SLionel Sambuc ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd> 148511be35a1SLionel Sambuc ** 148611be35a1SLionel Sambuc ** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt> 148711be35a1SLionel Sambuc ** <dd>There are no arguments to this option. ^This option sets the 148811be35a1SLionel Sambuc ** [threading mode] to Serialized. In other words, this option enables 148911be35a1SLionel Sambuc ** all mutexes including the recursive 149011be35a1SLionel Sambuc ** mutexes on [database connection] and [prepared statement] objects. 149111be35a1SLionel Sambuc ** In this mode (which is the default when SQLite is compiled with 149211be35a1SLionel Sambuc ** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access 149311be35a1SLionel Sambuc ** to [database connections] and [prepared statements] so that the 149411be35a1SLionel Sambuc ** application is free to use the same [database connection] or the 149511be35a1SLionel Sambuc ** same [prepared statement] in different threads at the same time. 149611be35a1SLionel Sambuc ** ^If SQLite is compiled with 149711be35a1SLionel Sambuc ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 149811be35a1SLionel Sambuc ** it is not possible to set the Serialized [threading mode] and 149911be35a1SLionel Sambuc ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the 150011be35a1SLionel Sambuc ** SQLITE_CONFIG_SERIALIZED configuration option.</dd> 150111be35a1SLionel Sambuc ** 150211be35a1SLionel Sambuc ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt> 150311be35a1SLionel Sambuc ** <dd> ^(This option takes a single argument which is a pointer to an 150411be35a1SLionel Sambuc ** instance of the [sqlite3_mem_methods] structure. The argument specifies 150511be35a1SLionel Sambuc ** alternative low-level memory allocation routines to be used in place of 150611be35a1SLionel Sambuc ** the memory allocation routines built into SQLite.)^ ^SQLite makes 150711be35a1SLionel Sambuc ** its own private copy of the content of the [sqlite3_mem_methods] structure 150811be35a1SLionel Sambuc ** before the [sqlite3_config()] call returns.</dd> 150911be35a1SLionel Sambuc ** 151011be35a1SLionel Sambuc ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt> 151111be35a1SLionel Sambuc ** <dd> ^(This option takes a single argument which is a pointer to an 151211be35a1SLionel Sambuc ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods] 151311be35a1SLionel Sambuc ** structure is filled with the currently defined memory allocation routines.)^ 151411be35a1SLionel Sambuc ** This option can be used to overload the default memory allocation 151511be35a1SLionel Sambuc ** routines with a wrapper that simulations memory allocation failure or 151611be35a1SLionel Sambuc ** tracks memory usage, for example. </dd> 151711be35a1SLionel Sambuc ** 151811be35a1SLionel Sambuc ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt> 151911be35a1SLionel Sambuc ** <dd> ^This option takes single argument of type int, interpreted as a 152011be35a1SLionel Sambuc ** boolean, which enables or disables the collection of memory allocation 152111be35a1SLionel Sambuc ** statistics. ^(When memory allocation statistics are disabled, the 152211be35a1SLionel Sambuc ** following SQLite interfaces become non-operational: 152311be35a1SLionel Sambuc ** <ul> 152411be35a1SLionel Sambuc ** <li> [sqlite3_memory_used()] 152511be35a1SLionel Sambuc ** <li> [sqlite3_memory_highwater()] 152611be35a1SLionel Sambuc ** <li> [sqlite3_soft_heap_limit64()] 152711be35a1SLionel Sambuc ** <li> [sqlite3_status()] 152811be35a1SLionel Sambuc ** </ul>)^ 152911be35a1SLionel Sambuc ** ^Memory allocation statistics are enabled by default unless SQLite is 153011be35a1SLionel Sambuc ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory 153111be35a1SLionel Sambuc ** allocation statistics are disabled by default. 153211be35a1SLionel Sambuc ** </dd> 153311be35a1SLionel Sambuc ** 153411be35a1SLionel Sambuc ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt> 153511be35a1SLionel Sambuc ** <dd> ^This option specifies a static memory buffer that SQLite can use for 153611be35a1SLionel Sambuc ** scratch memory. There are three arguments: A pointer an 8-byte 153711be35a1SLionel Sambuc ** aligned memory buffer from which the scratch allocations will be 153811be35a1SLionel Sambuc ** drawn, the size of each scratch allocation (sz), 153911be35a1SLionel Sambuc ** and the maximum number of scratch allocations (N). The sz 154011be35a1SLionel Sambuc ** argument must be a multiple of 16. 154111be35a1SLionel Sambuc ** The first argument must be a pointer to an 8-byte aligned buffer 154211be35a1SLionel Sambuc ** of at least sz*N bytes of memory. 154311be35a1SLionel Sambuc ** ^SQLite will use no more than two scratch buffers per thread. So 154411be35a1SLionel Sambuc ** N should be set to twice the expected maximum number of threads. 154511be35a1SLionel Sambuc ** ^SQLite will never require a scratch buffer that is more than 6 154611be35a1SLionel Sambuc ** times the database page size. ^If SQLite needs needs additional 154711be35a1SLionel Sambuc ** scratch memory beyond what is provided by this configuration option, then 154811be35a1SLionel Sambuc ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd> 154911be35a1SLionel Sambuc ** 155011be35a1SLionel Sambuc ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt> 155111be35a1SLionel Sambuc ** <dd> ^This option specifies a static memory buffer that SQLite can use for 155211be35a1SLionel Sambuc ** the database page cache with the default page cache implementation. 155311be35a1SLionel Sambuc ** This configuration should not be used if an application-define page 155411be35a1SLionel Sambuc ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE2 option. 155511be35a1SLionel Sambuc ** There are three arguments to this option: A pointer to 8-byte aligned 155611be35a1SLionel Sambuc ** memory, the size of each page buffer (sz), and the number of pages (N). 155711be35a1SLionel Sambuc ** The sz argument should be the size of the largest database page 155811be35a1SLionel Sambuc ** (a power of two between 512 and 32768) plus a little extra for each 155911be35a1SLionel Sambuc ** page header. ^The page header size is 20 to 40 bytes depending on 156011be35a1SLionel Sambuc ** the host architecture. ^It is harmless, apart from the wasted memory, 156111be35a1SLionel Sambuc ** to make sz a little too large. The first 156211be35a1SLionel Sambuc ** argument should point to an allocation of at least sz*N bytes of memory. 156311be35a1SLionel Sambuc ** ^SQLite will use the memory provided by the first argument to satisfy its 156411be35a1SLionel Sambuc ** memory needs for the first N pages that it adds to cache. ^If additional 156511be35a1SLionel Sambuc ** page cache memory is needed beyond what is provided by this option, then 156611be35a1SLionel Sambuc ** SQLite goes to [sqlite3_malloc()] for the additional storage space. 156711be35a1SLionel Sambuc ** The pointer in the first argument must 156811be35a1SLionel Sambuc ** be aligned to an 8-byte boundary or subsequent behavior of SQLite 156911be35a1SLionel Sambuc ** will be undefined.</dd> 157011be35a1SLionel Sambuc ** 157111be35a1SLionel Sambuc ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> 157211be35a1SLionel Sambuc ** <dd> ^This option specifies a static memory buffer that SQLite will use 157311be35a1SLionel Sambuc ** for all of its dynamic memory allocation needs beyond those provided 157411be35a1SLionel Sambuc ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. 157511be35a1SLionel Sambuc ** There are three arguments: An 8-byte aligned pointer to the memory, 157611be35a1SLionel Sambuc ** the number of bytes in the memory buffer, and the minimum allocation size. 157711be35a1SLionel Sambuc ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts 157811be35a1SLionel Sambuc ** to using its default memory allocator (the system malloc() implementation), 157911be35a1SLionel Sambuc ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the 158011be35a1SLionel Sambuc ** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or 158111be35a1SLionel Sambuc ** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory 158211be35a1SLionel Sambuc ** allocator is engaged to handle all of SQLites memory allocation needs. 158311be35a1SLionel Sambuc ** The first pointer (the memory pointer) must be aligned to an 8-byte 158411be35a1SLionel Sambuc ** boundary or subsequent behavior of SQLite will be undefined. 158511be35a1SLionel Sambuc ** The minimum allocation size is capped at 2**12. Reasonable values 158611be35a1SLionel Sambuc ** for the minimum allocation size are 2**5 through 2**8.</dd> 158711be35a1SLionel Sambuc ** 158811be35a1SLionel Sambuc ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt> 158911be35a1SLionel Sambuc ** <dd> ^(This option takes a single argument which is a pointer to an 159011be35a1SLionel Sambuc ** instance of the [sqlite3_mutex_methods] structure. The argument specifies 159111be35a1SLionel Sambuc ** alternative low-level mutex routines to be used in place 159211be35a1SLionel Sambuc ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the 159311be35a1SLionel Sambuc ** content of the [sqlite3_mutex_methods] structure before the call to 159411be35a1SLionel Sambuc ** [sqlite3_config()] returns. ^If SQLite is compiled with 159511be35a1SLionel Sambuc ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 159611be35a1SLionel Sambuc ** the entire mutexing subsystem is omitted from the build and hence calls to 159711be35a1SLionel Sambuc ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will 159811be35a1SLionel Sambuc ** return [SQLITE_ERROR].</dd> 159911be35a1SLionel Sambuc ** 160011be35a1SLionel Sambuc ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt> 160111be35a1SLionel Sambuc ** <dd> ^(This option takes a single argument which is a pointer to an 160211be35a1SLionel Sambuc ** instance of the [sqlite3_mutex_methods] structure. The 160311be35a1SLionel Sambuc ** [sqlite3_mutex_methods] 160411be35a1SLionel Sambuc ** structure is filled with the currently defined mutex routines.)^ 160511be35a1SLionel Sambuc ** This option can be used to overload the default mutex allocation 160611be35a1SLionel Sambuc ** routines with a wrapper used to track mutex usage for performance 160711be35a1SLionel Sambuc ** profiling or testing, for example. ^If SQLite is compiled with 160811be35a1SLionel Sambuc ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 160911be35a1SLionel Sambuc ** the entire mutexing subsystem is omitted from the build and hence calls to 161011be35a1SLionel Sambuc ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will 161111be35a1SLionel Sambuc ** return [SQLITE_ERROR].</dd> 161211be35a1SLionel Sambuc ** 161311be35a1SLionel Sambuc ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt> 161411be35a1SLionel Sambuc ** <dd> ^(This option takes two arguments that determine the default 161511be35a1SLionel Sambuc ** memory allocation for the lookaside memory allocator on each 161611be35a1SLionel Sambuc ** [database connection]. The first argument is the 161711be35a1SLionel Sambuc ** size of each lookaside buffer slot and the second is the number of 161811be35a1SLionel Sambuc ** slots allocated to each database connection.)^ ^(This option sets the 161911be35a1SLionel Sambuc ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] 162011be35a1SLionel Sambuc ** verb to [sqlite3_db_config()] can be used to change the lookaside 162111be35a1SLionel Sambuc ** configuration on individual connections.)^ </dd> 162211be35a1SLionel Sambuc ** 162311be35a1SLionel Sambuc ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt> 162411be35a1SLionel Sambuc ** <dd> ^(This option takes a single argument which is a pointer to 162511be35a1SLionel Sambuc ** an [sqlite3_pcache_methods2] object. This object specifies the interface 162611be35a1SLionel Sambuc ** to a custom page cache implementation.)^ ^SQLite makes a copy of the 162711be35a1SLionel Sambuc ** object and uses it for page cache memory allocations.</dd> 162811be35a1SLionel Sambuc ** 162911be35a1SLionel Sambuc ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt> 163011be35a1SLionel Sambuc ** <dd> ^(This option takes a single argument which is a pointer to an 163111be35a1SLionel Sambuc ** [sqlite3_pcache_methods2] object. SQLite copies of the current 163211be35a1SLionel Sambuc ** page cache implementation into that object.)^ </dd> 163311be35a1SLionel Sambuc ** 163411be35a1SLionel Sambuc ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> 1635*0a6a1f1dSLionel Sambuc ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite 1636*0a6a1f1dSLionel Sambuc ** global [error log]. 1637*0a6a1f1dSLionel Sambuc ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a 163811be35a1SLionel Sambuc ** function with a call signature of void(*)(void*,int,const char*), 163911be35a1SLionel Sambuc ** and a pointer to void. ^If the function pointer is not NULL, it is 164011be35a1SLionel Sambuc ** invoked by [sqlite3_log()] to process each logging event. ^If the 164111be35a1SLionel Sambuc ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op. 164211be35a1SLionel Sambuc ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is 164311be35a1SLionel Sambuc ** passed through as the first parameter to the application-defined logger 164411be35a1SLionel Sambuc ** function whenever that function is invoked. ^The second parameter to 164511be35a1SLionel Sambuc ** the logger function is a copy of the first parameter to the corresponding 164611be35a1SLionel Sambuc ** [sqlite3_log()] call and is intended to be a [result code] or an 164711be35a1SLionel Sambuc ** [extended result code]. ^The third parameter passed to the logger is 164811be35a1SLionel Sambuc ** log message after formatting via [sqlite3_snprintf()]. 164911be35a1SLionel Sambuc ** The SQLite logging interface is not reentrant; the logger function 165011be35a1SLionel Sambuc ** supplied by the application must not invoke any SQLite interface. 165111be35a1SLionel Sambuc ** In a multi-threaded application, the application-defined logger 165211be35a1SLionel Sambuc ** function must be threadsafe. </dd> 165311be35a1SLionel Sambuc ** 165411be35a1SLionel Sambuc ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI 1655*0a6a1f1dSLionel Sambuc ** <dd>^(This option takes a single argument of type int. If non-zero, then 165611be35a1SLionel Sambuc ** URI handling is globally enabled. If the parameter is zero, then URI handling 1657*0a6a1f1dSLionel Sambuc ** is globally disabled.)^ ^If URI handling is globally enabled, all filenames 165811be35a1SLionel Sambuc ** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or 165911be35a1SLionel Sambuc ** specified as part of [ATTACH] commands are interpreted as URIs, regardless 166011be35a1SLionel Sambuc ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database 1661*0a6a1f1dSLionel Sambuc ** connection is opened. ^If it is globally disabled, filenames are 166211be35a1SLionel Sambuc ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the 1663*0a6a1f1dSLionel Sambuc ** database connection is opened. ^(By default, URI handling is globally 166411be35a1SLionel Sambuc ** disabled. The default value may be changed by compiling with the 1665*0a6a1f1dSLionel Sambuc ** [SQLITE_USE_URI] symbol defined.)^ 1666*0a6a1f1dSLionel Sambuc ** 1667*0a6a1f1dSLionel Sambuc ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN 1668*0a6a1f1dSLionel Sambuc ** <dd>^This option takes a single integer argument which is interpreted as 1669*0a6a1f1dSLionel Sambuc ** a boolean in order to enable or disable the use of covering indices for 1670*0a6a1f1dSLionel Sambuc ** full table scans in the query optimizer. ^The default setting is determined 1671*0a6a1f1dSLionel Sambuc ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on" 1672*0a6a1f1dSLionel Sambuc ** if that compile-time option is omitted. 1673*0a6a1f1dSLionel Sambuc ** The ability to disable the use of covering indices for full table scans 1674*0a6a1f1dSLionel Sambuc ** is because some incorrectly coded legacy applications might malfunction 1675*0a6a1f1dSLionel Sambuc ** when the optimization is enabled. Providing the ability to 1676*0a6a1f1dSLionel Sambuc ** disable the optimization allows the older, buggy application code to work 1677*0a6a1f1dSLionel Sambuc ** without change even with newer versions of SQLite. 167811be35a1SLionel Sambuc ** 167911be35a1SLionel Sambuc ** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]] 1680*0a6a1f1dSLionel Sambuc ** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFIG_GETPCACHE 168111be35a1SLionel Sambuc ** <dd> These options are obsolete and should not be used by new code. 168211be35a1SLionel Sambuc ** They are retained for backwards compatibility but are now no-ops. 1683*0a6a1f1dSLionel Sambuc ** </dd> 1684*0a6a1f1dSLionel Sambuc ** 1685*0a6a1f1dSLionel Sambuc ** [[SQLITE_CONFIG_SQLLOG]] 1686*0a6a1f1dSLionel Sambuc ** <dt>SQLITE_CONFIG_SQLLOG 1687*0a6a1f1dSLionel Sambuc ** <dd>This option is only available if sqlite is compiled with the 1688*0a6a1f1dSLionel Sambuc ** [SQLITE_ENABLE_SQLLOG] pre-processor macro defined. The first argument should 1689*0a6a1f1dSLionel Sambuc ** be a pointer to a function of type void(*)(void*,sqlite3*,const char*, int). 1690*0a6a1f1dSLionel Sambuc ** The second should be of type (void*). The callback is invoked by the library 1691*0a6a1f1dSLionel Sambuc ** in three separate circumstances, identified by the value passed as the 1692*0a6a1f1dSLionel Sambuc ** fourth parameter. If the fourth parameter is 0, then the database connection 1693*0a6a1f1dSLionel Sambuc ** passed as the second argument has just been opened. The third argument 1694*0a6a1f1dSLionel Sambuc ** points to a buffer containing the name of the main database file. If the 1695*0a6a1f1dSLionel Sambuc ** fourth parameter is 1, then the SQL statement that the third parameter 1696*0a6a1f1dSLionel Sambuc ** points to has just been executed. Or, if the fourth parameter is 2, then 1697*0a6a1f1dSLionel Sambuc ** the connection being passed as the second parameter is being closed. The 1698*0a6a1f1dSLionel Sambuc ** third parameter is passed NULL In this case. An example of using this 1699*0a6a1f1dSLionel Sambuc ** configuration option can be seen in the "test_sqllog.c" source file in 1700*0a6a1f1dSLionel Sambuc ** the canonical SQLite source tree.</dd> 1701*0a6a1f1dSLionel Sambuc ** 1702*0a6a1f1dSLionel Sambuc ** [[SQLITE_CONFIG_MMAP_SIZE]] 1703*0a6a1f1dSLionel Sambuc ** <dt>SQLITE_CONFIG_MMAP_SIZE 1704*0a6a1f1dSLionel Sambuc ** <dd>^SQLITE_CONFIG_MMAP_SIZE takes two 64-bit integer (sqlite3_int64) values 1705*0a6a1f1dSLionel Sambuc ** that are the default mmap size limit (the default setting for 1706*0a6a1f1dSLionel Sambuc ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit. 1707*0a6a1f1dSLionel Sambuc ** ^The default setting can be overridden by each database connection using 1708*0a6a1f1dSLionel Sambuc ** either the [PRAGMA mmap_size] command, or by using the 1709*0a6a1f1dSLionel Sambuc ** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size 1710*0a6a1f1dSLionel Sambuc ** cannot be changed at run-time. Nor may the maximum allowed mmap size 1711*0a6a1f1dSLionel Sambuc ** exceed the compile-time maximum mmap size set by the 1712*0a6a1f1dSLionel Sambuc ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^ 1713*0a6a1f1dSLionel Sambuc ** ^If either argument to this option is negative, then that argument is 1714*0a6a1f1dSLionel Sambuc ** changed to its compile-time default. 1715*0a6a1f1dSLionel Sambuc ** 1716*0a6a1f1dSLionel Sambuc ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]] 1717*0a6a1f1dSLionel Sambuc ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE 1718*0a6a1f1dSLionel Sambuc ** <dd>^This option is only available if SQLite is compiled for Windows 1719*0a6a1f1dSLionel Sambuc ** with the [SQLITE_WIN32_MALLOC] pre-processor macro defined. 1720*0a6a1f1dSLionel Sambuc ** SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value 1721*0a6a1f1dSLionel Sambuc ** that specifies the maximum size of the created heap. 172211be35a1SLionel Sambuc ** </dl> 172311be35a1SLionel Sambuc */ 172411be35a1SLionel Sambuc #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ 172511be35a1SLionel Sambuc #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ 172611be35a1SLionel Sambuc #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ 172711be35a1SLionel Sambuc #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ 172811be35a1SLionel Sambuc #define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */ 172911be35a1SLionel Sambuc #define SQLITE_CONFIG_SCRATCH 6 /* void*, int sz, int N */ 173011be35a1SLionel Sambuc #define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */ 173111be35a1SLionel Sambuc #define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */ 173211be35a1SLionel Sambuc #define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */ 173311be35a1SLionel Sambuc #define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */ 173411be35a1SLionel Sambuc #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */ 173511be35a1SLionel Sambuc /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ 173611be35a1SLionel Sambuc #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ 173711be35a1SLionel Sambuc #define SQLITE_CONFIG_PCACHE 14 /* no-op */ 173811be35a1SLionel Sambuc #define SQLITE_CONFIG_GETPCACHE 15 /* no-op */ 173911be35a1SLionel Sambuc #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ 174011be35a1SLionel Sambuc #define SQLITE_CONFIG_URI 17 /* int */ 174111be35a1SLionel Sambuc #define SQLITE_CONFIG_PCACHE2 18 /* sqlite3_pcache_methods2* */ 174211be35a1SLionel Sambuc #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */ 1743*0a6a1f1dSLionel Sambuc #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */ 1744*0a6a1f1dSLionel Sambuc #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */ 1745*0a6a1f1dSLionel Sambuc #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */ 1746*0a6a1f1dSLionel Sambuc #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */ 174711be35a1SLionel Sambuc 174811be35a1SLionel Sambuc /* 174911be35a1SLionel Sambuc ** CAPI3REF: Database Connection Configuration Options 175011be35a1SLionel Sambuc ** 175111be35a1SLionel Sambuc ** These constants are the available integer configuration options that 175211be35a1SLionel Sambuc ** can be passed as the second argument to the [sqlite3_db_config()] interface. 175311be35a1SLionel Sambuc ** 175411be35a1SLionel Sambuc ** New configuration options may be added in future releases of SQLite. 175511be35a1SLionel Sambuc ** Existing configuration options might be discontinued. Applications 175611be35a1SLionel Sambuc ** should check the return code from [sqlite3_db_config()] to make sure that 175711be35a1SLionel Sambuc ** the call worked. ^The [sqlite3_db_config()] interface will return a 175811be35a1SLionel Sambuc ** non-zero [error code] if a discontinued or unsupported configuration option 175911be35a1SLionel Sambuc ** is invoked. 176011be35a1SLionel Sambuc ** 176111be35a1SLionel Sambuc ** <dl> 176211be35a1SLionel Sambuc ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt> 176311be35a1SLionel Sambuc ** <dd> ^This option takes three additional arguments that determine the 176411be35a1SLionel Sambuc ** [lookaside memory allocator] configuration for the [database connection]. 176511be35a1SLionel Sambuc ** ^The first argument (the third parameter to [sqlite3_db_config()] is a 176611be35a1SLionel Sambuc ** pointer to a memory buffer to use for lookaside memory. 176711be35a1SLionel Sambuc ** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb 176811be35a1SLionel Sambuc ** may be NULL in which case SQLite will allocate the 176911be35a1SLionel Sambuc ** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the 177011be35a1SLionel Sambuc ** size of each lookaside buffer slot. ^The third argument is the number of 177111be35a1SLionel Sambuc ** slots. The size of the buffer in the first argument must be greater than 177211be35a1SLionel Sambuc ** or equal to the product of the second and third arguments. The buffer 177311be35a1SLionel Sambuc ** must be aligned to an 8-byte boundary. ^If the second argument to 177411be35a1SLionel Sambuc ** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally 177511be35a1SLionel Sambuc ** rounded down to the next smaller multiple of 8. ^(The lookaside memory 177611be35a1SLionel Sambuc ** configuration for a database connection can only be changed when that 177711be35a1SLionel Sambuc ** connection is not currently using lookaside memory, or in other words 177811be35a1SLionel Sambuc ** when the "current value" returned by 177911be35a1SLionel Sambuc ** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero. 178011be35a1SLionel Sambuc ** Any attempt to change the lookaside memory configuration when lookaside 178111be35a1SLionel Sambuc ** memory is in use leaves the configuration unchanged and returns 178211be35a1SLionel Sambuc ** [SQLITE_BUSY].)^</dd> 178311be35a1SLionel Sambuc ** 178411be35a1SLionel Sambuc ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt> 178511be35a1SLionel Sambuc ** <dd> ^This option is used to enable or disable the enforcement of 178611be35a1SLionel Sambuc ** [foreign key constraints]. There should be two additional arguments. 178711be35a1SLionel Sambuc ** The first argument is an integer which is 0 to disable FK enforcement, 178811be35a1SLionel Sambuc ** positive to enable FK enforcement or negative to leave FK enforcement 178911be35a1SLionel Sambuc ** unchanged. The second parameter is a pointer to an integer into which 179011be35a1SLionel Sambuc ** is written 0 or 1 to indicate whether FK enforcement is off or on 179111be35a1SLionel Sambuc ** following this call. The second parameter may be a NULL pointer, in 179211be35a1SLionel Sambuc ** which case the FK enforcement setting is not reported back. </dd> 179311be35a1SLionel Sambuc ** 179411be35a1SLionel Sambuc ** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt> 179511be35a1SLionel Sambuc ** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers]. 179611be35a1SLionel Sambuc ** There should be two additional arguments. 179711be35a1SLionel Sambuc ** The first argument is an integer which is 0 to disable triggers, 179811be35a1SLionel Sambuc ** positive to enable triggers or negative to leave the setting unchanged. 179911be35a1SLionel Sambuc ** The second parameter is a pointer to an integer into which 180011be35a1SLionel Sambuc ** is written 0 or 1 to indicate whether triggers are disabled or enabled 180111be35a1SLionel Sambuc ** following this call. The second parameter may be a NULL pointer, in 180211be35a1SLionel Sambuc ** which case the trigger setting is not reported back. </dd> 180311be35a1SLionel Sambuc ** 180411be35a1SLionel Sambuc ** </dl> 180511be35a1SLionel Sambuc */ 180611be35a1SLionel Sambuc #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */ 180711be35a1SLionel Sambuc #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */ 180811be35a1SLionel Sambuc #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */ 180911be35a1SLionel Sambuc 181011be35a1SLionel Sambuc 181111be35a1SLionel Sambuc /* 181211be35a1SLionel Sambuc ** CAPI3REF: Enable Or Disable Extended Result Codes 181311be35a1SLionel Sambuc ** 181411be35a1SLionel Sambuc ** ^The sqlite3_extended_result_codes() routine enables or disables the 181511be35a1SLionel Sambuc ** [extended result codes] feature of SQLite. ^The extended result 181611be35a1SLionel Sambuc ** codes are disabled by default for historical compatibility. 181711be35a1SLionel Sambuc */ 181811be35a1SLionel Sambuc SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff); 181911be35a1SLionel Sambuc 182011be35a1SLionel Sambuc /* 182111be35a1SLionel Sambuc ** CAPI3REF: Last Insert Rowid 182211be35a1SLionel Sambuc ** 1823*0a6a1f1dSLionel Sambuc ** ^Each entry in most SQLite tables (except for [WITHOUT ROWID] tables) 1824*0a6a1f1dSLionel Sambuc ** has a unique 64-bit signed 182511be35a1SLionel Sambuc ** integer key called the [ROWID | "rowid"]. ^The rowid is always available 182611be35a1SLionel Sambuc ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those 182711be35a1SLionel Sambuc ** names are not also used by explicitly declared columns. ^If 182811be35a1SLionel Sambuc ** the table has a column of type [INTEGER PRIMARY KEY] then that column 182911be35a1SLionel Sambuc ** is another alias for the rowid. 183011be35a1SLionel Sambuc ** 1831*0a6a1f1dSLionel Sambuc ** ^The sqlite3_last_insert_rowid(D) interface returns the [rowid] of the 1832*0a6a1f1dSLionel Sambuc ** most recent successful [INSERT] into a rowid table or [virtual table] 1833*0a6a1f1dSLionel Sambuc ** on database connection D. 1834*0a6a1f1dSLionel Sambuc ** ^Inserts into [WITHOUT ROWID] tables are not recorded. 1835*0a6a1f1dSLionel Sambuc ** ^If no successful [INSERT]s into rowid tables 1836*0a6a1f1dSLionel Sambuc ** have ever occurred on the database connection D, 1837*0a6a1f1dSLionel Sambuc ** then sqlite3_last_insert_rowid(D) returns zero. 183811be35a1SLionel Sambuc ** 183911be35a1SLionel Sambuc ** ^(If an [INSERT] occurs within a trigger or within a [virtual table] 184011be35a1SLionel Sambuc ** method, then this routine will return the [rowid] of the inserted 184111be35a1SLionel Sambuc ** row as long as the trigger or virtual table method is running. 184211be35a1SLionel Sambuc ** But once the trigger or virtual table method ends, the value returned 184311be35a1SLionel Sambuc ** by this routine reverts to what it was before the trigger or virtual 184411be35a1SLionel Sambuc ** table method began.)^ 184511be35a1SLionel Sambuc ** 184611be35a1SLionel Sambuc ** ^An [INSERT] that fails due to a constraint violation is not a 184711be35a1SLionel Sambuc ** successful [INSERT] and does not change the value returned by this 184811be35a1SLionel Sambuc ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK, 184911be35a1SLionel Sambuc ** and INSERT OR ABORT make no changes to the return value of this 185011be35a1SLionel Sambuc ** routine when their insertion fails. ^(When INSERT OR REPLACE 185111be35a1SLionel Sambuc ** encounters a constraint violation, it does not fail. The 185211be35a1SLionel Sambuc ** INSERT continues to completion after deleting rows that caused 185311be35a1SLionel Sambuc ** the constraint problem so INSERT OR REPLACE will always change 185411be35a1SLionel Sambuc ** the return value of this interface.)^ 185511be35a1SLionel Sambuc ** 185611be35a1SLionel Sambuc ** ^For the purposes of this routine, an [INSERT] is considered to 185711be35a1SLionel Sambuc ** be successful even if it is subsequently rolled back. 185811be35a1SLionel Sambuc ** 185911be35a1SLionel Sambuc ** This function is accessible to SQL statements via the 186011be35a1SLionel Sambuc ** [last_insert_rowid() SQL function]. 186111be35a1SLionel Sambuc ** 186211be35a1SLionel Sambuc ** If a separate thread performs a new [INSERT] on the same 186311be35a1SLionel Sambuc ** database connection while the [sqlite3_last_insert_rowid()] 186411be35a1SLionel Sambuc ** function is running and thus changes the last insert [rowid], 186511be35a1SLionel Sambuc ** then the value returned by [sqlite3_last_insert_rowid()] is 186611be35a1SLionel Sambuc ** unpredictable and might not equal either the old or the new 186711be35a1SLionel Sambuc ** last insert [rowid]. 186811be35a1SLionel Sambuc */ 186911be35a1SLionel Sambuc SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); 187011be35a1SLionel Sambuc 187111be35a1SLionel Sambuc /* 187211be35a1SLionel Sambuc ** CAPI3REF: Count The Number Of Rows Modified 187311be35a1SLionel Sambuc ** 187411be35a1SLionel Sambuc ** ^This function returns the number of database rows that were changed 187511be35a1SLionel Sambuc ** or inserted or deleted by the most recently completed SQL statement 187611be35a1SLionel Sambuc ** on the [database connection] specified by the first parameter. 187711be35a1SLionel Sambuc ** ^(Only changes that are directly specified by the [INSERT], [UPDATE], 187811be35a1SLionel Sambuc ** or [DELETE] statement are counted. Auxiliary changes caused by 187911be35a1SLionel Sambuc ** triggers or [foreign key actions] are not counted.)^ Use the 188011be35a1SLionel Sambuc ** [sqlite3_total_changes()] function to find the total number of changes 188111be35a1SLionel Sambuc ** including changes caused by triggers and foreign key actions. 188211be35a1SLionel Sambuc ** 188311be35a1SLionel Sambuc ** ^Changes to a view that are simulated by an [INSTEAD OF trigger] 188411be35a1SLionel Sambuc ** are not counted. Only real table changes are counted. 188511be35a1SLionel Sambuc ** 188611be35a1SLionel Sambuc ** ^(A "row change" is a change to a single row of a single table 188711be35a1SLionel Sambuc ** caused by an INSERT, DELETE, or UPDATE statement. Rows that 188811be35a1SLionel Sambuc ** are changed as side effects of [REPLACE] constraint resolution, 188911be35a1SLionel Sambuc ** rollback, ABORT processing, [DROP TABLE], or by any other 189011be35a1SLionel Sambuc ** mechanisms do not count as direct row changes.)^ 189111be35a1SLionel Sambuc ** 189211be35a1SLionel Sambuc ** A "trigger context" is a scope of execution that begins and 189311be35a1SLionel Sambuc ** ends with the script of a [CREATE TRIGGER | trigger]. 189411be35a1SLionel Sambuc ** Most SQL statements are 189511be35a1SLionel Sambuc ** evaluated outside of any trigger. This is the "top level" 189611be35a1SLionel Sambuc ** trigger context. If a trigger fires from the top level, a 189711be35a1SLionel Sambuc ** new trigger context is entered for the duration of that one 189811be35a1SLionel Sambuc ** trigger. Subtriggers create subcontexts for their duration. 189911be35a1SLionel Sambuc ** 190011be35a1SLionel Sambuc ** ^Calling [sqlite3_exec()] or [sqlite3_step()] recursively does 190111be35a1SLionel Sambuc ** not create a new trigger context. 190211be35a1SLionel Sambuc ** 190311be35a1SLionel Sambuc ** ^This function returns the number of direct row changes in the 190411be35a1SLionel Sambuc ** most recent INSERT, UPDATE, or DELETE statement within the same 190511be35a1SLionel Sambuc ** trigger context. 190611be35a1SLionel Sambuc ** 190711be35a1SLionel Sambuc ** ^Thus, when called from the top level, this function returns the 190811be35a1SLionel Sambuc ** number of changes in the most recent INSERT, UPDATE, or DELETE 190911be35a1SLionel Sambuc ** that also occurred at the top level. ^(Within the body of a trigger, 191011be35a1SLionel Sambuc ** the sqlite3_changes() interface can be called to find the number of 191111be35a1SLionel Sambuc ** changes in the most recently completed INSERT, UPDATE, or DELETE 191211be35a1SLionel Sambuc ** statement within the body of the same trigger. 191311be35a1SLionel Sambuc ** However, the number returned does not include changes 191411be35a1SLionel Sambuc ** caused by subtriggers since those have their own context.)^ 191511be35a1SLionel Sambuc ** 191611be35a1SLionel Sambuc ** See also the [sqlite3_total_changes()] interface, the 191711be35a1SLionel Sambuc ** [count_changes pragma], and the [changes() SQL function]. 191811be35a1SLionel Sambuc ** 191911be35a1SLionel Sambuc ** If a separate thread makes changes on the same database connection 192011be35a1SLionel Sambuc ** while [sqlite3_changes()] is running then the value returned 192111be35a1SLionel Sambuc ** is unpredictable and not meaningful. 192211be35a1SLionel Sambuc */ 192311be35a1SLionel Sambuc SQLITE_API int sqlite3_changes(sqlite3*); 192411be35a1SLionel Sambuc 192511be35a1SLionel Sambuc /* 192611be35a1SLionel Sambuc ** CAPI3REF: Total Number Of Rows Modified 192711be35a1SLionel Sambuc ** 192811be35a1SLionel Sambuc ** ^This function returns the number of row changes caused by [INSERT], 192911be35a1SLionel Sambuc ** [UPDATE] or [DELETE] statements since the [database connection] was opened. 193011be35a1SLionel Sambuc ** ^(The count returned by sqlite3_total_changes() includes all changes 193111be35a1SLionel Sambuc ** from all [CREATE TRIGGER | trigger] contexts and changes made by 193211be35a1SLionel Sambuc ** [foreign key actions]. However, 193311be35a1SLionel Sambuc ** the count does not include changes used to implement [REPLACE] constraints, 193411be35a1SLionel Sambuc ** do rollbacks or ABORT processing, or [DROP TABLE] processing. The 193511be35a1SLionel Sambuc ** count does not include rows of views that fire an [INSTEAD OF trigger], 193611be35a1SLionel Sambuc ** though if the INSTEAD OF trigger makes changes of its own, those changes 193711be35a1SLionel Sambuc ** are counted.)^ 193811be35a1SLionel Sambuc ** ^The sqlite3_total_changes() function counts the changes as soon as 193911be35a1SLionel Sambuc ** the statement that makes them is completed (when the statement handle 194011be35a1SLionel Sambuc ** is passed to [sqlite3_reset()] or [sqlite3_finalize()]). 194111be35a1SLionel Sambuc ** 194211be35a1SLionel Sambuc ** See also the [sqlite3_changes()] interface, the 194311be35a1SLionel Sambuc ** [count_changes pragma], and the [total_changes() SQL function]. 194411be35a1SLionel Sambuc ** 194511be35a1SLionel Sambuc ** If a separate thread makes changes on the same database connection 194611be35a1SLionel Sambuc ** while [sqlite3_total_changes()] is running then the value 194711be35a1SLionel Sambuc ** returned is unpredictable and not meaningful. 194811be35a1SLionel Sambuc */ 194911be35a1SLionel Sambuc SQLITE_API int sqlite3_total_changes(sqlite3*); 195011be35a1SLionel Sambuc 195111be35a1SLionel Sambuc /* 195211be35a1SLionel Sambuc ** CAPI3REF: Interrupt A Long-Running Query 195311be35a1SLionel Sambuc ** 195411be35a1SLionel Sambuc ** ^This function causes any pending database operation to abort and 195511be35a1SLionel Sambuc ** return at its earliest opportunity. This routine is typically 195611be35a1SLionel Sambuc ** called in response to a user action such as pressing "Cancel" 195711be35a1SLionel Sambuc ** or Ctrl-C where the user wants a long query operation to halt 195811be35a1SLionel Sambuc ** immediately. 195911be35a1SLionel Sambuc ** 196011be35a1SLionel Sambuc ** ^It is safe to call this routine from a thread different from the 196111be35a1SLionel Sambuc ** thread that is currently running the database operation. But it 196211be35a1SLionel Sambuc ** is not safe to call this routine with a [database connection] that 196311be35a1SLionel Sambuc ** is closed or might close before sqlite3_interrupt() returns. 196411be35a1SLionel Sambuc ** 196511be35a1SLionel Sambuc ** ^If an SQL operation is very nearly finished at the time when 196611be35a1SLionel Sambuc ** sqlite3_interrupt() is called, then it might not have an opportunity 196711be35a1SLionel Sambuc ** to be interrupted and might continue to completion. 196811be35a1SLionel Sambuc ** 196911be35a1SLionel Sambuc ** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT]. 197011be35a1SLionel Sambuc ** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE 197111be35a1SLionel Sambuc ** that is inside an explicit transaction, then the entire transaction 197211be35a1SLionel Sambuc ** will be rolled back automatically. 197311be35a1SLionel Sambuc ** 197411be35a1SLionel Sambuc ** ^The sqlite3_interrupt(D) call is in effect until all currently running 197511be35a1SLionel Sambuc ** SQL statements on [database connection] D complete. ^Any new SQL statements 197611be35a1SLionel Sambuc ** that are started after the sqlite3_interrupt() call and before the 197711be35a1SLionel Sambuc ** running statements reaches zero are interrupted as if they had been 197811be35a1SLionel Sambuc ** running prior to the sqlite3_interrupt() call. ^New SQL statements 197911be35a1SLionel Sambuc ** that are started after the running statement count reaches zero are 198011be35a1SLionel Sambuc ** not effected by the sqlite3_interrupt(). 198111be35a1SLionel Sambuc ** ^A call to sqlite3_interrupt(D) that occurs when there are no running 198211be35a1SLionel Sambuc ** SQL statements is a no-op and has no effect on SQL statements 198311be35a1SLionel Sambuc ** that are started after the sqlite3_interrupt() call returns. 198411be35a1SLionel Sambuc ** 198511be35a1SLionel Sambuc ** If the database connection closes while [sqlite3_interrupt()] 198611be35a1SLionel Sambuc ** is running then bad things will likely happen. 198711be35a1SLionel Sambuc */ 198811be35a1SLionel Sambuc SQLITE_API void sqlite3_interrupt(sqlite3*); 198911be35a1SLionel Sambuc 199011be35a1SLionel Sambuc /* 199111be35a1SLionel Sambuc ** CAPI3REF: Determine If An SQL Statement Is Complete 199211be35a1SLionel Sambuc ** 199311be35a1SLionel Sambuc ** These routines are useful during command-line input to determine if the 199411be35a1SLionel Sambuc ** currently entered text seems to form a complete SQL statement or 199511be35a1SLionel Sambuc ** if additional input is needed before sending the text into 199611be35a1SLionel Sambuc ** SQLite for parsing. ^These routines return 1 if the input string 199711be35a1SLionel Sambuc ** appears to be a complete SQL statement. ^A statement is judged to be 199811be35a1SLionel Sambuc ** complete if it ends with a semicolon token and is not a prefix of a 199911be35a1SLionel Sambuc ** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within 200011be35a1SLionel Sambuc ** string literals or quoted identifier names or comments are not 200111be35a1SLionel Sambuc ** independent tokens (they are part of the token in which they are 200211be35a1SLionel Sambuc ** embedded) and thus do not count as a statement terminator. ^Whitespace 200311be35a1SLionel Sambuc ** and comments that follow the final semicolon are ignored. 200411be35a1SLionel Sambuc ** 200511be35a1SLionel Sambuc ** ^These routines return 0 if the statement is incomplete. ^If a 200611be35a1SLionel Sambuc ** memory allocation fails, then SQLITE_NOMEM is returned. 200711be35a1SLionel Sambuc ** 200811be35a1SLionel Sambuc ** ^These routines do not parse the SQL statements thus 200911be35a1SLionel Sambuc ** will not detect syntactically incorrect SQL. 201011be35a1SLionel Sambuc ** 201111be35a1SLionel Sambuc ** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior 201211be35a1SLionel Sambuc ** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked 201311be35a1SLionel Sambuc ** automatically by sqlite3_complete16(). If that initialization fails, 201411be35a1SLionel Sambuc ** then the return value from sqlite3_complete16() will be non-zero 201511be35a1SLionel Sambuc ** regardless of whether or not the input SQL is complete.)^ 201611be35a1SLionel Sambuc ** 201711be35a1SLionel Sambuc ** The input to [sqlite3_complete()] must be a zero-terminated 201811be35a1SLionel Sambuc ** UTF-8 string. 201911be35a1SLionel Sambuc ** 202011be35a1SLionel Sambuc ** The input to [sqlite3_complete16()] must be a zero-terminated 202111be35a1SLionel Sambuc ** UTF-16 string in native byte order. 202211be35a1SLionel Sambuc */ 202311be35a1SLionel Sambuc SQLITE_API int sqlite3_complete(const char *sql); 202411be35a1SLionel Sambuc SQLITE_API int sqlite3_complete16(const void *sql); 202511be35a1SLionel Sambuc 202611be35a1SLionel Sambuc /* 202711be35a1SLionel Sambuc ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors 202811be35a1SLionel Sambuc ** 202911be35a1SLionel Sambuc ** ^This routine sets a callback function that might be invoked whenever 203011be35a1SLionel Sambuc ** an attempt is made to open a database table that another thread 203111be35a1SLionel Sambuc ** or process has locked. 203211be35a1SLionel Sambuc ** 203311be35a1SLionel Sambuc ** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] 203411be35a1SLionel Sambuc ** is returned immediately upon encountering the lock. ^If the busy callback 203511be35a1SLionel Sambuc ** is not NULL, then the callback might be invoked with two arguments. 203611be35a1SLionel Sambuc ** 203711be35a1SLionel Sambuc ** ^The first argument to the busy handler is a copy of the void* pointer which 203811be35a1SLionel Sambuc ** is the third argument to sqlite3_busy_handler(). ^The second argument to 203911be35a1SLionel Sambuc ** the busy handler callback is the number of times that the busy handler has 204011be35a1SLionel Sambuc ** been invoked for this locking event. ^If the 204111be35a1SLionel Sambuc ** busy callback returns 0, then no additional attempts are made to 204211be35a1SLionel Sambuc ** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned. 204311be35a1SLionel Sambuc ** ^If the callback returns non-zero, then another attempt 204411be35a1SLionel Sambuc ** is made to open the database for reading and the cycle repeats. 204511be35a1SLionel Sambuc ** 204611be35a1SLionel Sambuc ** The presence of a busy handler does not guarantee that it will be invoked 204711be35a1SLionel Sambuc ** when there is lock contention. ^If SQLite determines that invoking the busy 204811be35a1SLionel Sambuc ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY] 204911be35a1SLionel Sambuc ** or [SQLITE_IOERR_BLOCKED] instead of invoking the busy handler. 205011be35a1SLionel Sambuc ** Consider a scenario where one process is holding a read lock that 205111be35a1SLionel Sambuc ** it is trying to promote to a reserved lock and 205211be35a1SLionel Sambuc ** a second process is holding a reserved lock that it is trying 205311be35a1SLionel Sambuc ** to promote to an exclusive lock. The first process cannot proceed 205411be35a1SLionel Sambuc ** because it is blocked by the second and the second process cannot 205511be35a1SLionel Sambuc ** proceed because it is blocked by the first. If both processes 205611be35a1SLionel Sambuc ** invoke the busy handlers, neither will make any progress. Therefore, 205711be35a1SLionel Sambuc ** SQLite returns [SQLITE_BUSY] for the first process, hoping that this 205811be35a1SLionel Sambuc ** will induce the first process to release its read lock and allow 205911be35a1SLionel Sambuc ** the second process to proceed. 206011be35a1SLionel Sambuc ** 206111be35a1SLionel Sambuc ** ^The default busy callback is NULL. 206211be35a1SLionel Sambuc ** 206311be35a1SLionel Sambuc ** ^The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED] 206411be35a1SLionel Sambuc ** when SQLite is in the middle of a large transaction where all the 206511be35a1SLionel Sambuc ** changes will not fit into the in-memory cache. SQLite will 206611be35a1SLionel Sambuc ** already hold a RESERVED lock on the database file, but it needs 206711be35a1SLionel Sambuc ** to promote this lock to EXCLUSIVE so that it can spill cache 206811be35a1SLionel Sambuc ** pages into the database file without harm to concurrent 206911be35a1SLionel Sambuc ** readers. ^If it is unable to promote the lock, then the in-memory 207011be35a1SLionel Sambuc ** cache will be left in an inconsistent state and so the error 207111be35a1SLionel Sambuc ** code is promoted from the relatively benign [SQLITE_BUSY] to 207211be35a1SLionel Sambuc ** the more severe [SQLITE_IOERR_BLOCKED]. ^This error code promotion 207311be35a1SLionel Sambuc ** forces an automatic rollback of the changes. See the 207411be35a1SLionel Sambuc ** <a href="/cvstrac/wiki?p=CorruptionFollowingBusyError"> 207511be35a1SLionel Sambuc ** CorruptionFollowingBusyError</a> wiki page for a discussion of why 207611be35a1SLionel Sambuc ** this is important. 207711be35a1SLionel Sambuc ** 207811be35a1SLionel Sambuc ** ^(There can only be a single busy handler defined for each 207911be35a1SLionel Sambuc ** [database connection]. Setting a new busy handler clears any 208011be35a1SLionel Sambuc ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()] 208111be35a1SLionel Sambuc ** will also set or clear the busy handler. 208211be35a1SLionel Sambuc ** 208311be35a1SLionel Sambuc ** The busy callback should not take any actions which modify the 208411be35a1SLionel Sambuc ** database connection that invoked the busy handler. Any such actions 208511be35a1SLionel Sambuc ** result in undefined behavior. 208611be35a1SLionel Sambuc ** 208711be35a1SLionel Sambuc ** A busy handler must not close the database connection 208811be35a1SLionel Sambuc ** or [prepared statement] that invoked the busy handler. 208911be35a1SLionel Sambuc */ 209011be35a1SLionel Sambuc SQLITE_API int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*); 209111be35a1SLionel Sambuc 209211be35a1SLionel Sambuc /* 209311be35a1SLionel Sambuc ** CAPI3REF: Set A Busy Timeout 209411be35a1SLionel Sambuc ** 209511be35a1SLionel Sambuc ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps 209611be35a1SLionel Sambuc ** for a specified amount of time when a table is locked. ^The handler 209711be35a1SLionel Sambuc ** will sleep multiple times until at least "ms" milliseconds of sleeping 209811be35a1SLionel Sambuc ** have accumulated. ^After at least "ms" milliseconds of sleeping, 209911be35a1SLionel Sambuc ** the handler returns 0 which causes [sqlite3_step()] to return 210011be35a1SLionel Sambuc ** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]. 210111be35a1SLionel Sambuc ** 210211be35a1SLionel Sambuc ** ^Calling this routine with an argument less than or equal to zero 210311be35a1SLionel Sambuc ** turns off all busy handlers. 210411be35a1SLionel Sambuc ** 210511be35a1SLionel Sambuc ** ^(There can only be a single busy handler for a particular 210611be35a1SLionel Sambuc ** [database connection] any any given moment. If another busy handler 210711be35a1SLionel Sambuc ** was defined (using [sqlite3_busy_handler()]) prior to calling 210811be35a1SLionel Sambuc ** this routine, that other busy handler is cleared.)^ 210911be35a1SLionel Sambuc */ 211011be35a1SLionel Sambuc SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms); 211111be35a1SLionel Sambuc 211211be35a1SLionel Sambuc /* 211311be35a1SLionel Sambuc ** CAPI3REF: Convenience Routines For Running Queries 211411be35a1SLionel Sambuc ** 211511be35a1SLionel Sambuc ** This is a legacy interface that is preserved for backwards compatibility. 211611be35a1SLionel Sambuc ** Use of this interface is not recommended. 211711be35a1SLionel Sambuc ** 211811be35a1SLionel Sambuc ** Definition: A <b>result table</b> is memory data structure created by the 211911be35a1SLionel Sambuc ** [sqlite3_get_table()] interface. A result table records the 212011be35a1SLionel Sambuc ** complete query results from one or more queries. 212111be35a1SLionel Sambuc ** 212211be35a1SLionel Sambuc ** The table conceptually has a number of rows and columns. But 212311be35a1SLionel Sambuc ** these numbers are not part of the result table itself. These 212411be35a1SLionel Sambuc ** numbers are obtained separately. Let N be the number of rows 212511be35a1SLionel Sambuc ** and M be the number of columns. 212611be35a1SLionel Sambuc ** 212711be35a1SLionel Sambuc ** A result table is an array of pointers to zero-terminated UTF-8 strings. 212811be35a1SLionel Sambuc ** There are (N+1)*M elements in the array. The first M pointers point 212911be35a1SLionel Sambuc ** to zero-terminated strings that contain the names of the columns. 213011be35a1SLionel Sambuc ** The remaining entries all point to query results. NULL values result 213111be35a1SLionel Sambuc ** in NULL pointers. All other values are in their UTF-8 zero-terminated 213211be35a1SLionel Sambuc ** string representation as returned by [sqlite3_column_text()]. 213311be35a1SLionel Sambuc ** 213411be35a1SLionel Sambuc ** A result table might consist of one or more memory allocations. 213511be35a1SLionel Sambuc ** It is not safe to pass a result table directly to [sqlite3_free()]. 213611be35a1SLionel Sambuc ** A result table should be deallocated using [sqlite3_free_table()]. 213711be35a1SLionel Sambuc ** 213811be35a1SLionel Sambuc ** ^(As an example of the result table format, suppose a query result 213911be35a1SLionel Sambuc ** is as follows: 214011be35a1SLionel Sambuc ** 214111be35a1SLionel Sambuc ** <blockquote><pre> 214211be35a1SLionel Sambuc ** Name | Age 214311be35a1SLionel Sambuc ** ----------------------- 214411be35a1SLionel Sambuc ** Alice | 43 214511be35a1SLionel Sambuc ** Bob | 28 214611be35a1SLionel Sambuc ** Cindy | 21 214711be35a1SLionel Sambuc ** </pre></blockquote> 214811be35a1SLionel Sambuc ** 214911be35a1SLionel Sambuc ** There are two column (M==2) and three rows (N==3). Thus the 215011be35a1SLionel Sambuc ** result table has 8 entries. Suppose the result table is stored 215111be35a1SLionel Sambuc ** in an array names azResult. Then azResult holds this content: 215211be35a1SLionel Sambuc ** 215311be35a1SLionel Sambuc ** <blockquote><pre> 215411be35a1SLionel Sambuc ** azResult[0] = "Name"; 215511be35a1SLionel Sambuc ** azResult[1] = "Age"; 215611be35a1SLionel Sambuc ** azResult[2] = "Alice"; 215711be35a1SLionel Sambuc ** azResult[3] = "43"; 215811be35a1SLionel Sambuc ** azResult[4] = "Bob"; 215911be35a1SLionel Sambuc ** azResult[5] = "28"; 216011be35a1SLionel Sambuc ** azResult[6] = "Cindy"; 216111be35a1SLionel Sambuc ** azResult[7] = "21"; 216211be35a1SLionel Sambuc ** </pre></blockquote>)^ 216311be35a1SLionel Sambuc ** 216411be35a1SLionel Sambuc ** ^The sqlite3_get_table() function evaluates one or more 216511be35a1SLionel Sambuc ** semicolon-separated SQL statements in the zero-terminated UTF-8 216611be35a1SLionel Sambuc ** string of its 2nd parameter and returns a result table to the 216711be35a1SLionel Sambuc ** pointer given in its 3rd parameter. 216811be35a1SLionel Sambuc ** 216911be35a1SLionel Sambuc ** After the application has finished with the result from sqlite3_get_table(), 217011be35a1SLionel Sambuc ** it must pass the result table pointer to sqlite3_free_table() in order to 217111be35a1SLionel Sambuc ** release the memory that was malloced. Because of the way the 217211be35a1SLionel Sambuc ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling 217311be35a1SLionel Sambuc ** function must not try to call [sqlite3_free()] directly. Only 217411be35a1SLionel Sambuc ** [sqlite3_free_table()] is able to release the memory properly and safely. 217511be35a1SLionel Sambuc ** 217611be35a1SLionel Sambuc ** The sqlite3_get_table() interface is implemented as a wrapper around 217711be35a1SLionel Sambuc ** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access 217811be35a1SLionel Sambuc ** to any internal data structures of SQLite. It uses only the public 217911be35a1SLionel Sambuc ** interface defined here. As a consequence, errors that occur in the 218011be35a1SLionel Sambuc ** wrapper layer outside of the internal [sqlite3_exec()] call are not 218111be35a1SLionel Sambuc ** reflected in subsequent calls to [sqlite3_errcode()] or 218211be35a1SLionel Sambuc ** [sqlite3_errmsg()]. 218311be35a1SLionel Sambuc */ 218411be35a1SLionel Sambuc SQLITE_API int sqlite3_get_table( 218511be35a1SLionel Sambuc sqlite3 *db, /* An open database */ 218611be35a1SLionel Sambuc const char *zSql, /* SQL to be evaluated */ 218711be35a1SLionel Sambuc char ***pazResult, /* Results of the query */ 218811be35a1SLionel Sambuc int *pnRow, /* Number of result rows written here */ 218911be35a1SLionel Sambuc int *pnColumn, /* Number of result columns written here */ 219011be35a1SLionel Sambuc char **pzErrmsg /* Error msg written here */ 219111be35a1SLionel Sambuc ); 219211be35a1SLionel Sambuc SQLITE_API void sqlite3_free_table(char **result); 219311be35a1SLionel Sambuc 219411be35a1SLionel Sambuc /* 219511be35a1SLionel Sambuc ** CAPI3REF: Formatted String Printing Functions 219611be35a1SLionel Sambuc ** 219711be35a1SLionel Sambuc ** These routines are work-alikes of the "printf()" family of functions 219811be35a1SLionel Sambuc ** from the standard C library. 219911be35a1SLionel Sambuc ** 220011be35a1SLionel Sambuc ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their 220111be35a1SLionel Sambuc ** results into memory obtained from [sqlite3_malloc()]. 220211be35a1SLionel Sambuc ** The strings returned by these two routines should be 220311be35a1SLionel Sambuc ** released by [sqlite3_free()]. ^Both routines return a 220411be35a1SLionel Sambuc ** NULL pointer if [sqlite3_malloc()] is unable to allocate enough 220511be35a1SLionel Sambuc ** memory to hold the resulting string. 220611be35a1SLionel Sambuc ** 220711be35a1SLionel Sambuc ** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from 220811be35a1SLionel Sambuc ** the standard C library. The result is written into the 220911be35a1SLionel Sambuc ** buffer supplied as the second parameter whose size is given by 221011be35a1SLionel Sambuc ** the first parameter. Note that the order of the 221111be35a1SLionel Sambuc ** first two parameters is reversed from snprintf().)^ This is an 221211be35a1SLionel Sambuc ** historical accident that cannot be fixed without breaking 221311be35a1SLionel Sambuc ** backwards compatibility. ^(Note also that sqlite3_snprintf() 221411be35a1SLionel Sambuc ** returns a pointer to its buffer instead of the number of 221511be35a1SLionel Sambuc ** characters actually written into the buffer.)^ We admit that 221611be35a1SLionel Sambuc ** the number of characters written would be a more useful return 221711be35a1SLionel Sambuc ** value but we cannot change the implementation of sqlite3_snprintf() 221811be35a1SLionel Sambuc ** now without breaking compatibility. 221911be35a1SLionel Sambuc ** 222011be35a1SLionel Sambuc ** ^As long as the buffer size is greater than zero, sqlite3_snprintf() 222111be35a1SLionel Sambuc ** guarantees that the buffer is always zero-terminated. ^The first 222211be35a1SLionel Sambuc ** parameter "n" is the total size of the buffer, including space for 222311be35a1SLionel Sambuc ** the zero terminator. So the longest string that can be completely 222411be35a1SLionel Sambuc ** written will be n-1 characters. 222511be35a1SLionel Sambuc ** 222611be35a1SLionel Sambuc ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf(). 222711be35a1SLionel Sambuc ** 222811be35a1SLionel Sambuc ** These routines all implement some additional formatting 222911be35a1SLionel Sambuc ** options that are useful for constructing SQL statements. 223011be35a1SLionel Sambuc ** All of the usual printf() formatting options apply. In addition, there 223111be35a1SLionel Sambuc ** is are "%q", "%Q", and "%z" options. 223211be35a1SLionel Sambuc ** 223311be35a1SLionel Sambuc ** ^(The %q option works like %s in that it substitutes a nul-terminated 223411be35a1SLionel Sambuc ** string from the argument list. But %q also doubles every '\'' character. 223511be35a1SLionel Sambuc ** %q is designed for use inside a string literal.)^ By doubling each '\'' 223611be35a1SLionel Sambuc ** character it escapes that character and allows it to be inserted into 223711be35a1SLionel Sambuc ** the string. 223811be35a1SLionel Sambuc ** 223911be35a1SLionel Sambuc ** For example, assume the string variable zText contains text as follows: 224011be35a1SLionel Sambuc ** 224111be35a1SLionel Sambuc ** <blockquote><pre> 224211be35a1SLionel Sambuc ** char *zText = "It's a happy day!"; 224311be35a1SLionel Sambuc ** </pre></blockquote> 224411be35a1SLionel Sambuc ** 224511be35a1SLionel Sambuc ** One can use this text in an SQL statement as follows: 224611be35a1SLionel Sambuc ** 224711be35a1SLionel Sambuc ** <blockquote><pre> 224811be35a1SLionel Sambuc ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText); 224911be35a1SLionel Sambuc ** sqlite3_exec(db, zSQL, 0, 0, 0); 225011be35a1SLionel Sambuc ** sqlite3_free(zSQL); 225111be35a1SLionel Sambuc ** </pre></blockquote> 225211be35a1SLionel Sambuc ** 225311be35a1SLionel Sambuc ** Because the %q format string is used, the '\'' character in zText 225411be35a1SLionel Sambuc ** is escaped and the SQL generated is as follows: 225511be35a1SLionel Sambuc ** 225611be35a1SLionel Sambuc ** <blockquote><pre> 225711be35a1SLionel Sambuc ** INSERT INTO table1 VALUES('It''s a happy day!') 225811be35a1SLionel Sambuc ** </pre></blockquote> 225911be35a1SLionel Sambuc ** 226011be35a1SLionel Sambuc ** This is correct. Had we used %s instead of %q, the generated SQL 226111be35a1SLionel Sambuc ** would have looked like this: 226211be35a1SLionel Sambuc ** 226311be35a1SLionel Sambuc ** <blockquote><pre> 226411be35a1SLionel Sambuc ** INSERT INTO table1 VALUES('It's a happy day!'); 226511be35a1SLionel Sambuc ** </pre></blockquote> 226611be35a1SLionel Sambuc ** 226711be35a1SLionel Sambuc ** This second example is an SQL syntax error. As a general rule you should 226811be35a1SLionel Sambuc ** always use %q instead of %s when inserting text into a string literal. 226911be35a1SLionel Sambuc ** 227011be35a1SLionel Sambuc ** ^(The %Q option works like %q except it also adds single quotes around 227111be35a1SLionel Sambuc ** the outside of the total string. Additionally, if the parameter in the 227211be35a1SLionel Sambuc ** argument list is a NULL pointer, %Q substitutes the text "NULL" (without 227311be35a1SLionel Sambuc ** single quotes).)^ So, for example, one could say: 227411be35a1SLionel Sambuc ** 227511be35a1SLionel Sambuc ** <blockquote><pre> 227611be35a1SLionel Sambuc ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText); 227711be35a1SLionel Sambuc ** sqlite3_exec(db, zSQL, 0, 0, 0); 227811be35a1SLionel Sambuc ** sqlite3_free(zSQL); 227911be35a1SLionel Sambuc ** </pre></blockquote> 228011be35a1SLionel Sambuc ** 228111be35a1SLionel Sambuc ** The code above will render a correct SQL statement in the zSQL 228211be35a1SLionel Sambuc ** variable even if the zText variable is a NULL pointer. 228311be35a1SLionel Sambuc ** 228411be35a1SLionel Sambuc ** ^(The "%z" formatting option works like "%s" but with the 228511be35a1SLionel Sambuc ** addition that after the string has been read and copied into 228611be35a1SLionel Sambuc ** the result, [sqlite3_free()] is called on the input string.)^ 228711be35a1SLionel Sambuc */ 228811be35a1SLionel Sambuc SQLITE_API char *sqlite3_mprintf(const char*,...); 228911be35a1SLionel Sambuc SQLITE_API char *sqlite3_vmprintf(const char*, va_list); 229011be35a1SLionel Sambuc SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...); 229111be35a1SLionel Sambuc SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list); 229211be35a1SLionel Sambuc 229311be35a1SLionel Sambuc /* 229411be35a1SLionel Sambuc ** CAPI3REF: Memory Allocation Subsystem 229511be35a1SLionel Sambuc ** 229611be35a1SLionel Sambuc ** The SQLite core uses these three routines for all of its own 229711be35a1SLionel Sambuc ** internal memory allocation needs. "Core" in the previous sentence 229811be35a1SLionel Sambuc ** does not include operating-system specific VFS implementation. The 229911be35a1SLionel Sambuc ** Windows VFS uses native malloc() and free() for some operations. 230011be35a1SLionel Sambuc ** 230111be35a1SLionel Sambuc ** ^The sqlite3_malloc() routine returns a pointer to a block 230211be35a1SLionel Sambuc ** of memory at least N bytes in length, where N is the parameter. 230311be35a1SLionel Sambuc ** ^If sqlite3_malloc() is unable to obtain sufficient free 230411be35a1SLionel Sambuc ** memory, it returns a NULL pointer. ^If the parameter N to 230511be35a1SLionel Sambuc ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns 230611be35a1SLionel Sambuc ** a NULL pointer. 230711be35a1SLionel Sambuc ** 230811be35a1SLionel Sambuc ** ^Calling sqlite3_free() with a pointer previously returned 230911be35a1SLionel Sambuc ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so 231011be35a1SLionel Sambuc ** that it might be reused. ^The sqlite3_free() routine is 231111be35a1SLionel Sambuc ** a no-op if is called with a NULL pointer. Passing a NULL pointer 231211be35a1SLionel Sambuc ** to sqlite3_free() is harmless. After being freed, memory 231311be35a1SLionel Sambuc ** should neither be read nor written. Even reading previously freed 231411be35a1SLionel Sambuc ** memory might result in a segmentation fault or other severe error. 231511be35a1SLionel Sambuc ** Memory corruption, a segmentation fault, or other severe error 231611be35a1SLionel Sambuc ** might result if sqlite3_free() is called with a non-NULL pointer that 231711be35a1SLionel Sambuc ** was not obtained from sqlite3_malloc() or sqlite3_realloc(). 231811be35a1SLionel Sambuc ** 231911be35a1SLionel Sambuc ** ^(The sqlite3_realloc() interface attempts to resize a 232011be35a1SLionel Sambuc ** prior memory allocation to be at least N bytes, where N is the 232111be35a1SLionel Sambuc ** second parameter. The memory allocation to be resized is the first 232211be35a1SLionel Sambuc ** parameter.)^ ^ If the first parameter to sqlite3_realloc() 232311be35a1SLionel Sambuc ** is a NULL pointer then its behavior is identical to calling 232411be35a1SLionel Sambuc ** sqlite3_malloc(N) where N is the second parameter to sqlite3_realloc(). 232511be35a1SLionel Sambuc ** ^If the second parameter to sqlite3_realloc() is zero or 232611be35a1SLionel Sambuc ** negative then the behavior is exactly the same as calling 232711be35a1SLionel Sambuc ** sqlite3_free(P) where P is the first parameter to sqlite3_realloc(). 232811be35a1SLionel Sambuc ** ^sqlite3_realloc() returns a pointer to a memory allocation 232911be35a1SLionel Sambuc ** of at least N bytes in size or NULL if sufficient memory is unavailable. 233011be35a1SLionel Sambuc ** ^If M is the size of the prior allocation, then min(N,M) bytes 233111be35a1SLionel Sambuc ** of the prior allocation are copied into the beginning of buffer returned 233211be35a1SLionel Sambuc ** by sqlite3_realloc() and the prior allocation is freed. 233311be35a1SLionel Sambuc ** ^If sqlite3_realloc() returns NULL, then the prior allocation 233411be35a1SLionel Sambuc ** is not freed. 233511be35a1SLionel Sambuc ** 233611be35a1SLionel Sambuc ** ^The memory returned by sqlite3_malloc() and sqlite3_realloc() 233711be35a1SLionel Sambuc ** is always aligned to at least an 8 byte boundary, or to a 233811be35a1SLionel Sambuc ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time 233911be35a1SLionel Sambuc ** option is used. 234011be35a1SLionel Sambuc ** 234111be35a1SLionel Sambuc ** In SQLite version 3.5.0 and 3.5.1, it was possible to define 234211be35a1SLionel Sambuc ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in 234311be35a1SLionel Sambuc ** implementation of these routines to be omitted. That capability 234411be35a1SLionel Sambuc ** is no longer provided. Only built-in memory allocators can be used. 234511be35a1SLionel Sambuc ** 2346*0a6a1f1dSLionel Sambuc ** Prior to SQLite version 3.7.10, the Windows OS interface layer called 234711be35a1SLionel Sambuc ** the system malloc() and free() directly when converting 234811be35a1SLionel Sambuc ** filenames between the UTF-8 encoding used by SQLite 234911be35a1SLionel Sambuc ** and whatever filename encoding is used by the particular Windows 2350*0a6a1f1dSLionel Sambuc ** installation. Memory allocation errors were detected, but 2351*0a6a1f1dSLionel Sambuc ** they were reported back as [SQLITE_CANTOPEN] or 235211be35a1SLionel Sambuc ** [SQLITE_IOERR] rather than [SQLITE_NOMEM]. 235311be35a1SLionel Sambuc ** 235411be35a1SLionel Sambuc ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()] 235511be35a1SLionel Sambuc ** must be either NULL or else pointers obtained from a prior 235611be35a1SLionel Sambuc ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have 235711be35a1SLionel Sambuc ** not yet been released. 235811be35a1SLionel Sambuc ** 235911be35a1SLionel Sambuc ** The application must not read or write any part of 236011be35a1SLionel Sambuc ** a block of memory after it has been released using 236111be35a1SLionel Sambuc ** [sqlite3_free()] or [sqlite3_realloc()]. 236211be35a1SLionel Sambuc */ 236311be35a1SLionel Sambuc SQLITE_API void *sqlite3_malloc(int); 236411be35a1SLionel Sambuc SQLITE_API void *sqlite3_realloc(void*, int); 236511be35a1SLionel Sambuc SQLITE_API void sqlite3_free(void*); 236611be35a1SLionel Sambuc 236711be35a1SLionel Sambuc /* 236811be35a1SLionel Sambuc ** CAPI3REF: Memory Allocator Statistics 236911be35a1SLionel Sambuc ** 237011be35a1SLionel Sambuc ** SQLite provides these two interfaces for reporting on the status 237111be35a1SLionel Sambuc ** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()] 237211be35a1SLionel Sambuc ** routines, which form the built-in memory allocation subsystem. 237311be35a1SLionel Sambuc ** 237411be35a1SLionel Sambuc ** ^The [sqlite3_memory_used()] routine returns the number of bytes 237511be35a1SLionel Sambuc ** of memory currently outstanding (malloced but not freed). 237611be35a1SLionel Sambuc ** ^The [sqlite3_memory_highwater()] routine returns the maximum 237711be35a1SLionel Sambuc ** value of [sqlite3_memory_used()] since the high-water mark 237811be35a1SLionel Sambuc ** was last reset. ^The values returned by [sqlite3_memory_used()] and 237911be35a1SLionel Sambuc ** [sqlite3_memory_highwater()] include any overhead 238011be35a1SLionel Sambuc ** added by SQLite in its implementation of [sqlite3_malloc()], 238111be35a1SLionel Sambuc ** but not overhead added by the any underlying system library 238211be35a1SLionel Sambuc ** routines that [sqlite3_malloc()] may call. 238311be35a1SLionel Sambuc ** 238411be35a1SLionel Sambuc ** ^The memory high-water mark is reset to the current value of 238511be35a1SLionel Sambuc ** [sqlite3_memory_used()] if and only if the parameter to 238611be35a1SLionel Sambuc ** [sqlite3_memory_highwater()] is true. ^The value returned 238711be35a1SLionel Sambuc ** by [sqlite3_memory_highwater(1)] is the high-water mark 238811be35a1SLionel Sambuc ** prior to the reset. 238911be35a1SLionel Sambuc */ 239011be35a1SLionel Sambuc SQLITE_API sqlite3_int64 sqlite3_memory_used(void); 239111be35a1SLionel Sambuc SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag); 239211be35a1SLionel Sambuc 239311be35a1SLionel Sambuc /* 239411be35a1SLionel Sambuc ** CAPI3REF: Pseudo-Random Number Generator 239511be35a1SLionel Sambuc ** 239611be35a1SLionel Sambuc ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to 239711be35a1SLionel Sambuc ** select random [ROWID | ROWIDs] when inserting new records into a table that 239811be35a1SLionel Sambuc ** already uses the largest possible [ROWID]. The PRNG is also used for 239911be35a1SLionel Sambuc ** the build-in random() and randomblob() SQL functions. This interface allows 240011be35a1SLionel Sambuc ** applications to access the same PRNG for other purposes. 240111be35a1SLionel Sambuc ** 240211be35a1SLionel Sambuc ** ^A call to this routine stores N bytes of randomness into buffer P. 2403*0a6a1f1dSLionel Sambuc ** ^If N is less than one, then P can be a NULL pointer. 240411be35a1SLionel Sambuc ** 2405*0a6a1f1dSLionel Sambuc ** ^If this routine has not been previously called or if the previous 2406*0a6a1f1dSLionel Sambuc ** call had N less than one, then the PRNG is seeded using randomness 2407*0a6a1f1dSLionel Sambuc ** obtained from the xRandomness method of the default [sqlite3_vfs] object. 2408*0a6a1f1dSLionel Sambuc ** ^If the previous call to this routine had an N of 1 or more then 2409*0a6a1f1dSLionel Sambuc ** the pseudo-randomness is generated 241011be35a1SLionel Sambuc ** internally and without recourse to the [sqlite3_vfs] xRandomness 241111be35a1SLionel Sambuc ** method. 241211be35a1SLionel Sambuc */ 241311be35a1SLionel Sambuc SQLITE_API void sqlite3_randomness(int N, void *P); 241411be35a1SLionel Sambuc 241511be35a1SLionel Sambuc /* 241611be35a1SLionel Sambuc ** CAPI3REF: Compile-Time Authorization Callbacks 241711be35a1SLionel Sambuc ** 241811be35a1SLionel Sambuc ** ^This routine registers an authorizer callback with a particular 241911be35a1SLionel Sambuc ** [database connection], supplied in the first argument. 242011be35a1SLionel Sambuc ** ^The authorizer callback is invoked as SQL statements are being compiled 242111be35a1SLionel Sambuc ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], 242211be35a1SLionel Sambuc ** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()]. ^At various 242311be35a1SLionel Sambuc ** points during the compilation process, as logic is being created 242411be35a1SLionel Sambuc ** to perform various actions, the authorizer callback is invoked to 242511be35a1SLionel Sambuc ** see if those actions are allowed. ^The authorizer callback should 242611be35a1SLionel Sambuc ** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the 242711be35a1SLionel Sambuc ** specific action but allow the SQL statement to continue to be 242811be35a1SLionel Sambuc ** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be 242911be35a1SLionel Sambuc ** rejected with an error. ^If the authorizer callback returns 243011be35a1SLionel Sambuc ** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY] 243111be35a1SLionel Sambuc ** then the [sqlite3_prepare_v2()] or equivalent call that triggered 243211be35a1SLionel Sambuc ** the authorizer will fail with an error message. 243311be35a1SLionel Sambuc ** 243411be35a1SLionel Sambuc ** When the callback returns [SQLITE_OK], that means the operation 243511be35a1SLionel Sambuc ** requested is ok. ^When the callback returns [SQLITE_DENY], the 243611be35a1SLionel Sambuc ** [sqlite3_prepare_v2()] or equivalent call that triggered the 243711be35a1SLionel Sambuc ** authorizer will fail with an error message explaining that 243811be35a1SLionel Sambuc ** access is denied. 243911be35a1SLionel Sambuc ** 244011be35a1SLionel Sambuc ** ^The first parameter to the authorizer callback is a copy of the third 244111be35a1SLionel Sambuc ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter 244211be35a1SLionel Sambuc ** to the callback is an integer [SQLITE_COPY | action code] that specifies 244311be35a1SLionel Sambuc ** the particular action to be authorized. ^The third through sixth parameters 244411be35a1SLionel Sambuc ** to the callback are zero-terminated strings that contain additional 244511be35a1SLionel Sambuc ** details about the action to be authorized. 244611be35a1SLionel Sambuc ** 244711be35a1SLionel Sambuc ** ^If the action code is [SQLITE_READ] 244811be35a1SLionel Sambuc ** and the callback returns [SQLITE_IGNORE] then the 244911be35a1SLionel Sambuc ** [prepared statement] statement is constructed to substitute 245011be35a1SLionel Sambuc ** a NULL value in place of the table column that would have 245111be35a1SLionel Sambuc ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE] 245211be35a1SLionel Sambuc ** return can be used to deny an untrusted user access to individual 245311be35a1SLionel Sambuc ** columns of a table. 245411be35a1SLionel Sambuc ** ^If the action code is [SQLITE_DELETE] and the callback returns 245511be35a1SLionel Sambuc ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the 245611be35a1SLionel Sambuc ** [truncate optimization] is disabled and all rows are deleted individually. 245711be35a1SLionel Sambuc ** 245811be35a1SLionel Sambuc ** An authorizer is used when [sqlite3_prepare | preparing] 245911be35a1SLionel Sambuc ** SQL statements from an untrusted source, to ensure that the SQL statements 246011be35a1SLionel Sambuc ** do not try to access data they are not allowed to see, or that they do not 246111be35a1SLionel Sambuc ** try to execute malicious statements that damage the database. For 246211be35a1SLionel Sambuc ** example, an application may allow a user to enter arbitrary 246311be35a1SLionel Sambuc ** SQL queries for evaluation by a database. But the application does 246411be35a1SLionel Sambuc ** not want the user to be able to make arbitrary changes to the 246511be35a1SLionel Sambuc ** database. An authorizer could then be put in place while the 246611be35a1SLionel Sambuc ** user-entered SQL is being [sqlite3_prepare | prepared] that 246711be35a1SLionel Sambuc ** disallows everything except [SELECT] statements. 246811be35a1SLionel Sambuc ** 246911be35a1SLionel Sambuc ** Applications that need to process SQL from untrusted sources 247011be35a1SLionel Sambuc ** might also consider lowering resource limits using [sqlite3_limit()] 247111be35a1SLionel Sambuc ** and limiting database size using the [max_page_count] [PRAGMA] 247211be35a1SLionel Sambuc ** in addition to using an authorizer. 247311be35a1SLionel Sambuc ** 247411be35a1SLionel Sambuc ** ^(Only a single authorizer can be in place on a database connection 247511be35a1SLionel Sambuc ** at a time. Each call to sqlite3_set_authorizer overrides the 247611be35a1SLionel Sambuc ** previous call.)^ ^Disable the authorizer by installing a NULL callback. 247711be35a1SLionel Sambuc ** The authorizer is disabled by default. 247811be35a1SLionel Sambuc ** 247911be35a1SLionel Sambuc ** The authorizer callback must not do anything that will modify 248011be35a1SLionel Sambuc ** the database connection that invoked the authorizer callback. 248111be35a1SLionel Sambuc ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 248211be35a1SLionel Sambuc ** database connections for the meaning of "modify" in this paragraph. 248311be35a1SLionel Sambuc ** 248411be35a1SLionel Sambuc ** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the 248511be35a1SLionel Sambuc ** statement might be re-prepared during [sqlite3_step()] due to a 248611be35a1SLionel Sambuc ** schema change. Hence, the application should ensure that the 248711be35a1SLionel Sambuc ** correct authorizer callback remains in place during the [sqlite3_step()]. 248811be35a1SLionel Sambuc ** 248911be35a1SLionel Sambuc ** ^Note that the authorizer callback is invoked only during 249011be35a1SLionel Sambuc ** [sqlite3_prepare()] or its variants. Authorization is not 249111be35a1SLionel Sambuc ** performed during statement evaluation in [sqlite3_step()], unless 249211be35a1SLionel Sambuc ** as stated in the previous paragraph, sqlite3_step() invokes 249311be35a1SLionel Sambuc ** sqlite3_prepare_v2() to reprepare a statement after a schema change. 249411be35a1SLionel Sambuc */ 249511be35a1SLionel Sambuc SQLITE_API int sqlite3_set_authorizer( 249611be35a1SLionel Sambuc sqlite3*, 249711be35a1SLionel Sambuc int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), 249811be35a1SLionel Sambuc void *pUserData 249911be35a1SLionel Sambuc ); 250011be35a1SLionel Sambuc 250111be35a1SLionel Sambuc /* 250211be35a1SLionel Sambuc ** CAPI3REF: Authorizer Return Codes 250311be35a1SLionel Sambuc ** 250411be35a1SLionel Sambuc ** The [sqlite3_set_authorizer | authorizer callback function] must 250511be35a1SLionel Sambuc ** return either [SQLITE_OK] or one of these two constants in order 250611be35a1SLionel Sambuc ** to signal SQLite whether or not the action is permitted. See the 250711be35a1SLionel Sambuc ** [sqlite3_set_authorizer | authorizer documentation] for additional 250811be35a1SLionel Sambuc ** information. 250911be35a1SLionel Sambuc ** 251011be35a1SLionel Sambuc ** Note that SQLITE_IGNORE is also used as a [SQLITE_ROLLBACK | return code] 251111be35a1SLionel Sambuc ** from the [sqlite3_vtab_on_conflict()] interface. 251211be35a1SLionel Sambuc */ 251311be35a1SLionel Sambuc #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ 251411be35a1SLionel Sambuc #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ 251511be35a1SLionel Sambuc 251611be35a1SLionel Sambuc /* 251711be35a1SLionel Sambuc ** CAPI3REF: Authorizer Action Codes 251811be35a1SLionel Sambuc ** 251911be35a1SLionel Sambuc ** The [sqlite3_set_authorizer()] interface registers a callback function 252011be35a1SLionel Sambuc ** that is invoked to authorize certain SQL statement actions. The 252111be35a1SLionel Sambuc ** second parameter to the callback is an integer code that specifies 252211be35a1SLionel Sambuc ** what action is being authorized. These are the integer action codes that 252311be35a1SLionel Sambuc ** the authorizer callback may be passed. 252411be35a1SLionel Sambuc ** 252511be35a1SLionel Sambuc ** These action code values signify what kind of operation is to be 252611be35a1SLionel Sambuc ** authorized. The 3rd and 4th parameters to the authorization 252711be35a1SLionel Sambuc ** callback function will be parameters or NULL depending on which of these 252811be35a1SLionel Sambuc ** codes is used as the second parameter. ^(The 5th parameter to the 252911be35a1SLionel Sambuc ** authorizer callback is the name of the database ("main", "temp", 253011be35a1SLionel Sambuc ** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback 253111be35a1SLionel Sambuc ** is the name of the inner-most trigger or view that is responsible for 253211be35a1SLionel Sambuc ** the access attempt or NULL if this access attempt is directly from 253311be35a1SLionel Sambuc ** top-level SQL code. 253411be35a1SLionel Sambuc */ 253511be35a1SLionel Sambuc /******************************************* 3rd ************ 4th ***********/ 253611be35a1SLionel Sambuc #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */ 253711be35a1SLionel Sambuc #define SQLITE_CREATE_TABLE 2 /* Table Name NULL */ 253811be35a1SLionel Sambuc #define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */ 253911be35a1SLionel Sambuc #define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */ 254011be35a1SLionel Sambuc #define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */ 254111be35a1SLionel Sambuc #define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */ 254211be35a1SLionel Sambuc #define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */ 254311be35a1SLionel Sambuc #define SQLITE_CREATE_VIEW 8 /* View Name NULL */ 254411be35a1SLionel Sambuc #define SQLITE_DELETE 9 /* Table Name NULL */ 254511be35a1SLionel Sambuc #define SQLITE_DROP_INDEX 10 /* Index Name Table Name */ 254611be35a1SLionel Sambuc #define SQLITE_DROP_TABLE 11 /* Table Name NULL */ 254711be35a1SLionel Sambuc #define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */ 254811be35a1SLionel Sambuc #define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */ 254911be35a1SLionel Sambuc #define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */ 255011be35a1SLionel Sambuc #define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */ 255111be35a1SLionel Sambuc #define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */ 255211be35a1SLionel Sambuc #define SQLITE_DROP_VIEW 17 /* View Name NULL */ 255311be35a1SLionel Sambuc #define SQLITE_INSERT 18 /* Table Name NULL */ 255411be35a1SLionel Sambuc #define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */ 255511be35a1SLionel Sambuc #define SQLITE_READ 20 /* Table Name Column Name */ 255611be35a1SLionel Sambuc #define SQLITE_SELECT 21 /* NULL NULL */ 255711be35a1SLionel Sambuc #define SQLITE_TRANSACTION 22 /* Operation NULL */ 255811be35a1SLionel Sambuc #define SQLITE_UPDATE 23 /* Table Name Column Name */ 255911be35a1SLionel Sambuc #define SQLITE_ATTACH 24 /* Filename NULL */ 256011be35a1SLionel Sambuc #define SQLITE_DETACH 25 /* Database Name NULL */ 256111be35a1SLionel Sambuc #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */ 256211be35a1SLionel Sambuc #define SQLITE_REINDEX 27 /* Index Name NULL */ 256311be35a1SLionel Sambuc #define SQLITE_ANALYZE 28 /* Table Name NULL */ 256411be35a1SLionel Sambuc #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */ 256511be35a1SLionel Sambuc #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */ 256611be35a1SLionel Sambuc #define SQLITE_FUNCTION 31 /* NULL Function Name */ 256711be35a1SLionel Sambuc #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */ 256811be35a1SLionel Sambuc #define SQLITE_COPY 0 /* No longer used */ 2569*0a6a1f1dSLionel Sambuc #define SQLITE_RECURSIVE 33 /* NULL NULL */ 257011be35a1SLionel Sambuc 257111be35a1SLionel Sambuc /* 257211be35a1SLionel Sambuc ** CAPI3REF: Tracing And Profiling Functions 257311be35a1SLionel Sambuc ** 257411be35a1SLionel Sambuc ** These routines register callback functions that can be used for 257511be35a1SLionel Sambuc ** tracing and profiling the execution of SQL statements. 257611be35a1SLionel Sambuc ** 257711be35a1SLionel Sambuc ** ^The callback function registered by sqlite3_trace() is invoked at 257811be35a1SLionel Sambuc ** various times when an SQL statement is being run by [sqlite3_step()]. 257911be35a1SLionel Sambuc ** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the 258011be35a1SLionel Sambuc ** SQL statement text as the statement first begins executing. 258111be35a1SLionel Sambuc ** ^(Additional sqlite3_trace() callbacks might occur 258211be35a1SLionel Sambuc ** as each triggered subprogram is entered. The callbacks for triggers 258311be35a1SLionel Sambuc ** contain a UTF-8 SQL comment that identifies the trigger.)^ 258411be35a1SLionel Sambuc ** 2585*0a6a1f1dSLionel Sambuc ** The [SQLITE_TRACE_SIZE_LIMIT] compile-time option can be used to limit 2586*0a6a1f1dSLionel Sambuc ** the length of [bound parameter] expansion in the output of sqlite3_trace(). 2587*0a6a1f1dSLionel Sambuc ** 258811be35a1SLionel Sambuc ** ^The callback function registered by sqlite3_profile() is invoked 258911be35a1SLionel Sambuc ** as each SQL statement finishes. ^The profile callback contains 259011be35a1SLionel Sambuc ** the original statement text and an estimate of wall-clock time 259111be35a1SLionel Sambuc ** of how long that statement took to run. ^The profile callback 259211be35a1SLionel Sambuc ** time is in units of nanoseconds, however the current implementation 259311be35a1SLionel Sambuc ** is only capable of millisecond resolution so the six least significant 259411be35a1SLionel Sambuc ** digits in the time are meaningless. Future versions of SQLite 259511be35a1SLionel Sambuc ** might provide greater resolution on the profiler callback. The 259611be35a1SLionel Sambuc ** sqlite3_profile() function is considered experimental and is 259711be35a1SLionel Sambuc ** subject to change in future versions of SQLite. 259811be35a1SLionel Sambuc */ 259911be35a1SLionel Sambuc SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*); 260011be35a1SLionel Sambuc SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*, 260111be35a1SLionel Sambuc void(*xProfile)(void*,const char*,sqlite3_uint64), void*); 260211be35a1SLionel Sambuc 260311be35a1SLionel Sambuc /* 260411be35a1SLionel Sambuc ** CAPI3REF: Query Progress Callbacks 260511be35a1SLionel Sambuc ** 260611be35a1SLionel Sambuc ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback 260711be35a1SLionel Sambuc ** function X to be invoked periodically during long running calls to 260811be35a1SLionel Sambuc ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for 260911be35a1SLionel Sambuc ** database connection D. An example use for this 261011be35a1SLionel Sambuc ** interface is to keep a GUI updated during a large query. 261111be35a1SLionel Sambuc ** 261211be35a1SLionel Sambuc ** ^The parameter P is passed through as the only parameter to the 2613*0a6a1f1dSLionel Sambuc ** callback function X. ^The parameter N is the approximate number of 261411be35a1SLionel Sambuc ** [virtual machine instructions] that are evaluated between successive 2615*0a6a1f1dSLionel Sambuc ** invocations of the callback X. ^If N is less than one then the progress 2616*0a6a1f1dSLionel Sambuc ** handler is disabled. 261711be35a1SLionel Sambuc ** 261811be35a1SLionel Sambuc ** ^Only a single progress handler may be defined at one time per 261911be35a1SLionel Sambuc ** [database connection]; setting a new progress handler cancels the 262011be35a1SLionel Sambuc ** old one. ^Setting parameter X to NULL disables the progress handler. 262111be35a1SLionel Sambuc ** ^The progress handler is also disabled by setting N to a value less 262211be35a1SLionel Sambuc ** than 1. 262311be35a1SLionel Sambuc ** 262411be35a1SLionel Sambuc ** ^If the progress callback returns non-zero, the operation is 262511be35a1SLionel Sambuc ** interrupted. This feature can be used to implement a 262611be35a1SLionel Sambuc ** "Cancel" button on a GUI progress dialog box. 262711be35a1SLionel Sambuc ** 262811be35a1SLionel Sambuc ** The progress handler callback must not do anything that will modify 262911be35a1SLionel Sambuc ** the database connection that invoked the progress handler. 263011be35a1SLionel Sambuc ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 263111be35a1SLionel Sambuc ** database connections for the meaning of "modify" in this paragraph. 263211be35a1SLionel Sambuc ** 263311be35a1SLionel Sambuc */ 263411be35a1SLionel Sambuc SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); 263511be35a1SLionel Sambuc 263611be35a1SLionel Sambuc /* 263711be35a1SLionel Sambuc ** CAPI3REF: Opening A New Database Connection 263811be35a1SLionel Sambuc ** 263911be35a1SLionel Sambuc ** ^These routines open an SQLite database file as specified by the 264011be35a1SLionel Sambuc ** filename argument. ^The filename argument is interpreted as UTF-8 for 264111be35a1SLionel Sambuc ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte 264211be35a1SLionel Sambuc ** order for sqlite3_open16(). ^(A [database connection] handle is usually 264311be35a1SLionel Sambuc ** returned in *ppDb, even if an error occurs. The only exception is that 264411be35a1SLionel Sambuc ** if SQLite is unable to allocate memory to hold the [sqlite3] object, 264511be35a1SLionel Sambuc ** a NULL will be written into *ppDb instead of a pointer to the [sqlite3] 264611be35a1SLionel Sambuc ** object.)^ ^(If the database is opened (and/or created) successfully, then 264711be35a1SLionel Sambuc ** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The 264811be35a1SLionel Sambuc ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain 264911be35a1SLionel Sambuc ** an English language description of the error following a failure of any 265011be35a1SLionel Sambuc ** of the sqlite3_open() routines. 265111be35a1SLionel Sambuc ** 265211be35a1SLionel Sambuc ** ^The default encoding for the database will be UTF-8 if 265311be35a1SLionel Sambuc ** sqlite3_open() or sqlite3_open_v2() is called and 265411be35a1SLionel Sambuc ** UTF-16 in the native byte order if sqlite3_open16() is used. 265511be35a1SLionel Sambuc ** 265611be35a1SLionel Sambuc ** Whether or not an error occurs when it is opened, resources 265711be35a1SLionel Sambuc ** associated with the [database connection] handle should be released by 265811be35a1SLionel Sambuc ** passing it to [sqlite3_close()] when it is no longer required. 265911be35a1SLionel Sambuc ** 266011be35a1SLionel Sambuc ** The sqlite3_open_v2() interface works like sqlite3_open() 266111be35a1SLionel Sambuc ** except that it accepts two additional parameters for additional control 266211be35a1SLionel Sambuc ** over the new database connection. ^(The flags parameter to 266311be35a1SLionel Sambuc ** sqlite3_open_v2() can take one of 266411be35a1SLionel Sambuc ** the following three values, optionally combined with the 266511be35a1SLionel Sambuc ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE], 266611be35a1SLionel Sambuc ** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^ 266711be35a1SLionel Sambuc ** 266811be35a1SLionel Sambuc ** <dl> 266911be35a1SLionel Sambuc ** ^(<dt>[SQLITE_OPEN_READONLY]</dt> 267011be35a1SLionel Sambuc ** <dd>The database is opened in read-only mode. If the database does not 267111be35a1SLionel Sambuc ** already exist, an error is returned.</dd>)^ 267211be35a1SLionel Sambuc ** 267311be35a1SLionel Sambuc ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt> 267411be35a1SLionel Sambuc ** <dd>The database is opened for reading and writing if possible, or reading 267511be35a1SLionel Sambuc ** only if the file is write protected by the operating system. In either 267611be35a1SLionel Sambuc ** case the database must already exist, otherwise an error is returned.</dd>)^ 267711be35a1SLionel Sambuc ** 267811be35a1SLionel Sambuc ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt> 267911be35a1SLionel Sambuc ** <dd>The database is opened for reading and writing, and is created if 268011be35a1SLionel Sambuc ** it does not already exist. This is the behavior that is always used for 268111be35a1SLionel Sambuc ** sqlite3_open() and sqlite3_open16().</dd>)^ 268211be35a1SLionel Sambuc ** </dl> 268311be35a1SLionel Sambuc ** 268411be35a1SLionel Sambuc ** If the 3rd parameter to sqlite3_open_v2() is not one of the 268511be35a1SLionel Sambuc ** combinations shown above optionally combined with other 268611be35a1SLionel Sambuc ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits] 268711be35a1SLionel Sambuc ** then the behavior is undefined. 268811be35a1SLionel Sambuc ** 268911be35a1SLionel Sambuc ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection 269011be35a1SLionel Sambuc ** opens in the multi-thread [threading mode] as long as the single-thread 269111be35a1SLionel Sambuc ** mode has not been set at compile-time or start-time. ^If the 269211be35a1SLionel Sambuc ** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens 269311be35a1SLionel Sambuc ** in the serialized [threading mode] unless single-thread was 269411be35a1SLionel Sambuc ** previously selected at compile-time or start-time. 269511be35a1SLionel Sambuc ** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be 269611be35a1SLionel Sambuc ** eligible to use [shared cache mode], regardless of whether or not shared 269711be35a1SLionel Sambuc ** cache is enabled using [sqlite3_enable_shared_cache()]. ^The 269811be35a1SLionel Sambuc ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not 269911be35a1SLionel Sambuc ** participate in [shared cache mode] even if it is enabled. 270011be35a1SLionel Sambuc ** 270111be35a1SLionel Sambuc ** ^The fourth parameter to sqlite3_open_v2() is the name of the 270211be35a1SLionel Sambuc ** [sqlite3_vfs] object that defines the operating system interface that 270311be35a1SLionel Sambuc ** the new database connection should use. ^If the fourth parameter is 270411be35a1SLionel Sambuc ** a NULL pointer then the default [sqlite3_vfs] object is used. 270511be35a1SLionel Sambuc ** 270611be35a1SLionel Sambuc ** ^If the filename is ":memory:", then a private, temporary in-memory database 270711be35a1SLionel Sambuc ** is created for the connection. ^This in-memory database will vanish when 270811be35a1SLionel Sambuc ** the database connection is closed. Future versions of SQLite might 270911be35a1SLionel Sambuc ** make use of additional special filenames that begin with the ":" character. 271011be35a1SLionel Sambuc ** It is recommended that when a database filename actually does begin with 271111be35a1SLionel Sambuc ** a ":" character you should prefix the filename with a pathname such as 271211be35a1SLionel Sambuc ** "./" to avoid ambiguity. 271311be35a1SLionel Sambuc ** 271411be35a1SLionel Sambuc ** ^If the filename is an empty string, then a private, temporary 271511be35a1SLionel Sambuc ** on-disk database will be created. ^This private database will be 271611be35a1SLionel Sambuc ** automatically deleted as soon as the database connection is closed. 271711be35a1SLionel Sambuc ** 271811be35a1SLionel Sambuc ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3> 271911be35a1SLionel Sambuc ** 272011be35a1SLionel Sambuc ** ^If [URI filename] interpretation is enabled, and the filename argument 272111be35a1SLionel Sambuc ** begins with "file:", then the filename is interpreted as a URI. ^URI 272211be35a1SLionel Sambuc ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is 272311be35a1SLionel Sambuc ** set in the fourth argument to sqlite3_open_v2(), or if it has 272411be35a1SLionel Sambuc ** been enabled globally using the [SQLITE_CONFIG_URI] option with the 272511be35a1SLionel Sambuc ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option. 272611be35a1SLionel Sambuc ** As of SQLite version 3.7.7, URI filename interpretation is turned off 272711be35a1SLionel Sambuc ** by default, but future releases of SQLite might enable URI filename 272811be35a1SLionel Sambuc ** interpretation by default. See "[URI filenames]" for additional 272911be35a1SLionel Sambuc ** information. 273011be35a1SLionel Sambuc ** 273111be35a1SLionel Sambuc ** URI filenames are parsed according to RFC 3986. ^If the URI contains an 273211be35a1SLionel Sambuc ** authority, then it must be either an empty string or the string 273311be35a1SLionel Sambuc ** "localhost". ^If the authority is not an empty string or "localhost", an 273411be35a1SLionel Sambuc ** error is returned to the caller. ^The fragment component of a URI, if 273511be35a1SLionel Sambuc ** present, is ignored. 273611be35a1SLionel Sambuc ** 273711be35a1SLionel Sambuc ** ^SQLite uses the path component of the URI as the name of the disk file 273811be35a1SLionel Sambuc ** which contains the database. ^If the path begins with a '/' character, 273911be35a1SLionel Sambuc ** then it is interpreted as an absolute path. ^If the path does not begin 274011be35a1SLionel Sambuc ** with a '/' (meaning that the authority section is omitted from the URI) 274111be35a1SLionel Sambuc ** then the path is interpreted as a relative path. 274211be35a1SLionel Sambuc ** ^On windows, the first component of an absolute path 274311be35a1SLionel Sambuc ** is a drive specification (e.g. "C:"). 274411be35a1SLionel Sambuc ** 274511be35a1SLionel Sambuc ** [[core URI query parameters]] 274611be35a1SLionel Sambuc ** The query component of a URI may contain parameters that are interpreted 274711be35a1SLionel Sambuc ** either by SQLite itself, or by a [VFS | custom VFS implementation]. 274811be35a1SLionel Sambuc ** SQLite interprets the following three query parameters: 274911be35a1SLionel Sambuc ** 275011be35a1SLionel Sambuc ** <ul> 275111be35a1SLionel Sambuc ** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of 275211be35a1SLionel Sambuc ** a VFS object that provides the operating system interface that should 275311be35a1SLionel Sambuc ** be used to access the database file on disk. ^If this option is set to 275411be35a1SLionel Sambuc ** an empty string the default VFS object is used. ^Specifying an unknown 275511be35a1SLionel Sambuc ** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is 275611be35a1SLionel Sambuc ** present, then the VFS specified by the option takes precedence over 275711be35a1SLionel Sambuc ** the value passed as the fourth parameter to sqlite3_open_v2(). 275811be35a1SLionel Sambuc ** 2759*0a6a1f1dSLionel Sambuc ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw", 2760*0a6a1f1dSLionel Sambuc ** "rwc", or "memory". Attempting to set it to any other value is 2761*0a6a1f1dSLionel Sambuc ** an error)^. 276211be35a1SLionel Sambuc ** ^If "ro" is specified, then the database is opened for read-only 276311be35a1SLionel Sambuc ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the 2764*0a6a1f1dSLionel Sambuc ** third argument to sqlite3_open_v2(). ^If the mode option is set to 276511be35a1SLionel Sambuc ** "rw", then the database is opened for read-write (but not create) 276611be35a1SLionel Sambuc ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had 276711be35a1SLionel Sambuc ** been set. ^Value "rwc" is equivalent to setting both 2768*0a6a1f1dSLionel Sambuc ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If the mode option is 2769*0a6a1f1dSLionel Sambuc ** set to "memory" then a pure [in-memory database] that never reads 2770*0a6a1f1dSLionel Sambuc ** or writes from disk is used. ^It is an error to specify a value for 2771*0a6a1f1dSLionel Sambuc ** the mode parameter that is less restrictive than that specified by 2772*0a6a1f1dSLionel Sambuc ** the flags passed in the third parameter to sqlite3_open_v2(). 277311be35a1SLionel Sambuc ** 277411be35a1SLionel Sambuc ** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or 277511be35a1SLionel Sambuc ** "private". ^Setting it to "shared" is equivalent to setting the 277611be35a1SLionel Sambuc ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to 277711be35a1SLionel Sambuc ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is 277811be35a1SLionel Sambuc ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit. 277911be35a1SLionel Sambuc ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in 2780*0a6a1f1dSLionel Sambuc ** a URI filename, its value overrides any behavior requested by setting 278111be35a1SLionel Sambuc ** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag. 278211be35a1SLionel Sambuc ** </ul> 278311be35a1SLionel Sambuc ** 278411be35a1SLionel Sambuc ** ^Specifying an unknown parameter in the query component of a URI is not an 278511be35a1SLionel Sambuc ** error. Future versions of SQLite might understand additional query 278611be35a1SLionel Sambuc ** parameters. See "[query parameters with special meaning to SQLite]" for 278711be35a1SLionel Sambuc ** additional information. 278811be35a1SLionel Sambuc ** 278911be35a1SLionel Sambuc ** [[URI filename examples]] <h3>URI filename examples</h3> 279011be35a1SLionel Sambuc ** 279111be35a1SLionel Sambuc ** <table border="1" align=center cellpadding=5> 279211be35a1SLionel Sambuc ** <tr><th> URI filenames <th> Results 279311be35a1SLionel Sambuc ** <tr><td> file:data.db <td> 279411be35a1SLionel Sambuc ** Open the file "data.db" in the current directory. 279511be35a1SLionel Sambuc ** <tr><td> file:/home/fred/data.db<br> 279611be35a1SLionel Sambuc ** file:///home/fred/data.db <br> 279711be35a1SLionel Sambuc ** file://localhost/home/fred/data.db <br> <td> 279811be35a1SLionel Sambuc ** Open the database file "/home/fred/data.db". 279911be35a1SLionel Sambuc ** <tr><td> file://darkstar/home/fred/data.db <td> 280011be35a1SLionel Sambuc ** An error. "darkstar" is not a recognized authority. 280111be35a1SLionel Sambuc ** <tr><td style="white-space:nowrap"> 280211be35a1SLionel Sambuc ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db 280311be35a1SLionel Sambuc ** <td> Windows only: Open the file "data.db" on fred's desktop on drive 280411be35a1SLionel Sambuc ** C:. Note that the %20 escaping in this example is not strictly 280511be35a1SLionel Sambuc ** necessary - space characters can be used literally 280611be35a1SLionel Sambuc ** in URI filenames. 280711be35a1SLionel Sambuc ** <tr><td> file:data.db?mode=ro&cache=private <td> 280811be35a1SLionel Sambuc ** Open file "data.db" in the current directory for read-only access. 280911be35a1SLionel Sambuc ** Regardless of whether or not shared-cache mode is enabled by 281011be35a1SLionel Sambuc ** default, use a private cache. 281111be35a1SLionel Sambuc ** <tr><td> file:/home/fred/data.db?vfs=unix-nolock <td> 281211be35a1SLionel Sambuc ** Open file "/home/fred/data.db". Use the special VFS "unix-nolock". 281311be35a1SLionel Sambuc ** <tr><td> file:data.db?mode=readonly <td> 281411be35a1SLionel Sambuc ** An error. "readonly" is not a valid option for the "mode" parameter. 281511be35a1SLionel Sambuc ** </table> 281611be35a1SLionel Sambuc ** 281711be35a1SLionel Sambuc ** ^URI hexadecimal escape sequences (%HH) are supported within the path and 281811be35a1SLionel Sambuc ** query components of a URI. A hexadecimal escape sequence consists of a 281911be35a1SLionel Sambuc ** percent sign - "%" - followed by exactly two hexadecimal digits 282011be35a1SLionel Sambuc ** specifying an octet value. ^Before the path or query components of a 282111be35a1SLionel Sambuc ** URI filename are interpreted, they are encoded using UTF-8 and all 282211be35a1SLionel Sambuc ** hexadecimal escape sequences replaced by a single byte containing the 282311be35a1SLionel Sambuc ** corresponding octet. If this process generates an invalid UTF-8 encoding, 282411be35a1SLionel Sambuc ** the results are undefined. 282511be35a1SLionel Sambuc ** 282611be35a1SLionel Sambuc ** <b>Note to Windows users:</b> The encoding used for the filename argument 282711be35a1SLionel Sambuc ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever 282811be35a1SLionel Sambuc ** codepage is currently defined. Filenames containing international 282911be35a1SLionel Sambuc ** characters must be converted to UTF-8 prior to passing them into 283011be35a1SLionel Sambuc ** sqlite3_open() or sqlite3_open_v2(). 2831*0a6a1f1dSLionel Sambuc ** 2832*0a6a1f1dSLionel Sambuc ** <b>Note to Windows Runtime users:</b> The temporary directory must be set 2833*0a6a1f1dSLionel Sambuc ** prior to calling sqlite3_open() or sqlite3_open_v2(). Otherwise, various 2834*0a6a1f1dSLionel Sambuc ** features that require the use of temporary files may fail. 2835*0a6a1f1dSLionel Sambuc ** 2836*0a6a1f1dSLionel Sambuc ** See also: [sqlite3_temp_directory] 283711be35a1SLionel Sambuc */ 283811be35a1SLionel Sambuc SQLITE_API int sqlite3_open( 283911be35a1SLionel Sambuc const char *filename, /* Database filename (UTF-8) */ 284011be35a1SLionel Sambuc sqlite3 **ppDb /* OUT: SQLite db handle */ 284111be35a1SLionel Sambuc ); 284211be35a1SLionel Sambuc SQLITE_API int sqlite3_open16( 284311be35a1SLionel Sambuc const void *filename, /* Database filename (UTF-16) */ 284411be35a1SLionel Sambuc sqlite3 **ppDb /* OUT: SQLite db handle */ 284511be35a1SLionel Sambuc ); 284611be35a1SLionel Sambuc SQLITE_API int sqlite3_open_v2( 284711be35a1SLionel Sambuc const char *filename, /* Database filename (UTF-8) */ 284811be35a1SLionel Sambuc sqlite3 **ppDb, /* OUT: SQLite db handle */ 284911be35a1SLionel Sambuc int flags, /* Flags */ 285011be35a1SLionel Sambuc const char *zVfs /* Name of VFS module to use */ 285111be35a1SLionel Sambuc ); 285211be35a1SLionel Sambuc 285311be35a1SLionel Sambuc /* 285411be35a1SLionel Sambuc ** CAPI3REF: Obtain Values For URI Parameters 285511be35a1SLionel Sambuc ** 285611be35a1SLionel Sambuc ** These are utility routines, useful to VFS implementations, that check 285711be35a1SLionel Sambuc ** to see if a database file was a URI that contained a specific query 285811be35a1SLionel Sambuc ** parameter, and if so obtains the value of that query parameter. 285911be35a1SLionel Sambuc ** 286011be35a1SLionel Sambuc ** If F is the database filename pointer passed into the xOpen() method of 286111be35a1SLionel Sambuc ** a VFS implementation when the flags parameter to xOpen() has one or 286211be35a1SLionel Sambuc ** more of the [SQLITE_OPEN_URI] or [SQLITE_OPEN_MAIN_DB] bits set and 286311be35a1SLionel Sambuc ** P is the name of the query parameter, then 286411be35a1SLionel Sambuc ** sqlite3_uri_parameter(F,P) returns the value of the P 286511be35a1SLionel Sambuc ** parameter if it exists or a NULL pointer if P does not appear as a 286611be35a1SLionel Sambuc ** query parameter on F. If P is a query parameter of F 286711be35a1SLionel Sambuc ** has no explicit value, then sqlite3_uri_parameter(F,P) returns 286811be35a1SLionel Sambuc ** a pointer to an empty string. 286911be35a1SLionel Sambuc ** 287011be35a1SLionel Sambuc ** The sqlite3_uri_boolean(F,P,B) routine assumes that P is a boolean 287111be35a1SLionel Sambuc ** parameter and returns true (1) or false (0) according to the value 2872*0a6a1f1dSLionel Sambuc ** of P. The sqlite3_uri_boolean(F,P,B) routine returns true (1) if the 2873*0a6a1f1dSLionel Sambuc ** value of query parameter P is one of "yes", "true", or "on" in any 2874*0a6a1f1dSLionel Sambuc ** case or if the value begins with a non-zero number. The 2875*0a6a1f1dSLionel Sambuc ** sqlite3_uri_boolean(F,P,B) routines returns false (0) if the value of 2876*0a6a1f1dSLionel Sambuc ** query parameter P is one of "no", "false", or "off" in any case or 2877*0a6a1f1dSLionel Sambuc ** if the value begins with a numeric zero. If P is not a query 2878*0a6a1f1dSLionel Sambuc ** parameter on F or if the value of P is does not match any of the 2879*0a6a1f1dSLionel Sambuc ** above, then sqlite3_uri_boolean(F,P,B) returns (B!=0). 288011be35a1SLionel Sambuc ** 288111be35a1SLionel Sambuc ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a 288211be35a1SLionel Sambuc ** 64-bit signed integer and returns that integer, or D if P does not 288311be35a1SLionel Sambuc ** exist. If the value of P is something other than an integer, then 288411be35a1SLionel Sambuc ** zero is returned. 288511be35a1SLionel Sambuc ** 288611be35a1SLionel Sambuc ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and 288711be35a1SLionel Sambuc ** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and 288811be35a1SLionel Sambuc ** is not a database file pathname pointer that SQLite passed into the xOpen 288911be35a1SLionel Sambuc ** VFS method, then the behavior of this routine is undefined and probably 289011be35a1SLionel Sambuc ** undesirable. 289111be35a1SLionel Sambuc */ 289211be35a1SLionel Sambuc SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam); 289311be35a1SLionel Sambuc SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault); 289411be35a1SLionel Sambuc SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64); 289511be35a1SLionel Sambuc 289611be35a1SLionel Sambuc 289711be35a1SLionel Sambuc /* 289811be35a1SLionel Sambuc ** CAPI3REF: Error Codes And Messages 289911be35a1SLionel Sambuc ** 290011be35a1SLionel Sambuc ** ^The sqlite3_errcode() interface returns the numeric [result code] or 290111be35a1SLionel Sambuc ** [extended result code] for the most recent failed sqlite3_* API call 290211be35a1SLionel Sambuc ** associated with a [database connection]. If a prior API call failed 290311be35a1SLionel Sambuc ** but the most recent API call succeeded, the return value from 290411be35a1SLionel Sambuc ** sqlite3_errcode() is undefined. ^The sqlite3_extended_errcode() 290511be35a1SLionel Sambuc ** interface is the same except that it always returns the 290611be35a1SLionel Sambuc ** [extended result code] even when extended result codes are 290711be35a1SLionel Sambuc ** disabled. 290811be35a1SLionel Sambuc ** 290911be35a1SLionel Sambuc ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language 291011be35a1SLionel Sambuc ** text that describes the error, as either UTF-8 or UTF-16 respectively. 291111be35a1SLionel Sambuc ** ^(Memory to hold the error message string is managed internally. 291211be35a1SLionel Sambuc ** The application does not need to worry about freeing the result. 291311be35a1SLionel Sambuc ** However, the error string might be overwritten or deallocated by 291411be35a1SLionel Sambuc ** subsequent calls to other SQLite interface functions.)^ 291511be35a1SLionel Sambuc ** 2916*0a6a1f1dSLionel Sambuc ** ^The sqlite3_errstr() interface returns the English-language text 2917*0a6a1f1dSLionel Sambuc ** that describes the [result code], as UTF-8. 2918*0a6a1f1dSLionel Sambuc ** ^(Memory to hold the error message string is managed internally 2919*0a6a1f1dSLionel Sambuc ** and must not be freed by the application)^. 2920*0a6a1f1dSLionel Sambuc ** 292111be35a1SLionel Sambuc ** When the serialized [threading mode] is in use, it might be the 292211be35a1SLionel Sambuc ** case that a second error occurs on a separate thread in between 292311be35a1SLionel Sambuc ** the time of the first error and the call to these interfaces. 292411be35a1SLionel Sambuc ** When that happens, the second error will be reported since these 292511be35a1SLionel Sambuc ** interfaces always report the most recent result. To avoid 292611be35a1SLionel Sambuc ** this, each thread can obtain exclusive use of the [database connection] D 292711be35a1SLionel Sambuc ** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning 292811be35a1SLionel Sambuc ** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after 292911be35a1SLionel Sambuc ** all calls to the interfaces listed here are completed. 293011be35a1SLionel Sambuc ** 293111be35a1SLionel Sambuc ** If an interface fails with SQLITE_MISUSE, that means the interface 293211be35a1SLionel Sambuc ** was invoked incorrectly by the application. In that case, the 293311be35a1SLionel Sambuc ** error code and message may or may not be set. 293411be35a1SLionel Sambuc */ 293511be35a1SLionel Sambuc SQLITE_API int sqlite3_errcode(sqlite3 *db); 293611be35a1SLionel Sambuc SQLITE_API int sqlite3_extended_errcode(sqlite3 *db); 293711be35a1SLionel Sambuc SQLITE_API const char *sqlite3_errmsg(sqlite3*); 293811be35a1SLionel Sambuc SQLITE_API const void *sqlite3_errmsg16(sqlite3*); 2939*0a6a1f1dSLionel Sambuc SQLITE_API const char *sqlite3_errstr(int); 294011be35a1SLionel Sambuc 294111be35a1SLionel Sambuc /* 294211be35a1SLionel Sambuc ** CAPI3REF: SQL Statement Object 294311be35a1SLionel Sambuc ** KEYWORDS: {prepared statement} {prepared statements} 294411be35a1SLionel Sambuc ** 294511be35a1SLionel Sambuc ** An instance of this object represents a single SQL statement. 294611be35a1SLionel Sambuc ** This object is variously known as a "prepared statement" or a 294711be35a1SLionel Sambuc ** "compiled SQL statement" or simply as a "statement". 294811be35a1SLionel Sambuc ** 294911be35a1SLionel Sambuc ** The life of a statement object goes something like this: 295011be35a1SLionel Sambuc ** 295111be35a1SLionel Sambuc ** <ol> 295211be35a1SLionel Sambuc ** <li> Create the object using [sqlite3_prepare_v2()] or a related 295311be35a1SLionel Sambuc ** function. 295411be35a1SLionel Sambuc ** <li> Bind values to [host parameters] using the sqlite3_bind_*() 295511be35a1SLionel Sambuc ** interfaces. 295611be35a1SLionel Sambuc ** <li> Run the SQL by calling [sqlite3_step()] one or more times. 295711be35a1SLionel Sambuc ** <li> Reset the statement using [sqlite3_reset()] then go back 295811be35a1SLionel Sambuc ** to step 2. Do this zero or more times. 295911be35a1SLionel Sambuc ** <li> Destroy the object using [sqlite3_finalize()]. 296011be35a1SLionel Sambuc ** </ol> 296111be35a1SLionel Sambuc ** 296211be35a1SLionel Sambuc ** Refer to documentation on individual methods above for additional 296311be35a1SLionel Sambuc ** information. 296411be35a1SLionel Sambuc */ 296511be35a1SLionel Sambuc typedef struct sqlite3_stmt sqlite3_stmt; 296611be35a1SLionel Sambuc 296711be35a1SLionel Sambuc /* 296811be35a1SLionel Sambuc ** CAPI3REF: Run-time Limits 296911be35a1SLionel Sambuc ** 297011be35a1SLionel Sambuc ** ^(This interface allows the size of various constructs to be limited 297111be35a1SLionel Sambuc ** on a connection by connection basis. The first parameter is the 297211be35a1SLionel Sambuc ** [database connection] whose limit is to be set or queried. The 297311be35a1SLionel Sambuc ** second parameter is one of the [limit categories] that define a 297411be35a1SLionel Sambuc ** class of constructs to be size limited. The third parameter is the 297511be35a1SLionel Sambuc ** new limit for that construct.)^ 297611be35a1SLionel Sambuc ** 297711be35a1SLionel Sambuc ** ^If the new limit is a negative number, the limit is unchanged. 297811be35a1SLionel Sambuc ** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a 297911be35a1SLionel Sambuc ** [limits | hard upper bound] 298011be35a1SLionel Sambuc ** set at compile-time by a C preprocessor macro called 298111be35a1SLionel Sambuc ** [limits | SQLITE_MAX_<i>NAME</i>]. 298211be35a1SLionel Sambuc ** (The "_LIMIT_" in the name is changed to "_MAX_".))^ 298311be35a1SLionel Sambuc ** ^Attempts to increase a limit above its hard upper bound are 298411be35a1SLionel Sambuc ** silently truncated to the hard upper bound. 298511be35a1SLionel Sambuc ** 298611be35a1SLionel Sambuc ** ^Regardless of whether or not the limit was changed, the 298711be35a1SLionel Sambuc ** [sqlite3_limit()] interface returns the prior value of the limit. 298811be35a1SLionel Sambuc ** ^Hence, to find the current value of a limit without changing it, 298911be35a1SLionel Sambuc ** simply invoke this interface with the third parameter set to -1. 299011be35a1SLionel Sambuc ** 299111be35a1SLionel Sambuc ** Run-time limits are intended for use in applications that manage 299211be35a1SLionel Sambuc ** both their own internal database and also databases that are controlled 299311be35a1SLionel Sambuc ** by untrusted external sources. An example application might be a 299411be35a1SLionel Sambuc ** web browser that has its own databases for storing history and 299511be35a1SLionel Sambuc ** separate databases controlled by JavaScript applications downloaded 299611be35a1SLionel Sambuc ** off the Internet. The internal databases can be given the 299711be35a1SLionel Sambuc ** large, default limits. Databases managed by external sources can 299811be35a1SLionel Sambuc ** be given much smaller limits designed to prevent a denial of service 299911be35a1SLionel Sambuc ** attack. Developers might also want to use the [sqlite3_set_authorizer()] 300011be35a1SLionel Sambuc ** interface to further control untrusted SQL. The size of the database 300111be35a1SLionel Sambuc ** created by an untrusted script can be contained using the 300211be35a1SLionel Sambuc ** [max_page_count] [PRAGMA]. 300311be35a1SLionel Sambuc ** 300411be35a1SLionel Sambuc ** New run-time limit categories may be added in future releases. 300511be35a1SLionel Sambuc */ 300611be35a1SLionel Sambuc SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal); 300711be35a1SLionel Sambuc 300811be35a1SLionel Sambuc /* 300911be35a1SLionel Sambuc ** CAPI3REF: Run-Time Limit Categories 301011be35a1SLionel Sambuc ** KEYWORDS: {limit category} {*limit categories} 301111be35a1SLionel Sambuc ** 301211be35a1SLionel Sambuc ** These constants define various performance limits 301311be35a1SLionel Sambuc ** that can be lowered at run-time using [sqlite3_limit()]. 301411be35a1SLionel Sambuc ** The synopsis of the meanings of the various limits is shown below. 301511be35a1SLionel Sambuc ** Additional information is available at [limits | Limits in SQLite]. 301611be35a1SLionel Sambuc ** 301711be35a1SLionel Sambuc ** <dl> 301811be35a1SLionel Sambuc ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt> 301911be35a1SLionel Sambuc ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^ 302011be35a1SLionel Sambuc ** 302111be35a1SLionel Sambuc ** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt> 302211be35a1SLionel Sambuc ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^ 302311be35a1SLionel Sambuc ** 302411be35a1SLionel Sambuc ** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt> 302511be35a1SLionel Sambuc ** <dd>The maximum number of columns in a table definition or in the 302611be35a1SLionel Sambuc ** result set of a [SELECT] or the maximum number of columns in an index 302711be35a1SLionel Sambuc ** or in an ORDER BY or GROUP BY clause.</dd>)^ 302811be35a1SLionel Sambuc ** 302911be35a1SLionel Sambuc ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> 303011be35a1SLionel Sambuc ** <dd>The maximum depth of the parse tree on any expression.</dd>)^ 303111be35a1SLionel Sambuc ** 303211be35a1SLionel Sambuc ** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt> 303311be35a1SLionel Sambuc ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^ 303411be35a1SLionel Sambuc ** 303511be35a1SLionel Sambuc ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt> 303611be35a1SLionel Sambuc ** <dd>The maximum number of instructions in a virtual machine program 303711be35a1SLionel Sambuc ** used to implement an SQL statement. This limit is not currently 303811be35a1SLionel Sambuc ** enforced, though that might be added in some future release of 303911be35a1SLionel Sambuc ** SQLite.</dd>)^ 304011be35a1SLionel Sambuc ** 304111be35a1SLionel Sambuc ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt> 304211be35a1SLionel Sambuc ** <dd>The maximum number of arguments on a function.</dd>)^ 304311be35a1SLionel Sambuc ** 304411be35a1SLionel Sambuc ** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt> 304511be35a1SLionel Sambuc ** <dd>The maximum number of [ATTACH | attached databases].)^</dd> 304611be35a1SLionel Sambuc ** 304711be35a1SLionel Sambuc ** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]] 304811be35a1SLionel Sambuc ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt> 304911be35a1SLionel Sambuc ** <dd>The maximum length of the pattern argument to the [LIKE] or 305011be35a1SLionel Sambuc ** [GLOB] operators.</dd>)^ 305111be35a1SLionel Sambuc ** 305211be35a1SLionel Sambuc ** [[SQLITE_LIMIT_VARIABLE_NUMBER]] 305311be35a1SLionel Sambuc ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt> 305411be35a1SLionel Sambuc ** <dd>The maximum index number of any [parameter] in an SQL statement.)^ 305511be35a1SLionel Sambuc ** 305611be35a1SLionel Sambuc ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> 305711be35a1SLionel Sambuc ** <dd>The maximum depth of recursion for triggers.</dd>)^ 305811be35a1SLionel Sambuc ** </dl> 305911be35a1SLionel Sambuc */ 306011be35a1SLionel Sambuc #define SQLITE_LIMIT_LENGTH 0 306111be35a1SLionel Sambuc #define SQLITE_LIMIT_SQL_LENGTH 1 306211be35a1SLionel Sambuc #define SQLITE_LIMIT_COLUMN 2 306311be35a1SLionel Sambuc #define SQLITE_LIMIT_EXPR_DEPTH 3 306411be35a1SLionel Sambuc #define SQLITE_LIMIT_COMPOUND_SELECT 4 306511be35a1SLionel Sambuc #define SQLITE_LIMIT_VDBE_OP 5 306611be35a1SLionel Sambuc #define SQLITE_LIMIT_FUNCTION_ARG 6 306711be35a1SLionel Sambuc #define SQLITE_LIMIT_ATTACHED 7 306811be35a1SLionel Sambuc #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8 306911be35a1SLionel Sambuc #define SQLITE_LIMIT_VARIABLE_NUMBER 9 307011be35a1SLionel Sambuc #define SQLITE_LIMIT_TRIGGER_DEPTH 10 307111be35a1SLionel Sambuc 307211be35a1SLionel Sambuc /* 307311be35a1SLionel Sambuc ** CAPI3REF: Compiling An SQL Statement 307411be35a1SLionel Sambuc ** KEYWORDS: {SQL statement compiler} 307511be35a1SLionel Sambuc ** 307611be35a1SLionel Sambuc ** To execute an SQL query, it must first be compiled into a byte-code 307711be35a1SLionel Sambuc ** program using one of these routines. 307811be35a1SLionel Sambuc ** 307911be35a1SLionel Sambuc ** The first argument, "db", is a [database connection] obtained from a 308011be35a1SLionel Sambuc ** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or 308111be35a1SLionel Sambuc ** [sqlite3_open16()]. The database connection must not have been closed. 308211be35a1SLionel Sambuc ** 308311be35a1SLionel Sambuc ** The second argument, "zSql", is the statement to be compiled, encoded 308411be35a1SLionel Sambuc ** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2() 308511be35a1SLionel Sambuc ** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2() 308611be35a1SLionel Sambuc ** use UTF-16. 308711be35a1SLionel Sambuc ** 308811be35a1SLionel Sambuc ** ^If the nByte argument is less than zero, then zSql is read up to the 308911be35a1SLionel Sambuc ** first zero terminator. ^If nByte is non-negative, then it is the maximum 309011be35a1SLionel Sambuc ** number of bytes read from zSql. ^When nByte is non-negative, the 309111be35a1SLionel Sambuc ** zSql string ends at either the first '\000' or '\u0000' character or 309211be35a1SLionel Sambuc ** the nByte-th byte, whichever comes first. If the caller knows 309311be35a1SLionel Sambuc ** that the supplied string is nul-terminated, then there is a small 309411be35a1SLionel Sambuc ** performance advantage to be gained by passing an nByte parameter that 309511be35a1SLionel Sambuc ** is equal to the number of bytes in the input string <i>including</i> 309611be35a1SLionel Sambuc ** the nul-terminator bytes as this saves SQLite from having to 309711be35a1SLionel Sambuc ** make a copy of the input string. 309811be35a1SLionel Sambuc ** 309911be35a1SLionel Sambuc ** ^If pzTail is not NULL then *pzTail is made to point to the first byte 310011be35a1SLionel Sambuc ** past the end of the first SQL statement in zSql. These routines only 310111be35a1SLionel Sambuc ** compile the first statement in zSql, so *pzTail is left pointing to 310211be35a1SLionel Sambuc ** what remains uncompiled. 310311be35a1SLionel Sambuc ** 310411be35a1SLionel Sambuc ** ^*ppStmt is left pointing to a compiled [prepared statement] that can be 310511be35a1SLionel Sambuc ** executed using [sqlite3_step()]. ^If there is an error, *ppStmt is set 310611be35a1SLionel Sambuc ** to NULL. ^If the input text contains no SQL (if the input is an empty 310711be35a1SLionel Sambuc ** string or a comment) then *ppStmt is set to NULL. 310811be35a1SLionel Sambuc ** The calling procedure is responsible for deleting the compiled 310911be35a1SLionel Sambuc ** SQL statement using [sqlite3_finalize()] after it has finished with it. 311011be35a1SLionel Sambuc ** ppStmt may not be NULL. 311111be35a1SLionel Sambuc ** 311211be35a1SLionel Sambuc ** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK]; 311311be35a1SLionel Sambuc ** otherwise an [error code] is returned. 311411be35a1SLionel Sambuc ** 311511be35a1SLionel Sambuc ** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are 311611be35a1SLionel Sambuc ** recommended for all new programs. The two older interfaces are retained 311711be35a1SLionel Sambuc ** for backwards compatibility, but their use is discouraged. 311811be35a1SLionel Sambuc ** ^In the "v2" interfaces, the prepared statement 311911be35a1SLionel Sambuc ** that is returned (the [sqlite3_stmt] object) contains a copy of the 312011be35a1SLionel Sambuc ** original SQL text. This causes the [sqlite3_step()] interface to 312111be35a1SLionel Sambuc ** behave differently in three ways: 312211be35a1SLionel Sambuc ** 312311be35a1SLionel Sambuc ** <ol> 312411be35a1SLionel Sambuc ** <li> 312511be35a1SLionel Sambuc ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it 312611be35a1SLionel Sambuc ** always used to do, [sqlite3_step()] will automatically recompile the SQL 3127*0a6a1f1dSLionel Sambuc ** statement and try to run it again. As many as [SQLITE_MAX_SCHEMA_RETRY] 3128*0a6a1f1dSLionel Sambuc ** retries will occur before sqlite3_step() gives up and returns an error. 312911be35a1SLionel Sambuc ** </li> 313011be35a1SLionel Sambuc ** 313111be35a1SLionel Sambuc ** <li> 313211be35a1SLionel Sambuc ** ^When an error occurs, [sqlite3_step()] will return one of the detailed 313311be35a1SLionel Sambuc ** [error codes] or [extended error codes]. ^The legacy behavior was that 313411be35a1SLionel Sambuc ** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code 313511be35a1SLionel Sambuc ** and the application would have to make a second call to [sqlite3_reset()] 313611be35a1SLionel Sambuc ** in order to find the underlying cause of the problem. With the "v2" prepare 313711be35a1SLionel Sambuc ** interfaces, the underlying reason for the error is returned immediately. 313811be35a1SLionel Sambuc ** </li> 313911be35a1SLionel Sambuc ** 314011be35a1SLionel Sambuc ** <li> 314111be35a1SLionel Sambuc ** ^If the specific value bound to [parameter | host parameter] in the 314211be35a1SLionel Sambuc ** WHERE clause might influence the choice of query plan for a statement, 314311be35a1SLionel Sambuc ** then the statement will be automatically recompiled, as if there had been 314411be35a1SLionel Sambuc ** a schema change, on the first [sqlite3_step()] call following any change 314511be35a1SLionel Sambuc ** to the [sqlite3_bind_text | bindings] of that [parameter]. 314611be35a1SLionel Sambuc ** ^The specific value of WHERE-clause [parameter] might influence the 314711be35a1SLionel Sambuc ** choice of query plan if the parameter is the left-hand side of a [LIKE] 314811be35a1SLionel Sambuc ** or [GLOB] operator or if the parameter is compared to an indexed column 314911be35a1SLionel Sambuc ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled. 315011be35a1SLionel Sambuc ** </li> 315111be35a1SLionel Sambuc ** </ol> 315211be35a1SLionel Sambuc */ 315311be35a1SLionel Sambuc SQLITE_API int sqlite3_prepare( 315411be35a1SLionel Sambuc sqlite3 *db, /* Database handle */ 315511be35a1SLionel Sambuc const char *zSql, /* SQL statement, UTF-8 encoded */ 315611be35a1SLionel Sambuc int nByte, /* Maximum length of zSql in bytes. */ 315711be35a1SLionel Sambuc sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 315811be35a1SLionel Sambuc const char **pzTail /* OUT: Pointer to unused portion of zSql */ 315911be35a1SLionel Sambuc ); 316011be35a1SLionel Sambuc SQLITE_API int sqlite3_prepare_v2( 316111be35a1SLionel Sambuc sqlite3 *db, /* Database handle */ 316211be35a1SLionel Sambuc const char *zSql, /* SQL statement, UTF-8 encoded */ 316311be35a1SLionel Sambuc int nByte, /* Maximum length of zSql in bytes. */ 316411be35a1SLionel Sambuc sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 316511be35a1SLionel Sambuc const char **pzTail /* OUT: Pointer to unused portion of zSql */ 316611be35a1SLionel Sambuc ); 316711be35a1SLionel Sambuc SQLITE_API int sqlite3_prepare16( 316811be35a1SLionel Sambuc sqlite3 *db, /* Database handle */ 316911be35a1SLionel Sambuc const void *zSql, /* SQL statement, UTF-16 encoded */ 317011be35a1SLionel Sambuc int nByte, /* Maximum length of zSql in bytes. */ 317111be35a1SLionel Sambuc sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 317211be35a1SLionel Sambuc const void **pzTail /* OUT: Pointer to unused portion of zSql */ 317311be35a1SLionel Sambuc ); 317411be35a1SLionel Sambuc SQLITE_API int sqlite3_prepare16_v2( 317511be35a1SLionel Sambuc sqlite3 *db, /* Database handle */ 317611be35a1SLionel Sambuc const void *zSql, /* SQL statement, UTF-16 encoded */ 317711be35a1SLionel Sambuc int nByte, /* Maximum length of zSql in bytes. */ 317811be35a1SLionel Sambuc sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 317911be35a1SLionel Sambuc const void **pzTail /* OUT: Pointer to unused portion of zSql */ 318011be35a1SLionel Sambuc ); 318111be35a1SLionel Sambuc 318211be35a1SLionel Sambuc /* 318311be35a1SLionel Sambuc ** CAPI3REF: Retrieving Statement SQL 318411be35a1SLionel Sambuc ** 318511be35a1SLionel Sambuc ** ^This interface can be used to retrieve a saved copy of the original 318611be35a1SLionel Sambuc ** SQL text used to create a [prepared statement] if that statement was 318711be35a1SLionel Sambuc ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()]. 318811be35a1SLionel Sambuc */ 318911be35a1SLionel Sambuc SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt); 319011be35a1SLionel Sambuc 319111be35a1SLionel Sambuc /* 319211be35a1SLionel Sambuc ** CAPI3REF: Determine If An SQL Statement Writes The Database 319311be35a1SLionel Sambuc ** 319411be35a1SLionel Sambuc ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if 319511be35a1SLionel Sambuc ** and only if the [prepared statement] X makes no direct changes to 319611be35a1SLionel Sambuc ** the content of the database file. 319711be35a1SLionel Sambuc ** 319811be35a1SLionel Sambuc ** Note that [application-defined SQL functions] or 319911be35a1SLionel Sambuc ** [virtual tables] might change the database indirectly as a side effect. 320011be35a1SLionel Sambuc ** ^(For example, if an application defines a function "eval()" that 320111be35a1SLionel Sambuc ** calls [sqlite3_exec()], then the following SQL statement would 320211be35a1SLionel Sambuc ** change the database file through side-effects: 320311be35a1SLionel Sambuc ** 320411be35a1SLionel Sambuc ** <blockquote><pre> 320511be35a1SLionel Sambuc ** SELECT eval('DELETE FROM t1') FROM t2; 320611be35a1SLionel Sambuc ** </pre></blockquote> 320711be35a1SLionel Sambuc ** 320811be35a1SLionel Sambuc ** But because the [SELECT] statement does not change the database file 320911be35a1SLionel Sambuc ** directly, sqlite3_stmt_readonly() would still return true.)^ 321011be35a1SLionel Sambuc ** 321111be35a1SLionel Sambuc ** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK], 321211be35a1SLionel Sambuc ** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true, 321311be35a1SLionel Sambuc ** since the statements themselves do not actually modify the database but 321411be35a1SLionel Sambuc ** rather they control the timing of when other statements modify the 321511be35a1SLionel Sambuc ** database. ^The [ATTACH] and [DETACH] statements also cause 321611be35a1SLionel Sambuc ** sqlite3_stmt_readonly() to return true since, while those statements 321711be35a1SLionel Sambuc ** change the configuration of a database connection, they do not make 321811be35a1SLionel Sambuc ** changes to the content of the database files on disk. 321911be35a1SLionel Sambuc */ 322011be35a1SLionel Sambuc SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt); 322111be35a1SLionel Sambuc 322211be35a1SLionel Sambuc /* 322311be35a1SLionel Sambuc ** CAPI3REF: Determine If A Prepared Statement Has Been Reset 322411be35a1SLionel Sambuc ** 322511be35a1SLionel Sambuc ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the 322611be35a1SLionel Sambuc ** [prepared statement] S has been stepped at least once using 322711be35a1SLionel Sambuc ** [sqlite3_step(S)] but has not run to completion and/or has not 322811be35a1SLionel Sambuc ** been reset using [sqlite3_reset(S)]. ^The sqlite3_stmt_busy(S) 322911be35a1SLionel Sambuc ** interface returns false if S is a NULL pointer. If S is not a 323011be35a1SLionel Sambuc ** NULL pointer and is not a pointer to a valid [prepared statement] 323111be35a1SLionel Sambuc ** object, then the behavior is undefined and probably undesirable. 323211be35a1SLionel Sambuc ** 323311be35a1SLionel Sambuc ** This interface can be used in combination [sqlite3_next_stmt()] 323411be35a1SLionel Sambuc ** to locate all prepared statements associated with a database 323511be35a1SLionel Sambuc ** connection that are in need of being reset. This can be used, 323611be35a1SLionel Sambuc ** for example, in diagnostic routines to search for prepared 323711be35a1SLionel Sambuc ** statements that are holding a transaction open. 323811be35a1SLionel Sambuc */ 323911be35a1SLionel Sambuc SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt*); 324011be35a1SLionel Sambuc 324111be35a1SLionel Sambuc /* 324211be35a1SLionel Sambuc ** CAPI3REF: Dynamically Typed Value Object 324311be35a1SLionel Sambuc ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value} 324411be35a1SLionel Sambuc ** 324511be35a1SLionel Sambuc ** SQLite uses the sqlite3_value object to represent all values 324611be35a1SLionel Sambuc ** that can be stored in a database table. SQLite uses dynamic typing 324711be35a1SLionel Sambuc ** for the values it stores. ^Values stored in sqlite3_value objects 324811be35a1SLionel Sambuc ** can be integers, floating point values, strings, BLOBs, or NULL. 324911be35a1SLionel Sambuc ** 325011be35a1SLionel Sambuc ** An sqlite3_value object may be either "protected" or "unprotected". 325111be35a1SLionel Sambuc ** Some interfaces require a protected sqlite3_value. Other interfaces 325211be35a1SLionel Sambuc ** will accept either a protected or an unprotected sqlite3_value. 325311be35a1SLionel Sambuc ** Every interface that accepts sqlite3_value arguments specifies 325411be35a1SLionel Sambuc ** whether or not it requires a protected sqlite3_value. 325511be35a1SLionel Sambuc ** 325611be35a1SLionel Sambuc ** The terms "protected" and "unprotected" refer to whether or not 325711be35a1SLionel Sambuc ** a mutex is held. An internal mutex is held for a protected 325811be35a1SLionel Sambuc ** sqlite3_value object but no mutex is held for an unprotected 325911be35a1SLionel Sambuc ** sqlite3_value object. If SQLite is compiled to be single-threaded 326011be35a1SLionel Sambuc ** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0) 326111be35a1SLionel Sambuc ** or if SQLite is run in one of reduced mutex modes 326211be35a1SLionel Sambuc ** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD] 326311be35a1SLionel Sambuc ** then there is no distinction between protected and unprotected 326411be35a1SLionel Sambuc ** sqlite3_value objects and they can be used interchangeably. However, 326511be35a1SLionel Sambuc ** for maximum code portability it is recommended that applications 326611be35a1SLionel Sambuc ** still make the distinction between protected and unprotected 326711be35a1SLionel Sambuc ** sqlite3_value objects even when not strictly required. 326811be35a1SLionel Sambuc ** 326911be35a1SLionel Sambuc ** ^The sqlite3_value objects that are passed as parameters into the 327011be35a1SLionel Sambuc ** implementation of [application-defined SQL functions] are protected. 327111be35a1SLionel Sambuc ** ^The sqlite3_value object returned by 327211be35a1SLionel Sambuc ** [sqlite3_column_value()] is unprotected. 327311be35a1SLionel Sambuc ** Unprotected sqlite3_value objects may only be used with 327411be35a1SLionel Sambuc ** [sqlite3_result_value()] and [sqlite3_bind_value()]. 327511be35a1SLionel Sambuc ** The [sqlite3_value_blob | sqlite3_value_type()] family of 327611be35a1SLionel Sambuc ** interfaces require protected sqlite3_value objects. 327711be35a1SLionel Sambuc */ 327811be35a1SLionel Sambuc typedef struct Mem sqlite3_value; 327911be35a1SLionel Sambuc 328011be35a1SLionel Sambuc /* 328111be35a1SLionel Sambuc ** CAPI3REF: SQL Function Context Object 328211be35a1SLionel Sambuc ** 328311be35a1SLionel Sambuc ** The context in which an SQL function executes is stored in an 328411be35a1SLionel Sambuc ** sqlite3_context object. ^A pointer to an sqlite3_context object 328511be35a1SLionel Sambuc ** is always first parameter to [application-defined SQL functions]. 328611be35a1SLionel Sambuc ** The application-defined SQL function implementation will pass this 328711be35a1SLionel Sambuc ** pointer through into calls to [sqlite3_result_int | sqlite3_result()], 328811be35a1SLionel Sambuc ** [sqlite3_aggregate_context()], [sqlite3_user_data()], 328911be35a1SLionel Sambuc ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()], 329011be35a1SLionel Sambuc ** and/or [sqlite3_set_auxdata()]. 329111be35a1SLionel Sambuc */ 329211be35a1SLionel Sambuc typedef struct sqlite3_context sqlite3_context; 329311be35a1SLionel Sambuc 329411be35a1SLionel Sambuc /* 329511be35a1SLionel Sambuc ** CAPI3REF: Binding Values To Prepared Statements 329611be35a1SLionel Sambuc ** KEYWORDS: {host parameter} {host parameters} {host parameter name} 329711be35a1SLionel Sambuc ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding} 329811be35a1SLionel Sambuc ** 329911be35a1SLionel Sambuc ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants, 330011be35a1SLionel Sambuc ** literals may be replaced by a [parameter] that matches one of following 330111be35a1SLionel Sambuc ** templates: 330211be35a1SLionel Sambuc ** 330311be35a1SLionel Sambuc ** <ul> 330411be35a1SLionel Sambuc ** <li> ? 330511be35a1SLionel Sambuc ** <li> ?NNN 330611be35a1SLionel Sambuc ** <li> :VVV 330711be35a1SLionel Sambuc ** <li> @VVV 330811be35a1SLionel Sambuc ** <li> $VVV 330911be35a1SLionel Sambuc ** </ul> 331011be35a1SLionel Sambuc ** 331111be35a1SLionel Sambuc ** In the templates above, NNN represents an integer literal, 331211be35a1SLionel Sambuc ** and VVV represents an alphanumeric identifier.)^ ^The values of these 331311be35a1SLionel Sambuc ** parameters (also called "host parameter names" or "SQL parameters") 331411be35a1SLionel Sambuc ** can be set using the sqlite3_bind_*() routines defined here. 331511be35a1SLionel Sambuc ** 331611be35a1SLionel Sambuc ** ^The first argument to the sqlite3_bind_*() routines is always 331711be35a1SLionel Sambuc ** a pointer to the [sqlite3_stmt] object returned from 331811be35a1SLionel Sambuc ** [sqlite3_prepare_v2()] or its variants. 331911be35a1SLionel Sambuc ** 332011be35a1SLionel Sambuc ** ^The second argument is the index of the SQL parameter to be set. 332111be35a1SLionel Sambuc ** ^The leftmost SQL parameter has an index of 1. ^When the same named 332211be35a1SLionel Sambuc ** SQL parameter is used more than once, second and subsequent 332311be35a1SLionel Sambuc ** occurrences have the same index as the first occurrence. 332411be35a1SLionel Sambuc ** ^The index for named parameters can be looked up using the 332511be35a1SLionel Sambuc ** [sqlite3_bind_parameter_index()] API if desired. ^The index 332611be35a1SLionel Sambuc ** for "?NNN" parameters is the value of NNN. 332711be35a1SLionel Sambuc ** ^The NNN value must be between 1 and the [sqlite3_limit()] 332811be35a1SLionel Sambuc ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999). 332911be35a1SLionel Sambuc ** 333011be35a1SLionel Sambuc ** ^The third argument is the value to bind to the parameter. 3331*0a6a1f1dSLionel Sambuc ** ^If the third parameter to sqlite3_bind_text() or sqlite3_bind_text16() 3332*0a6a1f1dSLionel Sambuc ** or sqlite3_bind_blob() is a NULL pointer then the fourth parameter 3333*0a6a1f1dSLionel Sambuc ** is ignored and the end result is the same as sqlite3_bind_null(). 333411be35a1SLionel Sambuc ** 333511be35a1SLionel Sambuc ** ^(In those routines that have a fourth argument, its value is the 333611be35a1SLionel Sambuc ** number of bytes in the parameter. To be clear: the value is the 333711be35a1SLionel Sambuc ** number of <u>bytes</u> in the value, not the number of characters.)^ 3338*0a6a1f1dSLionel Sambuc ** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16() 3339*0a6a1f1dSLionel Sambuc ** is negative, then the length of the string is 334011be35a1SLionel Sambuc ** the number of bytes up to the first zero terminator. 3341*0a6a1f1dSLionel Sambuc ** If the fourth parameter to sqlite3_bind_blob() is negative, then 3342*0a6a1f1dSLionel Sambuc ** the behavior is undefined. 334311be35a1SLionel Sambuc ** If a non-negative fourth parameter is provided to sqlite3_bind_text() 334411be35a1SLionel Sambuc ** or sqlite3_bind_text16() then that parameter must be the byte offset 334511be35a1SLionel Sambuc ** where the NUL terminator would occur assuming the string were NUL 334611be35a1SLionel Sambuc ** terminated. If any NUL characters occur at byte offsets less than 334711be35a1SLionel Sambuc ** the value of the fourth parameter then the resulting string value will 334811be35a1SLionel Sambuc ** contain embedded NULs. The result of expressions involving strings 334911be35a1SLionel Sambuc ** with embedded NULs is undefined. 335011be35a1SLionel Sambuc ** 335111be35a1SLionel Sambuc ** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and 335211be35a1SLionel Sambuc ** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or 335311be35a1SLionel Sambuc ** string after SQLite has finished with it. ^The destructor is called 335411be35a1SLionel Sambuc ** to dispose of the BLOB or string even if the call to sqlite3_bind_blob(), 335511be35a1SLionel Sambuc ** sqlite3_bind_text(), or sqlite3_bind_text16() fails. 335611be35a1SLionel Sambuc ** ^If the fifth argument is 335711be35a1SLionel Sambuc ** the special value [SQLITE_STATIC], then SQLite assumes that the 335811be35a1SLionel Sambuc ** information is in static, unmanaged space and does not need to be freed. 335911be35a1SLionel Sambuc ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then 336011be35a1SLionel Sambuc ** SQLite makes its own private copy of the data immediately, before 336111be35a1SLionel Sambuc ** the sqlite3_bind_*() routine returns. 336211be35a1SLionel Sambuc ** 336311be35a1SLionel Sambuc ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that 336411be35a1SLionel Sambuc ** is filled with zeroes. ^A zeroblob uses a fixed amount of memory 336511be35a1SLionel Sambuc ** (just an integer to hold its size) while it is being processed. 336611be35a1SLionel Sambuc ** Zeroblobs are intended to serve as placeholders for BLOBs whose 336711be35a1SLionel Sambuc ** content is later written using 336811be35a1SLionel Sambuc ** [sqlite3_blob_open | incremental BLOB I/O] routines. 336911be35a1SLionel Sambuc ** ^A negative value for the zeroblob results in a zero-length BLOB. 337011be35a1SLionel Sambuc ** 337111be35a1SLionel Sambuc ** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer 337211be35a1SLionel Sambuc ** for the [prepared statement] or with a prepared statement for which 337311be35a1SLionel Sambuc ** [sqlite3_step()] has been called more recently than [sqlite3_reset()], 337411be35a1SLionel Sambuc ** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_() 337511be35a1SLionel Sambuc ** routine is passed a [prepared statement] that has been finalized, the 337611be35a1SLionel Sambuc ** result is undefined and probably harmful. 337711be35a1SLionel Sambuc ** 337811be35a1SLionel Sambuc ** ^Bindings are not cleared by the [sqlite3_reset()] routine. 337911be35a1SLionel Sambuc ** ^Unbound parameters are interpreted as NULL. 338011be35a1SLionel Sambuc ** 338111be35a1SLionel Sambuc ** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an 338211be35a1SLionel Sambuc ** [error code] if anything goes wrong. 338311be35a1SLionel Sambuc ** ^[SQLITE_RANGE] is returned if the parameter 338411be35a1SLionel Sambuc ** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails. 338511be35a1SLionel Sambuc ** 338611be35a1SLionel Sambuc ** See also: [sqlite3_bind_parameter_count()], 338711be35a1SLionel Sambuc ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()]. 338811be35a1SLionel Sambuc */ 338911be35a1SLionel Sambuc SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); 339011be35a1SLionel Sambuc SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double); 339111be35a1SLionel Sambuc SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int); 339211be35a1SLionel Sambuc SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64); 339311be35a1SLionel Sambuc SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int); 339411be35a1SLionel Sambuc SQLITE_API int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*)); 339511be35a1SLionel Sambuc SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*)); 339611be35a1SLionel Sambuc SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); 339711be35a1SLionel Sambuc SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); 339811be35a1SLionel Sambuc 339911be35a1SLionel Sambuc /* 340011be35a1SLionel Sambuc ** CAPI3REF: Number Of SQL Parameters 340111be35a1SLionel Sambuc ** 340211be35a1SLionel Sambuc ** ^This routine can be used to find the number of [SQL parameters] 340311be35a1SLionel Sambuc ** in a [prepared statement]. SQL parameters are tokens of the 340411be35a1SLionel Sambuc ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as 340511be35a1SLionel Sambuc ** placeholders for values that are [sqlite3_bind_blob | bound] 340611be35a1SLionel Sambuc ** to the parameters at a later time. 340711be35a1SLionel Sambuc ** 340811be35a1SLionel Sambuc ** ^(This routine actually returns the index of the largest (rightmost) 340911be35a1SLionel Sambuc ** parameter. For all forms except ?NNN, this will correspond to the 341011be35a1SLionel Sambuc ** number of unique parameters. If parameters of the ?NNN form are used, 341111be35a1SLionel Sambuc ** there may be gaps in the list.)^ 341211be35a1SLionel Sambuc ** 341311be35a1SLionel Sambuc ** See also: [sqlite3_bind_blob|sqlite3_bind()], 341411be35a1SLionel Sambuc ** [sqlite3_bind_parameter_name()], and 341511be35a1SLionel Sambuc ** [sqlite3_bind_parameter_index()]. 341611be35a1SLionel Sambuc */ 341711be35a1SLionel Sambuc SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*); 341811be35a1SLionel Sambuc 341911be35a1SLionel Sambuc /* 342011be35a1SLionel Sambuc ** CAPI3REF: Name Of A Host Parameter 342111be35a1SLionel Sambuc ** 342211be35a1SLionel Sambuc ** ^The sqlite3_bind_parameter_name(P,N) interface returns 342311be35a1SLionel Sambuc ** the name of the N-th [SQL parameter] in the [prepared statement] P. 342411be35a1SLionel Sambuc ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA" 342511be35a1SLionel Sambuc ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA" 342611be35a1SLionel Sambuc ** respectively. 342711be35a1SLionel Sambuc ** In other words, the initial ":" or "$" or "@" or "?" 342811be35a1SLionel Sambuc ** is included as part of the name.)^ 342911be35a1SLionel Sambuc ** ^Parameters of the form "?" without a following integer have no name 343011be35a1SLionel Sambuc ** and are referred to as "nameless" or "anonymous parameters". 343111be35a1SLionel Sambuc ** 343211be35a1SLionel Sambuc ** ^The first host parameter has an index of 1, not 0. 343311be35a1SLionel Sambuc ** 343411be35a1SLionel Sambuc ** ^If the value N is out of range or if the N-th parameter is 343511be35a1SLionel Sambuc ** nameless, then NULL is returned. ^The returned string is 343611be35a1SLionel Sambuc ** always in UTF-8 encoding even if the named parameter was 343711be35a1SLionel Sambuc ** originally specified as UTF-16 in [sqlite3_prepare16()] or 343811be35a1SLionel Sambuc ** [sqlite3_prepare16_v2()]. 343911be35a1SLionel Sambuc ** 344011be35a1SLionel Sambuc ** See also: [sqlite3_bind_blob|sqlite3_bind()], 344111be35a1SLionel Sambuc ** [sqlite3_bind_parameter_count()], and 344211be35a1SLionel Sambuc ** [sqlite3_bind_parameter_index()]. 344311be35a1SLionel Sambuc */ 344411be35a1SLionel Sambuc SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int); 344511be35a1SLionel Sambuc 344611be35a1SLionel Sambuc /* 344711be35a1SLionel Sambuc ** CAPI3REF: Index Of A Parameter With A Given Name 344811be35a1SLionel Sambuc ** 344911be35a1SLionel Sambuc ** ^Return the index of an SQL parameter given its name. ^The 345011be35a1SLionel Sambuc ** index value returned is suitable for use as the second 345111be35a1SLionel Sambuc ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero 345211be35a1SLionel Sambuc ** is returned if no matching parameter is found. ^The parameter 345311be35a1SLionel Sambuc ** name must be given in UTF-8 even if the original statement 345411be35a1SLionel Sambuc ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()]. 345511be35a1SLionel Sambuc ** 345611be35a1SLionel Sambuc ** See also: [sqlite3_bind_blob|sqlite3_bind()], 345711be35a1SLionel Sambuc ** [sqlite3_bind_parameter_count()], and 345811be35a1SLionel Sambuc ** [sqlite3_bind_parameter_index()]. 345911be35a1SLionel Sambuc */ 346011be35a1SLionel Sambuc SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); 346111be35a1SLionel Sambuc 346211be35a1SLionel Sambuc /* 346311be35a1SLionel Sambuc ** CAPI3REF: Reset All Bindings On A Prepared Statement 346411be35a1SLionel Sambuc ** 346511be35a1SLionel Sambuc ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset 346611be35a1SLionel Sambuc ** the [sqlite3_bind_blob | bindings] on a [prepared statement]. 346711be35a1SLionel Sambuc ** ^Use this routine to reset all host parameters to NULL. 346811be35a1SLionel Sambuc */ 346911be35a1SLionel Sambuc SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*); 347011be35a1SLionel Sambuc 347111be35a1SLionel Sambuc /* 347211be35a1SLionel Sambuc ** CAPI3REF: Number Of Columns In A Result Set 347311be35a1SLionel Sambuc ** 347411be35a1SLionel Sambuc ** ^Return the number of columns in the result set returned by the 347511be35a1SLionel Sambuc ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL 347611be35a1SLionel Sambuc ** statement that does not return data (for example an [UPDATE]). 347711be35a1SLionel Sambuc ** 347811be35a1SLionel Sambuc ** See also: [sqlite3_data_count()] 347911be35a1SLionel Sambuc */ 348011be35a1SLionel Sambuc SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt); 348111be35a1SLionel Sambuc 348211be35a1SLionel Sambuc /* 348311be35a1SLionel Sambuc ** CAPI3REF: Column Names In A Result Set 348411be35a1SLionel Sambuc ** 348511be35a1SLionel Sambuc ** ^These routines return the name assigned to a particular column 348611be35a1SLionel Sambuc ** in the result set of a [SELECT] statement. ^The sqlite3_column_name() 348711be35a1SLionel Sambuc ** interface returns a pointer to a zero-terminated UTF-8 string 348811be35a1SLionel Sambuc ** and sqlite3_column_name16() returns a pointer to a zero-terminated 348911be35a1SLionel Sambuc ** UTF-16 string. ^The first parameter is the [prepared statement] 349011be35a1SLionel Sambuc ** that implements the [SELECT] statement. ^The second parameter is the 349111be35a1SLionel Sambuc ** column number. ^The leftmost column is number 0. 349211be35a1SLionel Sambuc ** 349311be35a1SLionel Sambuc ** ^The returned string pointer is valid until either the [prepared statement] 349411be35a1SLionel Sambuc ** is destroyed by [sqlite3_finalize()] or until the statement is automatically 349511be35a1SLionel Sambuc ** reprepared by the first call to [sqlite3_step()] for a particular run 349611be35a1SLionel Sambuc ** or until the next call to 349711be35a1SLionel Sambuc ** sqlite3_column_name() or sqlite3_column_name16() on the same column. 349811be35a1SLionel Sambuc ** 349911be35a1SLionel Sambuc ** ^If sqlite3_malloc() fails during the processing of either routine 350011be35a1SLionel Sambuc ** (for example during a conversion from UTF-8 to UTF-16) then a 350111be35a1SLionel Sambuc ** NULL pointer is returned. 350211be35a1SLionel Sambuc ** 350311be35a1SLionel Sambuc ** ^The name of a result column is the value of the "AS" clause for 350411be35a1SLionel Sambuc ** that column, if there is an AS clause. If there is no AS clause 350511be35a1SLionel Sambuc ** then the name of the column is unspecified and may change from 350611be35a1SLionel Sambuc ** one release of SQLite to the next. 350711be35a1SLionel Sambuc */ 350811be35a1SLionel Sambuc SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N); 350911be35a1SLionel Sambuc SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N); 351011be35a1SLionel Sambuc 351111be35a1SLionel Sambuc /* 351211be35a1SLionel Sambuc ** CAPI3REF: Source Of Data In A Query Result 351311be35a1SLionel Sambuc ** 351411be35a1SLionel Sambuc ** ^These routines provide a means to determine the database, table, and 351511be35a1SLionel Sambuc ** table column that is the origin of a particular result column in 351611be35a1SLionel Sambuc ** [SELECT] statement. 351711be35a1SLionel Sambuc ** ^The name of the database or table or column can be returned as 351811be35a1SLionel Sambuc ** either a UTF-8 or UTF-16 string. ^The _database_ routines return 351911be35a1SLionel Sambuc ** the database name, the _table_ routines return the table name, and 352011be35a1SLionel Sambuc ** the origin_ routines return the column name. 352111be35a1SLionel Sambuc ** ^The returned string is valid until the [prepared statement] is destroyed 352211be35a1SLionel Sambuc ** using [sqlite3_finalize()] or until the statement is automatically 352311be35a1SLionel Sambuc ** reprepared by the first call to [sqlite3_step()] for a particular run 352411be35a1SLionel Sambuc ** or until the same information is requested 352511be35a1SLionel Sambuc ** again in a different encoding. 352611be35a1SLionel Sambuc ** 352711be35a1SLionel Sambuc ** ^The names returned are the original un-aliased names of the 352811be35a1SLionel Sambuc ** database, table, and column. 352911be35a1SLionel Sambuc ** 353011be35a1SLionel Sambuc ** ^The first argument to these interfaces is a [prepared statement]. 353111be35a1SLionel Sambuc ** ^These functions return information about the Nth result column returned by 353211be35a1SLionel Sambuc ** the statement, where N is the second function argument. 353311be35a1SLionel Sambuc ** ^The left-most column is column 0 for these routines. 353411be35a1SLionel Sambuc ** 353511be35a1SLionel Sambuc ** ^If the Nth column returned by the statement is an expression or 353611be35a1SLionel Sambuc ** subquery and is not a column value, then all of these functions return 353711be35a1SLionel Sambuc ** NULL. ^These routine might also return NULL if a memory allocation error 353811be35a1SLionel Sambuc ** occurs. ^Otherwise, they return the name of the attached database, table, 353911be35a1SLionel Sambuc ** or column that query result column was extracted from. 354011be35a1SLionel Sambuc ** 354111be35a1SLionel Sambuc ** ^As with all other SQLite APIs, those whose names end with "16" return 354211be35a1SLionel Sambuc ** UTF-16 encoded strings and the other functions return UTF-8. 354311be35a1SLionel Sambuc ** 354411be35a1SLionel Sambuc ** ^These APIs are only available if the library was compiled with the 354511be35a1SLionel Sambuc ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol. 354611be35a1SLionel Sambuc ** 354711be35a1SLionel Sambuc ** If two or more threads call one or more of these routines against the same 354811be35a1SLionel Sambuc ** prepared statement and column at the same time then the results are 354911be35a1SLionel Sambuc ** undefined. 355011be35a1SLionel Sambuc ** 355111be35a1SLionel Sambuc ** If two or more threads call one or more 355211be35a1SLionel Sambuc ** [sqlite3_column_database_name | column metadata interfaces] 355311be35a1SLionel Sambuc ** for the same [prepared statement] and result column 355411be35a1SLionel Sambuc ** at the same time then the results are undefined. 355511be35a1SLionel Sambuc */ 355611be35a1SLionel Sambuc SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int); 355711be35a1SLionel Sambuc SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int); 355811be35a1SLionel Sambuc SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int); 355911be35a1SLionel Sambuc SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int); 356011be35a1SLionel Sambuc SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int); 356111be35a1SLionel Sambuc SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int); 356211be35a1SLionel Sambuc 356311be35a1SLionel Sambuc /* 356411be35a1SLionel Sambuc ** CAPI3REF: Declared Datatype Of A Query Result 356511be35a1SLionel Sambuc ** 356611be35a1SLionel Sambuc ** ^(The first parameter is a [prepared statement]. 356711be35a1SLionel Sambuc ** If this statement is a [SELECT] statement and the Nth column of the 356811be35a1SLionel Sambuc ** returned result set of that [SELECT] is a table column (not an 356911be35a1SLionel Sambuc ** expression or subquery) then the declared type of the table 357011be35a1SLionel Sambuc ** column is returned.)^ ^If the Nth column of the result set is an 357111be35a1SLionel Sambuc ** expression or subquery, then a NULL pointer is returned. 357211be35a1SLionel Sambuc ** ^The returned string is always UTF-8 encoded. 357311be35a1SLionel Sambuc ** 357411be35a1SLionel Sambuc ** ^(For example, given the database schema: 357511be35a1SLionel Sambuc ** 357611be35a1SLionel Sambuc ** CREATE TABLE t1(c1 VARIANT); 357711be35a1SLionel Sambuc ** 357811be35a1SLionel Sambuc ** and the following statement to be compiled: 357911be35a1SLionel Sambuc ** 358011be35a1SLionel Sambuc ** SELECT c1 + 1, c1 FROM t1; 358111be35a1SLionel Sambuc ** 358211be35a1SLionel Sambuc ** this routine would return the string "VARIANT" for the second result 358311be35a1SLionel Sambuc ** column (i==1), and a NULL pointer for the first result column (i==0).)^ 358411be35a1SLionel Sambuc ** 358511be35a1SLionel Sambuc ** ^SQLite uses dynamic run-time typing. ^So just because a column 358611be35a1SLionel Sambuc ** is declared to contain a particular type does not mean that the 358711be35a1SLionel Sambuc ** data stored in that column is of the declared type. SQLite is 358811be35a1SLionel Sambuc ** strongly typed, but the typing is dynamic not static. ^Type 358911be35a1SLionel Sambuc ** is associated with individual values, not with the containers 359011be35a1SLionel Sambuc ** used to hold those values. 359111be35a1SLionel Sambuc */ 359211be35a1SLionel Sambuc SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int); 359311be35a1SLionel Sambuc SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int); 359411be35a1SLionel Sambuc 359511be35a1SLionel Sambuc /* 359611be35a1SLionel Sambuc ** CAPI3REF: Evaluate An SQL Statement 359711be35a1SLionel Sambuc ** 359811be35a1SLionel Sambuc ** After a [prepared statement] has been prepared using either 359911be35a1SLionel Sambuc ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy 360011be35a1SLionel Sambuc ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function 360111be35a1SLionel Sambuc ** must be called one or more times to evaluate the statement. 360211be35a1SLionel Sambuc ** 360311be35a1SLionel Sambuc ** The details of the behavior of the sqlite3_step() interface depend 360411be35a1SLionel Sambuc ** on whether the statement was prepared using the newer "v2" interface 360511be35a1SLionel Sambuc ** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy 360611be35a1SLionel Sambuc ** interface [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the 360711be35a1SLionel Sambuc ** new "v2" interface is recommended for new applications but the legacy 360811be35a1SLionel Sambuc ** interface will continue to be supported. 360911be35a1SLionel Sambuc ** 361011be35a1SLionel Sambuc ** ^In the legacy interface, the return value will be either [SQLITE_BUSY], 361111be35a1SLionel Sambuc ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE]. 361211be35a1SLionel Sambuc ** ^With the "v2" interface, any of the other [result codes] or 361311be35a1SLionel Sambuc ** [extended result codes] might be returned as well. 361411be35a1SLionel Sambuc ** 361511be35a1SLionel Sambuc ** ^[SQLITE_BUSY] means that the database engine was unable to acquire the 361611be35a1SLionel Sambuc ** database locks it needs to do its job. ^If the statement is a [COMMIT] 361711be35a1SLionel Sambuc ** or occurs outside of an explicit transaction, then you can retry the 361811be35a1SLionel Sambuc ** statement. If the statement is not a [COMMIT] and occurs within an 361911be35a1SLionel Sambuc ** explicit transaction then you should rollback the transaction before 362011be35a1SLionel Sambuc ** continuing. 362111be35a1SLionel Sambuc ** 362211be35a1SLionel Sambuc ** ^[SQLITE_DONE] means that the statement has finished executing 362311be35a1SLionel Sambuc ** successfully. sqlite3_step() should not be called again on this virtual 362411be35a1SLionel Sambuc ** machine without first calling [sqlite3_reset()] to reset the virtual 362511be35a1SLionel Sambuc ** machine back to its initial state. 362611be35a1SLionel Sambuc ** 362711be35a1SLionel Sambuc ** ^If the SQL statement being executed returns any data, then [SQLITE_ROW] 362811be35a1SLionel Sambuc ** is returned each time a new row of data is ready for processing by the 362911be35a1SLionel Sambuc ** caller. The values may be accessed using the [column access functions]. 363011be35a1SLionel Sambuc ** sqlite3_step() is called again to retrieve the next row of data. 363111be35a1SLionel Sambuc ** 363211be35a1SLionel Sambuc ** ^[SQLITE_ERROR] means that a run-time error (such as a constraint 363311be35a1SLionel Sambuc ** violation) has occurred. sqlite3_step() should not be called again on 363411be35a1SLionel Sambuc ** the VM. More information may be found by calling [sqlite3_errmsg()]. 363511be35a1SLionel Sambuc ** ^With the legacy interface, a more specific error code (for example, 363611be35a1SLionel Sambuc ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth) 363711be35a1SLionel Sambuc ** can be obtained by calling [sqlite3_reset()] on the 363811be35a1SLionel Sambuc ** [prepared statement]. ^In the "v2" interface, 363911be35a1SLionel Sambuc ** the more specific error code is returned directly by sqlite3_step(). 364011be35a1SLionel Sambuc ** 364111be35a1SLionel Sambuc ** [SQLITE_MISUSE] means that the this routine was called inappropriately. 364211be35a1SLionel Sambuc ** Perhaps it was called on a [prepared statement] that has 364311be35a1SLionel Sambuc ** already been [sqlite3_finalize | finalized] or on one that had 364411be35a1SLionel Sambuc ** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could 364511be35a1SLionel Sambuc ** be the case that the same database connection is being used by two or 364611be35a1SLionel Sambuc ** more threads at the same moment in time. 364711be35a1SLionel Sambuc ** 364811be35a1SLionel Sambuc ** For all versions of SQLite up to and including 3.6.23.1, a call to 364911be35a1SLionel Sambuc ** [sqlite3_reset()] was required after sqlite3_step() returned anything 365011be35a1SLionel Sambuc ** other than [SQLITE_ROW] before any subsequent invocation of 365111be35a1SLionel Sambuc ** sqlite3_step(). Failure to reset the prepared statement using 365211be35a1SLionel Sambuc ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from 365311be35a1SLionel Sambuc ** sqlite3_step(). But after version 3.6.23.1, sqlite3_step() began 365411be35a1SLionel Sambuc ** calling [sqlite3_reset()] automatically in this circumstance rather 365511be35a1SLionel Sambuc ** than returning [SQLITE_MISUSE]. This is not considered a compatibility 365611be35a1SLionel Sambuc ** break because any application that ever receives an SQLITE_MISUSE error 365711be35a1SLionel Sambuc ** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option 365811be35a1SLionel Sambuc ** can be used to restore the legacy behavior. 365911be35a1SLionel Sambuc ** 366011be35a1SLionel Sambuc ** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step() 366111be35a1SLionel Sambuc ** API always returns a generic error code, [SQLITE_ERROR], following any 366211be35a1SLionel Sambuc ** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call 366311be35a1SLionel Sambuc ** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the 366411be35a1SLionel Sambuc ** specific [error codes] that better describes the error. 366511be35a1SLionel Sambuc ** We admit that this is a goofy design. The problem has been fixed 366611be35a1SLionel Sambuc ** with the "v2" interface. If you prepare all of your SQL statements 366711be35a1SLionel Sambuc ** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead 366811be35a1SLionel Sambuc ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces, 366911be35a1SLionel Sambuc ** then the more specific [error codes] are returned directly 367011be35a1SLionel Sambuc ** by sqlite3_step(). The use of the "v2" interface is recommended. 367111be35a1SLionel Sambuc */ 367211be35a1SLionel Sambuc SQLITE_API int sqlite3_step(sqlite3_stmt*); 367311be35a1SLionel Sambuc 367411be35a1SLionel Sambuc /* 367511be35a1SLionel Sambuc ** CAPI3REF: Number of columns in a result set 367611be35a1SLionel Sambuc ** 367711be35a1SLionel Sambuc ** ^The sqlite3_data_count(P) interface returns the number of columns in the 367811be35a1SLionel Sambuc ** current row of the result set of [prepared statement] P. 367911be35a1SLionel Sambuc ** ^If prepared statement P does not have results ready to return 368011be35a1SLionel Sambuc ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of 368111be35a1SLionel Sambuc ** interfaces) then sqlite3_data_count(P) returns 0. 368211be35a1SLionel Sambuc ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer. 368311be35a1SLionel Sambuc ** ^The sqlite3_data_count(P) routine returns 0 if the previous call to 368411be35a1SLionel Sambuc ** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P) 368511be35a1SLionel Sambuc ** will return non-zero if previous call to [sqlite3_step](P) returned 368611be35a1SLionel Sambuc ** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum] 368711be35a1SLionel Sambuc ** where it always returns zero since each step of that multi-step 368811be35a1SLionel Sambuc ** pragma returns 0 columns of data. 368911be35a1SLionel Sambuc ** 369011be35a1SLionel Sambuc ** See also: [sqlite3_column_count()] 369111be35a1SLionel Sambuc */ 369211be35a1SLionel Sambuc SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt); 369311be35a1SLionel Sambuc 369411be35a1SLionel Sambuc /* 369511be35a1SLionel Sambuc ** CAPI3REF: Fundamental Datatypes 369611be35a1SLionel Sambuc ** KEYWORDS: SQLITE_TEXT 369711be35a1SLionel Sambuc ** 369811be35a1SLionel Sambuc ** ^(Every value in SQLite has one of five fundamental datatypes: 369911be35a1SLionel Sambuc ** 370011be35a1SLionel Sambuc ** <ul> 370111be35a1SLionel Sambuc ** <li> 64-bit signed integer 370211be35a1SLionel Sambuc ** <li> 64-bit IEEE floating point number 370311be35a1SLionel Sambuc ** <li> string 370411be35a1SLionel Sambuc ** <li> BLOB 370511be35a1SLionel Sambuc ** <li> NULL 370611be35a1SLionel Sambuc ** </ul>)^ 370711be35a1SLionel Sambuc ** 370811be35a1SLionel Sambuc ** These constants are codes for each of those types. 370911be35a1SLionel Sambuc ** 371011be35a1SLionel Sambuc ** Note that the SQLITE_TEXT constant was also used in SQLite version 2 371111be35a1SLionel Sambuc ** for a completely different meaning. Software that links against both 371211be35a1SLionel Sambuc ** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not 371311be35a1SLionel Sambuc ** SQLITE_TEXT. 371411be35a1SLionel Sambuc */ 371511be35a1SLionel Sambuc #define SQLITE_INTEGER 1 371611be35a1SLionel Sambuc #define SQLITE_FLOAT 2 371711be35a1SLionel Sambuc #define SQLITE_BLOB 4 371811be35a1SLionel Sambuc #define SQLITE_NULL 5 371911be35a1SLionel Sambuc #ifdef SQLITE_TEXT 372011be35a1SLionel Sambuc # undef SQLITE_TEXT 372111be35a1SLionel Sambuc #else 372211be35a1SLionel Sambuc # define SQLITE_TEXT 3 372311be35a1SLionel Sambuc #endif 372411be35a1SLionel Sambuc #define SQLITE3_TEXT 3 372511be35a1SLionel Sambuc 372611be35a1SLionel Sambuc /* 372711be35a1SLionel Sambuc ** CAPI3REF: Result Values From A Query 372811be35a1SLionel Sambuc ** KEYWORDS: {column access functions} 372911be35a1SLionel Sambuc ** 373011be35a1SLionel Sambuc ** These routines form the "result set" interface. 373111be35a1SLionel Sambuc ** 373211be35a1SLionel Sambuc ** ^These routines return information about a single column of the current 373311be35a1SLionel Sambuc ** result row of a query. ^In every case the first argument is a pointer 373411be35a1SLionel Sambuc ** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*] 373511be35a1SLionel Sambuc ** that was returned from [sqlite3_prepare_v2()] or one of its variants) 373611be35a1SLionel Sambuc ** and the second argument is the index of the column for which information 373711be35a1SLionel Sambuc ** should be returned. ^The leftmost column of the result set has the index 0. 373811be35a1SLionel Sambuc ** ^The number of columns in the result can be determined using 373911be35a1SLionel Sambuc ** [sqlite3_column_count()]. 374011be35a1SLionel Sambuc ** 374111be35a1SLionel Sambuc ** If the SQL statement does not currently point to a valid row, or if the 374211be35a1SLionel Sambuc ** column index is out of range, the result is undefined. 374311be35a1SLionel Sambuc ** These routines may only be called when the most recent call to 374411be35a1SLionel Sambuc ** [sqlite3_step()] has returned [SQLITE_ROW] and neither 374511be35a1SLionel Sambuc ** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently. 374611be35a1SLionel Sambuc ** If any of these routines are called after [sqlite3_reset()] or 374711be35a1SLionel Sambuc ** [sqlite3_finalize()] or after [sqlite3_step()] has returned 374811be35a1SLionel Sambuc ** something other than [SQLITE_ROW], the results are undefined. 374911be35a1SLionel Sambuc ** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()] 375011be35a1SLionel Sambuc ** are called from a different thread while any of these routines 375111be35a1SLionel Sambuc ** are pending, then the results are undefined. 375211be35a1SLionel Sambuc ** 375311be35a1SLionel Sambuc ** ^The sqlite3_column_type() routine returns the 375411be35a1SLionel Sambuc ** [SQLITE_INTEGER | datatype code] for the initial data type 375511be35a1SLionel Sambuc ** of the result column. ^The returned value is one of [SQLITE_INTEGER], 375611be35a1SLionel Sambuc ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL]. The value 375711be35a1SLionel Sambuc ** returned by sqlite3_column_type() is only meaningful if no type 375811be35a1SLionel Sambuc ** conversions have occurred as described below. After a type conversion, 375911be35a1SLionel Sambuc ** the value returned by sqlite3_column_type() is undefined. Future 376011be35a1SLionel Sambuc ** versions of SQLite may change the behavior of sqlite3_column_type() 376111be35a1SLionel Sambuc ** following a type conversion. 376211be35a1SLionel Sambuc ** 376311be35a1SLionel Sambuc ** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes() 376411be35a1SLionel Sambuc ** routine returns the number of bytes in that BLOB or string. 376511be35a1SLionel Sambuc ** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts 376611be35a1SLionel Sambuc ** the string to UTF-8 and then returns the number of bytes. 376711be35a1SLionel Sambuc ** ^If the result is a numeric value then sqlite3_column_bytes() uses 376811be35a1SLionel Sambuc ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns 376911be35a1SLionel Sambuc ** the number of bytes in that string. 377011be35a1SLionel Sambuc ** ^If the result is NULL, then sqlite3_column_bytes() returns zero. 377111be35a1SLionel Sambuc ** 377211be35a1SLionel Sambuc ** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16() 377311be35a1SLionel Sambuc ** routine returns the number of bytes in that BLOB or string. 377411be35a1SLionel Sambuc ** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts 377511be35a1SLionel Sambuc ** the string to UTF-16 and then returns the number of bytes. 377611be35a1SLionel Sambuc ** ^If the result is a numeric value then sqlite3_column_bytes16() uses 377711be35a1SLionel Sambuc ** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns 377811be35a1SLionel Sambuc ** the number of bytes in that string. 377911be35a1SLionel Sambuc ** ^If the result is NULL, then sqlite3_column_bytes16() returns zero. 378011be35a1SLionel Sambuc ** 378111be35a1SLionel Sambuc ** ^The values returned by [sqlite3_column_bytes()] and 378211be35a1SLionel Sambuc ** [sqlite3_column_bytes16()] do not include the zero terminators at the end 378311be35a1SLionel Sambuc ** of the string. ^For clarity: the values returned by 378411be35a1SLionel Sambuc ** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of 378511be35a1SLionel Sambuc ** bytes in the string, not the number of characters. 378611be35a1SLionel Sambuc ** 378711be35a1SLionel Sambuc ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(), 378811be35a1SLionel Sambuc ** even empty strings, are always zero-terminated. ^The return 378911be35a1SLionel Sambuc ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer. 379011be35a1SLionel Sambuc ** 379111be35a1SLionel Sambuc ** ^The object returned by [sqlite3_column_value()] is an 379211be35a1SLionel Sambuc ** [unprotected sqlite3_value] object. An unprotected sqlite3_value object 379311be35a1SLionel Sambuc ** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()]. 379411be35a1SLionel Sambuc ** If the [unprotected sqlite3_value] object returned by 379511be35a1SLionel Sambuc ** [sqlite3_column_value()] is used in any other way, including calls 379611be35a1SLionel Sambuc ** to routines like [sqlite3_value_int()], [sqlite3_value_text()], 379711be35a1SLionel Sambuc ** or [sqlite3_value_bytes()], then the behavior is undefined. 379811be35a1SLionel Sambuc ** 379911be35a1SLionel Sambuc ** These routines attempt to convert the value where appropriate. ^For 380011be35a1SLionel Sambuc ** example, if the internal representation is FLOAT and a text result 380111be35a1SLionel Sambuc ** is requested, [sqlite3_snprintf()] is used internally to perform the 380211be35a1SLionel Sambuc ** conversion automatically. ^(The following table details the conversions 380311be35a1SLionel Sambuc ** that are applied: 380411be35a1SLionel Sambuc ** 380511be35a1SLionel Sambuc ** <blockquote> 380611be35a1SLionel Sambuc ** <table border="1"> 380711be35a1SLionel Sambuc ** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion 380811be35a1SLionel Sambuc ** 380911be35a1SLionel Sambuc ** <tr><td> NULL <td> INTEGER <td> Result is 0 381011be35a1SLionel Sambuc ** <tr><td> NULL <td> FLOAT <td> Result is 0.0 3811*0a6a1f1dSLionel Sambuc ** <tr><td> NULL <td> TEXT <td> Result is a NULL pointer 3812*0a6a1f1dSLionel Sambuc ** <tr><td> NULL <td> BLOB <td> Result is a NULL pointer 381311be35a1SLionel Sambuc ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float 381411be35a1SLionel Sambuc ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer 381511be35a1SLionel Sambuc ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT 3816*0a6a1f1dSLionel Sambuc ** <tr><td> FLOAT <td> INTEGER <td> [CAST] to INTEGER 381711be35a1SLionel Sambuc ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float 3818*0a6a1f1dSLionel Sambuc ** <tr><td> FLOAT <td> BLOB <td> [CAST] to BLOB 3819*0a6a1f1dSLionel Sambuc ** <tr><td> TEXT <td> INTEGER <td> [CAST] to INTEGER 3820*0a6a1f1dSLionel Sambuc ** <tr><td> TEXT <td> FLOAT <td> [CAST] to REAL 382111be35a1SLionel Sambuc ** <tr><td> TEXT <td> BLOB <td> No change 3822*0a6a1f1dSLionel Sambuc ** <tr><td> BLOB <td> INTEGER <td> [CAST] to INTEGER 3823*0a6a1f1dSLionel Sambuc ** <tr><td> BLOB <td> FLOAT <td> [CAST] to REAL 382411be35a1SLionel Sambuc ** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed 382511be35a1SLionel Sambuc ** </table> 382611be35a1SLionel Sambuc ** </blockquote>)^ 382711be35a1SLionel Sambuc ** 382811be35a1SLionel Sambuc ** The table above makes reference to standard C library functions atoi() 382911be35a1SLionel Sambuc ** and atof(). SQLite does not really use these functions. It has its 383011be35a1SLionel Sambuc ** own equivalent internal routines. The atoi() and atof() names are 383111be35a1SLionel Sambuc ** used in the table for brevity and because they are familiar to most 383211be35a1SLionel Sambuc ** C programmers. 383311be35a1SLionel Sambuc ** 383411be35a1SLionel Sambuc ** Note that when type conversions occur, pointers returned by prior 383511be35a1SLionel Sambuc ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or 383611be35a1SLionel Sambuc ** sqlite3_column_text16() may be invalidated. 383711be35a1SLionel Sambuc ** Type conversions and pointer invalidations might occur 383811be35a1SLionel Sambuc ** in the following cases: 383911be35a1SLionel Sambuc ** 384011be35a1SLionel Sambuc ** <ul> 384111be35a1SLionel Sambuc ** <li> The initial content is a BLOB and sqlite3_column_text() or 384211be35a1SLionel Sambuc ** sqlite3_column_text16() is called. A zero-terminator might 384311be35a1SLionel Sambuc ** need to be added to the string.</li> 384411be35a1SLionel Sambuc ** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or 384511be35a1SLionel Sambuc ** sqlite3_column_text16() is called. The content must be converted 384611be35a1SLionel Sambuc ** to UTF-16.</li> 384711be35a1SLionel Sambuc ** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or 384811be35a1SLionel Sambuc ** sqlite3_column_text() is called. The content must be converted 384911be35a1SLionel Sambuc ** to UTF-8.</li> 385011be35a1SLionel Sambuc ** </ul> 385111be35a1SLionel Sambuc ** 385211be35a1SLionel Sambuc ** ^Conversions between UTF-16be and UTF-16le are always done in place and do 385311be35a1SLionel Sambuc ** not invalidate a prior pointer, though of course the content of the buffer 385411be35a1SLionel Sambuc ** that the prior pointer references will have been modified. Other kinds 385511be35a1SLionel Sambuc ** of conversion are done in place when it is possible, but sometimes they 385611be35a1SLionel Sambuc ** are not possible and in those cases prior pointers are invalidated. 385711be35a1SLionel Sambuc ** 385811be35a1SLionel Sambuc ** The safest and easiest to remember policy is to invoke these routines 385911be35a1SLionel Sambuc ** in one of the following ways: 386011be35a1SLionel Sambuc ** 386111be35a1SLionel Sambuc ** <ul> 386211be35a1SLionel Sambuc ** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li> 386311be35a1SLionel Sambuc ** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li> 386411be35a1SLionel Sambuc ** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li> 386511be35a1SLionel Sambuc ** </ul> 386611be35a1SLionel Sambuc ** 386711be35a1SLionel Sambuc ** In other words, you should call sqlite3_column_text(), 386811be35a1SLionel Sambuc ** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result 386911be35a1SLionel Sambuc ** into the desired format, then invoke sqlite3_column_bytes() or 387011be35a1SLionel Sambuc ** sqlite3_column_bytes16() to find the size of the result. Do not mix calls 387111be35a1SLionel Sambuc ** to sqlite3_column_text() or sqlite3_column_blob() with calls to 387211be35a1SLionel Sambuc ** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16() 387311be35a1SLionel Sambuc ** with calls to sqlite3_column_bytes(). 387411be35a1SLionel Sambuc ** 387511be35a1SLionel Sambuc ** ^The pointers returned are valid until a type conversion occurs as 387611be35a1SLionel Sambuc ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or 387711be35a1SLionel Sambuc ** [sqlite3_finalize()] is called. ^The memory space used to hold strings 387811be35a1SLionel Sambuc ** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned 3879*0a6a1f1dSLionel Sambuc ** from [sqlite3_column_blob()], [sqlite3_column_text()], etc. into 388011be35a1SLionel Sambuc ** [sqlite3_free()]. 388111be35a1SLionel Sambuc ** 388211be35a1SLionel Sambuc ** ^(If a memory allocation error occurs during the evaluation of any 388311be35a1SLionel Sambuc ** of these routines, a default value is returned. The default value 388411be35a1SLionel Sambuc ** is either the integer 0, the floating point number 0.0, or a NULL 388511be35a1SLionel Sambuc ** pointer. Subsequent calls to [sqlite3_errcode()] will return 388611be35a1SLionel Sambuc ** [SQLITE_NOMEM].)^ 388711be35a1SLionel Sambuc */ 388811be35a1SLionel Sambuc SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol); 388911be35a1SLionel Sambuc SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol); 389011be35a1SLionel Sambuc SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol); 389111be35a1SLionel Sambuc SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol); 389211be35a1SLionel Sambuc SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol); 389311be35a1SLionel Sambuc SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol); 389411be35a1SLionel Sambuc SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol); 389511be35a1SLionel Sambuc SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol); 389611be35a1SLionel Sambuc SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol); 389711be35a1SLionel Sambuc SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol); 389811be35a1SLionel Sambuc 389911be35a1SLionel Sambuc /* 390011be35a1SLionel Sambuc ** CAPI3REF: Destroy A Prepared Statement Object 390111be35a1SLionel Sambuc ** 390211be35a1SLionel Sambuc ** ^The sqlite3_finalize() function is called to delete a [prepared statement]. 390311be35a1SLionel Sambuc ** ^If the most recent evaluation of the statement encountered no errors 390411be35a1SLionel Sambuc ** or if the statement is never been evaluated, then sqlite3_finalize() returns 390511be35a1SLionel Sambuc ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then 390611be35a1SLionel Sambuc ** sqlite3_finalize(S) returns the appropriate [error code] or 390711be35a1SLionel Sambuc ** [extended error code]. 390811be35a1SLionel Sambuc ** 390911be35a1SLionel Sambuc ** ^The sqlite3_finalize(S) routine can be called at any point during 391011be35a1SLionel Sambuc ** the life cycle of [prepared statement] S: 391111be35a1SLionel Sambuc ** before statement S is ever evaluated, after 391211be35a1SLionel Sambuc ** one or more calls to [sqlite3_reset()], or after any call 391311be35a1SLionel Sambuc ** to [sqlite3_step()] regardless of whether or not the statement has 391411be35a1SLionel Sambuc ** completed execution. 391511be35a1SLionel Sambuc ** 391611be35a1SLionel Sambuc ** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op. 391711be35a1SLionel Sambuc ** 391811be35a1SLionel Sambuc ** The application must finalize every [prepared statement] in order to avoid 391911be35a1SLionel Sambuc ** resource leaks. It is a grievous error for the application to try to use 392011be35a1SLionel Sambuc ** a prepared statement after it has been finalized. Any use of a prepared 392111be35a1SLionel Sambuc ** statement after it has been finalized can result in undefined and 392211be35a1SLionel Sambuc ** undesirable behavior such as segfaults and heap corruption. 392311be35a1SLionel Sambuc */ 392411be35a1SLionel Sambuc SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt); 392511be35a1SLionel Sambuc 392611be35a1SLionel Sambuc /* 392711be35a1SLionel Sambuc ** CAPI3REF: Reset A Prepared Statement Object 392811be35a1SLionel Sambuc ** 392911be35a1SLionel Sambuc ** The sqlite3_reset() function is called to reset a [prepared statement] 393011be35a1SLionel Sambuc ** object back to its initial state, ready to be re-executed. 393111be35a1SLionel Sambuc ** ^Any SQL statement variables that had values bound to them using 393211be35a1SLionel Sambuc ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values. 393311be35a1SLionel Sambuc ** Use [sqlite3_clear_bindings()] to reset the bindings. 393411be35a1SLionel Sambuc ** 393511be35a1SLionel Sambuc ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S 393611be35a1SLionel Sambuc ** back to the beginning of its program. 393711be35a1SLionel Sambuc ** 393811be35a1SLionel Sambuc ** ^If the most recent call to [sqlite3_step(S)] for the 393911be35a1SLionel Sambuc ** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE], 394011be35a1SLionel Sambuc ** or if [sqlite3_step(S)] has never before been called on S, 394111be35a1SLionel Sambuc ** then [sqlite3_reset(S)] returns [SQLITE_OK]. 394211be35a1SLionel Sambuc ** 394311be35a1SLionel Sambuc ** ^If the most recent call to [sqlite3_step(S)] for the 394411be35a1SLionel Sambuc ** [prepared statement] S indicated an error, then 394511be35a1SLionel Sambuc ** [sqlite3_reset(S)] returns an appropriate [error code]. 394611be35a1SLionel Sambuc ** 394711be35a1SLionel Sambuc ** ^The [sqlite3_reset(S)] interface does not change the values 394811be35a1SLionel Sambuc ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S. 394911be35a1SLionel Sambuc */ 395011be35a1SLionel Sambuc SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt); 395111be35a1SLionel Sambuc 395211be35a1SLionel Sambuc /* 395311be35a1SLionel Sambuc ** CAPI3REF: Create Or Redefine SQL Functions 395411be35a1SLionel Sambuc ** KEYWORDS: {function creation routines} 395511be35a1SLionel Sambuc ** KEYWORDS: {application-defined SQL function} 395611be35a1SLionel Sambuc ** KEYWORDS: {application-defined SQL functions} 395711be35a1SLionel Sambuc ** 395811be35a1SLionel Sambuc ** ^These functions (collectively known as "function creation routines") 395911be35a1SLionel Sambuc ** are used to add SQL functions or aggregates or to redefine the behavior 396011be35a1SLionel Sambuc ** of existing SQL functions or aggregates. The only differences between 396111be35a1SLionel Sambuc ** these routines are the text encoding expected for 396211be35a1SLionel Sambuc ** the second parameter (the name of the function being created) 396311be35a1SLionel Sambuc ** and the presence or absence of a destructor callback for 396411be35a1SLionel Sambuc ** the application data pointer. 396511be35a1SLionel Sambuc ** 396611be35a1SLionel Sambuc ** ^The first parameter is the [database connection] to which the SQL 396711be35a1SLionel Sambuc ** function is to be added. ^If an application uses more than one database 396811be35a1SLionel Sambuc ** connection then application-defined SQL functions must be added 396911be35a1SLionel Sambuc ** to each database connection separately. 397011be35a1SLionel Sambuc ** 397111be35a1SLionel Sambuc ** ^The second parameter is the name of the SQL function to be created or 397211be35a1SLionel Sambuc ** redefined. ^The length of the name is limited to 255 bytes in a UTF-8 397311be35a1SLionel Sambuc ** representation, exclusive of the zero-terminator. ^Note that the name 397411be35a1SLionel Sambuc ** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes. 397511be35a1SLionel Sambuc ** ^Any attempt to create a function with a longer name 397611be35a1SLionel Sambuc ** will result in [SQLITE_MISUSE] being returned. 397711be35a1SLionel Sambuc ** 397811be35a1SLionel Sambuc ** ^The third parameter (nArg) 397911be35a1SLionel Sambuc ** is the number of arguments that the SQL function or 398011be35a1SLionel Sambuc ** aggregate takes. ^If this parameter is -1, then the SQL function or 398111be35a1SLionel Sambuc ** aggregate may take any number of arguments between 0 and the limit 398211be35a1SLionel Sambuc ** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third 398311be35a1SLionel Sambuc ** parameter is less than -1 or greater than 127 then the behavior is 398411be35a1SLionel Sambuc ** undefined. 398511be35a1SLionel Sambuc ** 398611be35a1SLionel Sambuc ** ^The fourth parameter, eTextRep, specifies what 398711be35a1SLionel Sambuc ** [SQLITE_UTF8 | text encoding] this SQL function prefers for 3988*0a6a1f1dSLionel Sambuc ** its parameters. The application should set this parameter to 3989*0a6a1f1dSLionel Sambuc ** [SQLITE_UTF16LE] if the function implementation invokes 3990*0a6a1f1dSLionel Sambuc ** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the 3991*0a6a1f1dSLionel Sambuc ** implementation invokes [sqlite3_value_text16be()] on an input, or 3992*0a6a1f1dSLionel Sambuc ** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8] 3993*0a6a1f1dSLionel Sambuc ** otherwise. ^The same SQL function may be registered multiple times using 3994*0a6a1f1dSLionel Sambuc ** different preferred text encodings, with different implementations for 3995*0a6a1f1dSLionel Sambuc ** each encoding. 399611be35a1SLionel Sambuc ** ^When multiple implementations of the same function are available, SQLite 399711be35a1SLionel Sambuc ** will pick the one that involves the least amount of data conversion. 3998*0a6a1f1dSLionel Sambuc ** 3999*0a6a1f1dSLionel Sambuc ** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC] 4000*0a6a1f1dSLionel Sambuc ** to signal that the function will always return the same result given 4001*0a6a1f1dSLionel Sambuc ** the same inputs within a single SQL statement. Most SQL functions are 4002*0a6a1f1dSLionel Sambuc ** deterministic. The built-in [random()] SQL function is an example of a 4003*0a6a1f1dSLionel Sambuc ** function that is not deterministic. The SQLite query planner is able to 4004*0a6a1f1dSLionel Sambuc ** perform additional optimizations on deterministic functions, so use 4005*0a6a1f1dSLionel Sambuc ** of the [SQLITE_DETERMINISTIC] flag is recommended where possible. 400611be35a1SLionel Sambuc ** 400711be35a1SLionel Sambuc ** ^(The fifth parameter is an arbitrary pointer. The implementation of the 400811be35a1SLionel Sambuc ** function can gain access to this pointer using [sqlite3_user_data()].)^ 400911be35a1SLionel Sambuc ** 401011be35a1SLionel Sambuc ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are 401111be35a1SLionel Sambuc ** pointers to C-language functions that implement the SQL function or 401211be35a1SLionel Sambuc ** aggregate. ^A scalar SQL function requires an implementation of the xFunc 401311be35a1SLionel Sambuc ** callback only; NULL pointers must be passed as the xStep and xFinal 401411be35a1SLionel Sambuc ** parameters. ^An aggregate SQL function requires an implementation of xStep 401511be35a1SLionel Sambuc ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing 401611be35a1SLionel Sambuc ** SQL function or aggregate, pass NULL pointers for all three function 401711be35a1SLionel Sambuc ** callbacks. 401811be35a1SLionel Sambuc ** 401911be35a1SLionel Sambuc ** ^(If the ninth parameter to sqlite3_create_function_v2() is not NULL, 402011be35a1SLionel Sambuc ** then it is destructor for the application data pointer. 402111be35a1SLionel Sambuc ** The destructor is invoked when the function is deleted, either by being 402211be35a1SLionel Sambuc ** overloaded or when the database connection closes.)^ 402311be35a1SLionel Sambuc ** ^The destructor is also invoked if the call to 402411be35a1SLionel Sambuc ** sqlite3_create_function_v2() fails. 402511be35a1SLionel Sambuc ** ^When the destructor callback of the tenth parameter is invoked, it 402611be35a1SLionel Sambuc ** is passed a single argument which is a copy of the application data 402711be35a1SLionel Sambuc ** pointer which was the fifth parameter to sqlite3_create_function_v2(). 402811be35a1SLionel Sambuc ** 402911be35a1SLionel Sambuc ** ^It is permitted to register multiple implementations of the same 403011be35a1SLionel Sambuc ** functions with the same name but with either differing numbers of 403111be35a1SLionel Sambuc ** arguments or differing preferred text encodings. ^SQLite will use 403211be35a1SLionel Sambuc ** the implementation that most closely matches the way in which the 403311be35a1SLionel Sambuc ** SQL function is used. ^A function implementation with a non-negative 403411be35a1SLionel Sambuc ** nArg parameter is a better match than a function implementation with 403511be35a1SLionel Sambuc ** a negative nArg. ^A function where the preferred text encoding 403611be35a1SLionel Sambuc ** matches the database encoding is a better 403711be35a1SLionel Sambuc ** match than a function where the encoding is different. 403811be35a1SLionel Sambuc ** ^A function where the encoding difference is between UTF16le and UTF16be 403911be35a1SLionel Sambuc ** is a closer match than a function where the encoding difference is 404011be35a1SLionel Sambuc ** between UTF8 and UTF16. 404111be35a1SLionel Sambuc ** 404211be35a1SLionel Sambuc ** ^Built-in functions may be overloaded by new application-defined functions. 404311be35a1SLionel Sambuc ** 404411be35a1SLionel Sambuc ** ^An application-defined function is permitted to call other 404511be35a1SLionel Sambuc ** SQLite interfaces. However, such calls must not 404611be35a1SLionel Sambuc ** close the database connection nor finalize or reset the prepared 404711be35a1SLionel Sambuc ** statement in which the function is running. 404811be35a1SLionel Sambuc */ 404911be35a1SLionel Sambuc SQLITE_API int sqlite3_create_function( 405011be35a1SLionel Sambuc sqlite3 *db, 405111be35a1SLionel Sambuc const char *zFunctionName, 405211be35a1SLionel Sambuc int nArg, 405311be35a1SLionel Sambuc int eTextRep, 405411be35a1SLionel Sambuc void *pApp, 405511be35a1SLionel Sambuc void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 405611be35a1SLionel Sambuc void (*xStep)(sqlite3_context*,int,sqlite3_value**), 405711be35a1SLionel Sambuc void (*xFinal)(sqlite3_context*) 405811be35a1SLionel Sambuc ); 405911be35a1SLionel Sambuc SQLITE_API int sqlite3_create_function16( 406011be35a1SLionel Sambuc sqlite3 *db, 406111be35a1SLionel Sambuc const void *zFunctionName, 406211be35a1SLionel Sambuc int nArg, 406311be35a1SLionel Sambuc int eTextRep, 406411be35a1SLionel Sambuc void *pApp, 406511be35a1SLionel Sambuc void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 406611be35a1SLionel Sambuc void (*xStep)(sqlite3_context*,int,sqlite3_value**), 406711be35a1SLionel Sambuc void (*xFinal)(sqlite3_context*) 406811be35a1SLionel Sambuc ); 406911be35a1SLionel Sambuc SQLITE_API int sqlite3_create_function_v2( 407011be35a1SLionel Sambuc sqlite3 *db, 407111be35a1SLionel Sambuc const char *zFunctionName, 407211be35a1SLionel Sambuc int nArg, 407311be35a1SLionel Sambuc int eTextRep, 407411be35a1SLionel Sambuc void *pApp, 407511be35a1SLionel Sambuc void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 407611be35a1SLionel Sambuc void (*xStep)(sqlite3_context*,int,sqlite3_value**), 407711be35a1SLionel Sambuc void (*xFinal)(sqlite3_context*), 407811be35a1SLionel Sambuc void(*xDestroy)(void*) 407911be35a1SLionel Sambuc ); 408011be35a1SLionel Sambuc 408111be35a1SLionel Sambuc /* 408211be35a1SLionel Sambuc ** CAPI3REF: Text Encodings 408311be35a1SLionel Sambuc ** 408411be35a1SLionel Sambuc ** These constant define integer codes that represent the various 408511be35a1SLionel Sambuc ** text encodings supported by SQLite. 408611be35a1SLionel Sambuc */ 408711be35a1SLionel Sambuc #define SQLITE_UTF8 1 408811be35a1SLionel Sambuc #define SQLITE_UTF16LE 2 408911be35a1SLionel Sambuc #define SQLITE_UTF16BE 3 409011be35a1SLionel Sambuc #define SQLITE_UTF16 4 /* Use native byte order */ 4091*0a6a1f1dSLionel Sambuc #define SQLITE_ANY 5 /* Deprecated */ 409211be35a1SLionel Sambuc #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */ 409311be35a1SLionel Sambuc 409411be35a1SLionel Sambuc /* 4095*0a6a1f1dSLionel Sambuc ** CAPI3REF: Function Flags 4096*0a6a1f1dSLionel Sambuc ** 4097*0a6a1f1dSLionel Sambuc ** These constants may be ORed together with the 4098*0a6a1f1dSLionel Sambuc ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument 4099*0a6a1f1dSLionel Sambuc ** to [sqlite3_create_function()], [sqlite3_create_function16()], or 4100*0a6a1f1dSLionel Sambuc ** [sqlite3_create_function_v2()]. 4101*0a6a1f1dSLionel Sambuc */ 4102*0a6a1f1dSLionel Sambuc #define SQLITE_DETERMINISTIC 0x800 4103*0a6a1f1dSLionel Sambuc 4104*0a6a1f1dSLionel Sambuc /* 410511be35a1SLionel Sambuc ** CAPI3REF: Deprecated Functions 410611be35a1SLionel Sambuc ** DEPRECATED 410711be35a1SLionel Sambuc ** 410811be35a1SLionel Sambuc ** These functions are [deprecated]. In order to maintain 410911be35a1SLionel Sambuc ** backwards compatibility with older code, these functions continue 411011be35a1SLionel Sambuc ** to be supported. However, new applications should avoid 411111be35a1SLionel Sambuc ** the use of these functions. To help encourage people to avoid 411211be35a1SLionel Sambuc ** using these functions, we are not going to tell you what they do. 411311be35a1SLionel Sambuc */ 411411be35a1SLionel Sambuc #ifndef SQLITE_OMIT_DEPRECATED 411511be35a1SLionel Sambuc SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*); 411611be35a1SLionel Sambuc SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*); 411711be35a1SLionel Sambuc SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*); 411811be35a1SLionel Sambuc SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void); 411911be35a1SLionel Sambuc SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void); 4120*0a6a1f1dSLionel Sambuc SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int), 4121*0a6a1f1dSLionel Sambuc void*,sqlite3_int64); 412211be35a1SLionel Sambuc #endif 412311be35a1SLionel Sambuc 412411be35a1SLionel Sambuc /* 412511be35a1SLionel Sambuc ** CAPI3REF: Obtaining SQL Function Parameter Values 412611be35a1SLionel Sambuc ** 412711be35a1SLionel Sambuc ** The C-language implementation of SQL functions and aggregates uses 412811be35a1SLionel Sambuc ** this set of interface routines to access the parameter values on 412911be35a1SLionel Sambuc ** the function or aggregate. 413011be35a1SLionel Sambuc ** 413111be35a1SLionel Sambuc ** The xFunc (for scalar functions) or xStep (for aggregates) parameters 413211be35a1SLionel Sambuc ** to [sqlite3_create_function()] and [sqlite3_create_function16()] 413311be35a1SLionel Sambuc ** define callbacks that implement the SQL functions and aggregates. 413411be35a1SLionel Sambuc ** The 3rd parameter to these callbacks is an array of pointers to 413511be35a1SLionel Sambuc ** [protected sqlite3_value] objects. There is one [sqlite3_value] object for 413611be35a1SLionel Sambuc ** each parameter to the SQL function. These routines are used to 413711be35a1SLionel Sambuc ** extract values from the [sqlite3_value] objects. 413811be35a1SLionel Sambuc ** 413911be35a1SLionel Sambuc ** These routines work only with [protected sqlite3_value] objects. 414011be35a1SLionel Sambuc ** Any attempt to use these routines on an [unprotected sqlite3_value] 414111be35a1SLionel Sambuc ** object results in undefined behavior. 414211be35a1SLionel Sambuc ** 414311be35a1SLionel Sambuc ** ^These routines work just like the corresponding [column access functions] 414411be35a1SLionel Sambuc ** except that these routines take a single [protected sqlite3_value] object 414511be35a1SLionel Sambuc ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number. 414611be35a1SLionel Sambuc ** 414711be35a1SLionel Sambuc ** ^The sqlite3_value_text16() interface extracts a UTF-16 string 414811be35a1SLionel Sambuc ** in the native byte-order of the host machine. ^The 414911be35a1SLionel Sambuc ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces 415011be35a1SLionel Sambuc ** extract UTF-16 strings as big-endian and little-endian respectively. 415111be35a1SLionel Sambuc ** 415211be35a1SLionel Sambuc ** ^(The sqlite3_value_numeric_type() interface attempts to apply 415311be35a1SLionel Sambuc ** numeric affinity to the value. This means that an attempt is 415411be35a1SLionel Sambuc ** made to convert the value to an integer or floating point. If 415511be35a1SLionel Sambuc ** such a conversion is possible without loss of information (in other 415611be35a1SLionel Sambuc ** words, if the value is a string that looks like a number) 415711be35a1SLionel Sambuc ** then the conversion is performed. Otherwise no conversion occurs. 415811be35a1SLionel Sambuc ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^ 415911be35a1SLionel Sambuc ** 416011be35a1SLionel Sambuc ** Please pay particular attention to the fact that the pointer returned 416111be35a1SLionel Sambuc ** from [sqlite3_value_blob()], [sqlite3_value_text()], or 416211be35a1SLionel Sambuc ** [sqlite3_value_text16()] can be invalidated by a subsequent call to 416311be35a1SLionel Sambuc ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()], 416411be35a1SLionel Sambuc ** or [sqlite3_value_text16()]. 416511be35a1SLionel Sambuc ** 416611be35a1SLionel Sambuc ** These routines must be called from the same thread as 416711be35a1SLionel Sambuc ** the SQL function that supplied the [sqlite3_value*] parameters. 416811be35a1SLionel Sambuc */ 416911be35a1SLionel Sambuc SQLITE_API const void *sqlite3_value_blob(sqlite3_value*); 417011be35a1SLionel Sambuc SQLITE_API int sqlite3_value_bytes(sqlite3_value*); 417111be35a1SLionel Sambuc SQLITE_API int sqlite3_value_bytes16(sqlite3_value*); 417211be35a1SLionel Sambuc SQLITE_API double sqlite3_value_double(sqlite3_value*); 417311be35a1SLionel Sambuc SQLITE_API int sqlite3_value_int(sqlite3_value*); 417411be35a1SLionel Sambuc SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*); 417511be35a1SLionel Sambuc SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*); 417611be35a1SLionel Sambuc SQLITE_API const void *sqlite3_value_text16(sqlite3_value*); 417711be35a1SLionel Sambuc SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*); 417811be35a1SLionel Sambuc SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*); 417911be35a1SLionel Sambuc SQLITE_API int sqlite3_value_type(sqlite3_value*); 418011be35a1SLionel Sambuc SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*); 418111be35a1SLionel Sambuc 418211be35a1SLionel Sambuc /* 418311be35a1SLionel Sambuc ** CAPI3REF: Obtain Aggregate Function Context 418411be35a1SLionel Sambuc ** 418511be35a1SLionel Sambuc ** Implementations of aggregate SQL functions use this 418611be35a1SLionel Sambuc ** routine to allocate memory for storing their state. 418711be35a1SLionel Sambuc ** 418811be35a1SLionel Sambuc ** ^The first time the sqlite3_aggregate_context(C,N) routine is called 418911be35a1SLionel Sambuc ** for a particular aggregate function, SQLite 419011be35a1SLionel Sambuc ** allocates N of memory, zeroes out that memory, and returns a pointer 419111be35a1SLionel Sambuc ** to the new memory. ^On second and subsequent calls to 419211be35a1SLionel Sambuc ** sqlite3_aggregate_context() for the same aggregate function instance, 419311be35a1SLionel Sambuc ** the same buffer is returned. Sqlite3_aggregate_context() is normally 419411be35a1SLionel Sambuc ** called once for each invocation of the xStep callback and then one 419511be35a1SLionel Sambuc ** last time when the xFinal callback is invoked. ^(When no rows match 419611be35a1SLionel Sambuc ** an aggregate query, the xStep() callback of the aggregate function 419711be35a1SLionel Sambuc ** implementation is never called and xFinal() is called exactly once. 419811be35a1SLionel Sambuc ** In those cases, sqlite3_aggregate_context() might be called for the 419911be35a1SLionel Sambuc ** first time from within xFinal().)^ 420011be35a1SLionel Sambuc ** 4201*0a6a1f1dSLionel Sambuc ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer 4202*0a6a1f1dSLionel Sambuc ** when first called if N is less than or equal to zero or if a memory 4203*0a6a1f1dSLionel Sambuc ** allocate error occurs. 420411be35a1SLionel Sambuc ** 420511be35a1SLionel Sambuc ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is 420611be35a1SLionel Sambuc ** determined by the N parameter on first successful call. Changing the 420711be35a1SLionel Sambuc ** value of N in subsequent call to sqlite3_aggregate_context() within 420811be35a1SLionel Sambuc ** the same aggregate function instance will not resize the memory 4209*0a6a1f1dSLionel Sambuc ** allocation.)^ Within the xFinal callback, it is customary to set 4210*0a6a1f1dSLionel Sambuc ** N=0 in calls to sqlite3_aggregate_context(C,N) so that no 4211*0a6a1f1dSLionel Sambuc ** pointless memory allocations occur. 421211be35a1SLionel Sambuc ** 421311be35a1SLionel Sambuc ** ^SQLite automatically frees the memory allocated by 421411be35a1SLionel Sambuc ** sqlite3_aggregate_context() when the aggregate query concludes. 421511be35a1SLionel Sambuc ** 421611be35a1SLionel Sambuc ** The first parameter must be a copy of the 421711be35a1SLionel Sambuc ** [sqlite3_context | SQL function context] that is the first parameter 421811be35a1SLionel Sambuc ** to the xStep or xFinal callback routine that implements the aggregate 421911be35a1SLionel Sambuc ** function. 422011be35a1SLionel Sambuc ** 422111be35a1SLionel Sambuc ** This routine must be called from the same thread in which 422211be35a1SLionel Sambuc ** the aggregate SQL function is running. 422311be35a1SLionel Sambuc */ 422411be35a1SLionel Sambuc SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); 422511be35a1SLionel Sambuc 422611be35a1SLionel Sambuc /* 422711be35a1SLionel Sambuc ** CAPI3REF: User Data For Functions 422811be35a1SLionel Sambuc ** 422911be35a1SLionel Sambuc ** ^The sqlite3_user_data() interface returns a copy of 423011be35a1SLionel Sambuc ** the pointer that was the pUserData parameter (the 5th parameter) 423111be35a1SLionel Sambuc ** of the [sqlite3_create_function()] 423211be35a1SLionel Sambuc ** and [sqlite3_create_function16()] routines that originally 423311be35a1SLionel Sambuc ** registered the application defined function. 423411be35a1SLionel Sambuc ** 423511be35a1SLionel Sambuc ** This routine must be called from the same thread in which 423611be35a1SLionel Sambuc ** the application-defined function is running. 423711be35a1SLionel Sambuc */ 423811be35a1SLionel Sambuc SQLITE_API void *sqlite3_user_data(sqlite3_context*); 423911be35a1SLionel Sambuc 424011be35a1SLionel Sambuc /* 424111be35a1SLionel Sambuc ** CAPI3REF: Database Connection For Functions 424211be35a1SLionel Sambuc ** 424311be35a1SLionel Sambuc ** ^The sqlite3_context_db_handle() interface returns a copy of 424411be35a1SLionel Sambuc ** the pointer to the [database connection] (the 1st parameter) 424511be35a1SLionel Sambuc ** of the [sqlite3_create_function()] 424611be35a1SLionel Sambuc ** and [sqlite3_create_function16()] routines that originally 424711be35a1SLionel Sambuc ** registered the application defined function. 424811be35a1SLionel Sambuc */ 424911be35a1SLionel Sambuc SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*); 425011be35a1SLionel Sambuc 425111be35a1SLionel Sambuc /* 425211be35a1SLionel Sambuc ** CAPI3REF: Function Auxiliary Data 425311be35a1SLionel Sambuc ** 4254*0a6a1f1dSLionel Sambuc ** These functions may be used by (non-aggregate) SQL functions to 425511be35a1SLionel Sambuc ** associate metadata with argument values. If the same value is passed to 425611be35a1SLionel Sambuc ** multiple invocations of the same SQL function during query execution, under 4257*0a6a1f1dSLionel Sambuc ** some circumstances the associated metadata may be preserved. An example 4258*0a6a1f1dSLionel Sambuc ** of where this might be useful is in a regular-expression matching 4259*0a6a1f1dSLionel Sambuc ** function. The compiled version of the regular expression can be stored as 4260*0a6a1f1dSLionel Sambuc ** metadata associated with the pattern string. 4261*0a6a1f1dSLionel Sambuc ** Then as long as the pattern string remains the same, 4262*0a6a1f1dSLionel Sambuc ** the compiled regular expression can be reused on multiple 4263*0a6a1f1dSLionel Sambuc ** invocations of the same function. 426411be35a1SLionel Sambuc ** 426511be35a1SLionel Sambuc ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata 426611be35a1SLionel Sambuc ** associated by the sqlite3_set_auxdata() function with the Nth argument 4267*0a6a1f1dSLionel Sambuc ** value to the application-defined function. ^If there is no metadata 4268*0a6a1f1dSLionel Sambuc ** associated with the function argument, this sqlite3_get_auxdata() interface 4269*0a6a1f1dSLionel Sambuc ** returns a NULL pointer. 427011be35a1SLionel Sambuc ** 4271*0a6a1f1dSLionel Sambuc ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th 4272*0a6a1f1dSLionel Sambuc ** argument of the application-defined function. ^Subsequent 4273*0a6a1f1dSLionel Sambuc ** calls to sqlite3_get_auxdata(C,N) return P from the most recent 4274*0a6a1f1dSLionel Sambuc ** sqlite3_set_auxdata(C,N,P,X) call if the metadata is still valid or 4275*0a6a1f1dSLionel Sambuc ** NULL if the metadata has been discarded. 4276*0a6a1f1dSLionel Sambuc ** ^After each call to sqlite3_set_auxdata(C,N,P,X) where X is not NULL, 4277*0a6a1f1dSLionel Sambuc ** SQLite will invoke the destructor function X with parameter P exactly 4278*0a6a1f1dSLionel Sambuc ** once, when the metadata is discarded. 4279*0a6a1f1dSLionel Sambuc ** SQLite is free to discard the metadata at any time, including: <ul> 4280*0a6a1f1dSLionel Sambuc ** <li> when the corresponding function parameter changes, or 4281*0a6a1f1dSLionel Sambuc ** <li> when [sqlite3_reset()] or [sqlite3_finalize()] is called for the 4282*0a6a1f1dSLionel Sambuc ** SQL statement, or 4283*0a6a1f1dSLionel Sambuc ** <li> when sqlite3_set_auxdata() is invoked again on the same parameter, or 4284*0a6a1f1dSLionel Sambuc ** <li> during the original sqlite3_set_auxdata() call when a memory 4285*0a6a1f1dSLionel Sambuc ** allocation error occurs. </ul>)^ 428611be35a1SLionel Sambuc ** 4287*0a6a1f1dSLionel Sambuc ** Note the last bullet in particular. The destructor X in 4288*0a6a1f1dSLionel Sambuc ** sqlite3_set_auxdata(C,N,P,X) might be called immediately, before the 4289*0a6a1f1dSLionel Sambuc ** sqlite3_set_auxdata() interface even returns. Hence sqlite3_set_auxdata() 4290*0a6a1f1dSLionel Sambuc ** should be called near the end of the function implementation and the 4291*0a6a1f1dSLionel Sambuc ** function implementation should not make any use of P after 4292*0a6a1f1dSLionel Sambuc ** sqlite3_set_auxdata() has been called. 429311be35a1SLionel Sambuc ** 429411be35a1SLionel Sambuc ** ^(In practice, metadata is preserved between function calls for 4295*0a6a1f1dSLionel Sambuc ** function parameters that are compile-time constants, including literal 4296*0a6a1f1dSLionel Sambuc ** values and [parameters] and expressions composed from the same.)^ 429711be35a1SLionel Sambuc ** 429811be35a1SLionel Sambuc ** These routines must be called from the same thread in which 429911be35a1SLionel Sambuc ** the SQL function is running. 430011be35a1SLionel Sambuc */ 430111be35a1SLionel Sambuc SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N); 430211be35a1SLionel Sambuc SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*)); 430311be35a1SLionel Sambuc 430411be35a1SLionel Sambuc 430511be35a1SLionel Sambuc /* 430611be35a1SLionel Sambuc ** CAPI3REF: Constants Defining Special Destructor Behavior 430711be35a1SLionel Sambuc ** 430811be35a1SLionel Sambuc ** These are special values for the destructor that is passed in as the 430911be35a1SLionel Sambuc ** final argument to routines like [sqlite3_result_blob()]. ^If the destructor 431011be35a1SLionel Sambuc ** argument is SQLITE_STATIC, it means that the content pointer is constant 431111be35a1SLionel Sambuc ** and will never change. It does not need to be destroyed. ^The 431211be35a1SLionel Sambuc ** SQLITE_TRANSIENT value means that the content will likely change in 431311be35a1SLionel Sambuc ** the near future and that SQLite should make its own private copy of 431411be35a1SLionel Sambuc ** the content before returning. 431511be35a1SLionel Sambuc ** 431611be35a1SLionel Sambuc ** The typedef is necessary to work around problems in certain 4317*0a6a1f1dSLionel Sambuc ** C++ compilers. 431811be35a1SLionel Sambuc */ 431911be35a1SLionel Sambuc typedef void (*sqlite3_destructor_type)(void*); 432011be35a1SLionel Sambuc #define SQLITE_STATIC ((sqlite3_destructor_type)0) 432111be35a1SLionel Sambuc #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) 432211be35a1SLionel Sambuc 432311be35a1SLionel Sambuc /* 432411be35a1SLionel Sambuc ** CAPI3REF: Setting The Result Of An SQL Function 432511be35a1SLionel Sambuc ** 432611be35a1SLionel Sambuc ** These routines are used by the xFunc or xFinal callbacks that 432711be35a1SLionel Sambuc ** implement SQL functions and aggregates. See 432811be35a1SLionel Sambuc ** [sqlite3_create_function()] and [sqlite3_create_function16()] 432911be35a1SLionel Sambuc ** for additional information. 433011be35a1SLionel Sambuc ** 433111be35a1SLionel Sambuc ** These functions work very much like the [parameter binding] family of 433211be35a1SLionel Sambuc ** functions used to bind values to host parameters in prepared statements. 433311be35a1SLionel Sambuc ** Refer to the [SQL parameter] documentation for additional information. 433411be35a1SLionel Sambuc ** 433511be35a1SLionel Sambuc ** ^The sqlite3_result_blob() interface sets the result from 433611be35a1SLionel Sambuc ** an application-defined function to be the BLOB whose content is pointed 433711be35a1SLionel Sambuc ** to by the second parameter and which is N bytes long where N is the 433811be35a1SLionel Sambuc ** third parameter. 433911be35a1SLionel Sambuc ** 434011be35a1SLionel Sambuc ** ^The sqlite3_result_zeroblob() interfaces set the result of 434111be35a1SLionel Sambuc ** the application-defined function to be a BLOB containing all zero 434211be35a1SLionel Sambuc ** bytes and N bytes in size, where N is the value of the 2nd parameter. 434311be35a1SLionel Sambuc ** 434411be35a1SLionel Sambuc ** ^The sqlite3_result_double() interface sets the result from 434511be35a1SLionel Sambuc ** an application-defined function to be a floating point value specified 434611be35a1SLionel Sambuc ** by its 2nd argument. 434711be35a1SLionel Sambuc ** 434811be35a1SLionel Sambuc ** ^The sqlite3_result_error() and sqlite3_result_error16() functions 434911be35a1SLionel Sambuc ** cause the implemented SQL function to throw an exception. 435011be35a1SLionel Sambuc ** ^SQLite uses the string pointed to by the 435111be35a1SLionel Sambuc ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16() 435211be35a1SLionel Sambuc ** as the text of an error message. ^SQLite interprets the error 435311be35a1SLionel Sambuc ** message string from sqlite3_result_error() as UTF-8. ^SQLite 435411be35a1SLionel Sambuc ** interprets the string from sqlite3_result_error16() as UTF-16 in native 435511be35a1SLionel Sambuc ** byte order. ^If the third parameter to sqlite3_result_error() 435611be35a1SLionel Sambuc ** or sqlite3_result_error16() is negative then SQLite takes as the error 435711be35a1SLionel Sambuc ** message all text up through the first zero character. 435811be35a1SLionel Sambuc ** ^If the third parameter to sqlite3_result_error() or 435911be35a1SLionel Sambuc ** sqlite3_result_error16() is non-negative then SQLite takes that many 436011be35a1SLionel Sambuc ** bytes (not characters) from the 2nd parameter as the error message. 436111be35a1SLionel Sambuc ** ^The sqlite3_result_error() and sqlite3_result_error16() 436211be35a1SLionel Sambuc ** routines make a private copy of the error message text before 436311be35a1SLionel Sambuc ** they return. Hence, the calling function can deallocate or 436411be35a1SLionel Sambuc ** modify the text after they return without harm. 436511be35a1SLionel Sambuc ** ^The sqlite3_result_error_code() function changes the error code 436611be35a1SLionel Sambuc ** returned by SQLite as a result of an error in a function. ^By default, 436711be35a1SLionel Sambuc ** the error code is SQLITE_ERROR. ^A subsequent call to sqlite3_result_error() 436811be35a1SLionel Sambuc ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR. 436911be35a1SLionel Sambuc ** 4370*0a6a1f1dSLionel Sambuc ** ^The sqlite3_result_error_toobig() interface causes SQLite to throw an 4371*0a6a1f1dSLionel Sambuc ** error indicating that a string or BLOB is too long to represent. 437211be35a1SLionel Sambuc ** 4373*0a6a1f1dSLionel Sambuc ** ^The sqlite3_result_error_nomem() interface causes SQLite to throw an 4374*0a6a1f1dSLionel Sambuc ** error indicating that a memory allocation failed. 437511be35a1SLionel Sambuc ** 437611be35a1SLionel Sambuc ** ^The sqlite3_result_int() interface sets the return value 437711be35a1SLionel Sambuc ** of the application-defined function to be the 32-bit signed integer 437811be35a1SLionel Sambuc ** value given in the 2nd argument. 437911be35a1SLionel Sambuc ** ^The sqlite3_result_int64() interface sets the return value 438011be35a1SLionel Sambuc ** of the application-defined function to be the 64-bit signed integer 438111be35a1SLionel Sambuc ** value given in the 2nd argument. 438211be35a1SLionel Sambuc ** 438311be35a1SLionel Sambuc ** ^The sqlite3_result_null() interface sets the return value 438411be35a1SLionel Sambuc ** of the application-defined function to be NULL. 438511be35a1SLionel Sambuc ** 438611be35a1SLionel Sambuc ** ^The sqlite3_result_text(), sqlite3_result_text16(), 438711be35a1SLionel Sambuc ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces 438811be35a1SLionel Sambuc ** set the return value of the application-defined function to be 438911be35a1SLionel Sambuc ** a text string which is represented as UTF-8, UTF-16 native byte order, 439011be35a1SLionel Sambuc ** UTF-16 little endian, or UTF-16 big endian, respectively. 439111be35a1SLionel Sambuc ** ^SQLite takes the text result from the application from 439211be35a1SLionel Sambuc ** the 2nd parameter of the sqlite3_result_text* interfaces. 439311be35a1SLionel Sambuc ** ^If the 3rd parameter to the sqlite3_result_text* interfaces 439411be35a1SLionel Sambuc ** is negative, then SQLite takes result text from the 2nd parameter 439511be35a1SLionel Sambuc ** through the first zero character. 439611be35a1SLionel Sambuc ** ^If the 3rd parameter to the sqlite3_result_text* interfaces 439711be35a1SLionel Sambuc ** is non-negative, then as many bytes (not characters) of the text 439811be35a1SLionel Sambuc ** pointed to by the 2nd parameter are taken as the application-defined 439911be35a1SLionel Sambuc ** function result. If the 3rd parameter is non-negative, then it 440011be35a1SLionel Sambuc ** must be the byte offset into the string where the NUL terminator would 440111be35a1SLionel Sambuc ** appear if the string where NUL terminated. If any NUL characters occur 440211be35a1SLionel Sambuc ** in the string at a byte offset that is less than the value of the 3rd 440311be35a1SLionel Sambuc ** parameter, then the resulting string will contain embedded NULs and the 440411be35a1SLionel Sambuc ** result of expressions operating on strings with embedded NULs is undefined. 440511be35a1SLionel Sambuc ** ^If the 4th parameter to the sqlite3_result_text* interfaces 440611be35a1SLionel Sambuc ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that 440711be35a1SLionel Sambuc ** function as the destructor on the text or BLOB result when it has 440811be35a1SLionel Sambuc ** finished using that result. 440911be35a1SLionel Sambuc ** ^If the 4th parameter to the sqlite3_result_text* interfaces or to 441011be35a1SLionel Sambuc ** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite 441111be35a1SLionel Sambuc ** assumes that the text or BLOB result is in constant space and does not 441211be35a1SLionel Sambuc ** copy the content of the parameter nor call a destructor on the content 441311be35a1SLionel Sambuc ** when it has finished using that result. 441411be35a1SLionel Sambuc ** ^If the 4th parameter to the sqlite3_result_text* interfaces 441511be35a1SLionel Sambuc ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT 441611be35a1SLionel Sambuc ** then SQLite makes a copy of the result into space obtained from 441711be35a1SLionel Sambuc ** from [sqlite3_malloc()] before it returns. 441811be35a1SLionel Sambuc ** 441911be35a1SLionel Sambuc ** ^The sqlite3_result_value() interface sets the result of 442011be35a1SLionel Sambuc ** the application-defined function to be a copy the 442111be35a1SLionel Sambuc ** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The 442211be35a1SLionel Sambuc ** sqlite3_result_value() interface makes a copy of the [sqlite3_value] 442311be35a1SLionel Sambuc ** so that the [sqlite3_value] specified in the parameter may change or 442411be35a1SLionel Sambuc ** be deallocated after sqlite3_result_value() returns without harm. 442511be35a1SLionel Sambuc ** ^A [protected sqlite3_value] object may always be used where an 442611be35a1SLionel Sambuc ** [unprotected sqlite3_value] object is required, so either 442711be35a1SLionel Sambuc ** kind of [sqlite3_value] object can be used with this interface. 442811be35a1SLionel Sambuc ** 442911be35a1SLionel Sambuc ** If these routines are called from within the different thread 443011be35a1SLionel Sambuc ** than the one containing the application-defined function that received 443111be35a1SLionel Sambuc ** the [sqlite3_context] pointer, the results are undefined. 443211be35a1SLionel Sambuc */ 443311be35a1SLionel Sambuc SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*)); 443411be35a1SLionel Sambuc SQLITE_API void sqlite3_result_double(sqlite3_context*, double); 443511be35a1SLionel Sambuc SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int); 443611be35a1SLionel Sambuc SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int); 443711be35a1SLionel Sambuc SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*); 443811be35a1SLionel Sambuc SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*); 443911be35a1SLionel Sambuc SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int); 444011be35a1SLionel Sambuc SQLITE_API void sqlite3_result_int(sqlite3_context*, int); 444111be35a1SLionel Sambuc SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64); 444211be35a1SLionel Sambuc SQLITE_API void sqlite3_result_null(sqlite3_context*); 444311be35a1SLionel Sambuc SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*)); 444411be35a1SLionel Sambuc SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*)); 444511be35a1SLionel Sambuc SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*)); 444611be35a1SLionel Sambuc SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*)); 444711be35a1SLionel Sambuc SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*); 444811be35a1SLionel Sambuc SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n); 444911be35a1SLionel Sambuc 445011be35a1SLionel Sambuc /* 445111be35a1SLionel Sambuc ** CAPI3REF: Define New Collating Sequences 445211be35a1SLionel Sambuc ** 445311be35a1SLionel Sambuc ** ^These functions add, remove, or modify a [collation] associated 445411be35a1SLionel Sambuc ** with the [database connection] specified as the first argument. 445511be35a1SLionel Sambuc ** 445611be35a1SLionel Sambuc ** ^The name of the collation is a UTF-8 string 445711be35a1SLionel Sambuc ** for sqlite3_create_collation() and sqlite3_create_collation_v2() 445811be35a1SLionel Sambuc ** and a UTF-16 string in native byte order for sqlite3_create_collation16(). 445911be35a1SLionel Sambuc ** ^Collation names that compare equal according to [sqlite3_strnicmp()] are 446011be35a1SLionel Sambuc ** considered to be the same name. 446111be35a1SLionel Sambuc ** 446211be35a1SLionel Sambuc ** ^(The third argument (eTextRep) must be one of the constants: 446311be35a1SLionel Sambuc ** <ul> 446411be35a1SLionel Sambuc ** <li> [SQLITE_UTF8], 446511be35a1SLionel Sambuc ** <li> [SQLITE_UTF16LE], 446611be35a1SLionel Sambuc ** <li> [SQLITE_UTF16BE], 446711be35a1SLionel Sambuc ** <li> [SQLITE_UTF16], or 446811be35a1SLionel Sambuc ** <li> [SQLITE_UTF16_ALIGNED]. 446911be35a1SLionel Sambuc ** </ul>)^ 447011be35a1SLionel Sambuc ** ^The eTextRep argument determines the encoding of strings passed 447111be35a1SLionel Sambuc ** to the collating function callback, xCallback. 447211be35a1SLionel Sambuc ** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep 447311be35a1SLionel Sambuc ** force strings to be UTF16 with native byte order. 447411be35a1SLionel Sambuc ** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin 447511be35a1SLionel Sambuc ** on an even byte address. 447611be35a1SLionel Sambuc ** 447711be35a1SLionel Sambuc ** ^The fourth argument, pArg, is an application data pointer that is passed 447811be35a1SLionel Sambuc ** through as the first argument to the collating function callback. 447911be35a1SLionel Sambuc ** 448011be35a1SLionel Sambuc ** ^The fifth argument, xCallback, is a pointer to the collating function. 448111be35a1SLionel Sambuc ** ^Multiple collating functions can be registered using the same name but 448211be35a1SLionel Sambuc ** with different eTextRep parameters and SQLite will use whichever 448311be35a1SLionel Sambuc ** function requires the least amount of data transformation. 448411be35a1SLionel Sambuc ** ^If the xCallback argument is NULL then the collating function is 448511be35a1SLionel Sambuc ** deleted. ^When all collating functions having the same name are deleted, 448611be35a1SLionel Sambuc ** that collation is no longer usable. 448711be35a1SLionel Sambuc ** 448811be35a1SLionel Sambuc ** ^The collating function callback is invoked with a copy of the pArg 448911be35a1SLionel Sambuc ** application data pointer and with two strings in the encoding specified 449011be35a1SLionel Sambuc ** by the eTextRep argument. The collating function must return an 449111be35a1SLionel Sambuc ** integer that is negative, zero, or positive 449211be35a1SLionel Sambuc ** if the first string is less than, equal to, or greater than the second, 449311be35a1SLionel Sambuc ** respectively. A collating function must always return the same answer 449411be35a1SLionel Sambuc ** given the same inputs. If two or more collating functions are registered 449511be35a1SLionel Sambuc ** to the same collation name (using different eTextRep values) then all 449611be35a1SLionel Sambuc ** must give an equivalent answer when invoked with equivalent strings. 449711be35a1SLionel Sambuc ** The collating function must obey the following properties for all 449811be35a1SLionel Sambuc ** strings A, B, and C: 449911be35a1SLionel Sambuc ** 450011be35a1SLionel Sambuc ** <ol> 450111be35a1SLionel Sambuc ** <li> If A==B then B==A. 450211be35a1SLionel Sambuc ** <li> If A==B and B==C then A==C. 450311be35a1SLionel Sambuc ** <li> If A<B THEN B>A. 450411be35a1SLionel Sambuc ** <li> If A<B and B<C then A<C. 450511be35a1SLionel Sambuc ** </ol> 450611be35a1SLionel Sambuc ** 450711be35a1SLionel Sambuc ** If a collating function fails any of the above constraints and that 450811be35a1SLionel Sambuc ** collating function is registered and used, then the behavior of SQLite 450911be35a1SLionel Sambuc ** is undefined. 451011be35a1SLionel Sambuc ** 451111be35a1SLionel Sambuc ** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation() 451211be35a1SLionel Sambuc ** with the addition that the xDestroy callback is invoked on pArg when 451311be35a1SLionel Sambuc ** the collating function is deleted. 451411be35a1SLionel Sambuc ** ^Collating functions are deleted when they are overridden by later 451511be35a1SLionel Sambuc ** calls to the collation creation functions or when the 451611be35a1SLionel Sambuc ** [database connection] is closed using [sqlite3_close()]. 451711be35a1SLionel Sambuc ** 451811be35a1SLionel Sambuc ** ^The xDestroy callback is <u>not</u> called if the 451911be35a1SLionel Sambuc ** sqlite3_create_collation_v2() function fails. Applications that invoke 452011be35a1SLionel Sambuc ** sqlite3_create_collation_v2() with a non-NULL xDestroy argument should 452111be35a1SLionel Sambuc ** check the return code and dispose of the application data pointer 452211be35a1SLionel Sambuc ** themselves rather than expecting SQLite to deal with it for them. 452311be35a1SLionel Sambuc ** This is different from every other SQLite interface. The inconsistency 452411be35a1SLionel Sambuc ** is unfortunate but cannot be changed without breaking backwards 452511be35a1SLionel Sambuc ** compatibility. 452611be35a1SLionel Sambuc ** 452711be35a1SLionel Sambuc ** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()]. 452811be35a1SLionel Sambuc */ 452911be35a1SLionel Sambuc SQLITE_API int sqlite3_create_collation( 453011be35a1SLionel Sambuc sqlite3*, 453111be35a1SLionel Sambuc const char *zName, 453211be35a1SLionel Sambuc int eTextRep, 453311be35a1SLionel Sambuc void *pArg, 453411be35a1SLionel Sambuc int(*xCompare)(void*,int,const void*,int,const void*) 453511be35a1SLionel Sambuc ); 453611be35a1SLionel Sambuc SQLITE_API int sqlite3_create_collation_v2( 453711be35a1SLionel Sambuc sqlite3*, 453811be35a1SLionel Sambuc const char *zName, 453911be35a1SLionel Sambuc int eTextRep, 454011be35a1SLionel Sambuc void *pArg, 454111be35a1SLionel Sambuc int(*xCompare)(void*,int,const void*,int,const void*), 454211be35a1SLionel Sambuc void(*xDestroy)(void*) 454311be35a1SLionel Sambuc ); 454411be35a1SLionel Sambuc SQLITE_API int sqlite3_create_collation16( 454511be35a1SLionel Sambuc sqlite3*, 454611be35a1SLionel Sambuc const void *zName, 454711be35a1SLionel Sambuc int eTextRep, 454811be35a1SLionel Sambuc void *pArg, 454911be35a1SLionel Sambuc int(*xCompare)(void*,int,const void*,int,const void*) 455011be35a1SLionel Sambuc ); 455111be35a1SLionel Sambuc 455211be35a1SLionel Sambuc /* 455311be35a1SLionel Sambuc ** CAPI3REF: Collation Needed Callbacks 455411be35a1SLionel Sambuc ** 455511be35a1SLionel Sambuc ** ^To avoid having to register all collation sequences before a database 455611be35a1SLionel Sambuc ** can be used, a single callback function may be registered with the 455711be35a1SLionel Sambuc ** [database connection] to be invoked whenever an undefined collation 455811be35a1SLionel Sambuc ** sequence is required. 455911be35a1SLionel Sambuc ** 456011be35a1SLionel Sambuc ** ^If the function is registered using the sqlite3_collation_needed() API, 456111be35a1SLionel Sambuc ** then it is passed the names of undefined collation sequences as strings 456211be35a1SLionel Sambuc ** encoded in UTF-8. ^If sqlite3_collation_needed16() is used, 456311be35a1SLionel Sambuc ** the names are passed as UTF-16 in machine native byte order. 456411be35a1SLionel Sambuc ** ^A call to either function replaces the existing collation-needed callback. 456511be35a1SLionel Sambuc ** 456611be35a1SLionel Sambuc ** ^(When the callback is invoked, the first argument passed is a copy 456711be35a1SLionel Sambuc ** of the second argument to sqlite3_collation_needed() or 456811be35a1SLionel Sambuc ** sqlite3_collation_needed16(). The second argument is the database 456911be35a1SLionel Sambuc ** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE], 457011be35a1SLionel Sambuc ** or [SQLITE_UTF16LE], indicating the most desirable form of the collation 457111be35a1SLionel Sambuc ** sequence function required. The fourth parameter is the name of the 457211be35a1SLionel Sambuc ** required collation sequence.)^ 457311be35a1SLionel Sambuc ** 457411be35a1SLionel Sambuc ** The callback function should register the desired collation using 457511be35a1SLionel Sambuc ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or 457611be35a1SLionel Sambuc ** [sqlite3_create_collation_v2()]. 457711be35a1SLionel Sambuc */ 457811be35a1SLionel Sambuc SQLITE_API int sqlite3_collation_needed( 457911be35a1SLionel Sambuc sqlite3*, 458011be35a1SLionel Sambuc void*, 458111be35a1SLionel Sambuc void(*)(void*,sqlite3*,int eTextRep,const char*) 458211be35a1SLionel Sambuc ); 458311be35a1SLionel Sambuc SQLITE_API int sqlite3_collation_needed16( 458411be35a1SLionel Sambuc sqlite3*, 458511be35a1SLionel Sambuc void*, 458611be35a1SLionel Sambuc void(*)(void*,sqlite3*,int eTextRep,const void*) 458711be35a1SLionel Sambuc ); 458811be35a1SLionel Sambuc 458911be35a1SLionel Sambuc #ifdef SQLITE_HAS_CODEC 459011be35a1SLionel Sambuc /* 459111be35a1SLionel Sambuc ** Specify the key for an encrypted database. This routine should be 459211be35a1SLionel Sambuc ** called right after sqlite3_open(). 459311be35a1SLionel Sambuc ** 459411be35a1SLionel Sambuc ** The code to implement this API is not available in the public release 459511be35a1SLionel Sambuc ** of SQLite. 459611be35a1SLionel Sambuc */ 459711be35a1SLionel Sambuc SQLITE_API int sqlite3_key( 459811be35a1SLionel Sambuc sqlite3 *db, /* Database to be rekeyed */ 459911be35a1SLionel Sambuc const void *pKey, int nKey /* The key */ 460011be35a1SLionel Sambuc ); 4601*0a6a1f1dSLionel Sambuc SQLITE_API int sqlite3_key_v2( 4602*0a6a1f1dSLionel Sambuc sqlite3 *db, /* Database to be rekeyed */ 4603*0a6a1f1dSLionel Sambuc const char *zDbName, /* Name of the database */ 4604*0a6a1f1dSLionel Sambuc const void *pKey, int nKey /* The key */ 4605*0a6a1f1dSLionel Sambuc ); 460611be35a1SLionel Sambuc 460711be35a1SLionel Sambuc /* 460811be35a1SLionel Sambuc ** Change the key on an open database. If the current database is not 460911be35a1SLionel Sambuc ** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the 461011be35a1SLionel Sambuc ** database is decrypted. 461111be35a1SLionel Sambuc ** 461211be35a1SLionel Sambuc ** The code to implement this API is not available in the public release 461311be35a1SLionel Sambuc ** of SQLite. 461411be35a1SLionel Sambuc */ 461511be35a1SLionel Sambuc SQLITE_API int sqlite3_rekey( 461611be35a1SLionel Sambuc sqlite3 *db, /* Database to be rekeyed */ 461711be35a1SLionel Sambuc const void *pKey, int nKey /* The new key */ 461811be35a1SLionel Sambuc ); 4619*0a6a1f1dSLionel Sambuc SQLITE_API int sqlite3_rekey_v2( 4620*0a6a1f1dSLionel Sambuc sqlite3 *db, /* Database to be rekeyed */ 4621*0a6a1f1dSLionel Sambuc const char *zDbName, /* Name of the database */ 4622*0a6a1f1dSLionel Sambuc const void *pKey, int nKey /* The new key */ 4623*0a6a1f1dSLionel Sambuc ); 462411be35a1SLionel Sambuc 462511be35a1SLionel Sambuc /* 462611be35a1SLionel Sambuc ** Specify the activation key for a SEE database. Unless 462711be35a1SLionel Sambuc ** activated, none of the SEE routines will work. 462811be35a1SLionel Sambuc */ 462911be35a1SLionel Sambuc SQLITE_API void sqlite3_activate_see( 463011be35a1SLionel Sambuc const char *zPassPhrase /* Activation phrase */ 463111be35a1SLionel Sambuc ); 463211be35a1SLionel Sambuc #endif 463311be35a1SLionel Sambuc 463411be35a1SLionel Sambuc #ifdef SQLITE_ENABLE_CEROD 463511be35a1SLionel Sambuc /* 463611be35a1SLionel Sambuc ** Specify the activation key for a CEROD database. Unless 463711be35a1SLionel Sambuc ** activated, none of the CEROD routines will work. 463811be35a1SLionel Sambuc */ 463911be35a1SLionel Sambuc SQLITE_API void sqlite3_activate_cerod( 464011be35a1SLionel Sambuc const char *zPassPhrase /* Activation phrase */ 464111be35a1SLionel Sambuc ); 464211be35a1SLionel Sambuc #endif 464311be35a1SLionel Sambuc 464411be35a1SLionel Sambuc /* 464511be35a1SLionel Sambuc ** CAPI3REF: Suspend Execution For A Short Time 464611be35a1SLionel Sambuc ** 464711be35a1SLionel Sambuc ** The sqlite3_sleep() function causes the current thread to suspend execution 464811be35a1SLionel Sambuc ** for at least a number of milliseconds specified in its parameter. 464911be35a1SLionel Sambuc ** 465011be35a1SLionel Sambuc ** If the operating system does not support sleep requests with 465111be35a1SLionel Sambuc ** millisecond time resolution, then the time will be rounded up to 465211be35a1SLionel Sambuc ** the nearest second. The number of milliseconds of sleep actually 465311be35a1SLionel Sambuc ** requested from the operating system is returned. 465411be35a1SLionel Sambuc ** 465511be35a1SLionel Sambuc ** ^SQLite implements this interface by calling the xSleep() 465611be35a1SLionel Sambuc ** method of the default [sqlite3_vfs] object. If the xSleep() method 465711be35a1SLionel Sambuc ** of the default VFS is not implemented correctly, or not implemented at 465811be35a1SLionel Sambuc ** all, then the behavior of sqlite3_sleep() may deviate from the description 465911be35a1SLionel Sambuc ** in the previous paragraphs. 466011be35a1SLionel Sambuc */ 466111be35a1SLionel Sambuc SQLITE_API int sqlite3_sleep(int); 466211be35a1SLionel Sambuc 466311be35a1SLionel Sambuc /* 466411be35a1SLionel Sambuc ** CAPI3REF: Name Of The Folder Holding Temporary Files 466511be35a1SLionel Sambuc ** 466611be35a1SLionel Sambuc ** ^(If this global variable is made to point to a string which is 466711be35a1SLionel Sambuc ** the name of a folder (a.k.a. directory), then all temporary files 466811be35a1SLionel Sambuc ** created by SQLite when using a built-in [sqlite3_vfs | VFS] 466911be35a1SLionel Sambuc ** will be placed in that directory.)^ ^If this variable 467011be35a1SLionel Sambuc ** is a NULL pointer, then SQLite performs a search for an appropriate 467111be35a1SLionel Sambuc ** temporary file directory. 467211be35a1SLionel Sambuc ** 467311be35a1SLionel Sambuc ** It is not safe to read or modify this variable in more than one 467411be35a1SLionel Sambuc ** thread at a time. It is not safe to read or modify this variable 467511be35a1SLionel Sambuc ** if a [database connection] is being used at the same time in a separate 467611be35a1SLionel Sambuc ** thread. 467711be35a1SLionel Sambuc ** It is intended that this variable be set once 467811be35a1SLionel Sambuc ** as part of process initialization and before any SQLite interface 467911be35a1SLionel Sambuc ** routines have been called and that this variable remain unchanged 468011be35a1SLionel Sambuc ** thereafter. 468111be35a1SLionel Sambuc ** 468211be35a1SLionel Sambuc ** ^The [temp_store_directory pragma] may modify this variable and cause 468311be35a1SLionel Sambuc ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore, 468411be35a1SLionel Sambuc ** the [temp_store_directory pragma] always assumes that any string 468511be35a1SLionel Sambuc ** that this variable points to is held in memory obtained from 468611be35a1SLionel Sambuc ** [sqlite3_malloc] and the pragma may attempt to free that memory 468711be35a1SLionel Sambuc ** using [sqlite3_free]. 468811be35a1SLionel Sambuc ** Hence, if this variable is modified directly, either it should be 468911be35a1SLionel Sambuc ** made NULL or made to point to memory obtained from [sqlite3_malloc] 469011be35a1SLionel Sambuc ** or else the use of the [temp_store_directory pragma] should be avoided. 4691*0a6a1f1dSLionel Sambuc ** 4692*0a6a1f1dSLionel Sambuc ** <b>Note to Windows Runtime users:</b> The temporary directory must be set 4693*0a6a1f1dSLionel Sambuc ** prior to calling [sqlite3_open] or [sqlite3_open_v2]. Otherwise, various 4694*0a6a1f1dSLionel Sambuc ** features that require the use of temporary files may fail. Here is an 4695*0a6a1f1dSLionel Sambuc ** example of how to do this using C++ with the Windows Runtime: 4696*0a6a1f1dSLionel Sambuc ** 4697*0a6a1f1dSLionel Sambuc ** <blockquote><pre> 4698*0a6a1f1dSLionel Sambuc ** LPCWSTR zPath = Windows::Storage::ApplicationData::Current-> 4699*0a6a1f1dSLionel Sambuc ** TemporaryFolder->Path->Data(); 4700*0a6a1f1dSLionel Sambuc ** char zPathBuf[MAX_PATH + 1]; 4701*0a6a1f1dSLionel Sambuc ** memset(zPathBuf, 0, sizeof(zPathBuf)); 4702*0a6a1f1dSLionel Sambuc ** WideCharToMultiByte(CP_UTF8, 0, zPath, -1, zPathBuf, sizeof(zPathBuf), 4703*0a6a1f1dSLionel Sambuc ** NULL, NULL); 4704*0a6a1f1dSLionel Sambuc ** sqlite3_temp_directory = sqlite3_mprintf("%s", zPathBuf); 4705*0a6a1f1dSLionel Sambuc ** </pre></blockquote> 470611be35a1SLionel Sambuc */ 470711be35a1SLionel Sambuc SQLITE_API SQLITE_EXTERN char *sqlite3_temp_directory; 470811be35a1SLionel Sambuc 470911be35a1SLionel Sambuc /* 4710*0a6a1f1dSLionel Sambuc ** CAPI3REF: Name Of The Folder Holding Database Files 4711*0a6a1f1dSLionel Sambuc ** 4712*0a6a1f1dSLionel Sambuc ** ^(If this global variable is made to point to a string which is 4713*0a6a1f1dSLionel Sambuc ** the name of a folder (a.k.a. directory), then all database files 4714*0a6a1f1dSLionel Sambuc ** specified with a relative pathname and created or accessed by 4715*0a6a1f1dSLionel Sambuc ** SQLite when using a built-in windows [sqlite3_vfs | VFS] will be assumed 4716*0a6a1f1dSLionel Sambuc ** to be relative to that directory.)^ ^If this variable is a NULL 4717*0a6a1f1dSLionel Sambuc ** pointer, then SQLite assumes that all database files specified 4718*0a6a1f1dSLionel Sambuc ** with a relative pathname are relative to the current directory 4719*0a6a1f1dSLionel Sambuc ** for the process. Only the windows VFS makes use of this global 4720*0a6a1f1dSLionel Sambuc ** variable; it is ignored by the unix VFS. 4721*0a6a1f1dSLionel Sambuc ** 4722*0a6a1f1dSLionel Sambuc ** Changing the value of this variable while a database connection is 4723*0a6a1f1dSLionel Sambuc ** open can result in a corrupt database. 4724*0a6a1f1dSLionel Sambuc ** 4725*0a6a1f1dSLionel Sambuc ** It is not safe to read or modify this variable in more than one 4726*0a6a1f1dSLionel Sambuc ** thread at a time. It is not safe to read or modify this variable 4727*0a6a1f1dSLionel Sambuc ** if a [database connection] is being used at the same time in a separate 4728*0a6a1f1dSLionel Sambuc ** thread. 4729*0a6a1f1dSLionel Sambuc ** It is intended that this variable be set once 4730*0a6a1f1dSLionel Sambuc ** as part of process initialization and before any SQLite interface 4731*0a6a1f1dSLionel Sambuc ** routines have been called and that this variable remain unchanged 4732*0a6a1f1dSLionel Sambuc ** thereafter. 4733*0a6a1f1dSLionel Sambuc ** 4734*0a6a1f1dSLionel Sambuc ** ^The [data_store_directory pragma] may modify this variable and cause 4735*0a6a1f1dSLionel Sambuc ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore, 4736*0a6a1f1dSLionel Sambuc ** the [data_store_directory pragma] always assumes that any string 4737*0a6a1f1dSLionel Sambuc ** that this variable points to is held in memory obtained from 4738*0a6a1f1dSLionel Sambuc ** [sqlite3_malloc] and the pragma may attempt to free that memory 4739*0a6a1f1dSLionel Sambuc ** using [sqlite3_free]. 4740*0a6a1f1dSLionel Sambuc ** Hence, if this variable is modified directly, either it should be 4741*0a6a1f1dSLionel Sambuc ** made NULL or made to point to memory obtained from [sqlite3_malloc] 4742*0a6a1f1dSLionel Sambuc ** or else the use of the [data_store_directory pragma] should be avoided. 4743*0a6a1f1dSLionel Sambuc */ 4744*0a6a1f1dSLionel Sambuc SQLITE_API SQLITE_EXTERN char *sqlite3_data_directory; 4745*0a6a1f1dSLionel Sambuc 4746*0a6a1f1dSLionel Sambuc /* 474711be35a1SLionel Sambuc ** CAPI3REF: Test For Auto-Commit Mode 474811be35a1SLionel Sambuc ** KEYWORDS: {autocommit mode} 474911be35a1SLionel Sambuc ** 475011be35a1SLionel Sambuc ** ^The sqlite3_get_autocommit() interface returns non-zero or 475111be35a1SLionel Sambuc ** zero if the given database connection is or is not in autocommit mode, 475211be35a1SLionel Sambuc ** respectively. ^Autocommit mode is on by default. 475311be35a1SLionel Sambuc ** ^Autocommit mode is disabled by a [BEGIN] statement. 475411be35a1SLionel Sambuc ** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK]. 475511be35a1SLionel Sambuc ** 475611be35a1SLionel Sambuc ** If certain kinds of errors occur on a statement within a multi-statement 475711be35a1SLionel Sambuc ** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR], 475811be35a1SLionel Sambuc ** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the 475911be35a1SLionel Sambuc ** transaction might be rolled back automatically. The only way to 476011be35a1SLionel Sambuc ** find out whether SQLite automatically rolled back the transaction after 476111be35a1SLionel Sambuc ** an error is to use this function. 476211be35a1SLionel Sambuc ** 476311be35a1SLionel Sambuc ** If another thread changes the autocommit status of the database 476411be35a1SLionel Sambuc ** connection while this routine is running, then the return value 476511be35a1SLionel Sambuc ** is undefined. 476611be35a1SLionel Sambuc */ 476711be35a1SLionel Sambuc SQLITE_API int sqlite3_get_autocommit(sqlite3*); 476811be35a1SLionel Sambuc 476911be35a1SLionel Sambuc /* 477011be35a1SLionel Sambuc ** CAPI3REF: Find The Database Handle Of A Prepared Statement 477111be35a1SLionel Sambuc ** 477211be35a1SLionel Sambuc ** ^The sqlite3_db_handle interface returns the [database connection] handle 477311be35a1SLionel Sambuc ** to which a [prepared statement] belongs. ^The [database connection] 477411be35a1SLionel Sambuc ** returned by sqlite3_db_handle is the same [database connection] 477511be35a1SLionel Sambuc ** that was the first argument 477611be35a1SLionel Sambuc ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to 477711be35a1SLionel Sambuc ** create the statement in the first place. 477811be35a1SLionel Sambuc */ 477911be35a1SLionel Sambuc SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*); 478011be35a1SLionel Sambuc 478111be35a1SLionel Sambuc /* 478211be35a1SLionel Sambuc ** CAPI3REF: Return The Filename For A Database Connection 478311be35a1SLionel Sambuc ** 478411be35a1SLionel Sambuc ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename 478511be35a1SLionel Sambuc ** associated with database N of connection D. ^The main database file 478611be35a1SLionel Sambuc ** has the name "main". If there is no attached database N on the database 478711be35a1SLionel Sambuc ** connection D, or if database N is a temporary or in-memory database, then 478811be35a1SLionel Sambuc ** a NULL pointer is returned. 478911be35a1SLionel Sambuc ** 479011be35a1SLionel Sambuc ** ^The filename returned by this function is the output of the 479111be35a1SLionel Sambuc ** xFullPathname method of the [VFS]. ^In other words, the filename 479211be35a1SLionel Sambuc ** will be an absolute pathname, even if the filename used 479311be35a1SLionel Sambuc ** to open the database originally was a URI or relative pathname. 479411be35a1SLionel Sambuc */ 479511be35a1SLionel Sambuc SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName); 479611be35a1SLionel Sambuc 479711be35a1SLionel Sambuc /* 4798*0a6a1f1dSLionel Sambuc ** CAPI3REF: Determine if a database is read-only 4799*0a6a1f1dSLionel Sambuc ** 4800*0a6a1f1dSLionel Sambuc ** ^The sqlite3_db_readonly(D,N) interface returns 1 if the database N 4801*0a6a1f1dSLionel Sambuc ** of connection D is read-only, 0 if it is read/write, or -1 if N is not 4802*0a6a1f1dSLionel Sambuc ** the name of a database on connection D. 4803*0a6a1f1dSLionel Sambuc */ 4804*0a6a1f1dSLionel Sambuc SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName); 4805*0a6a1f1dSLionel Sambuc 4806*0a6a1f1dSLionel Sambuc /* 480711be35a1SLionel Sambuc ** CAPI3REF: Find the next prepared statement 480811be35a1SLionel Sambuc ** 480911be35a1SLionel Sambuc ** ^This interface returns a pointer to the next [prepared statement] after 481011be35a1SLionel Sambuc ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL 481111be35a1SLionel Sambuc ** then this interface returns a pointer to the first prepared statement 481211be35a1SLionel Sambuc ** associated with the database connection pDb. ^If no prepared statement 481311be35a1SLionel Sambuc ** satisfies the conditions of this routine, it returns NULL. 481411be35a1SLionel Sambuc ** 481511be35a1SLionel Sambuc ** The [database connection] pointer D in a call to 481611be35a1SLionel Sambuc ** [sqlite3_next_stmt(D,S)] must refer to an open database 481711be35a1SLionel Sambuc ** connection and in particular must not be a NULL pointer. 481811be35a1SLionel Sambuc */ 481911be35a1SLionel Sambuc SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); 482011be35a1SLionel Sambuc 482111be35a1SLionel Sambuc /* 482211be35a1SLionel Sambuc ** CAPI3REF: Commit And Rollback Notification Callbacks 482311be35a1SLionel Sambuc ** 482411be35a1SLionel Sambuc ** ^The sqlite3_commit_hook() interface registers a callback 482511be35a1SLionel Sambuc ** function to be invoked whenever a transaction is [COMMIT | committed]. 482611be35a1SLionel Sambuc ** ^Any callback set by a previous call to sqlite3_commit_hook() 482711be35a1SLionel Sambuc ** for the same database connection is overridden. 482811be35a1SLionel Sambuc ** ^The sqlite3_rollback_hook() interface registers a callback 482911be35a1SLionel Sambuc ** function to be invoked whenever a transaction is [ROLLBACK | rolled back]. 483011be35a1SLionel Sambuc ** ^Any callback set by a previous call to sqlite3_rollback_hook() 483111be35a1SLionel Sambuc ** for the same database connection is overridden. 483211be35a1SLionel Sambuc ** ^The pArg argument is passed through to the callback. 483311be35a1SLionel Sambuc ** ^If the callback on a commit hook function returns non-zero, 483411be35a1SLionel Sambuc ** then the commit is converted into a rollback. 483511be35a1SLionel Sambuc ** 483611be35a1SLionel Sambuc ** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions 483711be35a1SLionel Sambuc ** return the P argument from the previous call of the same function 483811be35a1SLionel Sambuc ** on the same [database connection] D, or NULL for 483911be35a1SLionel Sambuc ** the first call for each function on D. 484011be35a1SLionel Sambuc ** 484111be35a1SLionel Sambuc ** The commit and rollback hook callbacks are not reentrant. 484211be35a1SLionel Sambuc ** The callback implementation must not do anything that will modify 484311be35a1SLionel Sambuc ** the database connection that invoked the callback. Any actions 484411be35a1SLionel Sambuc ** to modify the database connection must be deferred until after the 484511be35a1SLionel Sambuc ** completion of the [sqlite3_step()] call that triggered the commit 484611be35a1SLionel Sambuc ** or rollback hook in the first place. 484711be35a1SLionel Sambuc ** Note that running any other SQL statements, including SELECT statements, 484811be35a1SLionel Sambuc ** or merely calling [sqlite3_prepare_v2()] and [sqlite3_step()] will modify 484911be35a1SLionel Sambuc ** the database connections for the meaning of "modify" in this paragraph. 485011be35a1SLionel Sambuc ** 485111be35a1SLionel Sambuc ** ^Registering a NULL function disables the callback. 485211be35a1SLionel Sambuc ** 485311be35a1SLionel Sambuc ** ^When the commit hook callback routine returns zero, the [COMMIT] 485411be35a1SLionel Sambuc ** operation is allowed to continue normally. ^If the commit hook 485511be35a1SLionel Sambuc ** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK]. 485611be35a1SLionel Sambuc ** ^The rollback hook is invoked on a rollback that results from a commit 485711be35a1SLionel Sambuc ** hook returning non-zero, just as it would be with any other rollback. 485811be35a1SLionel Sambuc ** 485911be35a1SLionel Sambuc ** ^For the purposes of this API, a transaction is said to have been 486011be35a1SLionel Sambuc ** rolled back if an explicit "ROLLBACK" statement is executed, or 486111be35a1SLionel Sambuc ** an error or constraint causes an implicit rollback to occur. 486211be35a1SLionel Sambuc ** ^The rollback callback is not invoked if a transaction is 486311be35a1SLionel Sambuc ** automatically rolled back because the database connection is closed. 486411be35a1SLionel Sambuc ** 486511be35a1SLionel Sambuc ** See also the [sqlite3_update_hook()] interface. 486611be35a1SLionel Sambuc */ 486711be35a1SLionel Sambuc SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); 486811be35a1SLionel Sambuc SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); 486911be35a1SLionel Sambuc 487011be35a1SLionel Sambuc /* 487111be35a1SLionel Sambuc ** CAPI3REF: Data Change Notification Callbacks 487211be35a1SLionel Sambuc ** 487311be35a1SLionel Sambuc ** ^The sqlite3_update_hook() interface registers a callback function 487411be35a1SLionel Sambuc ** with the [database connection] identified by the first argument 4875*0a6a1f1dSLionel Sambuc ** to be invoked whenever a row is updated, inserted or deleted in 4876*0a6a1f1dSLionel Sambuc ** a rowid table. 487711be35a1SLionel Sambuc ** ^Any callback set by a previous call to this function 487811be35a1SLionel Sambuc ** for the same database connection is overridden. 487911be35a1SLionel Sambuc ** 488011be35a1SLionel Sambuc ** ^The second argument is a pointer to the function to invoke when a 4881*0a6a1f1dSLionel Sambuc ** row is updated, inserted or deleted in a rowid table. 488211be35a1SLionel Sambuc ** ^The first argument to the callback is a copy of the third argument 488311be35a1SLionel Sambuc ** to sqlite3_update_hook(). 488411be35a1SLionel Sambuc ** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE], 488511be35a1SLionel Sambuc ** or [SQLITE_UPDATE], depending on the operation that caused the callback 488611be35a1SLionel Sambuc ** to be invoked. 488711be35a1SLionel Sambuc ** ^The third and fourth arguments to the callback contain pointers to the 488811be35a1SLionel Sambuc ** database and table name containing the affected row. 488911be35a1SLionel Sambuc ** ^The final callback parameter is the [rowid] of the row. 489011be35a1SLionel Sambuc ** ^In the case of an update, this is the [rowid] after the update takes place. 489111be35a1SLionel Sambuc ** 489211be35a1SLionel Sambuc ** ^(The update hook is not invoked when internal system tables are 489311be35a1SLionel Sambuc ** modified (i.e. sqlite_master and sqlite_sequence).)^ 4894*0a6a1f1dSLionel Sambuc ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified. 489511be35a1SLionel Sambuc ** 489611be35a1SLionel Sambuc ** ^In the current implementation, the update hook 489711be35a1SLionel Sambuc ** is not invoked when duplication rows are deleted because of an 489811be35a1SLionel Sambuc ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook 489911be35a1SLionel Sambuc ** invoked when rows are deleted using the [truncate optimization]. 490011be35a1SLionel Sambuc ** The exceptions defined in this paragraph might change in a future 490111be35a1SLionel Sambuc ** release of SQLite. 490211be35a1SLionel Sambuc ** 490311be35a1SLionel Sambuc ** The update hook implementation must not do anything that will modify 490411be35a1SLionel Sambuc ** the database connection that invoked the update hook. Any actions 490511be35a1SLionel Sambuc ** to modify the database connection must be deferred until after the 490611be35a1SLionel Sambuc ** completion of the [sqlite3_step()] call that triggered the update hook. 490711be35a1SLionel Sambuc ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 490811be35a1SLionel Sambuc ** database connections for the meaning of "modify" in this paragraph. 490911be35a1SLionel Sambuc ** 491011be35a1SLionel Sambuc ** ^The sqlite3_update_hook(D,C,P) function 491111be35a1SLionel Sambuc ** returns the P argument from the previous call 491211be35a1SLionel Sambuc ** on the same [database connection] D, or NULL for 491311be35a1SLionel Sambuc ** the first call on D. 491411be35a1SLionel Sambuc ** 491511be35a1SLionel Sambuc ** See also the [sqlite3_commit_hook()] and [sqlite3_rollback_hook()] 491611be35a1SLionel Sambuc ** interfaces. 491711be35a1SLionel Sambuc */ 491811be35a1SLionel Sambuc SQLITE_API void *sqlite3_update_hook( 491911be35a1SLionel Sambuc sqlite3*, 492011be35a1SLionel Sambuc void(*)(void *,int ,char const *,char const *,sqlite3_int64), 492111be35a1SLionel Sambuc void* 492211be35a1SLionel Sambuc ); 492311be35a1SLionel Sambuc 492411be35a1SLionel Sambuc /* 492511be35a1SLionel Sambuc ** CAPI3REF: Enable Or Disable Shared Pager Cache 492611be35a1SLionel Sambuc ** 492711be35a1SLionel Sambuc ** ^(This routine enables or disables the sharing of the database cache 492811be35a1SLionel Sambuc ** and schema data structures between [database connection | connections] 492911be35a1SLionel Sambuc ** to the same database. Sharing is enabled if the argument is true 493011be35a1SLionel Sambuc ** and disabled if the argument is false.)^ 493111be35a1SLionel Sambuc ** 493211be35a1SLionel Sambuc ** ^Cache sharing is enabled and disabled for an entire process. 493311be35a1SLionel Sambuc ** This is a change as of SQLite version 3.5.0. In prior versions of SQLite, 493411be35a1SLionel Sambuc ** sharing was enabled or disabled for each thread separately. 493511be35a1SLionel Sambuc ** 493611be35a1SLionel Sambuc ** ^(The cache sharing mode set by this interface effects all subsequent 493711be35a1SLionel Sambuc ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()]. 493811be35a1SLionel Sambuc ** Existing database connections continue use the sharing mode 493911be35a1SLionel Sambuc ** that was in effect at the time they were opened.)^ 494011be35a1SLionel Sambuc ** 494111be35a1SLionel Sambuc ** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled 494211be35a1SLionel Sambuc ** successfully. An [error code] is returned otherwise.)^ 494311be35a1SLionel Sambuc ** 494411be35a1SLionel Sambuc ** ^Shared cache is disabled by default. But this might change in 494511be35a1SLionel Sambuc ** future releases of SQLite. Applications that care about shared 494611be35a1SLionel Sambuc ** cache setting should set it explicitly. 494711be35a1SLionel Sambuc ** 4948*0a6a1f1dSLionel Sambuc ** This interface is threadsafe on processors where writing a 4949*0a6a1f1dSLionel Sambuc ** 32-bit integer is atomic. 4950*0a6a1f1dSLionel Sambuc ** 495111be35a1SLionel Sambuc ** See Also: [SQLite Shared-Cache Mode] 495211be35a1SLionel Sambuc */ 495311be35a1SLionel Sambuc SQLITE_API int sqlite3_enable_shared_cache(int); 495411be35a1SLionel Sambuc 495511be35a1SLionel Sambuc /* 495611be35a1SLionel Sambuc ** CAPI3REF: Attempt To Free Heap Memory 495711be35a1SLionel Sambuc ** 495811be35a1SLionel Sambuc ** ^The sqlite3_release_memory() interface attempts to free N bytes 495911be35a1SLionel Sambuc ** of heap memory by deallocating non-essential memory allocations 496011be35a1SLionel Sambuc ** held by the database library. Memory used to cache database 496111be35a1SLionel Sambuc ** pages to improve performance is an example of non-essential memory. 496211be35a1SLionel Sambuc ** ^sqlite3_release_memory() returns the number of bytes actually freed, 496311be35a1SLionel Sambuc ** which might be more or less than the amount requested. 496411be35a1SLionel Sambuc ** ^The sqlite3_release_memory() routine is a no-op returning zero 496511be35a1SLionel Sambuc ** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT]. 496611be35a1SLionel Sambuc ** 496711be35a1SLionel Sambuc ** See also: [sqlite3_db_release_memory()] 496811be35a1SLionel Sambuc */ 496911be35a1SLionel Sambuc SQLITE_API int sqlite3_release_memory(int); 497011be35a1SLionel Sambuc 497111be35a1SLionel Sambuc /* 497211be35a1SLionel Sambuc ** CAPI3REF: Free Memory Used By A Database Connection 497311be35a1SLionel Sambuc ** 497411be35a1SLionel Sambuc ** ^The sqlite3_db_release_memory(D) interface attempts to free as much heap 497511be35a1SLionel Sambuc ** memory as possible from database connection D. Unlike the 4976*0a6a1f1dSLionel Sambuc ** [sqlite3_release_memory()] interface, this interface is in effect even 4977*0a6a1f1dSLionel Sambuc ** when the [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is 497811be35a1SLionel Sambuc ** omitted. 497911be35a1SLionel Sambuc ** 498011be35a1SLionel Sambuc ** See also: [sqlite3_release_memory()] 498111be35a1SLionel Sambuc */ 498211be35a1SLionel Sambuc SQLITE_API int sqlite3_db_release_memory(sqlite3*); 498311be35a1SLionel Sambuc 498411be35a1SLionel Sambuc /* 498511be35a1SLionel Sambuc ** CAPI3REF: Impose A Limit On Heap Size 498611be35a1SLionel Sambuc ** 498711be35a1SLionel Sambuc ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the 498811be35a1SLionel Sambuc ** soft limit on the amount of heap memory that may be allocated by SQLite. 498911be35a1SLionel Sambuc ** ^SQLite strives to keep heap memory utilization below the soft heap 499011be35a1SLionel Sambuc ** limit by reducing the number of pages held in the page cache 499111be35a1SLionel Sambuc ** as heap memory usages approaches the limit. 499211be35a1SLionel Sambuc ** ^The soft heap limit is "soft" because even though SQLite strives to stay 499311be35a1SLionel Sambuc ** below the limit, it will exceed the limit rather than generate 499411be35a1SLionel Sambuc ** an [SQLITE_NOMEM] error. In other words, the soft heap limit 499511be35a1SLionel Sambuc ** is advisory only. 499611be35a1SLionel Sambuc ** 499711be35a1SLionel Sambuc ** ^The return value from sqlite3_soft_heap_limit64() is the size of 499811be35a1SLionel Sambuc ** the soft heap limit prior to the call, or negative in the case of an 499911be35a1SLionel Sambuc ** error. ^If the argument N is negative 500011be35a1SLionel Sambuc ** then no change is made to the soft heap limit. Hence, the current 500111be35a1SLionel Sambuc ** size of the soft heap limit can be determined by invoking 500211be35a1SLionel Sambuc ** sqlite3_soft_heap_limit64() with a negative argument. 500311be35a1SLionel Sambuc ** 500411be35a1SLionel Sambuc ** ^If the argument N is zero then the soft heap limit is disabled. 500511be35a1SLionel Sambuc ** 500611be35a1SLionel Sambuc ** ^(The soft heap limit is not enforced in the current implementation 500711be35a1SLionel Sambuc ** if one or more of following conditions are true: 500811be35a1SLionel Sambuc ** 500911be35a1SLionel Sambuc ** <ul> 501011be35a1SLionel Sambuc ** <li> The soft heap limit is set to zero. 501111be35a1SLionel Sambuc ** <li> Memory accounting is disabled using a combination of the 501211be35a1SLionel Sambuc ** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and 501311be35a1SLionel Sambuc ** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option. 501411be35a1SLionel Sambuc ** <li> An alternative page cache implementation is specified using 501511be35a1SLionel Sambuc ** [sqlite3_config]([SQLITE_CONFIG_PCACHE2],...). 501611be35a1SLionel Sambuc ** <li> The page cache allocates from its own memory pool supplied 501711be35a1SLionel Sambuc ** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than 501811be35a1SLionel Sambuc ** from the heap. 501911be35a1SLionel Sambuc ** </ul>)^ 502011be35a1SLionel Sambuc ** 502111be35a1SLionel Sambuc ** Beginning with SQLite version 3.7.3, the soft heap limit is enforced 502211be35a1SLionel Sambuc ** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT] 502311be35a1SLionel Sambuc ** compile-time option is invoked. With [SQLITE_ENABLE_MEMORY_MANAGEMENT], 502411be35a1SLionel Sambuc ** the soft heap limit is enforced on every memory allocation. Without 502511be35a1SLionel Sambuc ** [SQLITE_ENABLE_MEMORY_MANAGEMENT], the soft heap limit is only enforced 502611be35a1SLionel Sambuc ** when memory is allocated by the page cache. Testing suggests that because 502711be35a1SLionel Sambuc ** the page cache is the predominate memory user in SQLite, most 502811be35a1SLionel Sambuc ** applications will achieve adequate soft heap limit enforcement without 502911be35a1SLionel Sambuc ** the use of [SQLITE_ENABLE_MEMORY_MANAGEMENT]. 503011be35a1SLionel Sambuc ** 503111be35a1SLionel Sambuc ** The circumstances under which SQLite will enforce the soft heap limit may 503211be35a1SLionel Sambuc ** changes in future releases of SQLite. 503311be35a1SLionel Sambuc */ 503411be35a1SLionel Sambuc SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N); 503511be35a1SLionel Sambuc 503611be35a1SLionel Sambuc /* 503711be35a1SLionel Sambuc ** CAPI3REF: Deprecated Soft Heap Limit Interface 503811be35a1SLionel Sambuc ** DEPRECATED 503911be35a1SLionel Sambuc ** 504011be35a1SLionel Sambuc ** This is a deprecated version of the [sqlite3_soft_heap_limit64()] 504111be35a1SLionel Sambuc ** interface. This routine is provided for historical compatibility 504211be35a1SLionel Sambuc ** only. All new applications should use the 504311be35a1SLionel Sambuc ** [sqlite3_soft_heap_limit64()] interface rather than this one. 504411be35a1SLionel Sambuc */ 504511be35a1SLionel Sambuc SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N); 504611be35a1SLionel Sambuc 504711be35a1SLionel Sambuc 504811be35a1SLionel Sambuc /* 504911be35a1SLionel Sambuc ** CAPI3REF: Extract Metadata About A Column Of A Table 505011be35a1SLionel Sambuc ** 505111be35a1SLionel Sambuc ** ^This routine returns metadata about a specific column of a specific 505211be35a1SLionel Sambuc ** database table accessible using the [database connection] handle 505311be35a1SLionel Sambuc ** passed as the first function argument. 505411be35a1SLionel Sambuc ** 505511be35a1SLionel Sambuc ** ^The column is identified by the second, third and fourth parameters to 505611be35a1SLionel Sambuc ** this function. ^The second parameter is either the name of the database 505711be35a1SLionel Sambuc ** (i.e. "main", "temp", or an attached database) containing the specified 505811be35a1SLionel Sambuc ** table or NULL. ^If it is NULL, then all attached databases are searched 505911be35a1SLionel Sambuc ** for the table using the same algorithm used by the database engine to 506011be35a1SLionel Sambuc ** resolve unqualified table references. 506111be35a1SLionel Sambuc ** 506211be35a1SLionel Sambuc ** ^The third and fourth parameters to this function are the table and column 506311be35a1SLionel Sambuc ** name of the desired column, respectively. Neither of these parameters 506411be35a1SLionel Sambuc ** may be NULL. 506511be35a1SLionel Sambuc ** 506611be35a1SLionel Sambuc ** ^Metadata is returned by writing to the memory locations passed as the 5th 506711be35a1SLionel Sambuc ** and subsequent parameters to this function. ^Any of these arguments may be 506811be35a1SLionel Sambuc ** NULL, in which case the corresponding element of metadata is omitted. 506911be35a1SLionel Sambuc ** 507011be35a1SLionel Sambuc ** ^(<blockquote> 507111be35a1SLionel Sambuc ** <table border="1"> 507211be35a1SLionel Sambuc ** <tr><th> Parameter <th> Output<br>Type <th> Description 507311be35a1SLionel Sambuc ** 507411be35a1SLionel Sambuc ** <tr><td> 5th <td> const char* <td> Data type 507511be35a1SLionel Sambuc ** <tr><td> 6th <td> const char* <td> Name of default collation sequence 507611be35a1SLionel Sambuc ** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint 507711be35a1SLionel Sambuc ** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY 507811be35a1SLionel Sambuc ** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT] 507911be35a1SLionel Sambuc ** </table> 508011be35a1SLionel Sambuc ** </blockquote>)^ 508111be35a1SLionel Sambuc ** 508211be35a1SLionel Sambuc ** ^The memory pointed to by the character pointers returned for the 508311be35a1SLionel Sambuc ** declaration type and collation sequence is valid only until the next 508411be35a1SLionel Sambuc ** call to any SQLite API function. 508511be35a1SLionel Sambuc ** 508611be35a1SLionel Sambuc ** ^If the specified table is actually a view, an [error code] is returned. 508711be35a1SLionel Sambuc ** 508811be35a1SLionel Sambuc ** ^If the specified column is "rowid", "oid" or "_rowid_" and an 508911be35a1SLionel Sambuc ** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output 509011be35a1SLionel Sambuc ** parameters are set for the explicitly declared column. ^(If there is no 509111be35a1SLionel Sambuc ** explicitly declared [INTEGER PRIMARY KEY] column, then the output 509211be35a1SLionel Sambuc ** parameters are set as follows: 509311be35a1SLionel Sambuc ** 509411be35a1SLionel Sambuc ** <pre> 509511be35a1SLionel Sambuc ** data type: "INTEGER" 509611be35a1SLionel Sambuc ** collation sequence: "BINARY" 509711be35a1SLionel Sambuc ** not null: 0 509811be35a1SLionel Sambuc ** primary key: 1 509911be35a1SLionel Sambuc ** auto increment: 0 510011be35a1SLionel Sambuc ** </pre>)^ 510111be35a1SLionel Sambuc ** 510211be35a1SLionel Sambuc ** ^(This function may load one or more schemas from database files. If an 510311be35a1SLionel Sambuc ** error occurs during this process, or if the requested table or column 510411be35a1SLionel Sambuc ** cannot be found, an [error code] is returned and an error message left 510511be35a1SLionel Sambuc ** in the [database connection] (to be retrieved using sqlite3_errmsg()).)^ 510611be35a1SLionel Sambuc ** 510711be35a1SLionel Sambuc ** ^This API is only available if the library was compiled with the 510811be35a1SLionel Sambuc ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined. 510911be35a1SLionel Sambuc */ 511011be35a1SLionel Sambuc SQLITE_API int sqlite3_table_column_metadata( 511111be35a1SLionel Sambuc sqlite3 *db, /* Connection handle */ 511211be35a1SLionel Sambuc const char *zDbName, /* Database name or NULL */ 511311be35a1SLionel Sambuc const char *zTableName, /* Table name */ 511411be35a1SLionel Sambuc const char *zColumnName, /* Column name */ 511511be35a1SLionel Sambuc char const **pzDataType, /* OUTPUT: Declared data type */ 511611be35a1SLionel Sambuc char const **pzCollSeq, /* OUTPUT: Collation sequence name */ 511711be35a1SLionel Sambuc int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */ 511811be35a1SLionel Sambuc int *pPrimaryKey, /* OUTPUT: True if column part of PK */ 511911be35a1SLionel Sambuc int *pAutoinc /* OUTPUT: True if column is auto-increment */ 512011be35a1SLionel Sambuc ); 512111be35a1SLionel Sambuc 512211be35a1SLionel Sambuc /* 512311be35a1SLionel Sambuc ** CAPI3REF: Load An Extension 512411be35a1SLionel Sambuc ** 512511be35a1SLionel Sambuc ** ^This interface loads an SQLite extension library from the named file. 512611be35a1SLionel Sambuc ** 512711be35a1SLionel Sambuc ** ^The sqlite3_load_extension() interface attempts to load an 5128*0a6a1f1dSLionel Sambuc ** [SQLite extension] library contained in the file zFile. If 5129*0a6a1f1dSLionel Sambuc ** the file cannot be loaded directly, attempts are made to load 5130*0a6a1f1dSLionel Sambuc ** with various operating-system specific extensions added. 5131*0a6a1f1dSLionel Sambuc ** So for example, if "samplelib" cannot be loaded, then names like 5132*0a6a1f1dSLionel Sambuc ** "samplelib.so" or "samplelib.dylib" or "samplelib.dll" might 5133*0a6a1f1dSLionel Sambuc ** be tried also. 513411be35a1SLionel Sambuc ** 513511be35a1SLionel Sambuc ** ^The entry point is zProc. 5136*0a6a1f1dSLionel Sambuc ** ^(zProc may be 0, in which case SQLite will try to come up with an 5137*0a6a1f1dSLionel Sambuc ** entry point name on its own. It first tries "sqlite3_extension_init". 5138*0a6a1f1dSLionel Sambuc ** If that does not work, it constructs a name "sqlite3_X_init" where the 5139*0a6a1f1dSLionel Sambuc ** X is consists of the lower-case equivalent of all ASCII alphabetic 5140*0a6a1f1dSLionel Sambuc ** characters in the filename from the last "/" to the first following 5141*0a6a1f1dSLionel Sambuc ** "." and omitting any initial "lib".)^ 514211be35a1SLionel Sambuc ** ^The sqlite3_load_extension() interface returns 514311be35a1SLionel Sambuc ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong. 514411be35a1SLionel Sambuc ** ^If an error occurs and pzErrMsg is not 0, then the 514511be35a1SLionel Sambuc ** [sqlite3_load_extension()] interface shall attempt to 514611be35a1SLionel Sambuc ** fill *pzErrMsg with error message text stored in memory 514711be35a1SLionel Sambuc ** obtained from [sqlite3_malloc()]. The calling function 514811be35a1SLionel Sambuc ** should free this memory by calling [sqlite3_free()]. 514911be35a1SLionel Sambuc ** 515011be35a1SLionel Sambuc ** ^Extension loading must be enabled using 515111be35a1SLionel Sambuc ** [sqlite3_enable_load_extension()] prior to calling this API, 515211be35a1SLionel Sambuc ** otherwise an error will be returned. 515311be35a1SLionel Sambuc ** 515411be35a1SLionel Sambuc ** See also the [load_extension() SQL function]. 515511be35a1SLionel Sambuc */ 515611be35a1SLionel Sambuc SQLITE_API int sqlite3_load_extension( 515711be35a1SLionel Sambuc sqlite3 *db, /* Load the extension into this database connection */ 515811be35a1SLionel Sambuc const char *zFile, /* Name of the shared library containing extension */ 515911be35a1SLionel Sambuc const char *zProc, /* Entry point. Derived from zFile if 0 */ 516011be35a1SLionel Sambuc char **pzErrMsg /* Put error message here if not 0 */ 516111be35a1SLionel Sambuc ); 516211be35a1SLionel Sambuc 516311be35a1SLionel Sambuc /* 516411be35a1SLionel Sambuc ** CAPI3REF: Enable Or Disable Extension Loading 516511be35a1SLionel Sambuc ** 516611be35a1SLionel Sambuc ** ^So as not to open security holes in older applications that are 5167*0a6a1f1dSLionel Sambuc ** unprepared to deal with [extension loading], and as a means of disabling 5168*0a6a1f1dSLionel Sambuc ** [extension loading] while evaluating user-entered SQL, the following API 516911be35a1SLionel Sambuc ** is provided to turn the [sqlite3_load_extension()] mechanism on and off. 517011be35a1SLionel Sambuc ** 5171*0a6a1f1dSLionel Sambuc ** ^Extension loading is off by default. 517211be35a1SLionel Sambuc ** ^Call the sqlite3_enable_load_extension() routine with onoff==1 517311be35a1SLionel Sambuc ** to turn extension loading on and call it with onoff==0 to turn 517411be35a1SLionel Sambuc ** it back off again. 517511be35a1SLionel Sambuc */ 517611be35a1SLionel Sambuc SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff); 517711be35a1SLionel Sambuc 517811be35a1SLionel Sambuc /* 517911be35a1SLionel Sambuc ** CAPI3REF: Automatically Load Statically Linked Extensions 518011be35a1SLionel Sambuc ** 518111be35a1SLionel Sambuc ** ^This interface causes the xEntryPoint() function to be invoked for 518211be35a1SLionel Sambuc ** each new [database connection] that is created. The idea here is that 5183*0a6a1f1dSLionel Sambuc ** xEntryPoint() is the entry point for a statically linked [SQLite extension] 518411be35a1SLionel Sambuc ** that is to be automatically loaded into all new database connections. 518511be35a1SLionel Sambuc ** 518611be35a1SLionel Sambuc ** ^(Even though the function prototype shows that xEntryPoint() takes 518711be35a1SLionel Sambuc ** no arguments and returns void, SQLite invokes xEntryPoint() with three 518811be35a1SLionel Sambuc ** arguments and expects and integer result as if the signature of the 518911be35a1SLionel Sambuc ** entry point where as follows: 519011be35a1SLionel Sambuc ** 519111be35a1SLionel Sambuc ** <blockquote><pre> 519211be35a1SLionel Sambuc ** int xEntryPoint( 519311be35a1SLionel Sambuc ** sqlite3 *db, 519411be35a1SLionel Sambuc ** const char **pzErrMsg, 519511be35a1SLionel Sambuc ** const struct sqlite3_api_routines *pThunk 519611be35a1SLionel Sambuc ** ); 519711be35a1SLionel Sambuc ** </pre></blockquote>)^ 519811be35a1SLionel Sambuc ** 519911be35a1SLionel Sambuc ** If the xEntryPoint routine encounters an error, it should make *pzErrMsg 520011be35a1SLionel Sambuc ** point to an appropriate error message (obtained from [sqlite3_mprintf()]) 520111be35a1SLionel Sambuc ** and return an appropriate [error code]. ^SQLite ensures that *pzErrMsg 520211be35a1SLionel Sambuc ** is NULL before calling the xEntryPoint(). ^SQLite will invoke 520311be35a1SLionel Sambuc ** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns. ^If any 520411be35a1SLionel Sambuc ** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()], 520511be35a1SLionel Sambuc ** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail. 520611be35a1SLionel Sambuc ** 520711be35a1SLionel Sambuc ** ^Calling sqlite3_auto_extension(X) with an entry point X that is already 520811be35a1SLionel Sambuc ** on the list of automatic extensions is a harmless no-op. ^No entry point 520911be35a1SLionel Sambuc ** will be called more than once for each database connection that is opened. 521011be35a1SLionel Sambuc ** 5211*0a6a1f1dSLionel Sambuc ** See also: [sqlite3_reset_auto_extension()] 5212*0a6a1f1dSLionel Sambuc ** and [sqlite3_cancel_auto_extension()] 521311be35a1SLionel Sambuc */ 521411be35a1SLionel Sambuc SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void)); 521511be35a1SLionel Sambuc 521611be35a1SLionel Sambuc /* 5217*0a6a1f1dSLionel Sambuc ** CAPI3REF: Cancel Automatic Extension Loading 5218*0a6a1f1dSLionel Sambuc ** 5219*0a6a1f1dSLionel Sambuc ** ^The [sqlite3_cancel_auto_extension(X)] interface unregisters the 5220*0a6a1f1dSLionel Sambuc ** initialization routine X that was registered using a prior call to 5221*0a6a1f1dSLionel Sambuc ** [sqlite3_auto_extension(X)]. ^The [sqlite3_cancel_auto_extension(X)] 5222*0a6a1f1dSLionel Sambuc ** routine returns 1 if initialization routine X was successfully 5223*0a6a1f1dSLionel Sambuc ** unregistered and it returns 0 if X was not on the list of initialization 5224*0a6a1f1dSLionel Sambuc ** routines. 5225*0a6a1f1dSLionel Sambuc */ 5226*0a6a1f1dSLionel Sambuc SQLITE_API int sqlite3_cancel_auto_extension(void (*xEntryPoint)(void)); 5227*0a6a1f1dSLionel Sambuc 5228*0a6a1f1dSLionel Sambuc /* 522911be35a1SLionel Sambuc ** CAPI3REF: Reset Automatic Extension Loading 523011be35a1SLionel Sambuc ** 523111be35a1SLionel Sambuc ** ^This interface disables all automatic extensions previously 523211be35a1SLionel Sambuc ** registered using [sqlite3_auto_extension()]. 523311be35a1SLionel Sambuc */ 523411be35a1SLionel Sambuc SQLITE_API void sqlite3_reset_auto_extension(void); 523511be35a1SLionel Sambuc 523611be35a1SLionel Sambuc /* 523711be35a1SLionel Sambuc ** The interface to the virtual-table mechanism is currently considered 523811be35a1SLionel Sambuc ** to be experimental. The interface might change in incompatible ways. 523911be35a1SLionel Sambuc ** If this is a problem for you, do not use the interface at this time. 524011be35a1SLionel Sambuc ** 524111be35a1SLionel Sambuc ** When the virtual-table mechanism stabilizes, we will declare the 524211be35a1SLionel Sambuc ** interface fixed, support it indefinitely, and remove this comment. 524311be35a1SLionel Sambuc */ 524411be35a1SLionel Sambuc 524511be35a1SLionel Sambuc /* 524611be35a1SLionel Sambuc ** Structures used by the virtual table interface 524711be35a1SLionel Sambuc */ 524811be35a1SLionel Sambuc typedef struct sqlite3_vtab sqlite3_vtab; 524911be35a1SLionel Sambuc typedef struct sqlite3_index_info sqlite3_index_info; 525011be35a1SLionel Sambuc typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor; 525111be35a1SLionel Sambuc typedef struct sqlite3_module sqlite3_module; 525211be35a1SLionel Sambuc 525311be35a1SLionel Sambuc /* 525411be35a1SLionel Sambuc ** CAPI3REF: Virtual Table Object 525511be35a1SLionel Sambuc ** KEYWORDS: sqlite3_module {virtual table module} 525611be35a1SLionel Sambuc ** 525711be35a1SLionel Sambuc ** This structure, sometimes called a "virtual table module", 525811be35a1SLionel Sambuc ** defines the implementation of a [virtual tables]. 525911be35a1SLionel Sambuc ** This structure consists mostly of methods for the module. 526011be35a1SLionel Sambuc ** 526111be35a1SLionel Sambuc ** ^A virtual table module is created by filling in a persistent 526211be35a1SLionel Sambuc ** instance of this structure and passing a pointer to that instance 526311be35a1SLionel Sambuc ** to [sqlite3_create_module()] or [sqlite3_create_module_v2()]. 526411be35a1SLionel Sambuc ** ^The registration remains valid until it is replaced by a different 526511be35a1SLionel Sambuc ** module or until the [database connection] closes. The content 526611be35a1SLionel Sambuc ** of this structure must not change while it is registered with 526711be35a1SLionel Sambuc ** any database connection. 526811be35a1SLionel Sambuc */ 526911be35a1SLionel Sambuc struct sqlite3_module { 527011be35a1SLionel Sambuc int iVersion; 527111be35a1SLionel Sambuc int (*xCreate)(sqlite3*, void *pAux, 527211be35a1SLionel Sambuc int argc, const char *const*argv, 527311be35a1SLionel Sambuc sqlite3_vtab **ppVTab, char**); 527411be35a1SLionel Sambuc int (*xConnect)(sqlite3*, void *pAux, 527511be35a1SLionel Sambuc int argc, const char *const*argv, 527611be35a1SLionel Sambuc sqlite3_vtab **ppVTab, char**); 527711be35a1SLionel Sambuc int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*); 527811be35a1SLionel Sambuc int (*xDisconnect)(sqlite3_vtab *pVTab); 527911be35a1SLionel Sambuc int (*xDestroy)(sqlite3_vtab *pVTab); 528011be35a1SLionel Sambuc int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor); 528111be35a1SLionel Sambuc int (*xClose)(sqlite3_vtab_cursor*); 528211be35a1SLionel Sambuc int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr, 528311be35a1SLionel Sambuc int argc, sqlite3_value **argv); 528411be35a1SLionel Sambuc int (*xNext)(sqlite3_vtab_cursor*); 528511be35a1SLionel Sambuc int (*xEof)(sqlite3_vtab_cursor*); 528611be35a1SLionel Sambuc int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int); 528711be35a1SLionel Sambuc int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid); 528811be35a1SLionel Sambuc int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *); 528911be35a1SLionel Sambuc int (*xBegin)(sqlite3_vtab *pVTab); 529011be35a1SLionel Sambuc int (*xSync)(sqlite3_vtab *pVTab); 529111be35a1SLionel Sambuc int (*xCommit)(sqlite3_vtab *pVTab); 529211be35a1SLionel Sambuc int (*xRollback)(sqlite3_vtab *pVTab); 529311be35a1SLionel Sambuc int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName, 529411be35a1SLionel Sambuc void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), 529511be35a1SLionel Sambuc void **ppArg); 529611be35a1SLionel Sambuc int (*xRename)(sqlite3_vtab *pVtab, const char *zNew); 529711be35a1SLionel Sambuc /* The methods above are in version 1 of the sqlite_module object. Those 529811be35a1SLionel Sambuc ** below are for version 2 and greater. */ 529911be35a1SLionel Sambuc int (*xSavepoint)(sqlite3_vtab *pVTab, int); 530011be35a1SLionel Sambuc int (*xRelease)(sqlite3_vtab *pVTab, int); 530111be35a1SLionel Sambuc int (*xRollbackTo)(sqlite3_vtab *pVTab, int); 530211be35a1SLionel Sambuc }; 530311be35a1SLionel Sambuc 530411be35a1SLionel Sambuc /* 530511be35a1SLionel Sambuc ** CAPI3REF: Virtual Table Indexing Information 530611be35a1SLionel Sambuc ** KEYWORDS: sqlite3_index_info 530711be35a1SLionel Sambuc ** 530811be35a1SLionel Sambuc ** The sqlite3_index_info structure and its substructures is used as part 530911be35a1SLionel Sambuc ** of the [virtual table] interface to 531011be35a1SLionel Sambuc ** pass information into and receive the reply from the [xBestIndex] 531111be35a1SLionel Sambuc ** method of a [virtual table module]. The fields under **Inputs** are the 531211be35a1SLionel Sambuc ** inputs to xBestIndex and are read-only. xBestIndex inserts its 531311be35a1SLionel Sambuc ** results into the **Outputs** fields. 531411be35a1SLionel Sambuc ** 531511be35a1SLionel Sambuc ** ^(The aConstraint[] array records WHERE clause constraints of the form: 531611be35a1SLionel Sambuc ** 531711be35a1SLionel Sambuc ** <blockquote>column OP expr</blockquote> 531811be35a1SLionel Sambuc ** 531911be35a1SLionel Sambuc ** where OP is =, <, <=, >, or >=.)^ ^(The particular operator is 532011be35a1SLionel Sambuc ** stored in aConstraint[].op using one of the 532111be35a1SLionel Sambuc ** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^ 532211be35a1SLionel Sambuc ** ^(The index of the column is stored in 532311be35a1SLionel Sambuc ** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the 532411be35a1SLionel Sambuc ** expr on the right-hand side can be evaluated (and thus the constraint 532511be35a1SLionel Sambuc ** is usable) and false if it cannot.)^ 532611be35a1SLionel Sambuc ** 532711be35a1SLionel Sambuc ** ^The optimizer automatically inverts terms of the form "expr OP column" 532811be35a1SLionel Sambuc ** and makes other simplifications to the WHERE clause in an attempt to 532911be35a1SLionel Sambuc ** get as many WHERE clause terms into the form shown above as possible. 533011be35a1SLionel Sambuc ** ^The aConstraint[] array only reports WHERE clause terms that are 533111be35a1SLionel Sambuc ** relevant to the particular virtual table being queried. 533211be35a1SLionel Sambuc ** 533311be35a1SLionel Sambuc ** ^Information about the ORDER BY clause is stored in aOrderBy[]. 533411be35a1SLionel Sambuc ** ^Each term of aOrderBy records a column of the ORDER BY clause. 533511be35a1SLionel Sambuc ** 533611be35a1SLionel Sambuc ** The [xBestIndex] method must fill aConstraintUsage[] with information 533711be35a1SLionel Sambuc ** about what parameters to pass to xFilter. ^If argvIndex>0 then 533811be35a1SLionel Sambuc ** the right-hand side of the corresponding aConstraint[] is evaluated 533911be35a1SLionel Sambuc ** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit 534011be35a1SLionel Sambuc ** is true, then the constraint is assumed to be fully handled by the 534111be35a1SLionel Sambuc ** virtual table and is not checked again by SQLite.)^ 534211be35a1SLionel Sambuc ** 534311be35a1SLionel Sambuc ** ^The idxNum and idxPtr values are recorded and passed into the 534411be35a1SLionel Sambuc ** [xFilter] method. 534511be35a1SLionel Sambuc ** ^[sqlite3_free()] is used to free idxPtr if and only if 534611be35a1SLionel Sambuc ** needToFreeIdxPtr is true. 534711be35a1SLionel Sambuc ** 534811be35a1SLionel Sambuc ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in 534911be35a1SLionel Sambuc ** the correct order to satisfy the ORDER BY clause so that no separate 535011be35a1SLionel Sambuc ** sorting step is required. 535111be35a1SLionel Sambuc ** 5352*0a6a1f1dSLionel Sambuc ** ^The estimatedCost value is an estimate of the cost of a particular 5353*0a6a1f1dSLionel Sambuc ** strategy. A cost of N indicates that the cost of the strategy is similar 5354*0a6a1f1dSLionel Sambuc ** to a linear scan of an SQLite table with N rows. A cost of log(N) 5355*0a6a1f1dSLionel Sambuc ** indicates that the expense of the operation is similar to that of a 5356*0a6a1f1dSLionel Sambuc ** binary search on a unique indexed field of an SQLite table with N rows. 5357*0a6a1f1dSLionel Sambuc ** 5358*0a6a1f1dSLionel Sambuc ** ^The estimatedRows value is an estimate of the number of rows that 5359*0a6a1f1dSLionel Sambuc ** will be returned by the strategy. 5360*0a6a1f1dSLionel Sambuc ** 5361*0a6a1f1dSLionel Sambuc ** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info 5362*0a6a1f1dSLionel Sambuc ** structure for SQLite version 3.8.2. If a virtual table extension is 5363*0a6a1f1dSLionel Sambuc ** used with an SQLite version earlier than 3.8.2, the results of attempting 5364*0a6a1f1dSLionel Sambuc ** to read or write the estimatedRows field are undefined (but are likely 5365*0a6a1f1dSLionel Sambuc ** to included crashing the application). The estimatedRows field should 5366*0a6a1f1dSLionel Sambuc ** therefore only be used if [sqlite3_libversion_number()] returns a 5367*0a6a1f1dSLionel Sambuc ** value greater than or equal to 3008002. 536811be35a1SLionel Sambuc */ 536911be35a1SLionel Sambuc struct sqlite3_index_info { 537011be35a1SLionel Sambuc /* Inputs */ 537111be35a1SLionel Sambuc int nConstraint; /* Number of entries in aConstraint */ 537211be35a1SLionel Sambuc struct sqlite3_index_constraint { 537311be35a1SLionel Sambuc int iColumn; /* Column on left-hand side of constraint */ 537411be35a1SLionel Sambuc unsigned char op; /* Constraint operator */ 537511be35a1SLionel Sambuc unsigned char usable; /* True if this constraint is usable */ 537611be35a1SLionel Sambuc int iTermOffset; /* Used internally - xBestIndex should ignore */ 537711be35a1SLionel Sambuc } *aConstraint; /* Table of WHERE clause constraints */ 537811be35a1SLionel Sambuc int nOrderBy; /* Number of terms in the ORDER BY clause */ 537911be35a1SLionel Sambuc struct sqlite3_index_orderby { 538011be35a1SLionel Sambuc int iColumn; /* Column number */ 538111be35a1SLionel Sambuc unsigned char desc; /* True for DESC. False for ASC. */ 538211be35a1SLionel Sambuc } *aOrderBy; /* The ORDER BY clause */ 538311be35a1SLionel Sambuc /* Outputs */ 538411be35a1SLionel Sambuc struct sqlite3_index_constraint_usage { 538511be35a1SLionel Sambuc int argvIndex; /* if >0, constraint is part of argv to xFilter */ 538611be35a1SLionel Sambuc unsigned char omit; /* Do not code a test for this constraint */ 538711be35a1SLionel Sambuc } *aConstraintUsage; 538811be35a1SLionel Sambuc int idxNum; /* Number used to identify the index */ 538911be35a1SLionel Sambuc char *idxStr; /* String, possibly obtained from sqlite3_malloc */ 539011be35a1SLionel Sambuc int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */ 539111be35a1SLionel Sambuc int orderByConsumed; /* True if output is already ordered */ 539211be35a1SLionel Sambuc double estimatedCost; /* Estimated cost of using this index */ 5393*0a6a1f1dSLionel Sambuc /* Fields below are only available in SQLite 3.8.2 and later */ 5394*0a6a1f1dSLionel Sambuc sqlite3_int64 estimatedRows; /* Estimated number of rows returned */ 539511be35a1SLionel Sambuc }; 539611be35a1SLionel Sambuc 539711be35a1SLionel Sambuc /* 539811be35a1SLionel Sambuc ** CAPI3REF: Virtual Table Constraint Operator Codes 539911be35a1SLionel Sambuc ** 540011be35a1SLionel Sambuc ** These macros defined the allowed values for the 540111be35a1SLionel Sambuc ** [sqlite3_index_info].aConstraint[].op field. Each value represents 540211be35a1SLionel Sambuc ** an operator that is part of a constraint term in the wHERE clause of 540311be35a1SLionel Sambuc ** a query that uses a [virtual table]. 540411be35a1SLionel Sambuc */ 540511be35a1SLionel Sambuc #define SQLITE_INDEX_CONSTRAINT_EQ 2 540611be35a1SLionel Sambuc #define SQLITE_INDEX_CONSTRAINT_GT 4 540711be35a1SLionel Sambuc #define SQLITE_INDEX_CONSTRAINT_LE 8 540811be35a1SLionel Sambuc #define SQLITE_INDEX_CONSTRAINT_LT 16 540911be35a1SLionel Sambuc #define SQLITE_INDEX_CONSTRAINT_GE 32 541011be35a1SLionel Sambuc #define SQLITE_INDEX_CONSTRAINT_MATCH 64 541111be35a1SLionel Sambuc 541211be35a1SLionel Sambuc /* 541311be35a1SLionel Sambuc ** CAPI3REF: Register A Virtual Table Implementation 541411be35a1SLionel Sambuc ** 541511be35a1SLionel Sambuc ** ^These routines are used to register a new [virtual table module] name. 541611be35a1SLionel Sambuc ** ^Module names must be registered before 541711be35a1SLionel Sambuc ** creating a new [virtual table] using the module and before using a 541811be35a1SLionel Sambuc ** preexisting [virtual table] for the module. 541911be35a1SLionel Sambuc ** 542011be35a1SLionel Sambuc ** ^The module name is registered on the [database connection] specified 542111be35a1SLionel Sambuc ** by the first parameter. ^The name of the module is given by the 542211be35a1SLionel Sambuc ** second parameter. ^The third parameter is a pointer to 542311be35a1SLionel Sambuc ** the implementation of the [virtual table module]. ^The fourth 542411be35a1SLionel Sambuc ** parameter is an arbitrary client data pointer that is passed through 542511be35a1SLionel Sambuc ** into the [xCreate] and [xConnect] methods of the virtual table module 542611be35a1SLionel Sambuc ** when a new virtual table is be being created or reinitialized. 542711be35a1SLionel Sambuc ** 542811be35a1SLionel Sambuc ** ^The sqlite3_create_module_v2() interface has a fifth parameter which 542911be35a1SLionel Sambuc ** is a pointer to a destructor for the pClientData. ^SQLite will 543011be35a1SLionel Sambuc ** invoke the destructor function (if it is not NULL) when SQLite 543111be35a1SLionel Sambuc ** no longer needs the pClientData pointer. ^The destructor will also 543211be35a1SLionel Sambuc ** be invoked if the call to sqlite3_create_module_v2() fails. 543311be35a1SLionel Sambuc ** ^The sqlite3_create_module() 543411be35a1SLionel Sambuc ** interface is equivalent to sqlite3_create_module_v2() with a NULL 543511be35a1SLionel Sambuc ** destructor. 543611be35a1SLionel Sambuc */ 543711be35a1SLionel Sambuc SQLITE_API int sqlite3_create_module( 543811be35a1SLionel Sambuc sqlite3 *db, /* SQLite connection to register module with */ 543911be35a1SLionel Sambuc const char *zName, /* Name of the module */ 544011be35a1SLionel Sambuc const sqlite3_module *p, /* Methods for the module */ 544111be35a1SLionel Sambuc void *pClientData /* Client data for xCreate/xConnect */ 544211be35a1SLionel Sambuc ); 544311be35a1SLionel Sambuc SQLITE_API int sqlite3_create_module_v2( 544411be35a1SLionel Sambuc sqlite3 *db, /* SQLite connection to register module with */ 544511be35a1SLionel Sambuc const char *zName, /* Name of the module */ 544611be35a1SLionel Sambuc const sqlite3_module *p, /* Methods for the module */ 544711be35a1SLionel Sambuc void *pClientData, /* Client data for xCreate/xConnect */ 544811be35a1SLionel Sambuc void(*xDestroy)(void*) /* Module destructor function */ 544911be35a1SLionel Sambuc ); 545011be35a1SLionel Sambuc 545111be35a1SLionel Sambuc /* 545211be35a1SLionel Sambuc ** CAPI3REF: Virtual Table Instance Object 545311be35a1SLionel Sambuc ** KEYWORDS: sqlite3_vtab 545411be35a1SLionel Sambuc ** 545511be35a1SLionel Sambuc ** Every [virtual table module] implementation uses a subclass 545611be35a1SLionel Sambuc ** of this object to describe a particular instance 545711be35a1SLionel Sambuc ** of the [virtual table]. Each subclass will 545811be35a1SLionel Sambuc ** be tailored to the specific needs of the module implementation. 545911be35a1SLionel Sambuc ** The purpose of this superclass is to define certain fields that are 546011be35a1SLionel Sambuc ** common to all module implementations. 546111be35a1SLionel Sambuc ** 546211be35a1SLionel Sambuc ** ^Virtual tables methods can set an error message by assigning a 546311be35a1SLionel Sambuc ** string obtained from [sqlite3_mprintf()] to zErrMsg. The method should 546411be35a1SLionel Sambuc ** take care that any prior string is freed by a call to [sqlite3_free()] 546511be35a1SLionel Sambuc ** prior to assigning a new string to zErrMsg. ^After the error message 546611be35a1SLionel Sambuc ** is delivered up to the client application, the string will be automatically 546711be35a1SLionel Sambuc ** freed by sqlite3_free() and the zErrMsg field will be zeroed. 546811be35a1SLionel Sambuc */ 546911be35a1SLionel Sambuc struct sqlite3_vtab { 547011be35a1SLionel Sambuc const sqlite3_module *pModule; /* The module for this virtual table */ 547111be35a1SLionel Sambuc int nRef; /* NO LONGER USED */ 547211be35a1SLionel Sambuc char *zErrMsg; /* Error message from sqlite3_mprintf() */ 547311be35a1SLionel Sambuc /* Virtual table implementations will typically add additional fields */ 547411be35a1SLionel Sambuc }; 547511be35a1SLionel Sambuc 547611be35a1SLionel Sambuc /* 547711be35a1SLionel Sambuc ** CAPI3REF: Virtual Table Cursor Object 547811be35a1SLionel Sambuc ** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor} 547911be35a1SLionel Sambuc ** 548011be35a1SLionel Sambuc ** Every [virtual table module] implementation uses a subclass of the 548111be35a1SLionel Sambuc ** following structure to describe cursors that point into the 548211be35a1SLionel Sambuc ** [virtual table] and are used 548311be35a1SLionel Sambuc ** to loop through the virtual table. Cursors are created using the 548411be35a1SLionel Sambuc ** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed 548511be35a1SLionel Sambuc ** by the [sqlite3_module.xClose | xClose] method. Cursors are used 548611be35a1SLionel Sambuc ** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods 548711be35a1SLionel Sambuc ** of the module. Each module implementation will define 548811be35a1SLionel Sambuc ** the content of a cursor structure to suit its own needs. 548911be35a1SLionel Sambuc ** 549011be35a1SLionel Sambuc ** This superclass exists in order to define fields of the cursor that 549111be35a1SLionel Sambuc ** are common to all implementations. 549211be35a1SLionel Sambuc */ 549311be35a1SLionel Sambuc struct sqlite3_vtab_cursor { 549411be35a1SLionel Sambuc sqlite3_vtab *pVtab; /* Virtual table of this cursor */ 549511be35a1SLionel Sambuc /* Virtual table implementations will typically add additional fields */ 549611be35a1SLionel Sambuc }; 549711be35a1SLionel Sambuc 549811be35a1SLionel Sambuc /* 549911be35a1SLionel Sambuc ** CAPI3REF: Declare The Schema Of A Virtual Table 550011be35a1SLionel Sambuc ** 550111be35a1SLionel Sambuc ** ^The [xCreate] and [xConnect] methods of a 550211be35a1SLionel Sambuc ** [virtual table module] call this interface 550311be35a1SLionel Sambuc ** to declare the format (the names and datatypes of the columns) of 550411be35a1SLionel Sambuc ** the virtual tables they implement. 550511be35a1SLionel Sambuc */ 550611be35a1SLionel Sambuc SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL); 550711be35a1SLionel Sambuc 550811be35a1SLionel Sambuc /* 550911be35a1SLionel Sambuc ** CAPI3REF: Overload A Function For A Virtual Table 551011be35a1SLionel Sambuc ** 551111be35a1SLionel Sambuc ** ^(Virtual tables can provide alternative implementations of functions 551211be35a1SLionel Sambuc ** using the [xFindFunction] method of the [virtual table module]. 551311be35a1SLionel Sambuc ** But global versions of those functions 551411be35a1SLionel Sambuc ** must exist in order to be overloaded.)^ 551511be35a1SLionel Sambuc ** 551611be35a1SLionel Sambuc ** ^(This API makes sure a global version of a function with a particular 551711be35a1SLionel Sambuc ** name and number of parameters exists. If no such function exists 551811be35a1SLionel Sambuc ** before this API is called, a new function is created.)^ ^The implementation 551911be35a1SLionel Sambuc ** of the new function always causes an exception to be thrown. So 552011be35a1SLionel Sambuc ** the new function is not good for anything by itself. Its only 552111be35a1SLionel Sambuc ** purpose is to be a placeholder function that can be overloaded 552211be35a1SLionel Sambuc ** by a [virtual table]. 552311be35a1SLionel Sambuc */ 552411be35a1SLionel Sambuc SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg); 552511be35a1SLionel Sambuc 552611be35a1SLionel Sambuc /* 552711be35a1SLionel Sambuc ** The interface to the virtual-table mechanism defined above (back up 552811be35a1SLionel Sambuc ** to a comment remarkably similar to this one) is currently considered 552911be35a1SLionel Sambuc ** to be experimental. The interface might change in incompatible ways. 553011be35a1SLionel Sambuc ** If this is a problem for you, do not use the interface at this time. 553111be35a1SLionel Sambuc ** 553211be35a1SLionel Sambuc ** When the virtual-table mechanism stabilizes, we will declare the 553311be35a1SLionel Sambuc ** interface fixed, support it indefinitely, and remove this comment. 553411be35a1SLionel Sambuc */ 553511be35a1SLionel Sambuc 553611be35a1SLionel Sambuc /* 553711be35a1SLionel Sambuc ** CAPI3REF: A Handle To An Open BLOB 553811be35a1SLionel Sambuc ** KEYWORDS: {BLOB handle} {BLOB handles} 553911be35a1SLionel Sambuc ** 554011be35a1SLionel Sambuc ** An instance of this object represents an open BLOB on which 554111be35a1SLionel Sambuc ** [sqlite3_blob_open | incremental BLOB I/O] can be performed. 554211be35a1SLionel Sambuc ** ^Objects of this type are created by [sqlite3_blob_open()] 554311be35a1SLionel Sambuc ** and destroyed by [sqlite3_blob_close()]. 554411be35a1SLionel Sambuc ** ^The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces 554511be35a1SLionel Sambuc ** can be used to read or write small subsections of the BLOB. 554611be35a1SLionel Sambuc ** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes. 554711be35a1SLionel Sambuc */ 554811be35a1SLionel Sambuc typedef struct sqlite3_blob sqlite3_blob; 554911be35a1SLionel Sambuc 555011be35a1SLionel Sambuc /* 555111be35a1SLionel Sambuc ** CAPI3REF: Open A BLOB For Incremental I/O 555211be35a1SLionel Sambuc ** 555311be35a1SLionel Sambuc ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located 555411be35a1SLionel Sambuc ** in row iRow, column zColumn, table zTable in database zDb; 555511be35a1SLionel Sambuc ** in other words, the same BLOB that would be selected by: 555611be35a1SLionel Sambuc ** 555711be35a1SLionel Sambuc ** <pre> 555811be35a1SLionel Sambuc ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow; 555911be35a1SLionel Sambuc ** </pre>)^ 556011be35a1SLionel Sambuc ** 556111be35a1SLionel Sambuc ** ^If the flags parameter is non-zero, then the BLOB is opened for read 556211be35a1SLionel Sambuc ** and write access. ^If it is zero, the BLOB is opened for read access. 556311be35a1SLionel Sambuc ** ^It is not possible to open a column that is part of an index or primary 556411be35a1SLionel Sambuc ** key for writing. ^If [foreign key constraints] are enabled, it is 556511be35a1SLionel Sambuc ** not possible to open a column that is part of a [child key] for writing. 556611be35a1SLionel Sambuc ** 556711be35a1SLionel Sambuc ** ^Note that the database name is not the filename that contains 556811be35a1SLionel Sambuc ** the database but rather the symbolic name of the database that 556911be35a1SLionel Sambuc ** appears after the AS keyword when the database is connected using [ATTACH]. 557011be35a1SLionel Sambuc ** ^For the main database file, the database name is "main". 557111be35a1SLionel Sambuc ** ^For TEMP tables, the database name is "temp". 557211be35a1SLionel Sambuc ** 557311be35a1SLionel Sambuc ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is written 557411be35a1SLionel Sambuc ** to *ppBlob. Otherwise an [error code] is returned and *ppBlob is set 557511be35a1SLionel Sambuc ** to be a null pointer.)^ 557611be35a1SLionel Sambuc ** ^This function sets the [database connection] error code and message 557711be35a1SLionel Sambuc ** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()] and related 557811be35a1SLionel Sambuc ** functions. ^Note that the *ppBlob variable is always initialized in a 557911be35a1SLionel Sambuc ** way that makes it safe to invoke [sqlite3_blob_close()] on *ppBlob 558011be35a1SLionel Sambuc ** regardless of the success or failure of this routine. 558111be35a1SLionel Sambuc ** 558211be35a1SLionel Sambuc ** ^(If the row that a BLOB handle points to is modified by an 558311be35a1SLionel Sambuc ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects 558411be35a1SLionel Sambuc ** then the BLOB handle is marked as "expired". 558511be35a1SLionel Sambuc ** This is true if any column of the row is changed, even a column 558611be35a1SLionel Sambuc ** other than the one the BLOB handle is open on.)^ 558711be35a1SLionel Sambuc ** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for 558811be35a1SLionel Sambuc ** an expired BLOB handle fail with a return code of [SQLITE_ABORT]. 558911be35a1SLionel Sambuc ** ^(Changes written into a BLOB prior to the BLOB expiring are not 559011be35a1SLionel Sambuc ** rolled back by the expiration of the BLOB. Such changes will eventually 559111be35a1SLionel Sambuc ** commit if the transaction continues to completion.)^ 559211be35a1SLionel Sambuc ** 559311be35a1SLionel Sambuc ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of 559411be35a1SLionel Sambuc ** the opened blob. ^The size of a blob may not be changed by this 559511be35a1SLionel Sambuc ** interface. Use the [UPDATE] SQL command to change the size of a 559611be35a1SLionel Sambuc ** blob. 559711be35a1SLionel Sambuc ** 5598*0a6a1f1dSLionel Sambuc ** ^The [sqlite3_blob_open()] interface will fail for a [WITHOUT ROWID] 5599*0a6a1f1dSLionel Sambuc ** table. Incremental BLOB I/O is not possible on [WITHOUT ROWID] tables. 5600*0a6a1f1dSLionel Sambuc ** 560111be35a1SLionel Sambuc ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces 560211be35a1SLionel Sambuc ** and the built-in [zeroblob] SQL function can be used, if desired, 560311be35a1SLionel Sambuc ** to create an empty, zero-filled blob in which to read or write using 560411be35a1SLionel Sambuc ** this interface. 560511be35a1SLionel Sambuc ** 560611be35a1SLionel Sambuc ** To avoid a resource leak, every open [BLOB handle] should eventually 560711be35a1SLionel Sambuc ** be released by a call to [sqlite3_blob_close()]. 560811be35a1SLionel Sambuc */ 560911be35a1SLionel Sambuc SQLITE_API int sqlite3_blob_open( 561011be35a1SLionel Sambuc sqlite3*, 561111be35a1SLionel Sambuc const char *zDb, 561211be35a1SLionel Sambuc const char *zTable, 561311be35a1SLionel Sambuc const char *zColumn, 561411be35a1SLionel Sambuc sqlite3_int64 iRow, 561511be35a1SLionel Sambuc int flags, 561611be35a1SLionel Sambuc sqlite3_blob **ppBlob 561711be35a1SLionel Sambuc ); 561811be35a1SLionel Sambuc 561911be35a1SLionel Sambuc /* 562011be35a1SLionel Sambuc ** CAPI3REF: Move a BLOB Handle to a New Row 562111be35a1SLionel Sambuc ** 562211be35a1SLionel Sambuc ** ^This function is used to move an existing blob handle so that it points 562311be35a1SLionel Sambuc ** to a different row of the same database table. ^The new row is identified 562411be35a1SLionel Sambuc ** by the rowid value passed as the second argument. Only the row can be 562511be35a1SLionel Sambuc ** changed. ^The database, table and column on which the blob handle is open 562611be35a1SLionel Sambuc ** remain the same. Moving an existing blob handle to a new row can be 562711be35a1SLionel Sambuc ** faster than closing the existing handle and opening a new one. 562811be35a1SLionel Sambuc ** 562911be35a1SLionel Sambuc ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] - 563011be35a1SLionel Sambuc ** it must exist and there must be either a blob or text value stored in 563111be35a1SLionel Sambuc ** the nominated column.)^ ^If the new row is not present in the table, or if 563211be35a1SLionel Sambuc ** it does not contain a blob or text value, or if another error occurs, an 563311be35a1SLionel Sambuc ** SQLite error code is returned and the blob handle is considered aborted. 563411be35a1SLionel Sambuc ** ^All subsequent calls to [sqlite3_blob_read()], [sqlite3_blob_write()] or 563511be35a1SLionel Sambuc ** [sqlite3_blob_reopen()] on an aborted blob handle immediately return 563611be35a1SLionel Sambuc ** SQLITE_ABORT. ^Calling [sqlite3_blob_bytes()] on an aborted blob handle 563711be35a1SLionel Sambuc ** always returns zero. 563811be35a1SLionel Sambuc ** 563911be35a1SLionel Sambuc ** ^This function sets the database handle error code and message. 564011be35a1SLionel Sambuc */ 564111be35a1SLionel Sambuc SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); 564211be35a1SLionel Sambuc 564311be35a1SLionel Sambuc /* 564411be35a1SLionel Sambuc ** CAPI3REF: Close A BLOB Handle 564511be35a1SLionel Sambuc ** 564611be35a1SLionel Sambuc ** ^Closes an open [BLOB handle]. 564711be35a1SLionel Sambuc ** 564811be35a1SLionel Sambuc ** ^Closing a BLOB shall cause the current transaction to commit 564911be35a1SLionel Sambuc ** if there are no other BLOBs, no pending prepared statements, and the 565011be35a1SLionel Sambuc ** database connection is in [autocommit mode]. 565111be35a1SLionel Sambuc ** ^If any writes were made to the BLOB, they might be held in cache 565211be35a1SLionel Sambuc ** until the close operation if they will fit. 565311be35a1SLionel Sambuc ** 565411be35a1SLionel Sambuc ** ^(Closing the BLOB often forces the changes 565511be35a1SLionel Sambuc ** out to disk and so if any I/O errors occur, they will likely occur 565611be35a1SLionel Sambuc ** at the time when the BLOB is closed. Any errors that occur during 565711be35a1SLionel Sambuc ** closing are reported as a non-zero return value.)^ 565811be35a1SLionel Sambuc ** 565911be35a1SLionel Sambuc ** ^(The BLOB is closed unconditionally. Even if this routine returns 566011be35a1SLionel Sambuc ** an error code, the BLOB is still closed.)^ 566111be35a1SLionel Sambuc ** 566211be35a1SLionel Sambuc ** ^Calling this routine with a null pointer (such as would be returned 566311be35a1SLionel Sambuc ** by a failed call to [sqlite3_blob_open()]) is a harmless no-op. 566411be35a1SLionel Sambuc */ 566511be35a1SLionel Sambuc SQLITE_API int sqlite3_blob_close(sqlite3_blob *); 566611be35a1SLionel Sambuc 566711be35a1SLionel Sambuc /* 566811be35a1SLionel Sambuc ** CAPI3REF: Return The Size Of An Open BLOB 566911be35a1SLionel Sambuc ** 567011be35a1SLionel Sambuc ** ^Returns the size in bytes of the BLOB accessible via the 567111be35a1SLionel Sambuc ** successfully opened [BLOB handle] in its only argument. ^The 567211be35a1SLionel Sambuc ** incremental blob I/O routines can only read or overwriting existing 567311be35a1SLionel Sambuc ** blob content; they cannot change the size of a blob. 567411be35a1SLionel Sambuc ** 567511be35a1SLionel Sambuc ** This routine only works on a [BLOB handle] which has been created 567611be35a1SLionel Sambuc ** by a prior successful call to [sqlite3_blob_open()] and which has not 567711be35a1SLionel Sambuc ** been closed by [sqlite3_blob_close()]. Passing any other pointer in 567811be35a1SLionel Sambuc ** to this routine results in undefined and probably undesirable behavior. 567911be35a1SLionel Sambuc */ 568011be35a1SLionel Sambuc SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *); 568111be35a1SLionel Sambuc 568211be35a1SLionel Sambuc /* 568311be35a1SLionel Sambuc ** CAPI3REF: Read Data From A BLOB Incrementally 568411be35a1SLionel Sambuc ** 568511be35a1SLionel Sambuc ** ^(This function is used to read data from an open [BLOB handle] into a 568611be35a1SLionel Sambuc ** caller-supplied buffer. N bytes of data are copied into buffer Z 568711be35a1SLionel Sambuc ** from the open BLOB, starting at offset iOffset.)^ 568811be35a1SLionel Sambuc ** 568911be35a1SLionel Sambuc ** ^If offset iOffset is less than N bytes from the end of the BLOB, 569011be35a1SLionel Sambuc ** [SQLITE_ERROR] is returned and no data is read. ^If N or iOffset is 569111be35a1SLionel Sambuc ** less than zero, [SQLITE_ERROR] is returned and no data is read. 569211be35a1SLionel Sambuc ** ^The size of the blob (and hence the maximum value of N+iOffset) 569311be35a1SLionel Sambuc ** can be determined using the [sqlite3_blob_bytes()] interface. 569411be35a1SLionel Sambuc ** 569511be35a1SLionel Sambuc ** ^An attempt to read from an expired [BLOB handle] fails with an 569611be35a1SLionel Sambuc ** error code of [SQLITE_ABORT]. 569711be35a1SLionel Sambuc ** 569811be35a1SLionel Sambuc ** ^(On success, sqlite3_blob_read() returns SQLITE_OK. 569911be35a1SLionel Sambuc ** Otherwise, an [error code] or an [extended error code] is returned.)^ 570011be35a1SLionel Sambuc ** 570111be35a1SLionel Sambuc ** This routine only works on a [BLOB handle] which has been created 570211be35a1SLionel Sambuc ** by a prior successful call to [sqlite3_blob_open()] and which has not 570311be35a1SLionel Sambuc ** been closed by [sqlite3_blob_close()]. Passing any other pointer in 570411be35a1SLionel Sambuc ** to this routine results in undefined and probably undesirable behavior. 570511be35a1SLionel Sambuc ** 570611be35a1SLionel Sambuc ** See also: [sqlite3_blob_write()]. 570711be35a1SLionel Sambuc */ 570811be35a1SLionel Sambuc SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); 570911be35a1SLionel Sambuc 571011be35a1SLionel Sambuc /* 571111be35a1SLionel Sambuc ** CAPI3REF: Write Data Into A BLOB Incrementally 571211be35a1SLionel Sambuc ** 571311be35a1SLionel Sambuc ** ^This function is used to write data into an open [BLOB handle] from a 571411be35a1SLionel Sambuc ** caller-supplied buffer. ^N bytes of data are copied from the buffer Z 571511be35a1SLionel Sambuc ** into the open BLOB, starting at offset iOffset. 571611be35a1SLionel Sambuc ** 571711be35a1SLionel Sambuc ** ^If the [BLOB handle] passed as the first argument was not opened for 571811be35a1SLionel Sambuc ** writing (the flags parameter to [sqlite3_blob_open()] was zero), 571911be35a1SLionel Sambuc ** this function returns [SQLITE_READONLY]. 572011be35a1SLionel Sambuc ** 572111be35a1SLionel Sambuc ** ^This function may only modify the contents of the BLOB; it is 572211be35a1SLionel Sambuc ** not possible to increase the size of a BLOB using this API. 572311be35a1SLionel Sambuc ** ^If offset iOffset is less than N bytes from the end of the BLOB, 572411be35a1SLionel Sambuc ** [SQLITE_ERROR] is returned and no data is written. ^If N is 572511be35a1SLionel Sambuc ** less than zero [SQLITE_ERROR] is returned and no data is written. 572611be35a1SLionel Sambuc ** The size of the BLOB (and hence the maximum value of N+iOffset) 572711be35a1SLionel Sambuc ** can be determined using the [sqlite3_blob_bytes()] interface. 572811be35a1SLionel Sambuc ** 572911be35a1SLionel Sambuc ** ^An attempt to write to an expired [BLOB handle] fails with an 573011be35a1SLionel Sambuc ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred 573111be35a1SLionel Sambuc ** before the [BLOB handle] expired are not rolled back by the 573211be35a1SLionel Sambuc ** expiration of the handle, though of course those changes might 573311be35a1SLionel Sambuc ** have been overwritten by the statement that expired the BLOB handle 573411be35a1SLionel Sambuc ** or by other independent statements. 573511be35a1SLionel Sambuc ** 573611be35a1SLionel Sambuc ** ^(On success, sqlite3_blob_write() returns SQLITE_OK. 573711be35a1SLionel Sambuc ** Otherwise, an [error code] or an [extended error code] is returned.)^ 573811be35a1SLionel Sambuc ** 573911be35a1SLionel Sambuc ** This routine only works on a [BLOB handle] which has been created 574011be35a1SLionel Sambuc ** by a prior successful call to [sqlite3_blob_open()] and which has not 574111be35a1SLionel Sambuc ** been closed by [sqlite3_blob_close()]. Passing any other pointer in 574211be35a1SLionel Sambuc ** to this routine results in undefined and probably undesirable behavior. 574311be35a1SLionel Sambuc ** 574411be35a1SLionel Sambuc ** See also: [sqlite3_blob_read()]. 574511be35a1SLionel Sambuc */ 574611be35a1SLionel Sambuc SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset); 574711be35a1SLionel Sambuc 574811be35a1SLionel Sambuc /* 574911be35a1SLionel Sambuc ** CAPI3REF: Virtual File System Objects 575011be35a1SLionel Sambuc ** 575111be35a1SLionel Sambuc ** A virtual filesystem (VFS) is an [sqlite3_vfs] object 575211be35a1SLionel Sambuc ** that SQLite uses to interact 575311be35a1SLionel Sambuc ** with the underlying operating system. Most SQLite builds come with a 575411be35a1SLionel Sambuc ** single default VFS that is appropriate for the host computer. 575511be35a1SLionel Sambuc ** New VFSes can be registered and existing VFSes can be unregistered. 575611be35a1SLionel Sambuc ** The following interfaces are provided. 575711be35a1SLionel Sambuc ** 575811be35a1SLionel Sambuc ** ^The sqlite3_vfs_find() interface returns a pointer to a VFS given its name. 575911be35a1SLionel Sambuc ** ^Names are case sensitive. 576011be35a1SLionel Sambuc ** ^Names are zero-terminated UTF-8 strings. 576111be35a1SLionel Sambuc ** ^If there is no match, a NULL pointer is returned. 576211be35a1SLionel Sambuc ** ^If zVfsName is NULL then the default VFS is returned. 576311be35a1SLionel Sambuc ** 576411be35a1SLionel Sambuc ** ^New VFSes are registered with sqlite3_vfs_register(). 576511be35a1SLionel Sambuc ** ^Each new VFS becomes the default VFS if the makeDflt flag is set. 576611be35a1SLionel Sambuc ** ^The same VFS can be registered multiple times without injury. 576711be35a1SLionel Sambuc ** ^To make an existing VFS into the default VFS, register it again 576811be35a1SLionel Sambuc ** with the makeDflt flag set. If two different VFSes with the 576911be35a1SLionel Sambuc ** same name are registered, the behavior is undefined. If a 577011be35a1SLionel Sambuc ** VFS is registered with a name that is NULL or an empty string, 577111be35a1SLionel Sambuc ** then the behavior is undefined. 577211be35a1SLionel Sambuc ** 577311be35a1SLionel Sambuc ** ^Unregister a VFS with the sqlite3_vfs_unregister() interface. 577411be35a1SLionel Sambuc ** ^(If the default VFS is unregistered, another VFS is chosen as 577511be35a1SLionel Sambuc ** the default. The choice for the new VFS is arbitrary.)^ 577611be35a1SLionel Sambuc */ 577711be35a1SLionel Sambuc SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName); 577811be35a1SLionel Sambuc SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt); 577911be35a1SLionel Sambuc SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*); 578011be35a1SLionel Sambuc 578111be35a1SLionel Sambuc /* 578211be35a1SLionel Sambuc ** CAPI3REF: Mutexes 578311be35a1SLionel Sambuc ** 578411be35a1SLionel Sambuc ** The SQLite core uses these routines for thread 578511be35a1SLionel Sambuc ** synchronization. Though they are intended for internal 578611be35a1SLionel Sambuc ** use by SQLite, code that links against SQLite is 578711be35a1SLionel Sambuc ** permitted to use any of these routines. 578811be35a1SLionel Sambuc ** 578911be35a1SLionel Sambuc ** The SQLite source code contains multiple implementations 579011be35a1SLionel Sambuc ** of these mutex routines. An appropriate implementation 579111be35a1SLionel Sambuc ** is selected automatically at compile-time. ^(The following 579211be35a1SLionel Sambuc ** implementations are available in the SQLite core: 579311be35a1SLionel Sambuc ** 579411be35a1SLionel Sambuc ** <ul> 579511be35a1SLionel Sambuc ** <li> SQLITE_MUTEX_PTHREADS 579611be35a1SLionel Sambuc ** <li> SQLITE_MUTEX_W32 579711be35a1SLionel Sambuc ** <li> SQLITE_MUTEX_NOOP 579811be35a1SLionel Sambuc ** </ul>)^ 579911be35a1SLionel Sambuc ** 580011be35a1SLionel Sambuc ** ^The SQLITE_MUTEX_NOOP implementation is a set of routines 580111be35a1SLionel Sambuc ** that does no real locking and is appropriate for use in 5802*0a6a1f1dSLionel Sambuc ** a single-threaded application. ^The SQLITE_MUTEX_PTHREADS and 5803*0a6a1f1dSLionel Sambuc ** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix 5804*0a6a1f1dSLionel Sambuc ** and Windows. 580511be35a1SLionel Sambuc ** 580611be35a1SLionel Sambuc ** ^(If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor 580711be35a1SLionel Sambuc ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex 580811be35a1SLionel Sambuc ** implementation is included with the library. In this case the 580911be35a1SLionel Sambuc ** application must supply a custom mutex implementation using the 581011be35a1SLionel Sambuc ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function 581111be35a1SLionel Sambuc ** before calling sqlite3_initialize() or any other public sqlite3_ 581211be35a1SLionel Sambuc ** function that calls sqlite3_initialize().)^ 581311be35a1SLionel Sambuc ** 581411be35a1SLionel Sambuc ** ^The sqlite3_mutex_alloc() routine allocates a new 581511be35a1SLionel Sambuc ** mutex and returns a pointer to it. ^If it returns NULL 581611be35a1SLionel Sambuc ** that means that a mutex could not be allocated. ^SQLite 581711be35a1SLionel Sambuc ** will unwind its stack and return an error. ^(The argument 581811be35a1SLionel Sambuc ** to sqlite3_mutex_alloc() is one of these integer constants: 581911be35a1SLionel Sambuc ** 582011be35a1SLionel Sambuc ** <ul> 582111be35a1SLionel Sambuc ** <li> SQLITE_MUTEX_FAST 582211be35a1SLionel Sambuc ** <li> SQLITE_MUTEX_RECURSIVE 582311be35a1SLionel Sambuc ** <li> SQLITE_MUTEX_STATIC_MASTER 582411be35a1SLionel Sambuc ** <li> SQLITE_MUTEX_STATIC_MEM 582511be35a1SLionel Sambuc ** <li> SQLITE_MUTEX_STATIC_MEM2 582611be35a1SLionel Sambuc ** <li> SQLITE_MUTEX_STATIC_PRNG 582711be35a1SLionel Sambuc ** <li> SQLITE_MUTEX_STATIC_LRU 582811be35a1SLionel Sambuc ** <li> SQLITE_MUTEX_STATIC_LRU2 582911be35a1SLionel Sambuc ** </ul>)^ 583011be35a1SLionel Sambuc ** 583111be35a1SLionel Sambuc ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) 583211be35a1SLionel Sambuc ** cause sqlite3_mutex_alloc() to create 583311be35a1SLionel Sambuc ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE 583411be35a1SLionel Sambuc ** is used but not necessarily so when SQLITE_MUTEX_FAST is used. 583511be35a1SLionel Sambuc ** The mutex implementation does not need to make a distinction 583611be35a1SLionel Sambuc ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does 583711be35a1SLionel Sambuc ** not want to. ^SQLite will only request a recursive mutex in 583811be35a1SLionel Sambuc ** cases where it really needs one. ^If a faster non-recursive mutex 583911be35a1SLionel Sambuc ** implementation is available on the host platform, the mutex subsystem 584011be35a1SLionel Sambuc ** might return such a mutex in response to SQLITE_MUTEX_FAST. 584111be35a1SLionel Sambuc ** 584211be35a1SLionel Sambuc ** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other 584311be35a1SLionel Sambuc ** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return 584411be35a1SLionel Sambuc ** a pointer to a static preexisting mutex. ^Six static mutexes are 584511be35a1SLionel Sambuc ** used by the current version of SQLite. Future versions of SQLite 584611be35a1SLionel Sambuc ** may add additional static mutexes. Static mutexes are for internal 584711be35a1SLionel Sambuc ** use by SQLite only. Applications that use SQLite mutexes should 584811be35a1SLionel Sambuc ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or 584911be35a1SLionel Sambuc ** SQLITE_MUTEX_RECURSIVE. 585011be35a1SLionel Sambuc ** 585111be35a1SLionel Sambuc ** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST 585211be35a1SLionel Sambuc ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc() 585311be35a1SLionel Sambuc ** returns a different mutex on every call. ^But for the static 585411be35a1SLionel Sambuc ** mutex types, the same mutex is returned on every call that has 585511be35a1SLionel Sambuc ** the same type number. 585611be35a1SLionel Sambuc ** 585711be35a1SLionel Sambuc ** ^The sqlite3_mutex_free() routine deallocates a previously 585811be35a1SLionel Sambuc ** allocated dynamic mutex. ^SQLite is careful to deallocate every 585911be35a1SLionel Sambuc ** dynamic mutex that it allocates. The dynamic mutexes must not be in 586011be35a1SLionel Sambuc ** use when they are deallocated. Attempting to deallocate a static 586111be35a1SLionel Sambuc ** mutex results in undefined behavior. ^SQLite never deallocates 586211be35a1SLionel Sambuc ** a static mutex. 586311be35a1SLionel Sambuc ** 586411be35a1SLionel Sambuc ** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt 586511be35a1SLionel Sambuc ** to enter a mutex. ^If another thread is already within the mutex, 586611be35a1SLionel Sambuc ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return 586711be35a1SLionel Sambuc ** SQLITE_BUSY. ^The sqlite3_mutex_try() interface returns [SQLITE_OK] 586811be35a1SLionel Sambuc ** upon successful entry. ^(Mutexes created using 586911be35a1SLionel Sambuc ** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread. 587011be35a1SLionel Sambuc ** In such cases the, 587111be35a1SLionel Sambuc ** mutex must be exited an equal number of times before another thread 587211be35a1SLionel Sambuc ** can enter.)^ ^(If the same thread tries to enter any other 587311be35a1SLionel Sambuc ** kind of mutex more than once, the behavior is undefined. 587411be35a1SLionel Sambuc ** SQLite will never exhibit 587511be35a1SLionel Sambuc ** such behavior in its own use of mutexes.)^ 587611be35a1SLionel Sambuc ** 587711be35a1SLionel Sambuc ** ^(Some systems (for example, Windows 95) do not support the operation 587811be35a1SLionel Sambuc ** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try() 587911be35a1SLionel Sambuc ** will always return SQLITE_BUSY. The SQLite core only ever uses 588011be35a1SLionel Sambuc ** sqlite3_mutex_try() as an optimization so this is acceptable behavior.)^ 588111be35a1SLionel Sambuc ** 588211be35a1SLionel Sambuc ** ^The sqlite3_mutex_leave() routine exits a mutex that was 588311be35a1SLionel Sambuc ** previously entered by the same thread. ^(The behavior 588411be35a1SLionel Sambuc ** is undefined if the mutex is not currently entered by the 588511be35a1SLionel Sambuc ** calling thread or is not currently allocated. SQLite will 588611be35a1SLionel Sambuc ** never do either.)^ 588711be35a1SLionel Sambuc ** 588811be35a1SLionel Sambuc ** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or 588911be35a1SLionel Sambuc ** sqlite3_mutex_leave() is a NULL pointer, then all three routines 589011be35a1SLionel Sambuc ** behave as no-ops. 589111be35a1SLionel Sambuc ** 589211be35a1SLionel Sambuc ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()]. 589311be35a1SLionel Sambuc */ 589411be35a1SLionel Sambuc SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int); 589511be35a1SLionel Sambuc SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*); 589611be35a1SLionel Sambuc SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*); 589711be35a1SLionel Sambuc SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*); 589811be35a1SLionel Sambuc SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*); 589911be35a1SLionel Sambuc 590011be35a1SLionel Sambuc /* 590111be35a1SLionel Sambuc ** CAPI3REF: Mutex Methods Object 590211be35a1SLionel Sambuc ** 590311be35a1SLionel Sambuc ** An instance of this structure defines the low-level routines 590411be35a1SLionel Sambuc ** used to allocate and use mutexes. 590511be35a1SLionel Sambuc ** 590611be35a1SLionel Sambuc ** Usually, the default mutex implementations provided by SQLite are 590711be35a1SLionel Sambuc ** sufficient, however the user has the option of substituting a custom 590811be35a1SLionel Sambuc ** implementation for specialized deployments or systems for which SQLite 590911be35a1SLionel Sambuc ** does not provide a suitable implementation. In this case, the user 591011be35a1SLionel Sambuc ** creates and populates an instance of this structure to pass 591111be35a1SLionel Sambuc ** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option. 591211be35a1SLionel Sambuc ** Additionally, an instance of this structure can be used as an 591311be35a1SLionel Sambuc ** output variable when querying the system for the current mutex 591411be35a1SLionel Sambuc ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option. 591511be35a1SLionel Sambuc ** 591611be35a1SLionel Sambuc ** ^The xMutexInit method defined by this structure is invoked as 591711be35a1SLionel Sambuc ** part of system initialization by the sqlite3_initialize() function. 591811be35a1SLionel Sambuc ** ^The xMutexInit routine is called by SQLite exactly once for each 591911be35a1SLionel Sambuc ** effective call to [sqlite3_initialize()]. 592011be35a1SLionel Sambuc ** 592111be35a1SLionel Sambuc ** ^The xMutexEnd method defined by this structure is invoked as 592211be35a1SLionel Sambuc ** part of system shutdown by the sqlite3_shutdown() function. The 592311be35a1SLionel Sambuc ** implementation of this method is expected to release all outstanding 592411be35a1SLionel Sambuc ** resources obtained by the mutex methods implementation, especially 592511be35a1SLionel Sambuc ** those obtained by the xMutexInit method. ^The xMutexEnd() 592611be35a1SLionel Sambuc ** interface is invoked exactly once for each call to [sqlite3_shutdown()]. 592711be35a1SLionel Sambuc ** 592811be35a1SLionel Sambuc ** ^(The remaining seven methods defined by this structure (xMutexAlloc, 592911be35a1SLionel Sambuc ** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and 593011be35a1SLionel Sambuc ** xMutexNotheld) implement the following interfaces (respectively): 593111be35a1SLionel Sambuc ** 593211be35a1SLionel Sambuc ** <ul> 593311be35a1SLionel Sambuc ** <li> [sqlite3_mutex_alloc()] </li> 593411be35a1SLionel Sambuc ** <li> [sqlite3_mutex_free()] </li> 593511be35a1SLionel Sambuc ** <li> [sqlite3_mutex_enter()] </li> 593611be35a1SLionel Sambuc ** <li> [sqlite3_mutex_try()] </li> 593711be35a1SLionel Sambuc ** <li> [sqlite3_mutex_leave()] </li> 593811be35a1SLionel Sambuc ** <li> [sqlite3_mutex_held()] </li> 593911be35a1SLionel Sambuc ** <li> [sqlite3_mutex_notheld()] </li> 594011be35a1SLionel Sambuc ** </ul>)^ 594111be35a1SLionel Sambuc ** 594211be35a1SLionel Sambuc ** The only difference is that the public sqlite3_XXX functions enumerated 594311be35a1SLionel Sambuc ** above silently ignore any invocations that pass a NULL pointer instead 594411be35a1SLionel Sambuc ** of a valid mutex handle. The implementations of the methods defined 594511be35a1SLionel Sambuc ** by this structure are not required to handle this case, the results 594611be35a1SLionel Sambuc ** of passing a NULL pointer instead of a valid mutex handle are undefined 594711be35a1SLionel Sambuc ** (i.e. it is acceptable to provide an implementation that segfaults if 594811be35a1SLionel Sambuc ** it is passed a NULL pointer). 594911be35a1SLionel Sambuc ** 595011be35a1SLionel Sambuc ** The xMutexInit() method must be threadsafe. ^It must be harmless to 595111be35a1SLionel Sambuc ** invoke xMutexInit() multiple times within the same process and without 595211be35a1SLionel Sambuc ** intervening calls to xMutexEnd(). Second and subsequent calls to 595311be35a1SLionel Sambuc ** xMutexInit() must be no-ops. 595411be35a1SLionel Sambuc ** 595511be35a1SLionel Sambuc ** ^xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()] 595611be35a1SLionel Sambuc ** and its associates). ^Similarly, xMutexAlloc() must not use SQLite memory 595711be35a1SLionel Sambuc ** allocation for a static mutex. ^However xMutexAlloc() may use SQLite 595811be35a1SLionel Sambuc ** memory allocation for a fast or recursive mutex. 595911be35a1SLionel Sambuc ** 596011be35a1SLionel Sambuc ** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is 596111be35a1SLionel Sambuc ** called, but only if the prior call to xMutexInit returned SQLITE_OK. 596211be35a1SLionel Sambuc ** If xMutexInit fails in any way, it is expected to clean up after itself 596311be35a1SLionel Sambuc ** prior to returning. 596411be35a1SLionel Sambuc */ 596511be35a1SLionel Sambuc typedef struct sqlite3_mutex_methods sqlite3_mutex_methods; 596611be35a1SLionel Sambuc struct sqlite3_mutex_methods { 596711be35a1SLionel Sambuc int (*xMutexInit)(void); 596811be35a1SLionel Sambuc int (*xMutexEnd)(void); 596911be35a1SLionel Sambuc sqlite3_mutex *(*xMutexAlloc)(int); 597011be35a1SLionel Sambuc void (*xMutexFree)(sqlite3_mutex *); 597111be35a1SLionel Sambuc void (*xMutexEnter)(sqlite3_mutex *); 597211be35a1SLionel Sambuc int (*xMutexTry)(sqlite3_mutex *); 597311be35a1SLionel Sambuc void (*xMutexLeave)(sqlite3_mutex *); 597411be35a1SLionel Sambuc int (*xMutexHeld)(sqlite3_mutex *); 597511be35a1SLionel Sambuc int (*xMutexNotheld)(sqlite3_mutex *); 597611be35a1SLionel Sambuc }; 597711be35a1SLionel Sambuc 597811be35a1SLionel Sambuc /* 597911be35a1SLionel Sambuc ** CAPI3REF: Mutex Verification Routines 598011be35a1SLionel Sambuc ** 598111be35a1SLionel Sambuc ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines 598211be35a1SLionel Sambuc ** are intended for use inside assert() statements. ^The SQLite core 598311be35a1SLionel Sambuc ** never uses these routines except inside an assert() and applications 598411be35a1SLionel Sambuc ** are advised to follow the lead of the core. ^The SQLite core only 598511be35a1SLionel Sambuc ** provides implementations for these routines when it is compiled 598611be35a1SLionel Sambuc ** with the SQLITE_DEBUG flag. ^External mutex implementations 598711be35a1SLionel Sambuc ** are only required to provide these routines if SQLITE_DEBUG is 598811be35a1SLionel Sambuc ** defined and if NDEBUG is not defined. 598911be35a1SLionel Sambuc ** 599011be35a1SLionel Sambuc ** ^These routines should return true if the mutex in their argument 599111be35a1SLionel Sambuc ** is held or not held, respectively, by the calling thread. 599211be35a1SLionel Sambuc ** 599311be35a1SLionel Sambuc ** ^The implementation is not required to provide versions of these 599411be35a1SLionel Sambuc ** routines that actually work. If the implementation does not provide working 599511be35a1SLionel Sambuc ** versions of these routines, it should at least provide stubs that always 599611be35a1SLionel Sambuc ** return true so that one does not get spurious assertion failures. 599711be35a1SLionel Sambuc ** 599811be35a1SLionel Sambuc ** ^If the argument to sqlite3_mutex_held() is a NULL pointer then 599911be35a1SLionel Sambuc ** the routine should return 1. This seems counter-intuitive since 600011be35a1SLionel Sambuc ** clearly the mutex cannot be held if it does not exist. But 600111be35a1SLionel Sambuc ** the reason the mutex does not exist is because the build is not 600211be35a1SLionel Sambuc ** using mutexes. And we do not want the assert() containing the 600311be35a1SLionel Sambuc ** call to sqlite3_mutex_held() to fail, so a non-zero return is 600411be35a1SLionel Sambuc ** the appropriate thing to do. ^The sqlite3_mutex_notheld() 600511be35a1SLionel Sambuc ** interface should also return 1 when given a NULL pointer. 600611be35a1SLionel Sambuc */ 600711be35a1SLionel Sambuc #ifndef NDEBUG 600811be35a1SLionel Sambuc SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*); 600911be35a1SLionel Sambuc SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*); 601011be35a1SLionel Sambuc #endif 601111be35a1SLionel Sambuc 601211be35a1SLionel Sambuc /* 601311be35a1SLionel Sambuc ** CAPI3REF: Mutex Types 601411be35a1SLionel Sambuc ** 601511be35a1SLionel Sambuc ** The [sqlite3_mutex_alloc()] interface takes a single argument 601611be35a1SLionel Sambuc ** which is one of these integer constants. 601711be35a1SLionel Sambuc ** 601811be35a1SLionel Sambuc ** The set of static mutexes may change from one SQLite release to the 601911be35a1SLionel Sambuc ** next. Applications that override the built-in mutex logic must be 602011be35a1SLionel Sambuc ** prepared to accommodate additional static mutexes. 602111be35a1SLionel Sambuc */ 602211be35a1SLionel Sambuc #define SQLITE_MUTEX_FAST 0 602311be35a1SLionel Sambuc #define SQLITE_MUTEX_RECURSIVE 1 602411be35a1SLionel Sambuc #define SQLITE_MUTEX_STATIC_MASTER 2 602511be35a1SLionel Sambuc #define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */ 602611be35a1SLionel Sambuc #define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */ 602711be35a1SLionel Sambuc #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */ 602811be35a1SLionel Sambuc #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_random() */ 602911be35a1SLionel Sambuc #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */ 603011be35a1SLionel Sambuc #define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */ 603111be35a1SLionel Sambuc #define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */ 603211be35a1SLionel Sambuc 603311be35a1SLionel Sambuc /* 603411be35a1SLionel Sambuc ** CAPI3REF: Retrieve the mutex for a database connection 603511be35a1SLionel Sambuc ** 603611be35a1SLionel Sambuc ** ^This interface returns a pointer the [sqlite3_mutex] object that 603711be35a1SLionel Sambuc ** serializes access to the [database connection] given in the argument 603811be35a1SLionel Sambuc ** when the [threading mode] is Serialized. 603911be35a1SLionel Sambuc ** ^If the [threading mode] is Single-thread or Multi-thread then this 604011be35a1SLionel Sambuc ** routine returns a NULL pointer. 604111be35a1SLionel Sambuc */ 604211be35a1SLionel Sambuc SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*); 604311be35a1SLionel Sambuc 604411be35a1SLionel Sambuc /* 604511be35a1SLionel Sambuc ** CAPI3REF: Low-Level Control Of Database Files 604611be35a1SLionel Sambuc ** 604711be35a1SLionel Sambuc ** ^The [sqlite3_file_control()] interface makes a direct call to the 604811be35a1SLionel Sambuc ** xFileControl method for the [sqlite3_io_methods] object associated 604911be35a1SLionel Sambuc ** with a particular database identified by the second argument. ^The 605011be35a1SLionel Sambuc ** name of the database is "main" for the main database or "temp" for the 605111be35a1SLionel Sambuc ** TEMP database, or the name that appears after the AS keyword for 605211be35a1SLionel Sambuc ** databases that are added using the [ATTACH] SQL command. 605311be35a1SLionel Sambuc ** ^A NULL pointer can be used in place of "main" to refer to the 605411be35a1SLionel Sambuc ** main database file. 605511be35a1SLionel Sambuc ** ^The third and fourth parameters to this routine 605611be35a1SLionel Sambuc ** are passed directly through to the second and third parameters of 605711be35a1SLionel Sambuc ** the xFileControl method. ^The return value of the xFileControl 605811be35a1SLionel Sambuc ** method becomes the return value of this routine. 605911be35a1SLionel Sambuc ** 606011be35a1SLionel Sambuc ** ^The SQLITE_FCNTL_FILE_POINTER value for the op parameter causes 606111be35a1SLionel Sambuc ** a pointer to the underlying [sqlite3_file] object to be written into 606211be35a1SLionel Sambuc ** the space pointed to by the 4th parameter. ^The SQLITE_FCNTL_FILE_POINTER 606311be35a1SLionel Sambuc ** case is a short-circuit path which does not actually invoke the 606411be35a1SLionel Sambuc ** underlying sqlite3_io_methods.xFileControl method. 606511be35a1SLionel Sambuc ** 606611be35a1SLionel Sambuc ** ^If the second parameter (zDbName) does not match the name of any 606711be35a1SLionel Sambuc ** open database file, then SQLITE_ERROR is returned. ^This error 606811be35a1SLionel Sambuc ** code is not remembered and will not be recalled by [sqlite3_errcode()] 606911be35a1SLionel Sambuc ** or [sqlite3_errmsg()]. The underlying xFileControl method might 607011be35a1SLionel Sambuc ** also return SQLITE_ERROR. There is no way to distinguish between 607111be35a1SLionel Sambuc ** an incorrect zDbName and an SQLITE_ERROR return from the underlying 607211be35a1SLionel Sambuc ** xFileControl method. 607311be35a1SLionel Sambuc ** 607411be35a1SLionel Sambuc ** See also: [SQLITE_FCNTL_LOCKSTATE] 607511be35a1SLionel Sambuc */ 607611be35a1SLionel Sambuc SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*); 607711be35a1SLionel Sambuc 607811be35a1SLionel Sambuc /* 607911be35a1SLionel Sambuc ** CAPI3REF: Testing Interface 608011be35a1SLionel Sambuc ** 608111be35a1SLionel Sambuc ** ^The sqlite3_test_control() interface is used to read out internal 608211be35a1SLionel Sambuc ** state of SQLite and to inject faults into SQLite for testing 608311be35a1SLionel Sambuc ** purposes. ^The first parameter is an operation code that determines 608411be35a1SLionel Sambuc ** the number, meaning, and operation of all subsequent parameters. 608511be35a1SLionel Sambuc ** 608611be35a1SLionel Sambuc ** This interface is not for use by applications. It exists solely 608711be35a1SLionel Sambuc ** for verifying the correct operation of the SQLite library. Depending 608811be35a1SLionel Sambuc ** on how the SQLite library is compiled, this interface might not exist. 608911be35a1SLionel Sambuc ** 609011be35a1SLionel Sambuc ** The details of the operation codes, their meanings, the parameters 609111be35a1SLionel Sambuc ** they take, and what they do are all subject to change without notice. 609211be35a1SLionel Sambuc ** Unlike most of the SQLite API, this function is not guaranteed to 609311be35a1SLionel Sambuc ** operate consistently from one release to the next. 609411be35a1SLionel Sambuc */ 609511be35a1SLionel Sambuc SQLITE_API int sqlite3_test_control(int op, ...); 609611be35a1SLionel Sambuc 609711be35a1SLionel Sambuc /* 609811be35a1SLionel Sambuc ** CAPI3REF: Testing Interface Operation Codes 609911be35a1SLionel Sambuc ** 610011be35a1SLionel Sambuc ** These constants are the valid operation code parameters used 610111be35a1SLionel Sambuc ** as the first argument to [sqlite3_test_control()]. 610211be35a1SLionel Sambuc ** 610311be35a1SLionel Sambuc ** These parameters and their meanings are subject to change 610411be35a1SLionel Sambuc ** without notice. These values are for testing purposes only. 610511be35a1SLionel Sambuc ** Applications should not use any of these parameters or the 610611be35a1SLionel Sambuc ** [sqlite3_test_control()] interface. 610711be35a1SLionel Sambuc */ 610811be35a1SLionel Sambuc #define SQLITE_TESTCTRL_FIRST 5 610911be35a1SLionel Sambuc #define SQLITE_TESTCTRL_PRNG_SAVE 5 611011be35a1SLionel Sambuc #define SQLITE_TESTCTRL_PRNG_RESTORE 6 611111be35a1SLionel Sambuc #define SQLITE_TESTCTRL_PRNG_RESET 7 611211be35a1SLionel Sambuc #define SQLITE_TESTCTRL_BITVEC_TEST 8 611311be35a1SLionel Sambuc #define SQLITE_TESTCTRL_FAULT_INSTALL 9 611411be35a1SLionel Sambuc #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10 611511be35a1SLionel Sambuc #define SQLITE_TESTCTRL_PENDING_BYTE 11 611611be35a1SLionel Sambuc #define SQLITE_TESTCTRL_ASSERT 12 611711be35a1SLionel Sambuc #define SQLITE_TESTCTRL_ALWAYS 13 611811be35a1SLionel Sambuc #define SQLITE_TESTCTRL_RESERVE 14 611911be35a1SLionel Sambuc #define SQLITE_TESTCTRL_OPTIMIZATIONS 15 612011be35a1SLionel Sambuc #define SQLITE_TESTCTRL_ISKEYWORD 16 612111be35a1SLionel Sambuc #define SQLITE_TESTCTRL_SCRATCHMALLOC 17 612211be35a1SLionel Sambuc #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18 612311be35a1SLionel Sambuc #define SQLITE_TESTCTRL_EXPLAIN_STMT 19 6124*0a6a1f1dSLionel Sambuc #define SQLITE_TESTCTRL_NEVER_CORRUPT 20 6125*0a6a1f1dSLionel Sambuc #define SQLITE_TESTCTRL_LAST 20 612611be35a1SLionel Sambuc 612711be35a1SLionel Sambuc /* 612811be35a1SLionel Sambuc ** CAPI3REF: SQLite Runtime Status 612911be35a1SLionel Sambuc ** 613011be35a1SLionel Sambuc ** ^This interface is used to retrieve runtime status information 613111be35a1SLionel Sambuc ** about the performance of SQLite, and optionally to reset various 613211be35a1SLionel Sambuc ** highwater marks. ^The first argument is an integer code for 613311be35a1SLionel Sambuc ** the specific parameter to measure. ^(Recognized integer codes 613411be35a1SLionel Sambuc ** are of the form [status parameters | SQLITE_STATUS_...].)^ 613511be35a1SLionel Sambuc ** ^The current value of the parameter is returned into *pCurrent. 613611be35a1SLionel Sambuc ** ^The highest recorded value is returned in *pHighwater. ^If the 613711be35a1SLionel Sambuc ** resetFlag is true, then the highest record value is reset after 613811be35a1SLionel Sambuc ** *pHighwater is written. ^(Some parameters do not record the highest 613911be35a1SLionel Sambuc ** value. For those parameters 614011be35a1SLionel Sambuc ** nothing is written into *pHighwater and the resetFlag is ignored.)^ 614111be35a1SLionel Sambuc ** ^(Other parameters record only the highwater mark and not the current 614211be35a1SLionel Sambuc ** value. For these latter parameters nothing is written into *pCurrent.)^ 614311be35a1SLionel Sambuc ** 614411be35a1SLionel Sambuc ** ^The sqlite3_status() routine returns SQLITE_OK on success and a 614511be35a1SLionel Sambuc ** non-zero [error code] on failure. 614611be35a1SLionel Sambuc ** 614711be35a1SLionel Sambuc ** This routine is threadsafe but is not atomic. This routine can be 614811be35a1SLionel Sambuc ** called while other threads are running the same or different SQLite 614911be35a1SLionel Sambuc ** interfaces. However the values returned in *pCurrent and 615011be35a1SLionel Sambuc ** *pHighwater reflect the status of SQLite at different points in time 615111be35a1SLionel Sambuc ** and it is possible that another thread might change the parameter 615211be35a1SLionel Sambuc ** in between the times when *pCurrent and *pHighwater are written. 615311be35a1SLionel Sambuc ** 615411be35a1SLionel Sambuc ** See also: [sqlite3_db_status()] 615511be35a1SLionel Sambuc */ 615611be35a1SLionel Sambuc SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag); 615711be35a1SLionel Sambuc 615811be35a1SLionel Sambuc 615911be35a1SLionel Sambuc /* 616011be35a1SLionel Sambuc ** CAPI3REF: Status Parameters 616111be35a1SLionel Sambuc ** KEYWORDS: {status parameters} 616211be35a1SLionel Sambuc ** 616311be35a1SLionel Sambuc ** These integer constants designate various run-time status parameters 616411be35a1SLionel Sambuc ** that can be returned by [sqlite3_status()]. 616511be35a1SLionel Sambuc ** 616611be35a1SLionel Sambuc ** <dl> 616711be35a1SLionel Sambuc ** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt> 616811be35a1SLionel Sambuc ** <dd>This parameter is the current amount of memory checked out 616911be35a1SLionel Sambuc ** using [sqlite3_malloc()], either directly or indirectly. The 617011be35a1SLionel Sambuc ** figure includes calls made to [sqlite3_malloc()] by the application 617111be35a1SLionel Sambuc ** and internal memory usage by the SQLite library. Scratch memory 617211be35a1SLionel Sambuc ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache 617311be35a1SLionel Sambuc ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in 617411be35a1SLionel Sambuc ** this parameter. The amount returned is the sum of the allocation 617511be35a1SLionel Sambuc ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^ 617611be35a1SLionel Sambuc ** 617711be35a1SLionel Sambuc ** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt> 617811be35a1SLionel Sambuc ** <dd>This parameter records the largest memory allocation request 617911be35a1SLionel Sambuc ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their 618011be35a1SLionel Sambuc ** internal equivalents). Only the value returned in the 618111be35a1SLionel Sambuc ** *pHighwater parameter to [sqlite3_status()] is of interest. 618211be35a1SLionel Sambuc ** The value written into the *pCurrent parameter is undefined.</dd>)^ 618311be35a1SLionel Sambuc ** 618411be35a1SLionel Sambuc ** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt> 618511be35a1SLionel Sambuc ** <dd>This parameter records the number of separate memory allocations 618611be35a1SLionel Sambuc ** currently checked out.</dd>)^ 618711be35a1SLionel Sambuc ** 618811be35a1SLionel Sambuc ** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt> 618911be35a1SLionel Sambuc ** <dd>This parameter returns the number of pages used out of the 619011be35a1SLionel Sambuc ** [pagecache memory allocator] that was configured using 619111be35a1SLionel Sambuc ** [SQLITE_CONFIG_PAGECACHE]. The 619211be35a1SLionel Sambuc ** value returned is in pages, not in bytes.</dd>)^ 619311be35a1SLionel Sambuc ** 619411be35a1SLionel Sambuc ** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]] 619511be35a1SLionel Sambuc ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt> 619611be35a1SLionel Sambuc ** <dd>This parameter returns the number of bytes of page cache 619711be35a1SLionel Sambuc ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE] 619811be35a1SLionel Sambuc ** buffer and where forced to overflow to [sqlite3_malloc()]. The 619911be35a1SLionel Sambuc ** returned value includes allocations that overflowed because they 620011be35a1SLionel Sambuc ** where too large (they were larger than the "sz" parameter to 620111be35a1SLionel Sambuc ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because 620211be35a1SLionel Sambuc ** no space was left in the page cache.</dd>)^ 620311be35a1SLionel Sambuc ** 620411be35a1SLionel Sambuc ** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt> 620511be35a1SLionel Sambuc ** <dd>This parameter records the largest memory allocation request 620611be35a1SLionel Sambuc ** handed to [pagecache memory allocator]. Only the value returned in the 620711be35a1SLionel Sambuc ** *pHighwater parameter to [sqlite3_status()] is of interest. 620811be35a1SLionel Sambuc ** The value written into the *pCurrent parameter is undefined.</dd>)^ 620911be35a1SLionel Sambuc ** 621011be35a1SLionel Sambuc ** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt> 621111be35a1SLionel Sambuc ** <dd>This parameter returns the number of allocations used out of the 621211be35a1SLionel Sambuc ** [scratch memory allocator] configured using 621311be35a1SLionel Sambuc ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not 621411be35a1SLionel Sambuc ** in bytes. Since a single thread may only have one scratch allocation 621511be35a1SLionel Sambuc ** outstanding at time, this parameter also reports the number of threads 621611be35a1SLionel Sambuc ** using scratch memory at the same time.</dd>)^ 621711be35a1SLionel Sambuc ** 621811be35a1SLionel Sambuc ** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt> 621911be35a1SLionel Sambuc ** <dd>This parameter returns the number of bytes of scratch memory 622011be35a1SLionel Sambuc ** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH] 622111be35a1SLionel Sambuc ** buffer and where forced to overflow to [sqlite3_malloc()]. The values 622211be35a1SLionel Sambuc ** returned include overflows because the requested allocation was too 622311be35a1SLionel Sambuc ** larger (that is, because the requested allocation was larger than the 622411be35a1SLionel Sambuc ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer 622511be35a1SLionel Sambuc ** slots were available. 622611be35a1SLionel Sambuc ** </dd>)^ 622711be35a1SLionel Sambuc ** 622811be35a1SLionel Sambuc ** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt> 622911be35a1SLionel Sambuc ** <dd>This parameter records the largest memory allocation request 623011be35a1SLionel Sambuc ** handed to [scratch memory allocator]. Only the value returned in the 623111be35a1SLionel Sambuc ** *pHighwater parameter to [sqlite3_status()] is of interest. 623211be35a1SLionel Sambuc ** The value written into the *pCurrent parameter is undefined.</dd>)^ 623311be35a1SLionel Sambuc ** 623411be35a1SLionel Sambuc ** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt> 623511be35a1SLionel Sambuc ** <dd>This parameter records the deepest parser stack. It is only 623611be35a1SLionel Sambuc ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^ 623711be35a1SLionel Sambuc ** </dl> 623811be35a1SLionel Sambuc ** 623911be35a1SLionel Sambuc ** New status parameters may be added from time to time. 624011be35a1SLionel Sambuc */ 624111be35a1SLionel Sambuc #define SQLITE_STATUS_MEMORY_USED 0 624211be35a1SLionel Sambuc #define SQLITE_STATUS_PAGECACHE_USED 1 624311be35a1SLionel Sambuc #define SQLITE_STATUS_PAGECACHE_OVERFLOW 2 624411be35a1SLionel Sambuc #define SQLITE_STATUS_SCRATCH_USED 3 624511be35a1SLionel Sambuc #define SQLITE_STATUS_SCRATCH_OVERFLOW 4 624611be35a1SLionel Sambuc #define SQLITE_STATUS_MALLOC_SIZE 5 624711be35a1SLionel Sambuc #define SQLITE_STATUS_PARSER_STACK 6 624811be35a1SLionel Sambuc #define SQLITE_STATUS_PAGECACHE_SIZE 7 624911be35a1SLionel Sambuc #define SQLITE_STATUS_SCRATCH_SIZE 8 625011be35a1SLionel Sambuc #define SQLITE_STATUS_MALLOC_COUNT 9 625111be35a1SLionel Sambuc 625211be35a1SLionel Sambuc /* 625311be35a1SLionel Sambuc ** CAPI3REF: Database Connection Status 625411be35a1SLionel Sambuc ** 625511be35a1SLionel Sambuc ** ^This interface is used to retrieve runtime status information 625611be35a1SLionel Sambuc ** about a single [database connection]. ^The first argument is the 625711be35a1SLionel Sambuc ** database connection object to be interrogated. ^The second argument 625811be35a1SLionel Sambuc ** is an integer constant, taken from the set of 625911be35a1SLionel Sambuc ** [SQLITE_DBSTATUS options], that 626011be35a1SLionel Sambuc ** determines the parameter to interrogate. The set of 626111be35a1SLionel Sambuc ** [SQLITE_DBSTATUS options] is likely 626211be35a1SLionel Sambuc ** to grow in future releases of SQLite. 626311be35a1SLionel Sambuc ** 626411be35a1SLionel Sambuc ** ^The current value of the requested parameter is written into *pCur 626511be35a1SLionel Sambuc ** and the highest instantaneous value is written into *pHiwtr. ^If 626611be35a1SLionel Sambuc ** the resetFlg is true, then the highest instantaneous value is 626711be35a1SLionel Sambuc ** reset back down to the current value. 626811be35a1SLionel Sambuc ** 626911be35a1SLionel Sambuc ** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a 627011be35a1SLionel Sambuc ** non-zero [error code] on failure. 627111be35a1SLionel Sambuc ** 627211be35a1SLionel Sambuc ** See also: [sqlite3_status()] and [sqlite3_stmt_status()]. 627311be35a1SLionel Sambuc */ 627411be35a1SLionel Sambuc SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); 627511be35a1SLionel Sambuc 627611be35a1SLionel Sambuc /* 627711be35a1SLionel Sambuc ** CAPI3REF: Status Parameters for database connections 627811be35a1SLionel Sambuc ** KEYWORDS: {SQLITE_DBSTATUS options} 627911be35a1SLionel Sambuc ** 628011be35a1SLionel Sambuc ** These constants are the available integer "verbs" that can be passed as 628111be35a1SLionel Sambuc ** the second argument to the [sqlite3_db_status()] interface. 628211be35a1SLionel Sambuc ** 628311be35a1SLionel Sambuc ** New verbs may be added in future releases of SQLite. Existing verbs 628411be35a1SLionel Sambuc ** might be discontinued. Applications should check the return code from 628511be35a1SLionel Sambuc ** [sqlite3_db_status()] to make sure that the call worked. 628611be35a1SLionel Sambuc ** The [sqlite3_db_status()] interface will return a non-zero error code 628711be35a1SLionel Sambuc ** if a discontinued or unsupported verb is invoked. 628811be35a1SLionel Sambuc ** 628911be35a1SLionel Sambuc ** <dl> 629011be35a1SLionel Sambuc ** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt> 629111be35a1SLionel Sambuc ** <dd>This parameter returns the number of lookaside memory slots currently 629211be35a1SLionel Sambuc ** checked out.</dd>)^ 629311be35a1SLionel Sambuc ** 629411be35a1SLionel Sambuc ** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt> 629511be35a1SLionel Sambuc ** <dd>This parameter returns the number malloc attempts that were 629611be35a1SLionel Sambuc ** satisfied using lookaside memory. Only the high-water value is meaningful; 629711be35a1SLionel Sambuc ** the current value is always zero.)^ 629811be35a1SLionel Sambuc ** 629911be35a1SLionel Sambuc ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]] 630011be35a1SLionel Sambuc ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt> 630111be35a1SLionel Sambuc ** <dd>This parameter returns the number malloc attempts that might have 630211be35a1SLionel Sambuc ** been satisfied using lookaside memory but failed due to the amount of 630311be35a1SLionel Sambuc ** memory requested being larger than the lookaside slot size. 630411be35a1SLionel Sambuc ** Only the high-water value is meaningful; 630511be35a1SLionel Sambuc ** the current value is always zero.)^ 630611be35a1SLionel Sambuc ** 630711be35a1SLionel Sambuc ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]] 630811be35a1SLionel Sambuc ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt> 630911be35a1SLionel Sambuc ** <dd>This parameter returns the number malloc attempts that might have 631011be35a1SLionel Sambuc ** been satisfied using lookaside memory but failed due to all lookaside 631111be35a1SLionel Sambuc ** memory already being in use. 631211be35a1SLionel Sambuc ** Only the high-water value is meaningful; 631311be35a1SLionel Sambuc ** the current value is always zero.)^ 631411be35a1SLionel Sambuc ** 631511be35a1SLionel Sambuc ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt> 631611be35a1SLionel Sambuc ** <dd>This parameter returns the approximate number of of bytes of heap 631711be35a1SLionel Sambuc ** memory used by all pager caches associated with the database connection.)^ 631811be35a1SLionel Sambuc ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0. 631911be35a1SLionel Sambuc ** 632011be35a1SLionel Sambuc ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt> 632111be35a1SLionel Sambuc ** <dd>This parameter returns the approximate number of of bytes of heap 632211be35a1SLionel Sambuc ** memory used to store the schema for all databases associated 632311be35a1SLionel Sambuc ** with the connection - main, temp, and any [ATTACH]-ed databases.)^ 632411be35a1SLionel Sambuc ** ^The full amount of memory used by the schemas is reported, even if the 632511be35a1SLionel Sambuc ** schema memory is shared with other database connections due to 632611be35a1SLionel Sambuc ** [shared cache mode] being enabled. 632711be35a1SLionel Sambuc ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0. 632811be35a1SLionel Sambuc ** 632911be35a1SLionel Sambuc ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt> 633011be35a1SLionel Sambuc ** <dd>This parameter returns the approximate number of of bytes of heap 633111be35a1SLionel Sambuc ** and lookaside memory used by all prepared statements associated with 633211be35a1SLionel Sambuc ** the database connection.)^ 633311be35a1SLionel Sambuc ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0. 633411be35a1SLionel Sambuc ** </dd> 633511be35a1SLionel Sambuc ** 633611be35a1SLionel Sambuc ** [[SQLITE_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE_DBSTATUS_CACHE_HIT</dt> 633711be35a1SLionel Sambuc ** <dd>This parameter returns the number of pager cache hits that have 633811be35a1SLionel Sambuc ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_HIT 633911be35a1SLionel Sambuc ** is always 0. 634011be35a1SLionel Sambuc ** </dd> 634111be35a1SLionel Sambuc ** 634211be35a1SLionel Sambuc ** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt> 634311be35a1SLionel Sambuc ** <dd>This parameter returns the number of pager cache misses that have 634411be35a1SLionel Sambuc ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS 634511be35a1SLionel Sambuc ** is always 0. 634611be35a1SLionel Sambuc ** </dd> 6347*0a6a1f1dSLionel Sambuc ** 6348*0a6a1f1dSLionel Sambuc ** [[SQLITE_DBSTATUS_CACHE_WRITE]] ^(<dt>SQLITE_DBSTATUS_CACHE_WRITE</dt> 6349*0a6a1f1dSLionel Sambuc ** <dd>This parameter returns the number of dirty cache entries that have 6350*0a6a1f1dSLionel Sambuc ** been written to disk. Specifically, the number of pages written to the 6351*0a6a1f1dSLionel Sambuc ** wal file in wal mode databases, or the number of pages written to the 6352*0a6a1f1dSLionel Sambuc ** database file in rollback mode databases. Any pages written as part of 6353*0a6a1f1dSLionel Sambuc ** transaction rollback or database recovery operations are not included. 6354*0a6a1f1dSLionel Sambuc ** If an IO or other error occurs while writing a page to disk, the effect 6355*0a6a1f1dSLionel Sambuc ** on subsequent SQLITE_DBSTATUS_CACHE_WRITE requests is undefined.)^ ^The 6356*0a6a1f1dSLionel Sambuc ** highwater mark associated with SQLITE_DBSTATUS_CACHE_WRITE is always 0. 6357*0a6a1f1dSLionel Sambuc ** </dd> 6358*0a6a1f1dSLionel Sambuc ** 6359*0a6a1f1dSLionel Sambuc ** [[SQLITE_DBSTATUS_DEFERRED_FKS]] ^(<dt>SQLITE_DBSTATUS_DEFERRED_FKS</dt> 6360*0a6a1f1dSLionel Sambuc ** <dd>This parameter returns zero for the current value if and only if 6361*0a6a1f1dSLionel Sambuc ** all foreign key constraints (deferred or immediate) have been 6362*0a6a1f1dSLionel Sambuc ** resolved.)^ ^The highwater mark is always 0. 6363*0a6a1f1dSLionel Sambuc ** </dd> 636411be35a1SLionel Sambuc ** </dl> 636511be35a1SLionel Sambuc */ 636611be35a1SLionel Sambuc #define SQLITE_DBSTATUS_LOOKASIDE_USED 0 636711be35a1SLionel Sambuc #define SQLITE_DBSTATUS_CACHE_USED 1 636811be35a1SLionel Sambuc #define SQLITE_DBSTATUS_SCHEMA_USED 2 636911be35a1SLionel Sambuc #define SQLITE_DBSTATUS_STMT_USED 3 637011be35a1SLionel Sambuc #define SQLITE_DBSTATUS_LOOKASIDE_HIT 4 637111be35a1SLionel Sambuc #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5 637211be35a1SLionel Sambuc #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6 637311be35a1SLionel Sambuc #define SQLITE_DBSTATUS_CACHE_HIT 7 637411be35a1SLionel Sambuc #define SQLITE_DBSTATUS_CACHE_MISS 8 6375*0a6a1f1dSLionel Sambuc #define SQLITE_DBSTATUS_CACHE_WRITE 9 6376*0a6a1f1dSLionel Sambuc #define SQLITE_DBSTATUS_DEFERRED_FKS 10 6377*0a6a1f1dSLionel Sambuc #define SQLITE_DBSTATUS_MAX 10 /* Largest defined DBSTATUS */ 637811be35a1SLionel Sambuc 637911be35a1SLionel Sambuc 638011be35a1SLionel Sambuc /* 638111be35a1SLionel Sambuc ** CAPI3REF: Prepared Statement Status 638211be35a1SLionel Sambuc ** 638311be35a1SLionel Sambuc ** ^(Each prepared statement maintains various 638411be35a1SLionel Sambuc ** [SQLITE_STMTSTATUS counters] that measure the number 638511be35a1SLionel Sambuc ** of times it has performed specific operations.)^ These counters can 638611be35a1SLionel Sambuc ** be used to monitor the performance characteristics of the prepared 638711be35a1SLionel Sambuc ** statements. For example, if the number of table steps greatly exceeds 638811be35a1SLionel Sambuc ** the number of table searches or result rows, that would tend to indicate 638911be35a1SLionel Sambuc ** that the prepared statement is using a full table scan rather than 639011be35a1SLionel Sambuc ** an index. 639111be35a1SLionel Sambuc ** 639211be35a1SLionel Sambuc ** ^(This interface is used to retrieve and reset counter values from 639311be35a1SLionel Sambuc ** a [prepared statement]. The first argument is the prepared statement 639411be35a1SLionel Sambuc ** object to be interrogated. The second argument 639511be35a1SLionel Sambuc ** is an integer code for a specific [SQLITE_STMTSTATUS counter] 639611be35a1SLionel Sambuc ** to be interrogated.)^ 639711be35a1SLionel Sambuc ** ^The current value of the requested counter is returned. 639811be35a1SLionel Sambuc ** ^If the resetFlg is true, then the counter is reset to zero after this 639911be35a1SLionel Sambuc ** interface call returns. 640011be35a1SLionel Sambuc ** 640111be35a1SLionel Sambuc ** See also: [sqlite3_status()] and [sqlite3_db_status()]. 640211be35a1SLionel Sambuc */ 640311be35a1SLionel Sambuc SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); 640411be35a1SLionel Sambuc 640511be35a1SLionel Sambuc /* 640611be35a1SLionel Sambuc ** CAPI3REF: Status Parameters for prepared statements 640711be35a1SLionel Sambuc ** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters} 640811be35a1SLionel Sambuc ** 640911be35a1SLionel Sambuc ** These preprocessor macros define integer codes that name counter 641011be35a1SLionel Sambuc ** values associated with the [sqlite3_stmt_status()] interface. 641111be35a1SLionel Sambuc ** The meanings of the various counters are as follows: 641211be35a1SLionel Sambuc ** 641311be35a1SLionel Sambuc ** <dl> 641411be35a1SLionel Sambuc ** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt> 641511be35a1SLionel Sambuc ** <dd>^This is the number of times that SQLite has stepped forward in 641611be35a1SLionel Sambuc ** a table as part of a full table scan. Large numbers for this counter 641711be35a1SLionel Sambuc ** may indicate opportunities for performance improvement through 641811be35a1SLionel Sambuc ** careful use of indices.</dd> 641911be35a1SLionel Sambuc ** 642011be35a1SLionel Sambuc ** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt> 642111be35a1SLionel Sambuc ** <dd>^This is the number of sort operations that have occurred. 642211be35a1SLionel Sambuc ** A non-zero value in this counter may indicate an opportunity to 642311be35a1SLionel Sambuc ** improvement performance through careful use of indices.</dd> 642411be35a1SLionel Sambuc ** 642511be35a1SLionel Sambuc ** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt> 642611be35a1SLionel Sambuc ** <dd>^This is the number of rows inserted into transient indices that 642711be35a1SLionel Sambuc ** were created automatically in order to help joins run faster. 642811be35a1SLionel Sambuc ** A non-zero value in this counter may indicate an opportunity to 642911be35a1SLionel Sambuc ** improvement performance by adding permanent indices that do not 643011be35a1SLionel Sambuc ** need to be reinitialized each time the statement is run.</dd> 6431*0a6a1f1dSLionel Sambuc ** 6432*0a6a1f1dSLionel Sambuc ** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt> 6433*0a6a1f1dSLionel Sambuc ** <dd>^This is the number of virtual machine operations executed 6434*0a6a1f1dSLionel Sambuc ** by the prepared statement if that number is less than or equal 6435*0a6a1f1dSLionel Sambuc ** to 2147483647. The number of virtual machine operations can be 6436*0a6a1f1dSLionel Sambuc ** used as a proxy for the total work done by the prepared statement. 6437*0a6a1f1dSLionel Sambuc ** If the number of virtual machine operations exceeds 2147483647 6438*0a6a1f1dSLionel Sambuc ** then the value returned by this statement status code is undefined. 6439*0a6a1f1dSLionel Sambuc ** </dd> 644011be35a1SLionel Sambuc ** </dl> 644111be35a1SLionel Sambuc */ 644211be35a1SLionel Sambuc #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1 644311be35a1SLionel Sambuc #define SQLITE_STMTSTATUS_SORT 2 644411be35a1SLionel Sambuc #define SQLITE_STMTSTATUS_AUTOINDEX 3 6445*0a6a1f1dSLionel Sambuc #define SQLITE_STMTSTATUS_VM_STEP 4 644611be35a1SLionel Sambuc 644711be35a1SLionel Sambuc /* 644811be35a1SLionel Sambuc ** CAPI3REF: Custom Page Cache Object 644911be35a1SLionel Sambuc ** 645011be35a1SLionel Sambuc ** The sqlite3_pcache type is opaque. It is implemented by 645111be35a1SLionel Sambuc ** the pluggable module. The SQLite core has no knowledge of 645211be35a1SLionel Sambuc ** its size or internal structure and never deals with the 645311be35a1SLionel Sambuc ** sqlite3_pcache object except by holding and passing pointers 645411be35a1SLionel Sambuc ** to the object. 645511be35a1SLionel Sambuc ** 645611be35a1SLionel Sambuc ** See [sqlite3_pcache_methods2] for additional information. 645711be35a1SLionel Sambuc */ 645811be35a1SLionel Sambuc typedef struct sqlite3_pcache sqlite3_pcache; 645911be35a1SLionel Sambuc 646011be35a1SLionel Sambuc /* 646111be35a1SLionel Sambuc ** CAPI3REF: Custom Page Cache Object 646211be35a1SLionel Sambuc ** 646311be35a1SLionel Sambuc ** The sqlite3_pcache_page object represents a single page in the 646411be35a1SLionel Sambuc ** page cache. The page cache will allocate instances of this 646511be35a1SLionel Sambuc ** object. Various methods of the page cache use pointers to instances 646611be35a1SLionel Sambuc ** of this object as parameters or as their return value. 646711be35a1SLionel Sambuc ** 646811be35a1SLionel Sambuc ** See [sqlite3_pcache_methods2] for additional information. 646911be35a1SLionel Sambuc */ 647011be35a1SLionel Sambuc typedef struct sqlite3_pcache_page sqlite3_pcache_page; 647111be35a1SLionel Sambuc struct sqlite3_pcache_page { 647211be35a1SLionel Sambuc void *pBuf; /* The content of the page */ 647311be35a1SLionel Sambuc void *pExtra; /* Extra information associated with the page */ 647411be35a1SLionel Sambuc }; 647511be35a1SLionel Sambuc 647611be35a1SLionel Sambuc /* 647711be35a1SLionel Sambuc ** CAPI3REF: Application Defined Page Cache. 647811be35a1SLionel Sambuc ** KEYWORDS: {page cache} 647911be35a1SLionel Sambuc ** 648011be35a1SLionel Sambuc ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE2], ...) interface can 648111be35a1SLionel Sambuc ** register an alternative page cache implementation by passing in an 648211be35a1SLionel Sambuc ** instance of the sqlite3_pcache_methods2 structure.)^ 648311be35a1SLionel Sambuc ** In many applications, most of the heap memory allocated by 648411be35a1SLionel Sambuc ** SQLite is used for the page cache. 648511be35a1SLionel Sambuc ** By implementing a 648611be35a1SLionel Sambuc ** custom page cache using this API, an application can better control 648711be35a1SLionel Sambuc ** the amount of memory consumed by SQLite, the way in which 648811be35a1SLionel Sambuc ** that memory is allocated and released, and the policies used to 648911be35a1SLionel Sambuc ** determine exactly which parts of a database file are cached and for 649011be35a1SLionel Sambuc ** how long. 649111be35a1SLionel Sambuc ** 649211be35a1SLionel Sambuc ** The alternative page cache mechanism is an 649311be35a1SLionel Sambuc ** extreme measure that is only needed by the most demanding applications. 649411be35a1SLionel Sambuc ** The built-in page cache is recommended for most uses. 649511be35a1SLionel Sambuc ** 649611be35a1SLionel Sambuc ** ^(The contents of the sqlite3_pcache_methods2 structure are copied to an 649711be35a1SLionel Sambuc ** internal buffer by SQLite within the call to [sqlite3_config]. Hence 649811be35a1SLionel Sambuc ** the application may discard the parameter after the call to 649911be35a1SLionel Sambuc ** [sqlite3_config()] returns.)^ 650011be35a1SLionel Sambuc ** 650111be35a1SLionel Sambuc ** [[the xInit() page cache method]] 650211be35a1SLionel Sambuc ** ^(The xInit() method is called once for each effective 650311be35a1SLionel Sambuc ** call to [sqlite3_initialize()])^ 650411be35a1SLionel Sambuc ** (usually only once during the lifetime of the process). ^(The xInit() 650511be35a1SLionel Sambuc ** method is passed a copy of the sqlite3_pcache_methods2.pArg value.)^ 650611be35a1SLionel Sambuc ** The intent of the xInit() method is to set up global data structures 650711be35a1SLionel Sambuc ** required by the custom page cache implementation. 650811be35a1SLionel Sambuc ** ^(If the xInit() method is NULL, then the 650911be35a1SLionel Sambuc ** built-in default page cache is used instead of the application defined 651011be35a1SLionel Sambuc ** page cache.)^ 651111be35a1SLionel Sambuc ** 651211be35a1SLionel Sambuc ** [[the xShutdown() page cache method]] 651311be35a1SLionel Sambuc ** ^The xShutdown() method is called by [sqlite3_shutdown()]. 651411be35a1SLionel Sambuc ** It can be used to clean up 651511be35a1SLionel Sambuc ** any outstanding resources before process shutdown, if required. 651611be35a1SLionel Sambuc ** ^The xShutdown() method may be NULL. 651711be35a1SLionel Sambuc ** 651811be35a1SLionel Sambuc ** ^SQLite automatically serializes calls to the xInit method, 651911be35a1SLionel Sambuc ** so the xInit method need not be threadsafe. ^The 652011be35a1SLionel Sambuc ** xShutdown method is only called from [sqlite3_shutdown()] so it does 652111be35a1SLionel Sambuc ** not need to be threadsafe either. All other methods must be threadsafe 652211be35a1SLionel Sambuc ** in multithreaded applications. 652311be35a1SLionel Sambuc ** 652411be35a1SLionel Sambuc ** ^SQLite will never invoke xInit() more than once without an intervening 652511be35a1SLionel Sambuc ** call to xShutdown(). 652611be35a1SLionel Sambuc ** 652711be35a1SLionel Sambuc ** [[the xCreate() page cache methods]] 652811be35a1SLionel Sambuc ** ^SQLite invokes the xCreate() method to construct a new cache instance. 652911be35a1SLionel Sambuc ** SQLite will typically create one cache instance for each open database file, 653011be35a1SLionel Sambuc ** though this is not guaranteed. ^The 653111be35a1SLionel Sambuc ** first parameter, szPage, is the size in bytes of the pages that must 653211be35a1SLionel Sambuc ** be allocated by the cache. ^szPage will always a power of two. ^The 653311be35a1SLionel Sambuc ** second parameter szExtra is a number of bytes of extra storage 653411be35a1SLionel Sambuc ** associated with each page cache entry. ^The szExtra parameter will 653511be35a1SLionel Sambuc ** a number less than 250. SQLite will use the 653611be35a1SLionel Sambuc ** extra szExtra bytes on each page to store metadata about the underlying 653711be35a1SLionel Sambuc ** database page on disk. The value passed into szExtra depends 653811be35a1SLionel Sambuc ** on the SQLite version, the target platform, and how SQLite was compiled. 653911be35a1SLionel Sambuc ** ^The third argument to xCreate(), bPurgeable, is true if the cache being 654011be35a1SLionel Sambuc ** created will be used to cache database pages of a file stored on disk, or 654111be35a1SLionel Sambuc ** false if it is used for an in-memory database. The cache implementation 654211be35a1SLionel Sambuc ** does not have to do anything special based with the value of bPurgeable; 654311be35a1SLionel Sambuc ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will 654411be35a1SLionel Sambuc ** never invoke xUnpin() except to deliberately delete a page. 654511be35a1SLionel Sambuc ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to 654611be35a1SLionel Sambuc ** false will always have the "discard" flag set to true. 654711be35a1SLionel Sambuc ** ^Hence, a cache created with bPurgeable false will 654811be35a1SLionel Sambuc ** never contain any unpinned pages. 654911be35a1SLionel Sambuc ** 655011be35a1SLionel Sambuc ** [[the xCachesize() page cache method]] 655111be35a1SLionel Sambuc ** ^(The xCachesize() method may be called at any time by SQLite to set the 655211be35a1SLionel Sambuc ** suggested maximum cache-size (number of pages stored by) the cache 655311be35a1SLionel Sambuc ** instance passed as the first argument. This is the value configured using 655411be35a1SLionel Sambuc ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable 655511be35a1SLionel Sambuc ** parameter, the implementation is not required to do anything with this 655611be35a1SLionel Sambuc ** value; it is advisory only. 655711be35a1SLionel Sambuc ** 655811be35a1SLionel Sambuc ** [[the xPagecount() page cache methods]] 655911be35a1SLionel Sambuc ** The xPagecount() method must return the number of pages currently 656011be35a1SLionel Sambuc ** stored in the cache, both pinned and unpinned. 656111be35a1SLionel Sambuc ** 656211be35a1SLionel Sambuc ** [[the xFetch() page cache methods]] 656311be35a1SLionel Sambuc ** The xFetch() method locates a page in the cache and returns a pointer to 656411be35a1SLionel Sambuc ** an sqlite3_pcache_page object associated with that page, or a NULL pointer. 656511be35a1SLionel Sambuc ** The pBuf element of the returned sqlite3_pcache_page object will be a 656611be35a1SLionel Sambuc ** pointer to a buffer of szPage bytes used to store the content of a 656711be35a1SLionel Sambuc ** single database page. The pExtra element of sqlite3_pcache_page will be 656811be35a1SLionel Sambuc ** a pointer to the szExtra bytes of extra storage that SQLite has requested 656911be35a1SLionel Sambuc ** for each entry in the page cache. 657011be35a1SLionel Sambuc ** 657111be35a1SLionel Sambuc ** The page to be fetched is determined by the key. ^The minimum key value 657211be35a1SLionel Sambuc ** is 1. After it has been retrieved using xFetch, the page is considered 657311be35a1SLionel Sambuc ** to be "pinned". 657411be35a1SLionel Sambuc ** 657511be35a1SLionel Sambuc ** If the requested page is already in the page cache, then the page cache 657611be35a1SLionel Sambuc ** implementation must return a pointer to the page buffer with its content 657711be35a1SLionel Sambuc ** intact. If the requested page is not already in the cache, then the 657811be35a1SLionel Sambuc ** cache implementation should use the value of the createFlag 657911be35a1SLionel Sambuc ** parameter to help it determined what action to take: 658011be35a1SLionel Sambuc ** 658111be35a1SLionel Sambuc ** <table border=1 width=85% align=center> 6582*0a6a1f1dSLionel Sambuc ** <tr><th> createFlag <th> Behavior when page is not already in cache 658311be35a1SLionel Sambuc ** <tr><td> 0 <td> Do not allocate a new page. Return NULL. 658411be35a1SLionel Sambuc ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so. 658511be35a1SLionel Sambuc ** Otherwise return NULL. 658611be35a1SLionel Sambuc ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return 658711be35a1SLionel Sambuc ** NULL if allocating a new page is effectively impossible. 658811be35a1SLionel Sambuc ** </table> 658911be35a1SLionel Sambuc ** 659011be35a1SLionel Sambuc ** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite 659111be35a1SLionel Sambuc ** will only use a createFlag of 2 after a prior call with a createFlag of 1 659211be35a1SLionel Sambuc ** failed.)^ In between the to xFetch() calls, SQLite may 659311be35a1SLionel Sambuc ** attempt to unpin one or more cache pages by spilling the content of 659411be35a1SLionel Sambuc ** pinned pages to disk and synching the operating system disk cache. 659511be35a1SLionel Sambuc ** 659611be35a1SLionel Sambuc ** [[the xUnpin() page cache method]] 659711be35a1SLionel Sambuc ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page 659811be35a1SLionel Sambuc ** as its second argument. If the third parameter, discard, is non-zero, 659911be35a1SLionel Sambuc ** then the page must be evicted from the cache. 660011be35a1SLionel Sambuc ** ^If the discard parameter is 660111be35a1SLionel Sambuc ** zero, then the page may be discarded or retained at the discretion of 660211be35a1SLionel Sambuc ** page cache implementation. ^The page cache implementation 660311be35a1SLionel Sambuc ** may choose to evict unpinned pages at any time. 660411be35a1SLionel Sambuc ** 660511be35a1SLionel Sambuc ** The cache must not perform any reference counting. A single 660611be35a1SLionel Sambuc ** call to xUnpin() unpins the page regardless of the number of prior calls 660711be35a1SLionel Sambuc ** to xFetch(). 660811be35a1SLionel Sambuc ** 660911be35a1SLionel Sambuc ** [[the xRekey() page cache methods]] 661011be35a1SLionel Sambuc ** The xRekey() method is used to change the key value associated with the 661111be35a1SLionel Sambuc ** page passed as the second argument. If the cache 661211be35a1SLionel Sambuc ** previously contains an entry associated with newKey, it must be 661311be35a1SLionel Sambuc ** discarded. ^Any prior cache entry associated with newKey is guaranteed not 661411be35a1SLionel Sambuc ** to be pinned. 661511be35a1SLionel Sambuc ** 661611be35a1SLionel Sambuc ** When SQLite calls the xTruncate() method, the cache must discard all 661711be35a1SLionel Sambuc ** existing cache entries with page numbers (keys) greater than or equal 661811be35a1SLionel Sambuc ** to the value of the iLimit parameter passed to xTruncate(). If any 661911be35a1SLionel Sambuc ** of these pages are pinned, they are implicitly unpinned, meaning that 662011be35a1SLionel Sambuc ** they can be safely discarded. 662111be35a1SLionel Sambuc ** 662211be35a1SLionel Sambuc ** [[the xDestroy() page cache method]] 662311be35a1SLionel Sambuc ** ^The xDestroy() method is used to delete a cache allocated by xCreate(). 662411be35a1SLionel Sambuc ** All resources associated with the specified cache should be freed. ^After 662511be35a1SLionel Sambuc ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*] 662611be35a1SLionel Sambuc ** handle invalid, and will not use it with any other sqlite3_pcache_methods2 662711be35a1SLionel Sambuc ** functions. 662811be35a1SLionel Sambuc ** 662911be35a1SLionel Sambuc ** [[the xShrink() page cache method]] 663011be35a1SLionel Sambuc ** ^SQLite invokes the xShrink() method when it wants the page cache to 663111be35a1SLionel Sambuc ** free up as much of heap memory as possible. The page cache implementation 663211be35a1SLionel Sambuc ** is not obligated to free any memory, but well-behaved implementations should 663311be35a1SLionel Sambuc ** do their best. 663411be35a1SLionel Sambuc */ 663511be35a1SLionel Sambuc typedef struct sqlite3_pcache_methods2 sqlite3_pcache_methods2; 663611be35a1SLionel Sambuc struct sqlite3_pcache_methods2 { 663711be35a1SLionel Sambuc int iVersion; 663811be35a1SLionel Sambuc void *pArg; 663911be35a1SLionel Sambuc int (*xInit)(void*); 664011be35a1SLionel Sambuc void (*xShutdown)(void*); 664111be35a1SLionel Sambuc sqlite3_pcache *(*xCreate)(int szPage, int szExtra, int bPurgeable); 664211be35a1SLionel Sambuc void (*xCachesize)(sqlite3_pcache*, int nCachesize); 664311be35a1SLionel Sambuc int (*xPagecount)(sqlite3_pcache*); 664411be35a1SLionel Sambuc sqlite3_pcache_page *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag); 664511be35a1SLionel Sambuc void (*xUnpin)(sqlite3_pcache*, sqlite3_pcache_page*, int discard); 664611be35a1SLionel Sambuc void (*xRekey)(sqlite3_pcache*, sqlite3_pcache_page*, 664711be35a1SLionel Sambuc unsigned oldKey, unsigned newKey); 664811be35a1SLionel Sambuc void (*xTruncate)(sqlite3_pcache*, unsigned iLimit); 664911be35a1SLionel Sambuc void (*xDestroy)(sqlite3_pcache*); 665011be35a1SLionel Sambuc void (*xShrink)(sqlite3_pcache*); 665111be35a1SLionel Sambuc }; 665211be35a1SLionel Sambuc 665311be35a1SLionel Sambuc /* 665411be35a1SLionel Sambuc ** This is the obsolete pcache_methods object that has now been replaced 665511be35a1SLionel Sambuc ** by sqlite3_pcache_methods2. This object is not used by SQLite. It is 665611be35a1SLionel Sambuc ** retained in the header file for backwards compatibility only. 665711be35a1SLionel Sambuc */ 665811be35a1SLionel Sambuc typedef struct sqlite3_pcache_methods sqlite3_pcache_methods; 665911be35a1SLionel Sambuc struct sqlite3_pcache_methods { 666011be35a1SLionel Sambuc void *pArg; 666111be35a1SLionel Sambuc int (*xInit)(void*); 666211be35a1SLionel Sambuc void (*xShutdown)(void*); 666311be35a1SLionel Sambuc sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable); 666411be35a1SLionel Sambuc void (*xCachesize)(sqlite3_pcache*, int nCachesize); 666511be35a1SLionel Sambuc int (*xPagecount)(sqlite3_pcache*); 666611be35a1SLionel Sambuc void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag); 666711be35a1SLionel Sambuc void (*xUnpin)(sqlite3_pcache*, void*, int discard); 666811be35a1SLionel Sambuc void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey); 666911be35a1SLionel Sambuc void (*xTruncate)(sqlite3_pcache*, unsigned iLimit); 667011be35a1SLionel Sambuc void (*xDestroy)(sqlite3_pcache*); 667111be35a1SLionel Sambuc }; 667211be35a1SLionel Sambuc 667311be35a1SLionel Sambuc 667411be35a1SLionel Sambuc /* 667511be35a1SLionel Sambuc ** CAPI3REF: Online Backup Object 667611be35a1SLionel Sambuc ** 667711be35a1SLionel Sambuc ** The sqlite3_backup object records state information about an ongoing 667811be35a1SLionel Sambuc ** online backup operation. ^The sqlite3_backup object is created by 667911be35a1SLionel Sambuc ** a call to [sqlite3_backup_init()] and is destroyed by a call to 668011be35a1SLionel Sambuc ** [sqlite3_backup_finish()]. 668111be35a1SLionel Sambuc ** 668211be35a1SLionel Sambuc ** See Also: [Using the SQLite Online Backup API] 668311be35a1SLionel Sambuc */ 668411be35a1SLionel Sambuc typedef struct sqlite3_backup sqlite3_backup; 668511be35a1SLionel Sambuc 668611be35a1SLionel Sambuc /* 668711be35a1SLionel Sambuc ** CAPI3REF: Online Backup API. 668811be35a1SLionel Sambuc ** 668911be35a1SLionel Sambuc ** The backup API copies the content of one database into another. 669011be35a1SLionel Sambuc ** It is useful either for creating backups of databases or 669111be35a1SLionel Sambuc ** for copying in-memory databases to or from persistent files. 669211be35a1SLionel Sambuc ** 669311be35a1SLionel Sambuc ** See Also: [Using the SQLite Online Backup API] 669411be35a1SLionel Sambuc ** 669511be35a1SLionel Sambuc ** ^SQLite holds a write transaction open on the destination database file 669611be35a1SLionel Sambuc ** for the duration of the backup operation. 669711be35a1SLionel Sambuc ** ^The source database is read-locked only while it is being read; 669811be35a1SLionel Sambuc ** it is not locked continuously for the entire backup operation. 669911be35a1SLionel Sambuc ** ^Thus, the backup may be performed on a live source database without 670011be35a1SLionel Sambuc ** preventing other database connections from 670111be35a1SLionel Sambuc ** reading or writing to the source database while the backup is underway. 670211be35a1SLionel Sambuc ** 670311be35a1SLionel Sambuc ** ^(To perform a backup operation: 670411be35a1SLionel Sambuc ** <ol> 670511be35a1SLionel Sambuc ** <li><b>sqlite3_backup_init()</b> is called once to initialize the 670611be35a1SLionel Sambuc ** backup, 670711be35a1SLionel Sambuc ** <li><b>sqlite3_backup_step()</b> is called one or more times to transfer 670811be35a1SLionel Sambuc ** the data between the two databases, and finally 670911be35a1SLionel Sambuc ** <li><b>sqlite3_backup_finish()</b> is called to release all resources 671011be35a1SLionel Sambuc ** associated with the backup operation. 671111be35a1SLionel Sambuc ** </ol>)^ 671211be35a1SLionel Sambuc ** There should be exactly one call to sqlite3_backup_finish() for each 671311be35a1SLionel Sambuc ** successful call to sqlite3_backup_init(). 671411be35a1SLionel Sambuc ** 671511be35a1SLionel Sambuc ** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b> 671611be35a1SLionel Sambuc ** 671711be35a1SLionel Sambuc ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the 671811be35a1SLionel Sambuc ** [database connection] associated with the destination database 671911be35a1SLionel Sambuc ** and the database name, respectively. 672011be35a1SLionel Sambuc ** ^The database name is "main" for the main database, "temp" for the 672111be35a1SLionel Sambuc ** temporary database, or the name specified after the AS keyword in 672211be35a1SLionel Sambuc ** an [ATTACH] statement for an attached database. 672311be35a1SLionel Sambuc ** ^The S and M arguments passed to 672411be35a1SLionel Sambuc ** sqlite3_backup_init(D,N,S,M) identify the [database connection] 672511be35a1SLionel Sambuc ** and database name of the source database, respectively. 672611be35a1SLionel Sambuc ** ^The source and destination [database connections] (parameters S and D) 672711be35a1SLionel Sambuc ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with 672811be35a1SLionel Sambuc ** an error. 672911be35a1SLionel Sambuc ** 673011be35a1SLionel Sambuc ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is 673111be35a1SLionel Sambuc ** returned and an error code and error message are stored in the 673211be35a1SLionel Sambuc ** destination [database connection] D. 673311be35a1SLionel Sambuc ** ^The error code and message for the failed call to sqlite3_backup_init() 673411be35a1SLionel Sambuc ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or 673511be35a1SLionel Sambuc ** [sqlite3_errmsg16()] functions. 673611be35a1SLionel Sambuc ** ^A successful call to sqlite3_backup_init() returns a pointer to an 673711be35a1SLionel Sambuc ** [sqlite3_backup] object. 673811be35a1SLionel Sambuc ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and 673911be35a1SLionel Sambuc ** sqlite3_backup_finish() functions to perform the specified backup 674011be35a1SLionel Sambuc ** operation. 674111be35a1SLionel Sambuc ** 674211be35a1SLionel Sambuc ** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b> 674311be35a1SLionel Sambuc ** 674411be35a1SLionel Sambuc ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between 674511be35a1SLionel Sambuc ** the source and destination databases specified by [sqlite3_backup] object B. 674611be35a1SLionel Sambuc ** ^If N is negative, all remaining source pages are copied. 674711be35a1SLionel Sambuc ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there 674811be35a1SLionel Sambuc ** are still more pages to be copied, then the function returns [SQLITE_OK]. 674911be35a1SLionel Sambuc ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages 675011be35a1SLionel Sambuc ** from source to destination, then it returns [SQLITE_DONE]. 675111be35a1SLionel Sambuc ** ^If an error occurs while running sqlite3_backup_step(B,N), 675211be35a1SLionel Sambuc ** then an [error code] is returned. ^As well as [SQLITE_OK] and 675311be35a1SLionel Sambuc ** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY], 675411be35a1SLionel Sambuc ** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an 675511be35a1SLionel Sambuc ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code. 675611be35a1SLionel Sambuc ** 675711be35a1SLionel Sambuc ** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if 675811be35a1SLionel Sambuc ** <ol> 675911be35a1SLionel Sambuc ** <li> the destination database was opened read-only, or 676011be35a1SLionel Sambuc ** <li> the destination database is using write-ahead-log journaling 676111be35a1SLionel Sambuc ** and the destination and source page sizes differ, or 676211be35a1SLionel Sambuc ** <li> the destination database is an in-memory database and the 676311be35a1SLionel Sambuc ** destination and source page sizes differ. 676411be35a1SLionel Sambuc ** </ol>)^ 676511be35a1SLionel Sambuc ** 676611be35a1SLionel Sambuc ** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then 676711be35a1SLionel Sambuc ** the [sqlite3_busy_handler | busy-handler function] 676811be35a1SLionel Sambuc ** is invoked (if one is specified). ^If the 676911be35a1SLionel Sambuc ** busy-handler returns non-zero before the lock is available, then 677011be35a1SLionel Sambuc ** [SQLITE_BUSY] is returned to the caller. ^In this case the call to 677111be35a1SLionel Sambuc ** sqlite3_backup_step() can be retried later. ^If the source 677211be35a1SLionel Sambuc ** [database connection] 677311be35a1SLionel Sambuc ** is being used to write to the source database when sqlite3_backup_step() 677411be35a1SLionel Sambuc ** is called, then [SQLITE_LOCKED] is returned immediately. ^Again, in this 677511be35a1SLionel Sambuc ** case the call to sqlite3_backup_step() can be retried later on. ^(If 677611be35a1SLionel Sambuc ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or 677711be35a1SLionel Sambuc ** [SQLITE_READONLY] is returned, then 677811be35a1SLionel Sambuc ** there is no point in retrying the call to sqlite3_backup_step(). These 677911be35a1SLionel Sambuc ** errors are considered fatal.)^ The application must accept 678011be35a1SLionel Sambuc ** that the backup operation has failed and pass the backup operation handle 678111be35a1SLionel Sambuc ** to the sqlite3_backup_finish() to release associated resources. 678211be35a1SLionel Sambuc ** 678311be35a1SLionel Sambuc ** ^The first call to sqlite3_backup_step() obtains an exclusive lock 678411be35a1SLionel Sambuc ** on the destination file. ^The exclusive lock is not released until either 678511be35a1SLionel Sambuc ** sqlite3_backup_finish() is called or the backup operation is complete 678611be35a1SLionel Sambuc ** and sqlite3_backup_step() returns [SQLITE_DONE]. ^Every call to 678711be35a1SLionel Sambuc ** sqlite3_backup_step() obtains a [shared lock] on the source database that 678811be35a1SLionel Sambuc ** lasts for the duration of the sqlite3_backup_step() call. 678911be35a1SLionel Sambuc ** ^Because the source database is not locked between calls to 679011be35a1SLionel Sambuc ** sqlite3_backup_step(), the source database may be modified mid-way 679111be35a1SLionel Sambuc ** through the backup process. ^If the source database is modified by an 679211be35a1SLionel Sambuc ** external process or via a database connection other than the one being 679311be35a1SLionel Sambuc ** used by the backup operation, then the backup will be automatically 679411be35a1SLionel Sambuc ** restarted by the next call to sqlite3_backup_step(). ^If the source 679511be35a1SLionel Sambuc ** database is modified by the using the same database connection as is used 679611be35a1SLionel Sambuc ** by the backup operation, then the backup database is automatically 679711be35a1SLionel Sambuc ** updated at the same time. 679811be35a1SLionel Sambuc ** 679911be35a1SLionel Sambuc ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b> 680011be35a1SLionel Sambuc ** 680111be35a1SLionel Sambuc ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the 680211be35a1SLionel Sambuc ** application wishes to abandon the backup operation, the application 680311be35a1SLionel Sambuc ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish(). 680411be35a1SLionel Sambuc ** ^The sqlite3_backup_finish() interfaces releases all 680511be35a1SLionel Sambuc ** resources associated with the [sqlite3_backup] object. 680611be35a1SLionel Sambuc ** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any 680711be35a1SLionel Sambuc ** active write-transaction on the destination database is rolled back. 680811be35a1SLionel Sambuc ** The [sqlite3_backup] object is invalid 680911be35a1SLionel Sambuc ** and may not be used following a call to sqlite3_backup_finish(). 681011be35a1SLionel Sambuc ** 681111be35a1SLionel Sambuc ** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no 681211be35a1SLionel Sambuc ** sqlite3_backup_step() errors occurred, regardless or whether or not 681311be35a1SLionel Sambuc ** sqlite3_backup_step() completed. 681411be35a1SLionel Sambuc ** ^If an out-of-memory condition or IO error occurred during any prior 681511be35a1SLionel Sambuc ** sqlite3_backup_step() call on the same [sqlite3_backup] object, then 681611be35a1SLionel Sambuc ** sqlite3_backup_finish() returns the corresponding [error code]. 681711be35a1SLionel Sambuc ** 681811be35a1SLionel Sambuc ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step() 681911be35a1SLionel Sambuc ** is not a permanent error and does not affect the return value of 682011be35a1SLionel Sambuc ** sqlite3_backup_finish(). 682111be35a1SLionel Sambuc ** 682211be35a1SLionel Sambuc ** [[sqlite3_backup__remaining()]] [[sqlite3_backup_pagecount()]] 682311be35a1SLionel Sambuc ** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b> 682411be35a1SLionel Sambuc ** 682511be35a1SLionel Sambuc ** ^Each call to sqlite3_backup_step() sets two values inside 682611be35a1SLionel Sambuc ** the [sqlite3_backup] object: the number of pages still to be backed 682711be35a1SLionel Sambuc ** up and the total number of pages in the source database file. 682811be35a1SLionel Sambuc ** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces 682911be35a1SLionel Sambuc ** retrieve these two values, respectively. 683011be35a1SLionel Sambuc ** 683111be35a1SLionel Sambuc ** ^The values returned by these functions are only updated by 683211be35a1SLionel Sambuc ** sqlite3_backup_step(). ^If the source database is modified during a backup 683311be35a1SLionel Sambuc ** operation, then the values are not updated to account for any extra 683411be35a1SLionel Sambuc ** pages that need to be updated or the size of the source database file 683511be35a1SLionel Sambuc ** changing. 683611be35a1SLionel Sambuc ** 683711be35a1SLionel Sambuc ** <b>Concurrent Usage of Database Handles</b> 683811be35a1SLionel Sambuc ** 683911be35a1SLionel Sambuc ** ^The source [database connection] may be used by the application for other 684011be35a1SLionel Sambuc ** purposes while a backup operation is underway or being initialized. 684111be35a1SLionel Sambuc ** ^If SQLite is compiled and configured to support threadsafe database 684211be35a1SLionel Sambuc ** connections, then the source database connection may be used concurrently 684311be35a1SLionel Sambuc ** from within other threads. 684411be35a1SLionel Sambuc ** 684511be35a1SLionel Sambuc ** However, the application must guarantee that the destination 684611be35a1SLionel Sambuc ** [database connection] is not passed to any other API (by any thread) after 684711be35a1SLionel Sambuc ** sqlite3_backup_init() is called and before the corresponding call to 684811be35a1SLionel Sambuc ** sqlite3_backup_finish(). SQLite does not currently check to see 684911be35a1SLionel Sambuc ** if the application incorrectly accesses the destination [database connection] 685011be35a1SLionel Sambuc ** and so no error code is reported, but the operations may malfunction 685111be35a1SLionel Sambuc ** nevertheless. Use of the destination database connection while a 685211be35a1SLionel Sambuc ** backup is in progress might also also cause a mutex deadlock. 685311be35a1SLionel Sambuc ** 685411be35a1SLionel Sambuc ** If running in [shared cache mode], the application must 685511be35a1SLionel Sambuc ** guarantee that the shared cache used by the destination database 685611be35a1SLionel Sambuc ** is not accessed while the backup is running. In practice this means 685711be35a1SLionel Sambuc ** that the application must guarantee that the disk file being 685811be35a1SLionel Sambuc ** backed up to is not accessed by any connection within the process, 685911be35a1SLionel Sambuc ** not just the specific connection that was passed to sqlite3_backup_init(). 686011be35a1SLionel Sambuc ** 686111be35a1SLionel Sambuc ** The [sqlite3_backup] object itself is partially threadsafe. Multiple 686211be35a1SLionel Sambuc ** threads may safely make multiple concurrent calls to sqlite3_backup_step(). 686311be35a1SLionel Sambuc ** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount() 686411be35a1SLionel Sambuc ** APIs are not strictly speaking threadsafe. If they are invoked at the 686511be35a1SLionel Sambuc ** same time as another thread is invoking sqlite3_backup_step() it is 686611be35a1SLionel Sambuc ** possible that they return invalid values. 686711be35a1SLionel Sambuc */ 686811be35a1SLionel Sambuc SQLITE_API sqlite3_backup *sqlite3_backup_init( 686911be35a1SLionel Sambuc sqlite3 *pDest, /* Destination database handle */ 687011be35a1SLionel Sambuc const char *zDestName, /* Destination database name */ 687111be35a1SLionel Sambuc sqlite3 *pSource, /* Source database handle */ 687211be35a1SLionel Sambuc const char *zSourceName /* Source database name */ 687311be35a1SLionel Sambuc ); 687411be35a1SLionel Sambuc SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage); 687511be35a1SLionel Sambuc SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p); 687611be35a1SLionel Sambuc SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p); 687711be35a1SLionel Sambuc SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p); 687811be35a1SLionel Sambuc 687911be35a1SLionel Sambuc /* 688011be35a1SLionel Sambuc ** CAPI3REF: Unlock Notification 688111be35a1SLionel Sambuc ** 688211be35a1SLionel Sambuc ** ^When running in shared-cache mode, a database operation may fail with 688311be35a1SLionel Sambuc ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or 688411be35a1SLionel Sambuc ** individual tables within the shared-cache cannot be obtained. See 688511be35a1SLionel Sambuc ** [SQLite Shared-Cache Mode] for a description of shared-cache locking. 688611be35a1SLionel Sambuc ** ^This API may be used to register a callback that SQLite will invoke 688711be35a1SLionel Sambuc ** when the connection currently holding the required lock relinquishes it. 688811be35a1SLionel Sambuc ** ^This API is only available if the library was compiled with the 688911be35a1SLionel Sambuc ** [SQLITE_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined. 689011be35a1SLionel Sambuc ** 689111be35a1SLionel Sambuc ** See Also: [Using the SQLite Unlock Notification Feature]. 689211be35a1SLionel Sambuc ** 689311be35a1SLionel Sambuc ** ^Shared-cache locks are released when a database connection concludes 689411be35a1SLionel Sambuc ** its current transaction, either by committing it or rolling it back. 689511be35a1SLionel Sambuc ** 689611be35a1SLionel Sambuc ** ^When a connection (known as the blocked connection) fails to obtain a 689711be35a1SLionel Sambuc ** shared-cache lock and SQLITE_LOCKED is returned to the caller, the 689811be35a1SLionel Sambuc ** identity of the database connection (the blocking connection) that 689911be35a1SLionel Sambuc ** has locked the required resource is stored internally. ^After an 690011be35a1SLionel Sambuc ** application receives an SQLITE_LOCKED error, it may call the 690111be35a1SLionel Sambuc ** sqlite3_unlock_notify() method with the blocked connection handle as 690211be35a1SLionel Sambuc ** the first argument to register for a callback that will be invoked 690311be35a1SLionel Sambuc ** when the blocking connections current transaction is concluded. ^The 690411be35a1SLionel Sambuc ** callback is invoked from within the [sqlite3_step] or [sqlite3_close] 690511be35a1SLionel Sambuc ** call that concludes the blocking connections transaction. 690611be35a1SLionel Sambuc ** 690711be35a1SLionel Sambuc ** ^(If sqlite3_unlock_notify() is called in a multi-threaded application, 690811be35a1SLionel Sambuc ** there is a chance that the blocking connection will have already 690911be35a1SLionel Sambuc ** concluded its transaction by the time sqlite3_unlock_notify() is invoked. 691011be35a1SLionel Sambuc ** If this happens, then the specified callback is invoked immediately, 691111be35a1SLionel Sambuc ** from within the call to sqlite3_unlock_notify().)^ 691211be35a1SLionel Sambuc ** 691311be35a1SLionel Sambuc ** ^If the blocked connection is attempting to obtain a write-lock on a 691411be35a1SLionel Sambuc ** shared-cache table, and more than one other connection currently holds 691511be35a1SLionel Sambuc ** a read-lock on the same table, then SQLite arbitrarily selects one of 691611be35a1SLionel Sambuc ** the other connections to use as the blocking connection. 691711be35a1SLionel Sambuc ** 691811be35a1SLionel Sambuc ** ^(There may be at most one unlock-notify callback registered by a 691911be35a1SLionel Sambuc ** blocked connection. If sqlite3_unlock_notify() is called when the 692011be35a1SLionel Sambuc ** blocked connection already has a registered unlock-notify callback, 692111be35a1SLionel Sambuc ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is 692211be35a1SLionel Sambuc ** called with a NULL pointer as its second argument, then any existing 692311be35a1SLionel Sambuc ** unlock-notify callback is canceled. ^The blocked connections 692411be35a1SLionel Sambuc ** unlock-notify callback may also be canceled by closing the blocked 692511be35a1SLionel Sambuc ** connection using [sqlite3_close()]. 692611be35a1SLionel Sambuc ** 692711be35a1SLionel Sambuc ** The unlock-notify callback is not reentrant. If an application invokes 692811be35a1SLionel Sambuc ** any sqlite3_xxx API functions from within an unlock-notify callback, a 692911be35a1SLionel Sambuc ** crash or deadlock may be the result. 693011be35a1SLionel Sambuc ** 693111be35a1SLionel Sambuc ** ^Unless deadlock is detected (see below), sqlite3_unlock_notify() always 693211be35a1SLionel Sambuc ** returns SQLITE_OK. 693311be35a1SLionel Sambuc ** 693411be35a1SLionel Sambuc ** <b>Callback Invocation Details</b> 693511be35a1SLionel Sambuc ** 693611be35a1SLionel Sambuc ** When an unlock-notify callback is registered, the application provides a 693711be35a1SLionel Sambuc ** single void* pointer that is passed to the callback when it is invoked. 693811be35a1SLionel Sambuc ** However, the signature of the callback function allows SQLite to pass 693911be35a1SLionel Sambuc ** it an array of void* context pointers. The first argument passed to 694011be35a1SLionel Sambuc ** an unlock-notify callback is a pointer to an array of void* pointers, 694111be35a1SLionel Sambuc ** and the second is the number of entries in the array. 694211be35a1SLionel Sambuc ** 694311be35a1SLionel Sambuc ** When a blocking connections transaction is concluded, there may be 694411be35a1SLionel Sambuc ** more than one blocked connection that has registered for an unlock-notify 694511be35a1SLionel Sambuc ** callback. ^If two or more such blocked connections have specified the 694611be35a1SLionel Sambuc ** same callback function, then instead of invoking the callback function 694711be35a1SLionel Sambuc ** multiple times, it is invoked once with the set of void* context pointers 694811be35a1SLionel Sambuc ** specified by the blocked connections bundled together into an array. 694911be35a1SLionel Sambuc ** This gives the application an opportunity to prioritize any actions 695011be35a1SLionel Sambuc ** related to the set of unblocked database connections. 695111be35a1SLionel Sambuc ** 695211be35a1SLionel Sambuc ** <b>Deadlock Detection</b> 695311be35a1SLionel Sambuc ** 695411be35a1SLionel Sambuc ** Assuming that after registering for an unlock-notify callback a 695511be35a1SLionel Sambuc ** database waits for the callback to be issued before taking any further 695611be35a1SLionel Sambuc ** action (a reasonable assumption), then using this API may cause the 695711be35a1SLionel Sambuc ** application to deadlock. For example, if connection X is waiting for 695811be35a1SLionel Sambuc ** connection Y's transaction to be concluded, and similarly connection 695911be35a1SLionel Sambuc ** Y is waiting on connection X's transaction, then neither connection 696011be35a1SLionel Sambuc ** will proceed and the system may remain deadlocked indefinitely. 696111be35a1SLionel Sambuc ** 696211be35a1SLionel Sambuc ** To avoid this scenario, the sqlite3_unlock_notify() performs deadlock 696311be35a1SLionel Sambuc ** detection. ^If a given call to sqlite3_unlock_notify() would put the 696411be35a1SLionel Sambuc ** system in a deadlocked state, then SQLITE_LOCKED is returned and no 696511be35a1SLionel Sambuc ** unlock-notify callback is registered. The system is said to be in 696611be35a1SLionel Sambuc ** a deadlocked state if connection A has registered for an unlock-notify 696711be35a1SLionel Sambuc ** callback on the conclusion of connection B's transaction, and connection 696811be35a1SLionel Sambuc ** B has itself registered for an unlock-notify callback when connection 696911be35a1SLionel Sambuc ** A's transaction is concluded. ^Indirect deadlock is also detected, so 697011be35a1SLionel Sambuc ** the system is also considered to be deadlocked if connection B has 697111be35a1SLionel Sambuc ** registered for an unlock-notify callback on the conclusion of connection 697211be35a1SLionel Sambuc ** C's transaction, where connection C is waiting on connection A. ^Any 697311be35a1SLionel Sambuc ** number of levels of indirection are allowed. 697411be35a1SLionel Sambuc ** 697511be35a1SLionel Sambuc ** <b>The "DROP TABLE" Exception</b> 697611be35a1SLionel Sambuc ** 697711be35a1SLionel Sambuc ** When a call to [sqlite3_step()] returns SQLITE_LOCKED, it is almost 697811be35a1SLionel Sambuc ** always appropriate to call sqlite3_unlock_notify(). There is however, 697911be35a1SLionel Sambuc ** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement, 698011be35a1SLionel Sambuc ** SQLite checks if there are any currently executing SELECT statements 698111be35a1SLionel Sambuc ** that belong to the same connection. If there are, SQLITE_LOCKED is 698211be35a1SLionel Sambuc ** returned. In this case there is no "blocking connection", so invoking 698311be35a1SLionel Sambuc ** sqlite3_unlock_notify() results in the unlock-notify callback being 698411be35a1SLionel Sambuc ** invoked immediately. If the application then re-attempts the "DROP TABLE" 698511be35a1SLionel Sambuc ** or "DROP INDEX" query, an infinite loop might be the result. 698611be35a1SLionel Sambuc ** 698711be35a1SLionel Sambuc ** One way around this problem is to check the extended error code returned 698811be35a1SLionel Sambuc ** by an sqlite3_step() call. ^(If there is a blocking connection, then the 698911be35a1SLionel Sambuc ** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in 699011be35a1SLionel Sambuc ** the special "DROP TABLE/INDEX" case, the extended error code is just 699111be35a1SLionel Sambuc ** SQLITE_LOCKED.)^ 699211be35a1SLionel Sambuc */ 699311be35a1SLionel Sambuc SQLITE_API int sqlite3_unlock_notify( 699411be35a1SLionel Sambuc sqlite3 *pBlocked, /* Waiting connection */ 699511be35a1SLionel Sambuc void (*xNotify)(void **apArg, int nArg), /* Callback function to invoke */ 699611be35a1SLionel Sambuc void *pNotifyArg /* Argument to pass to xNotify */ 699711be35a1SLionel Sambuc ); 699811be35a1SLionel Sambuc 699911be35a1SLionel Sambuc 700011be35a1SLionel Sambuc /* 700111be35a1SLionel Sambuc ** CAPI3REF: String Comparison 700211be35a1SLionel Sambuc ** 7003*0a6a1f1dSLionel Sambuc ** ^The [sqlite3_stricmp()] and [sqlite3_strnicmp()] APIs allow applications 7004*0a6a1f1dSLionel Sambuc ** and extensions to compare the contents of two buffers containing UTF-8 7005*0a6a1f1dSLionel Sambuc ** strings in a case-independent fashion, using the same definition of "case 7006*0a6a1f1dSLionel Sambuc ** independence" that SQLite uses internally when comparing identifiers. 700711be35a1SLionel Sambuc */ 7008*0a6a1f1dSLionel Sambuc SQLITE_API int sqlite3_stricmp(const char *, const char *); 700911be35a1SLionel Sambuc SQLITE_API int sqlite3_strnicmp(const char *, const char *, int); 701011be35a1SLionel Sambuc 701111be35a1SLionel Sambuc /* 7012*0a6a1f1dSLionel Sambuc ** CAPI3REF: String Globbing 7013*0a6a1f1dSLionel Sambuc * 7014*0a6a1f1dSLionel Sambuc ** ^The [sqlite3_strglob(P,X)] interface returns zero if string X matches 7015*0a6a1f1dSLionel Sambuc ** the glob pattern P, and it returns non-zero if string X does not match 7016*0a6a1f1dSLionel Sambuc ** the glob pattern P. ^The definition of glob pattern matching used in 7017*0a6a1f1dSLionel Sambuc ** [sqlite3_strglob(P,X)] is the same as for the "X GLOB P" operator in the 7018*0a6a1f1dSLionel Sambuc ** SQL dialect used by SQLite. ^The sqlite3_strglob(P,X) function is case 7019*0a6a1f1dSLionel Sambuc ** sensitive. 7020*0a6a1f1dSLionel Sambuc ** 7021*0a6a1f1dSLionel Sambuc ** Note that this routine returns zero on a match and non-zero if the strings 7022*0a6a1f1dSLionel Sambuc ** do not match, the same as [sqlite3_stricmp()] and [sqlite3_strnicmp()]. 7023*0a6a1f1dSLionel Sambuc */ 7024*0a6a1f1dSLionel Sambuc SQLITE_API int sqlite3_strglob(const char *zGlob, const char *zStr); 7025*0a6a1f1dSLionel Sambuc 7026*0a6a1f1dSLionel Sambuc /* 702711be35a1SLionel Sambuc ** CAPI3REF: Error Logging Interface 702811be35a1SLionel Sambuc ** 7029*0a6a1f1dSLionel Sambuc ** ^The [sqlite3_log()] interface writes a message into the [error log] 703011be35a1SLionel Sambuc ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()]. 703111be35a1SLionel Sambuc ** ^If logging is enabled, the zFormat string and subsequent arguments are 703211be35a1SLionel Sambuc ** used with [sqlite3_snprintf()] to generate the final output string. 703311be35a1SLionel Sambuc ** 703411be35a1SLionel Sambuc ** The sqlite3_log() interface is intended for use by extensions such as 703511be35a1SLionel Sambuc ** virtual tables, collating functions, and SQL functions. While there is 703611be35a1SLionel Sambuc ** nothing to prevent an application from calling sqlite3_log(), doing so 703711be35a1SLionel Sambuc ** is considered bad form. 703811be35a1SLionel Sambuc ** 703911be35a1SLionel Sambuc ** The zFormat string must not be NULL. 704011be35a1SLionel Sambuc ** 704111be35a1SLionel Sambuc ** To avoid deadlocks and other threading problems, the sqlite3_log() routine 704211be35a1SLionel Sambuc ** will not use dynamically allocated memory. The log message is stored in 704311be35a1SLionel Sambuc ** a fixed-length buffer on the stack. If the log message is longer than 704411be35a1SLionel Sambuc ** a few hundred characters, it will be truncated to the length of the 704511be35a1SLionel Sambuc ** buffer. 704611be35a1SLionel Sambuc */ 704711be35a1SLionel Sambuc SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...); 704811be35a1SLionel Sambuc 704911be35a1SLionel Sambuc /* 705011be35a1SLionel Sambuc ** CAPI3REF: Write-Ahead Log Commit Hook 705111be35a1SLionel Sambuc ** 705211be35a1SLionel Sambuc ** ^The [sqlite3_wal_hook()] function is used to register a callback that 705311be35a1SLionel Sambuc ** will be invoked each time a database connection commits data to a 705411be35a1SLionel Sambuc ** [write-ahead log] (i.e. whenever a transaction is committed in 705511be35a1SLionel Sambuc ** [journal_mode | journal_mode=WAL mode]). 705611be35a1SLionel Sambuc ** 705711be35a1SLionel Sambuc ** ^The callback is invoked by SQLite after the commit has taken place and 705811be35a1SLionel Sambuc ** the associated write-lock on the database released, so the implementation 705911be35a1SLionel Sambuc ** may read, write or [checkpoint] the database as required. 706011be35a1SLionel Sambuc ** 706111be35a1SLionel Sambuc ** ^The first parameter passed to the callback function when it is invoked 706211be35a1SLionel Sambuc ** is a copy of the third parameter passed to sqlite3_wal_hook() when 706311be35a1SLionel Sambuc ** registering the callback. ^The second is a copy of the database handle. 706411be35a1SLionel Sambuc ** ^The third parameter is the name of the database that was written to - 706511be35a1SLionel Sambuc ** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter 706611be35a1SLionel Sambuc ** is the number of pages currently in the write-ahead log file, 706711be35a1SLionel Sambuc ** including those that were just committed. 706811be35a1SLionel Sambuc ** 706911be35a1SLionel Sambuc ** The callback function should normally return [SQLITE_OK]. ^If an error 707011be35a1SLionel Sambuc ** code is returned, that error will propagate back up through the 707111be35a1SLionel Sambuc ** SQLite code base to cause the statement that provoked the callback 707211be35a1SLionel Sambuc ** to report an error, though the commit will have still occurred. If the 707311be35a1SLionel Sambuc ** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value 707411be35a1SLionel Sambuc ** that does not correspond to any valid SQLite error code, the results 707511be35a1SLionel Sambuc ** are undefined. 707611be35a1SLionel Sambuc ** 707711be35a1SLionel Sambuc ** A single database handle may have at most a single write-ahead log callback 707811be35a1SLionel Sambuc ** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any 707911be35a1SLionel Sambuc ** previously registered write-ahead log callback. ^Note that the 708011be35a1SLionel Sambuc ** [sqlite3_wal_autocheckpoint()] interface and the 708111be35a1SLionel Sambuc ** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will 708211be35a1SLionel Sambuc ** those overwrite any prior [sqlite3_wal_hook()] settings. 708311be35a1SLionel Sambuc */ 708411be35a1SLionel Sambuc SQLITE_API void *sqlite3_wal_hook( 708511be35a1SLionel Sambuc sqlite3*, 708611be35a1SLionel Sambuc int(*)(void *,sqlite3*,const char*,int), 708711be35a1SLionel Sambuc void* 708811be35a1SLionel Sambuc ); 708911be35a1SLionel Sambuc 709011be35a1SLionel Sambuc /* 709111be35a1SLionel Sambuc ** CAPI3REF: Configure an auto-checkpoint 709211be35a1SLionel Sambuc ** 709311be35a1SLionel Sambuc ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around 709411be35a1SLionel Sambuc ** [sqlite3_wal_hook()] that causes any database on [database connection] D 709511be35a1SLionel Sambuc ** to automatically [checkpoint] 709611be35a1SLionel Sambuc ** after committing a transaction if there are N or 709711be35a1SLionel Sambuc ** more frames in the [write-ahead log] file. ^Passing zero or 709811be35a1SLionel Sambuc ** a negative value as the nFrame parameter disables automatic 709911be35a1SLionel Sambuc ** checkpoints entirely. 710011be35a1SLionel Sambuc ** 710111be35a1SLionel Sambuc ** ^The callback registered by this function replaces any existing callback 710211be35a1SLionel Sambuc ** registered using [sqlite3_wal_hook()]. ^Likewise, registering a callback 710311be35a1SLionel Sambuc ** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism 710411be35a1SLionel Sambuc ** configured by this function. 710511be35a1SLionel Sambuc ** 710611be35a1SLionel Sambuc ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface 710711be35a1SLionel Sambuc ** from SQL. 710811be35a1SLionel Sambuc ** 710911be35a1SLionel Sambuc ** ^Every new [database connection] defaults to having the auto-checkpoint 711011be35a1SLionel Sambuc ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT] 711111be35a1SLionel Sambuc ** pages. The use of this interface 711211be35a1SLionel Sambuc ** is only necessary if the default setting is found to be suboptimal 711311be35a1SLionel Sambuc ** for a particular application. 711411be35a1SLionel Sambuc */ 711511be35a1SLionel Sambuc SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N); 711611be35a1SLionel Sambuc 711711be35a1SLionel Sambuc /* 711811be35a1SLionel Sambuc ** CAPI3REF: Checkpoint a database 711911be35a1SLionel Sambuc ** 712011be35a1SLionel Sambuc ** ^The [sqlite3_wal_checkpoint(D,X)] interface causes database named X 712111be35a1SLionel Sambuc ** on [database connection] D to be [checkpointed]. ^If X is NULL or an 712211be35a1SLionel Sambuc ** empty string, then a checkpoint is run on all databases of 712311be35a1SLionel Sambuc ** connection D. ^If the database connection D is not in 712411be35a1SLionel Sambuc ** [WAL | write-ahead log mode] then this interface is a harmless no-op. 712511be35a1SLionel Sambuc ** 712611be35a1SLionel Sambuc ** ^The [wal_checkpoint pragma] can be used to invoke this interface 712711be35a1SLionel Sambuc ** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the 712811be35a1SLionel Sambuc ** [wal_autocheckpoint pragma] can be used to cause this interface to be 712911be35a1SLionel Sambuc ** run whenever the WAL reaches a certain size threshold. 713011be35a1SLionel Sambuc ** 713111be35a1SLionel Sambuc ** See also: [sqlite3_wal_checkpoint_v2()] 713211be35a1SLionel Sambuc */ 713311be35a1SLionel Sambuc SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); 713411be35a1SLionel Sambuc 713511be35a1SLionel Sambuc /* 713611be35a1SLionel Sambuc ** CAPI3REF: Checkpoint a database 713711be35a1SLionel Sambuc ** 713811be35a1SLionel Sambuc ** Run a checkpoint operation on WAL database zDb attached to database 713911be35a1SLionel Sambuc ** handle db. The specific operation is determined by the value of the 714011be35a1SLionel Sambuc ** eMode parameter: 714111be35a1SLionel Sambuc ** 714211be35a1SLionel Sambuc ** <dl> 714311be35a1SLionel Sambuc ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd> 714411be35a1SLionel Sambuc ** Checkpoint as many frames as possible without waiting for any database 714511be35a1SLionel Sambuc ** readers or writers to finish. Sync the db file if all frames in the log 714611be35a1SLionel Sambuc ** are checkpointed. This mode is the same as calling 714711be35a1SLionel Sambuc ** sqlite3_wal_checkpoint(). The busy-handler callback is never invoked. 714811be35a1SLionel Sambuc ** 714911be35a1SLionel Sambuc ** <dt>SQLITE_CHECKPOINT_FULL<dd> 715011be35a1SLionel Sambuc ** This mode blocks (calls the busy-handler callback) until there is no 715111be35a1SLionel Sambuc ** database writer and all readers are reading from the most recent database 715211be35a1SLionel Sambuc ** snapshot. It then checkpoints all frames in the log file and syncs the 715311be35a1SLionel Sambuc ** database file. This call blocks database writers while it is running, 715411be35a1SLionel Sambuc ** but not database readers. 715511be35a1SLionel Sambuc ** 715611be35a1SLionel Sambuc ** <dt>SQLITE_CHECKPOINT_RESTART<dd> 715711be35a1SLionel Sambuc ** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after 715811be35a1SLionel Sambuc ** checkpointing the log file it blocks (calls the busy-handler callback) 715911be35a1SLionel Sambuc ** until all readers are reading from the database file only. This ensures 716011be35a1SLionel Sambuc ** that the next client to write to the database file restarts the log file 716111be35a1SLionel Sambuc ** from the beginning. This call blocks database writers while it is running, 716211be35a1SLionel Sambuc ** but not database readers. 716311be35a1SLionel Sambuc ** </dl> 716411be35a1SLionel Sambuc ** 716511be35a1SLionel Sambuc ** If pnLog is not NULL, then *pnLog is set to the total number of frames in 716611be35a1SLionel Sambuc ** the log file before returning. If pnCkpt is not NULL, then *pnCkpt is set to 716711be35a1SLionel Sambuc ** the total number of checkpointed frames (including any that were already 716811be35a1SLionel Sambuc ** checkpointed when this function is called). *pnLog and *pnCkpt may be 716911be35a1SLionel Sambuc ** populated even if sqlite3_wal_checkpoint_v2() returns other than SQLITE_OK. 717011be35a1SLionel Sambuc ** If no values are available because of an error, they are both set to -1 717111be35a1SLionel Sambuc ** before returning to communicate this to the caller. 717211be35a1SLionel Sambuc ** 717311be35a1SLionel Sambuc ** All calls obtain an exclusive "checkpoint" lock on the database file. If 717411be35a1SLionel Sambuc ** any other process is running a checkpoint operation at the same time, the 717511be35a1SLionel Sambuc ** lock cannot be obtained and SQLITE_BUSY is returned. Even if there is a 717611be35a1SLionel Sambuc ** busy-handler configured, it will not be invoked in this case. 717711be35a1SLionel Sambuc ** 717811be35a1SLionel Sambuc ** The SQLITE_CHECKPOINT_FULL and RESTART modes also obtain the exclusive 717911be35a1SLionel Sambuc ** "writer" lock on the database file. If the writer lock cannot be obtained 718011be35a1SLionel Sambuc ** immediately, and a busy-handler is configured, it is invoked and the writer 718111be35a1SLionel Sambuc ** lock retried until either the busy-handler returns 0 or the lock is 718211be35a1SLionel Sambuc ** successfully obtained. The busy-handler is also invoked while waiting for 718311be35a1SLionel Sambuc ** database readers as described above. If the busy-handler returns 0 before 718411be35a1SLionel Sambuc ** the writer lock is obtained or while waiting for database readers, the 718511be35a1SLionel Sambuc ** checkpoint operation proceeds from that point in the same way as 718611be35a1SLionel Sambuc ** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible 718711be35a1SLionel Sambuc ** without blocking any further. SQLITE_BUSY is returned in this case. 718811be35a1SLionel Sambuc ** 718911be35a1SLionel Sambuc ** If parameter zDb is NULL or points to a zero length string, then the 719011be35a1SLionel Sambuc ** specified operation is attempted on all WAL databases. In this case the 719111be35a1SLionel Sambuc ** values written to output parameters *pnLog and *pnCkpt are undefined. If 719211be35a1SLionel Sambuc ** an SQLITE_BUSY error is encountered when processing one or more of the 719311be35a1SLionel Sambuc ** attached WAL databases, the operation is still attempted on any remaining 719411be35a1SLionel Sambuc ** attached databases and SQLITE_BUSY is returned to the caller. If any other 719511be35a1SLionel Sambuc ** error occurs while processing an attached database, processing is abandoned 719611be35a1SLionel Sambuc ** and the error code returned to the caller immediately. If no error 719711be35a1SLionel Sambuc ** (SQLITE_BUSY or otherwise) is encountered while processing the attached 719811be35a1SLionel Sambuc ** databases, SQLITE_OK is returned. 719911be35a1SLionel Sambuc ** 720011be35a1SLionel Sambuc ** If database zDb is the name of an attached database that is not in WAL 720111be35a1SLionel Sambuc ** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. If 720211be35a1SLionel Sambuc ** zDb is not NULL (or a zero length string) and is not the name of any 720311be35a1SLionel Sambuc ** attached database, SQLITE_ERROR is returned to the caller. 720411be35a1SLionel Sambuc */ 720511be35a1SLionel Sambuc SQLITE_API int sqlite3_wal_checkpoint_v2( 720611be35a1SLionel Sambuc sqlite3 *db, /* Database handle */ 720711be35a1SLionel Sambuc const char *zDb, /* Name of attached database (or NULL) */ 720811be35a1SLionel Sambuc int eMode, /* SQLITE_CHECKPOINT_* value */ 720911be35a1SLionel Sambuc int *pnLog, /* OUT: Size of WAL log in frames */ 721011be35a1SLionel Sambuc int *pnCkpt /* OUT: Total number of frames checkpointed */ 721111be35a1SLionel Sambuc ); 721211be35a1SLionel Sambuc 721311be35a1SLionel Sambuc /* 721411be35a1SLionel Sambuc ** CAPI3REF: Checkpoint operation parameters 721511be35a1SLionel Sambuc ** 721611be35a1SLionel Sambuc ** These constants can be used as the 3rd parameter to 721711be35a1SLionel Sambuc ** [sqlite3_wal_checkpoint_v2()]. See the [sqlite3_wal_checkpoint_v2()] 721811be35a1SLionel Sambuc ** documentation for additional information about the meaning and use of 721911be35a1SLionel Sambuc ** each of these values. 722011be35a1SLionel Sambuc */ 722111be35a1SLionel Sambuc #define SQLITE_CHECKPOINT_PASSIVE 0 722211be35a1SLionel Sambuc #define SQLITE_CHECKPOINT_FULL 1 722311be35a1SLionel Sambuc #define SQLITE_CHECKPOINT_RESTART 2 722411be35a1SLionel Sambuc 722511be35a1SLionel Sambuc /* 722611be35a1SLionel Sambuc ** CAPI3REF: Virtual Table Interface Configuration 722711be35a1SLionel Sambuc ** 722811be35a1SLionel Sambuc ** This function may be called by either the [xConnect] or [xCreate] method 722911be35a1SLionel Sambuc ** of a [virtual table] implementation to configure 723011be35a1SLionel Sambuc ** various facets of the virtual table interface. 723111be35a1SLionel Sambuc ** 723211be35a1SLionel Sambuc ** If this interface is invoked outside the context of an xConnect or 723311be35a1SLionel Sambuc ** xCreate virtual table method then the behavior is undefined. 723411be35a1SLionel Sambuc ** 723511be35a1SLionel Sambuc ** At present, there is only one option that may be configured using 723611be35a1SLionel Sambuc ** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].) Further options 723711be35a1SLionel Sambuc ** may be added in the future. 723811be35a1SLionel Sambuc */ 723911be35a1SLionel Sambuc SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...); 724011be35a1SLionel Sambuc 724111be35a1SLionel Sambuc /* 724211be35a1SLionel Sambuc ** CAPI3REF: Virtual Table Configuration Options 724311be35a1SLionel Sambuc ** 724411be35a1SLionel Sambuc ** These macros define the various options to the 724511be35a1SLionel Sambuc ** [sqlite3_vtab_config()] interface that [virtual table] implementations 724611be35a1SLionel Sambuc ** can use to customize and optimize their behavior. 724711be35a1SLionel Sambuc ** 724811be35a1SLionel Sambuc ** <dl> 724911be35a1SLionel Sambuc ** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT 725011be35a1SLionel Sambuc ** <dd>Calls of the form 725111be35a1SLionel Sambuc ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported, 725211be35a1SLionel Sambuc ** where X is an integer. If X is zero, then the [virtual table] whose 725311be35a1SLionel Sambuc ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not 725411be35a1SLionel Sambuc ** support constraints. In this configuration (which is the default) if 725511be35a1SLionel Sambuc ** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire 725611be35a1SLionel Sambuc ** statement is rolled back as if [ON CONFLICT | OR ABORT] had been 725711be35a1SLionel Sambuc ** specified as part of the users SQL statement, regardless of the actual 725811be35a1SLionel Sambuc ** ON CONFLICT mode specified. 725911be35a1SLionel Sambuc ** 726011be35a1SLionel Sambuc ** If X is non-zero, then the virtual table implementation guarantees 726111be35a1SLionel Sambuc ** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before 726211be35a1SLionel Sambuc ** any modifications to internal or persistent data structures have been made. 726311be35a1SLionel Sambuc ** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite 726411be35a1SLionel Sambuc ** is able to roll back a statement or database transaction, and abandon 726511be35a1SLionel Sambuc ** or continue processing the current SQL statement as appropriate. 726611be35a1SLionel Sambuc ** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns 726711be35a1SLionel Sambuc ** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode 726811be35a1SLionel Sambuc ** had been ABORT. 726911be35a1SLionel Sambuc ** 727011be35a1SLionel Sambuc ** Virtual table implementations that are required to handle OR REPLACE 727111be35a1SLionel Sambuc ** must do so within the [xUpdate] method. If a call to the 727211be35a1SLionel Sambuc ** [sqlite3_vtab_on_conflict()] function indicates that the current ON 727311be35a1SLionel Sambuc ** CONFLICT policy is REPLACE, the virtual table implementation should 727411be35a1SLionel Sambuc ** silently replace the appropriate rows within the xUpdate callback and 727511be35a1SLionel Sambuc ** return SQLITE_OK. Or, if this is not possible, it may return 727611be35a1SLionel Sambuc ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT 727711be35a1SLionel Sambuc ** constraint handling. 727811be35a1SLionel Sambuc ** </dl> 727911be35a1SLionel Sambuc */ 728011be35a1SLionel Sambuc #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1 728111be35a1SLionel Sambuc 728211be35a1SLionel Sambuc /* 728311be35a1SLionel Sambuc ** CAPI3REF: Determine The Virtual Table Conflict Policy 728411be35a1SLionel Sambuc ** 728511be35a1SLionel Sambuc ** This function may only be called from within a call to the [xUpdate] method 728611be35a1SLionel Sambuc ** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The 728711be35a1SLionel Sambuc ** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL], 728811be35a1SLionel Sambuc ** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode 728911be35a1SLionel Sambuc ** of the SQL statement that triggered the call to the [xUpdate] method of the 729011be35a1SLionel Sambuc ** [virtual table]. 729111be35a1SLionel Sambuc */ 729211be35a1SLionel Sambuc SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *); 729311be35a1SLionel Sambuc 729411be35a1SLionel Sambuc /* 729511be35a1SLionel Sambuc ** CAPI3REF: Conflict resolution modes 729611be35a1SLionel Sambuc ** 729711be35a1SLionel Sambuc ** These constants are returned by [sqlite3_vtab_on_conflict()] to 729811be35a1SLionel Sambuc ** inform a [virtual table] implementation what the [ON CONFLICT] mode 729911be35a1SLionel Sambuc ** is for the SQL statement being evaluated. 730011be35a1SLionel Sambuc ** 730111be35a1SLionel Sambuc ** Note that the [SQLITE_IGNORE] constant is also used as a potential 730211be35a1SLionel Sambuc ** return value from the [sqlite3_set_authorizer()] callback and that 730311be35a1SLionel Sambuc ** [SQLITE_ABORT] is also a [result code]. 730411be35a1SLionel Sambuc */ 730511be35a1SLionel Sambuc #define SQLITE_ROLLBACK 1 730611be35a1SLionel Sambuc /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */ 730711be35a1SLionel Sambuc #define SQLITE_FAIL 3 730811be35a1SLionel Sambuc /* #define SQLITE_ABORT 4 // Also an error code */ 730911be35a1SLionel Sambuc #define SQLITE_REPLACE 5 731011be35a1SLionel Sambuc 731111be35a1SLionel Sambuc 731211be35a1SLionel Sambuc 731311be35a1SLionel Sambuc /* 731411be35a1SLionel Sambuc ** Undo the hack that converts floating point types to integer for 731511be35a1SLionel Sambuc ** builds on processors without floating point support. 731611be35a1SLionel Sambuc */ 731711be35a1SLionel Sambuc #ifdef SQLITE_OMIT_FLOATING_POINT 731811be35a1SLionel Sambuc # undef double 731911be35a1SLionel Sambuc #endif 732011be35a1SLionel Sambuc 732111be35a1SLionel Sambuc #ifdef __cplusplus 732211be35a1SLionel Sambuc } /* End of the 'extern "C"' block */ 732311be35a1SLionel Sambuc #endif 7324*0a6a1f1dSLionel Sambuc #endif /* _SQLITE3_H_ */ 732511be35a1SLionel Sambuc 732611be35a1SLionel Sambuc /* 732711be35a1SLionel Sambuc ** 2010 August 30 732811be35a1SLionel Sambuc ** 732911be35a1SLionel Sambuc ** The author disclaims copyright to this source code. In place of 733011be35a1SLionel Sambuc ** a legal notice, here is a blessing: 733111be35a1SLionel Sambuc ** 733211be35a1SLionel Sambuc ** May you do good and not evil. 733311be35a1SLionel Sambuc ** May you find forgiveness for yourself and forgive others. 733411be35a1SLionel Sambuc ** May you share freely, never taking more than you give. 733511be35a1SLionel Sambuc ** 733611be35a1SLionel Sambuc ************************************************************************* 733711be35a1SLionel Sambuc */ 733811be35a1SLionel Sambuc 733911be35a1SLionel Sambuc #ifndef _SQLITE3RTREE_H_ 734011be35a1SLionel Sambuc #define _SQLITE3RTREE_H_ 734111be35a1SLionel Sambuc 734211be35a1SLionel Sambuc 734311be35a1SLionel Sambuc #ifdef __cplusplus 734411be35a1SLionel Sambuc extern "C" { 734511be35a1SLionel Sambuc #endif 734611be35a1SLionel Sambuc 734711be35a1SLionel Sambuc typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry; 734811be35a1SLionel Sambuc 734911be35a1SLionel Sambuc /* 735011be35a1SLionel Sambuc ** Register a geometry callback named zGeom that can be used as part of an 735111be35a1SLionel Sambuc ** R-Tree geometry query as follows: 735211be35a1SLionel Sambuc ** 735311be35a1SLionel Sambuc ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...) 735411be35a1SLionel Sambuc */ 735511be35a1SLionel Sambuc SQLITE_API int sqlite3_rtree_geometry_callback( 735611be35a1SLionel Sambuc sqlite3 *db, 735711be35a1SLionel Sambuc const char *zGeom, 7358*0a6a1f1dSLionel Sambuc #ifdef SQLITE_RTREE_INT_ONLY 7359*0a6a1f1dSLionel Sambuc int (*xGeom)(sqlite3_rtree_geometry*, int n, sqlite3_int64 *a, int *pRes), 7360*0a6a1f1dSLionel Sambuc #else 7361*0a6a1f1dSLionel Sambuc int (*xGeom)(sqlite3_rtree_geometry*, int n, double *a, int *pRes), 7362*0a6a1f1dSLionel Sambuc #endif 736311be35a1SLionel Sambuc void *pContext 736411be35a1SLionel Sambuc ); 736511be35a1SLionel Sambuc 736611be35a1SLionel Sambuc 736711be35a1SLionel Sambuc /* 736811be35a1SLionel Sambuc ** A pointer to a structure of the following type is passed as the first 736911be35a1SLionel Sambuc ** argument to callbacks registered using rtree_geometry_callback(). 737011be35a1SLionel Sambuc */ 737111be35a1SLionel Sambuc struct sqlite3_rtree_geometry { 737211be35a1SLionel Sambuc void *pContext; /* Copy of pContext passed to s_r_g_c() */ 737311be35a1SLionel Sambuc int nParam; /* Size of array aParam[] */ 737411be35a1SLionel Sambuc double *aParam; /* Parameters passed to SQL geom function */ 737511be35a1SLionel Sambuc void *pUser; /* Callback implementation user data */ 737611be35a1SLionel Sambuc void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */ 737711be35a1SLionel Sambuc }; 737811be35a1SLionel Sambuc 737911be35a1SLionel Sambuc 738011be35a1SLionel Sambuc #ifdef __cplusplus 738111be35a1SLionel Sambuc } /* end of the 'extern "C"' block */ 738211be35a1SLionel Sambuc #endif 738311be35a1SLionel Sambuc 738411be35a1SLionel Sambuc #endif /* ifndef _SQLITE3RTREE_H_ */ 738511be35a1SLionel Sambuc 7386