ds@1952: /* ds@1952: ** 2001 September 15 ds@1952: ** ds@1952: ** The author disclaims copyright to this source code. In place of ds@1952: ** a legal notice, here is a blessing: ds@1952: ** ds@1952: ** May you do good and not evil. ds@1952: ** May you find forgiveness for yourself and forgive others. ds@1952: ** May you share freely, never taking more than you give. ds@1952: ** ds@1952: ************************************************************************* ds@1952: ** This header file defines the interface that the SQLite library ds@1952: ** presents to client programs. If a C-function, structure, datatype, ds@1952: ** or constant definition does not appear in this file, then it is ds@1952: ** not a published API of SQLite, is subject to change without ds@1952: ** notice, and should not be referenced by programs that use SQLite. ds@1952: ** ds@1952: ** Some of the definitions that are in this file are marked as ds@1952: ** "experimental". Experimental interfaces are normally new ds@1952: ** features recently added to SQLite. We do not anticipate changes ds@1952: ** to experimental interfaces but reserve to make minor changes if ds@1952: ** experience from use "in the wild" suggest such changes are prudent. ds@1952: ** ds@1952: ** The official C-language API documentation for SQLite is derived ds@1952: ** from comments in this file. This file is the authoritative source ds@1952: ** on how SQLite interfaces are suppose to operate. ds@1952: ** ds@1952: ** The name of this file under configuration management is "sqlite.h.in". ds@1952: ** The makefile makes some minor changes to this file (such as inserting ds@1952: ** the version number) and changes its name to "sqlite3.h" as ds@1952: ** part of the build process. ds@1952: ** ds@1952: ** @(#) $Id$ ds@1952: */ ds@1952: #ifndef _SQLITE3_H_ ds@1952: #define _SQLITE3_H_ ds@1952: #include /* Needed for the definition of va_list */ ds@1952: ds@1952: /* ds@1952: ** Make sure we can call this stuff from C++. ds@1952: */ ds@1952: #ifdef __cplusplus ds@1952: extern "C" { ds@1952: #endif ds@1952: ds@1952: ds@1952: /* ds@1952: ** Add the ability to override 'extern' ds@1952: */ ds@1952: #ifndef SQLITE_EXTERN ds@1952: # define SQLITE_EXTERN extern ds@1952: #endif ds@1952: ds@1952: /* ds@1952: ** Make sure these symbols where not defined by some previous header ds@1952: ** file. ds@1952: */ ds@1952: #ifdef SQLITE_VERSION ds@1952: # undef SQLITE_VERSION ds@1952: #endif ds@1952: #ifdef SQLITE_VERSION_NUMBER ds@1952: # undef SQLITE_VERSION_NUMBER ds@1952: #endif ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Compile-Time Library Version Numbers ds@1952: ** ds@1952: ** The version of the SQLite library is contained in the sqlite3.h ds@1952: ** header file in a #define named SQLITE_VERSION. The SQLITE_VERSION ds@1952: ** macro resolves to a string constant. ds@1952: ** ds@1952: ** The format of the version string is "X.Y.Z", where ds@1952: ** X is the major version number, Y is the minor version number and Z ds@1952: ** is the release number. The X.Y.Z might be followed by "alpha" or "beta". ds@1952: ** For example "3.1.1beta". ds@1952: ** ds@1952: ** The X value is always 3 in SQLite. The X value only changes when ds@1952: ** backwards compatibility is broken and we intend to never break ds@1952: ** backwards compatibility. The Y value only changes when ds@1952: ** there are major feature enhancements that are forwards compatible ds@1952: ** but not backwards compatible. The Z value is incremented with ds@1952: ** each release but resets back to 0 when Y is incremented. ds@1952: ** ds@1952: ** The SQLITE_VERSION_NUMBER is an integer with the value ds@1952: ** (X*1000000 + Y*1000 + Z). For example, for version "3.1.1beta", ds@1952: ** SQLITE_VERSION_NUMBER is set to 3001001. To detect if they are using ds@1952: ** version 3.1.1 or greater at compile time, programs may use the test ds@1952: ** (SQLITE_VERSION_NUMBER>=3001001). ds@1952: ** ds@1952: ** See also: [sqlite3_libversion()] and [sqlite3_libversion_number()]. ds@1952: */ ds@1952: #define SQLITE_VERSION "3.5.1" ds@1952: #define SQLITE_VERSION_NUMBER 3005001 ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Run-Time Library Version Numbers ds@1952: ** ds@1952: ** These routines return values equivalent to the header constants ds@1952: ** [SQLITE_VERSION] and [SQLITE_VERSION_NUMBER]. The values returned ds@1952: ** by this routines should only be different from the header values ds@1952: ** if you compile your program using an sqlite3.h header from a ds@1952: ** different version of SQLite that the version of the library you ds@1952: ** link against. ds@1952: ** ds@1952: ** The sqlite3_version[] string constant contains the text of the ds@1952: ** [SQLITE_VERSION] string. The sqlite3_libversion() function returns ds@1952: ** a poiner to the sqlite3_version[] string constant. The function ds@1952: ** is provided for DLL users who can only access functions and not ds@1952: ** constants within the DLL. ds@1952: */ ds@1952: SQLITE_EXTERN const char sqlite3_version[]; ds@1952: const char *sqlite3_libversion(void); ds@1952: int sqlite3_libversion_number(void); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Test To See If The Library Is Threadsafe ds@1952: ** ds@1952: ** This routine returns TRUE (nonzero) if SQLite was compiled with ds@1952: ** all of its mutexes enabled and is thus threadsafe. It returns ds@1952: ** zero if the particular build is for single-threaded operation ds@1952: ** only. ds@1952: ** ds@1952: ** Really all this routine does is return true if SQLite was compiled ds@1952: ** with the -DSQLITE_THREADSAFE=1 option and false if ds@1952: ** compiled with -DSQLITE_THREADSAFE=0. If SQLite uses an ds@1952: ** application-defined mutex subsystem, malloc subsystem, collating ds@1952: ** sequence, VFS, SQL function, progress callback, commit hook, ds@1952: ** extension, or other accessories and these add-ons are not ds@1952: ** threadsafe, then clearly the combination will not be threadsafe ds@1952: ** either. Hence, this routine never reports that the library ds@1952: ** is guaranteed to be threadsafe, only when it is guaranteed not ds@1952: ** to be. ds@1952: ** ds@1952: ** This is an experimental API and may go away or change in future ds@1952: ** releases. ds@1952: */ ds@1952: int sqlite3_threadsafe(void); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Database Connection Handle ds@1952: ** ds@1952: ** Each open SQLite database is represented by pointer to an instance of the ds@1952: ** opaque structure named "sqlite3". It is useful to think of an sqlite3 ds@1952: ** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and ds@1952: ** [sqlite3_open_v2()] interfaces are its constructors ds@1952: ** and [sqlite3_close()] is its destructor. There are many other interfaces ds@1952: ** (such as [sqlite3_prepare_v2()], [sqlite3_create_function()], and ds@1952: ** [sqlite3_busy_timeout()] to name but three) that are methods on this ds@1952: ** object. ds@1952: */ ds@1952: typedef struct sqlite3 sqlite3; ds@1952: ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: 64-Bit Integer Types ds@1952: ** ds@1952: ** Some compilers do not support the "long long" datatype. So we have ds@1952: ** to do compiler-specific typedefs for 64-bit signed and unsigned integers. ds@1952: ** ds@1952: ** Many SQLite interface functions require a 64-bit integer arguments. ds@1952: ** Those interfaces are declared using this typedef. ds@1952: */ ds@1952: #ifdef SQLITE_INT64_TYPE ds@1952: typedef SQLITE_INT64_TYPE sqlite_int64; ds@1952: typedef unsigned SQLITE_INT64_TYPE sqlite_uint64; ds@1952: #elif defined(_MSC_VER) || defined(__BORLANDC__) ds@1952: typedef __int64 sqlite_int64; ds@1952: typedef unsigned __int64 sqlite_uint64; ds@1952: #else ds@1952: typedef long long int sqlite_int64; ds@1952: typedef unsigned long long int sqlite_uint64; ds@1952: #endif ds@1952: typedef sqlite_int64 sqlite3_int64; ds@1952: typedef sqlite_uint64 sqlite3_uint64; ds@1952: ds@1952: /* ds@1952: ** If compiling for a processor that lacks floating point support, ds@1952: ** substitute integer for floating-point ds@1952: */ ds@1952: #ifdef SQLITE_OMIT_FLOATING_POINT ds@1952: # define double sqlite3_int64 ds@1952: #endif ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Closing A Database Connection ds@1952: ** ds@1952: ** Call this function with a pointer to a structure that was previously ds@1952: ** returned from [sqlite3_open()], [sqlite3_open16()], or ds@1952: ** [sqlite3_open_v2()] and the corresponding database will by ds@1952: ** closed. ds@1952: ** ds@1952: ** All SQL statements prepared using [sqlite3_prepare_v2()] or ds@1952: ** [sqlite3_prepare16_v2()] must be destroyed using [sqlite3_finalize()] ds@1952: ** before this routine is called. Otherwise, SQLITE_BUSY is returned and the ds@1952: ** database connection remains open. ds@1952: ** ds@1952: ** Passing this routine a database connection that has already been ds@1952: ** closed results in undefined behavior. If other interfaces that ds@1952: ** reference the same database connection are pending (either in the ds@1952: ** same thread or in different threads) when this routine is called, ds@1952: ** then the behavior is undefined and is almost certainly undesirable. ds@1952: */ ds@1952: int sqlite3_close(sqlite3 *); ds@1952: ds@1952: /* ds@1952: ** The type for a callback function. ds@1952: ** This is legacy and deprecated. It is included for historical ds@1952: ** compatibility and is not documented. ds@1952: */ ds@1952: typedef int (*sqlite3_callback)(void*,int,char**, char**); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: One-Step Query Execution Interface ds@1952: ** ds@1952: ** This interface is used to do a one-time evaluatation of zero ds@1952: ** or more SQL statements. UTF-8 text of the SQL statements to ds@1952: ** be evaluted is passed in as the second parameter. The statements ds@1952: ** are prepared one by one using [sqlite3_prepare()], evaluated ds@1952: ** using [sqlite3_step()], then destroyed using [sqlite3_finalize()]. ds@1952: ** ds@1952: ** If one or more of the SQL statements are queries, then ds@1952: ** the callback function specified by the 3rd parameter is ds@1952: ** invoked once for each row of the query result. This callback ds@1952: ** should normally return 0. If the callback returns a non-zero ds@1952: ** value then the query is aborted, all subsequent SQL statements ds@1952: ** are skipped and the sqlite3_exec() function returns the [SQLITE_ABORT]. ds@1952: ** ds@1952: ** The 4th parameter to this interface is an arbitrary pointer that is ds@1952: ** passed through to the callback function as its first parameter. ds@1952: ** ds@1952: ** The 2nd parameter to the callback function is the number of ds@1952: ** columns in the query result. The 3rd parameter to the callback ds@1952: ** is an array of strings holding the values for each column ds@1952: ** as extracted using [sqlite3_column_text()]. ds@1952: ** The 4th parameter to the callback is an array of strings ds@1952: ** obtained using [sqlite3_column_name()] and holding ds@1952: ** the names of each column. ds@1952: ** ds@1952: ** The callback function may be NULL, even for queries. A NULL ds@1952: ** callback is not an error. It just means that no callback ds@1952: ** will be invoked. ds@1952: ** ds@1952: ** If an error occurs while parsing or evaluating the SQL (but ds@1952: ** not while executing the callback) then an appropriate error ds@1952: ** message is written into memory obtained from [sqlite3_malloc()] and ds@1952: ** *errmsg is made to point to that message. The calling function ds@1952: ** is responsible for freeing the memory using [sqlite3_free()]. ds@1952: ** If errmsg==NULL, then no error message is ever written. ds@1952: ** ds@1952: ** The return value is is SQLITE_OK if there are no errors and ds@1952: ** some other [SQLITE_OK | return code] if there is an error. ds@1952: ** The particular return value depends on the type of error. ds@1952: ** ds@1952: */ ds@1952: int sqlite3_exec( ds@1952: sqlite3*, /* An open database */ ds@1952: const char *sql, /* SQL to be evaluted */ ds@1952: int (*callback)(void*,int,char**,char**), /* Callback function */ ds@1952: void *, /* 1st argument to callback */ ds@1952: char **errmsg /* Error msg written here */ ds@1952: ); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Result Codes ds@1952: ** KEYWORDS: SQLITE_OK ds@1952: ** ds@1952: ** Many SQLite functions return an integer result code from the set shown ds@1952: ** above in order to indicates success or failure. ds@1952: ** ds@1952: ** The result codes above are the only ones returned by SQLite in its ds@1952: ** default configuration. However, the [sqlite3_extended_result_codes()] ds@1952: ** API can be used to set a database connectoin to return more detailed ds@1952: ** result codes. ds@1952: ** ds@1952: ** See also: [SQLITE_IOERR_READ | extended result codes] ds@1952: ** ds@1952: */ ds@1952: #define SQLITE_OK 0 /* Successful result */ ds@1952: /* beginning-of-error-codes */ ds@1952: #define SQLITE_ERROR 1 /* SQL error or missing database */ ds@1952: #define SQLITE_INTERNAL 2 /* NOT USED. Internal logic error in SQLite */ ds@1952: #define SQLITE_PERM 3 /* Access permission denied */ ds@1952: #define SQLITE_ABORT 4 /* Callback routine requested an abort */ ds@1952: #define SQLITE_BUSY 5 /* The database file is locked */ ds@1952: #define SQLITE_LOCKED 6 /* A table in the database is locked */ ds@1952: #define SQLITE_NOMEM 7 /* A malloc() failed */ ds@1952: #define SQLITE_READONLY 8 /* Attempt to write a readonly database */ ds@1952: #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/ ds@1952: #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */ ds@1952: #define SQLITE_CORRUPT 11 /* The database disk image is malformed */ ds@1952: #define SQLITE_NOTFOUND 12 /* NOT USED. Table or record not found */ ds@1952: #define SQLITE_FULL 13 /* Insertion failed because database is full */ ds@1952: #define SQLITE_CANTOPEN 14 /* Unable to open the database file */ ds@1952: #define SQLITE_PROTOCOL 15 /* NOT USED. Database lock protocol error */ ds@1952: #define SQLITE_EMPTY 16 /* Database is empty */ ds@1952: #define SQLITE_SCHEMA 17 /* The database schema changed */ ds@1952: #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */ ds@1952: #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */ ds@1952: #define SQLITE_MISMATCH 20 /* Data type mismatch */ ds@1952: #define SQLITE_MISUSE 21 /* Library used incorrectly */ ds@1952: #define SQLITE_NOLFS 22 /* Uses OS features not supported on host */ ds@1952: #define SQLITE_AUTH 23 /* Authorization denied */ ds@1952: #define SQLITE_FORMAT 24 /* Auxiliary database format error */ ds@1952: #define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */ ds@1952: #define SQLITE_NOTADB 26 /* File opened that is not a database file */ ds@1952: #define SQLITE_ROW 100 /* sqlite3_step() has another row ready */ ds@1952: #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */ ds@1952: /* end-of-error-codes */ ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Extended Result Codes ds@1952: ** ds@1952: ** In its default configuration, SQLite API routines return one of 26 integer ds@1952: ** result codes described at result-codes. However, experience has shown that ds@1952: ** many of these result codes are too course-grained. They do not provide as ds@1952: ** much information about problems as users might like. In an effort to ds@1952: ** address this, newer versions of SQLite (version 3.3.8 and later) include ds@1952: ** support for additional result codes that provide more detailed information ds@1952: ** about errors. The extended result codes are enabled (or disabled) for ds@1952: ** each database ds@1952: ** connection using the [sqlite3_extended_result_codes()] API. ds@1952: ** ds@1952: ** Some of the available extended result codes are listed above. ds@1952: ** We expect the number of extended result codes will be expand ds@1952: ** over time. Software that uses extended result codes should expect ds@1952: ** to see new result codes in future releases of SQLite. ds@1952: ** ds@1952: ** The symbolic name for an extended result code always contains a related ds@1952: ** primary result code as a prefix. Primary result codes contain a single ds@1952: ** "_" character. Extended result codes contain two or more "_" characters. ds@1952: ** The numeric value of an extended result code can be converted to its ds@1952: ** corresponding primary result code by masking off the lower 8 bytes. ds@1952: ** ds@1952: ** The SQLITE_OK result code will never be extended. It will always ds@1952: ** be exactly zero. ds@1952: */ ds@1952: #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) ds@1952: #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) ds@1952: #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) ds@1952: #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) ds@1952: #define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8)) ds@1952: #define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8)) ds@1952: #define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8)) ds@1952: #define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8)) ds@1952: #define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8)) ds@1952: #define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8)) ds@1952: #define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8)) ds@1952: #define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8)) ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Flags For File Open Operations ds@1952: ** ds@1952: ** Combination of the following bit values are used as the ds@1952: ** third argument to the [sqlite3_open_v2()] interface and ds@1952: ** as fourth argument to the xOpen method of the ds@1952: ** [sqlite3_vfs] object. ds@1952: ** ds@1952: */ ds@1952: #define SQLITE_OPEN_READONLY 0x00000001 ds@1952: #define SQLITE_OPEN_READWRITE 0x00000002 ds@1952: #define SQLITE_OPEN_CREATE 0x00000004 ds@1952: #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 ds@1952: #define SQLITE_OPEN_EXCLUSIVE 0x00000010 ds@1952: #define SQLITE_OPEN_MAIN_DB 0x00000100 ds@1952: #define SQLITE_OPEN_TEMP_DB 0x00000200 ds@1952: #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 ds@1952: #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 ds@1952: #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 ds@1952: #define SQLITE_OPEN_SUBJOURNAL 0x00002000 ds@1952: #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Device Characteristics ds@1952: ** ds@1952: ** The xDeviceCapabilities method of the [sqlite3_io_methods] ds@1952: ** object returns an integer which is a vector of the following ds@1952: ** bit values expressing I/O characteristics of the mass storage ds@1952: ** device that holds the file that the [sqlite3_io_methods] ds@1952: ** refers to. ds@1952: ** ds@1952: ** The SQLITE_IOCAP_ATOMIC property means that all writes of ds@1952: ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values ds@1952: ** mean that writes of blocks that are nnn bytes in size and ds@1952: ** are aligned to an address which is an integer multiple of ds@1952: ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means ds@1952: ** that when data is appended to a file, the data is appended ds@1952: ** first then the size of the file is extended, never the other ds@1952: ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that ds@1952: ** information is written to disk in the same order as calls ds@1952: ** to xWrite(). ds@1952: */ ds@1952: #define SQLITE_IOCAP_ATOMIC 0x00000001 ds@1952: #define SQLITE_IOCAP_ATOMIC512 0x00000002 ds@1952: #define SQLITE_IOCAP_ATOMIC1K 0x00000004 ds@1952: #define SQLITE_IOCAP_ATOMIC2K 0x00000008 ds@1952: #define SQLITE_IOCAP_ATOMIC4K 0x00000010 ds@1952: #define SQLITE_IOCAP_ATOMIC8K 0x00000020 ds@1952: #define SQLITE_IOCAP_ATOMIC16K 0x00000040 ds@1952: #define SQLITE_IOCAP_ATOMIC32K 0x00000080 ds@1952: #define SQLITE_IOCAP_ATOMIC64K 0x00000100 ds@1952: #define SQLITE_IOCAP_SAFE_APPEND 0x00000200 ds@1952: #define SQLITE_IOCAP_SEQUENTIAL 0x00000400 ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: File Locking Levels ds@1952: ** ds@1952: ** SQLite uses one of the following integer values as the second ds@1952: ** argument to calls it makes to the xLock() and xUnlock() methods ds@1952: ** of an [sqlite3_io_methods] object. ds@1952: */ ds@1952: #define SQLITE_LOCK_NONE 0 ds@1952: #define SQLITE_LOCK_SHARED 1 ds@1952: #define SQLITE_LOCK_RESERVED 2 ds@1952: #define SQLITE_LOCK_PENDING 3 ds@1952: #define SQLITE_LOCK_EXCLUSIVE 4 ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Synchronization Type Flags ds@1952: ** ds@1952: ** When SQLite invokes the xSync() method of an [sqlite3_io_methods] ds@1952: ** object it uses a combination of the following integer values as ds@1952: ** the second argument. ds@1952: ** ds@1952: ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the ds@1952: ** sync operation only needs to flush data to mass storage. Inode ds@1952: ** information need not be flushed. The SQLITE_SYNC_NORMAL means ds@1952: ** to use normal fsync() semantics. The SQLITE_SYNC_FULL flag means ds@1952: ** to use Mac OS-X style fullsync instead of fsync(). ds@1952: */ ds@1952: #define SQLITE_SYNC_NORMAL 0x00002 ds@1952: #define SQLITE_SYNC_FULL 0x00003 ds@1952: #define SQLITE_SYNC_DATAONLY 0x00010 ds@1952: ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: OS Interface Open File Handle ds@1952: ** ds@1952: ** An [sqlite3_file] object represents an open file in the OS ds@1952: ** interface layer. Individual OS interface implementations will ds@1952: ** want to subclass this object by appending additional fields ds@1952: ** for their own use. The pMethods entry is a pointer to an ds@1952: ** [sqlite3_io_methods] object that defines methods for performing ds@1952: ** I/O operations on the open file. ds@1952: */ ds@1952: typedef struct sqlite3_file sqlite3_file; ds@1952: struct sqlite3_file { ds@1952: const struct sqlite3_io_methods *pMethods; /* Methods for an open file */ ds@1952: }; ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: OS Interface File Virtual Methods Object ds@1952: ** ds@1952: ** Every file opened by the [sqlite3_vfs] xOpen method contains a pointer to ds@1952: ** an instance of the this object. This object defines the ds@1952: ** methods used to perform various operations against the open file. ds@1952: ** ds@1952: ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or ds@1952: ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync(). ds@1952: * The second choice is an ds@1952: ** OS-X style fullsync. The SQLITE_SYNC_DATA flag may be ORed in to ds@1952: ** indicate that only the data of the file and not its inode needs to be ds@1952: ** synced. ds@1952: ** ds@1952: ** The integer values to xLock() and xUnlock() are one of ds@1952: ** ds@1952: ** xLock() increases the lock. xUnlock() decreases the lock. ds@1952: ** The xCheckReservedLock() method looks ds@1952: ** to see if any database connection, either in this ds@1952: ** process or in some other process, is holding an RESERVED, ds@1952: ** PENDING, or EXCLUSIVE lock on the file. It returns true ds@1952: ** if such a lock exists and false if not. ds@1952: ** ds@1952: ** The xFileControl() method is a generic interface that allows custom ds@1952: ** VFS implementations to directly control an open file using the ds@1952: ** [sqlite3_file_control()] interface. The second "op" argument ds@1952: ** is an integer opcode. The third ds@1952: ** argument is a generic pointer which is intended to be a pointer ds@1952: ** to a structure that may contain arguments or space in which to ds@1952: ** write return values. Potential uses for xFileControl() might be ds@1952: ** functions to enable blocking locks with timeouts, to change the ds@1952: ** locking strategy (for example to use dot-file locks), to inquire ds@1952: ** about the status of a lock, or to break stale locks. The SQLite ds@1952: ** core reserves opcodes less than 100 for its own use. ds@1952: ** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available. ds@1952: ** Applications that define a custom xFileControl method should use opcodes ds@1952: ** greater than 100 to avoid conflicts. ds@1952: ** ds@1952: ** The xSectorSize() method returns the sector size of the ds@1952: ** device that underlies the file. The sector size is the ds@1952: ** minimum write that can be performed without disturbing ds@1952: ** other bytes in the file. The xDeviceCharacteristics() ds@1952: ** method returns a bit vector describing behaviors of the ds@1952: ** underlying device: ds@1952: ** ds@1952: ** ds@1952: ** ds@1952: ** The SQLITE_IOCAP_ATOMIC property means that all writes of ds@1952: ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values ds@1952: ** mean that writes of blocks that are nnn bytes in size and ds@1952: ** are aligned to an address which is an integer multiple of ds@1952: ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means ds@1952: ** that when data is appended to a file, the data is appended ds@1952: ** first then the size of the file is extended, never the other ds@1952: ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that ds@1952: ** information is written to disk in the same order as calls ds@1952: ** to xWrite(). ds@1952: */ ds@1952: typedef struct sqlite3_io_methods sqlite3_io_methods; ds@1952: struct sqlite3_io_methods { ds@1952: int iVersion; ds@1952: int (*xClose)(sqlite3_file*); ds@1952: int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); ds@1952: int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst); ds@1952: int (*xTruncate)(sqlite3_file*, sqlite3_int64 size); ds@1952: int (*xSync)(sqlite3_file*, int flags); ds@1952: int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize); ds@1952: int (*xLock)(sqlite3_file*, int); ds@1952: int (*xUnlock)(sqlite3_file*, int); ds@1952: int (*xCheckReservedLock)(sqlite3_file*); ds@1952: int (*xFileControl)(sqlite3_file*, int op, void *pArg); ds@1952: int (*xSectorSize)(sqlite3_file*); ds@1952: int (*xDeviceCharacteristics)(sqlite3_file*); ds@1952: /* Additional methods may be added in future releases */ ds@1952: }; ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Standard File Control Opcodes ds@1952: ** ds@1952: ** These integer constants are opcodes for the xFileControl method ds@1952: ** of the [sqlite3_io_methods] object and to the [sqlite3_file_control()] ds@1952: ** interface. ds@1952: ** ds@1952: ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This ds@1952: ** opcode cases the xFileControl method to write the current state of ds@1952: ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED], ds@1952: ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE]) ds@1952: ** into an integer that the pArg argument points to. This capability ds@1952: ** is used during testing and only needs to be supported when SQLITE_TEST ds@1952: ** is defined. ds@1952: */ ds@1952: #define SQLITE_FCNTL_LOCKSTATE 1 ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Mutex Handle ds@1952: ** ds@1952: ** The mutex module within SQLite defines [sqlite3_mutex] to be an ds@1952: ** abstract type for a mutex object. The SQLite core never looks ds@1952: ** at the internal representation of an [sqlite3_mutex]. It only ds@1952: ** deals with pointers to the [sqlite3_mutex] object. ds@1952: ** ds@1952: ** Mutexes are created using [sqlite3_mutex_alloc()]. ds@1952: */ ds@1952: typedef struct sqlite3_mutex sqlite3_mutex; ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: OS Interface Object ds@1952: ** ds@1952: ** An instance of this object defines the interface between the ds@1952: ** SQLite core and the underlying operating system. The "vfs" ds@1952: ** in the name of the object stands for "virtual file system". ds@1952: ** ds@1952: ** The iVersion field is initially 1 but may be larger for future ds@1952: ** versions of SQLite. Additional fields may be appended to this ds@1952: ** object when the iVersion value is increased. ds@1952: ** ds@1952: ** The szOsFile field is the size of the subclassed [sqlite3_file] ds@1952: ** structure used by this VFS. mxPathname is the maximum length of ds@1952: ** a pathname in this VFS. ds@1952: ** ds@1952: ** Registered vfs modules are kept on a linked list formed by ds@1952: ** the pNext pointer. The [sqlite3_vfs_register()] ds@1952: ** and [sqlite3_vfs_unregister()] interfaces manage this list ds@1952: ** in a thread-safe way. The [sqlite3_vfs_find()] interface ds@1952: ** searches the list. ds@1952: ** ds@1952: ** The pNext field is the only fields in the sqlite3_vfs ds@1952: ** structure that SQLite will ever modify. SQLite will only access ds@1952: ** or modify this field while holding a particular static mutex. ds@1952: ** The application should never modify anything within the sqlite3_vfs ds@1952: ** object once the object has been registered. ds@1952: ** ds@1952: ** The zName field holds the name of the VFS module. The name must ds@1952: ** be unique across all VFS modules. ds@1952: ** ds@1952: ** SQLite will guarantee that the zFilename string passed to ds@1952: ** xOpen() is a full pathname as generated by xFullPathname() and ds@1952: ** that the string will be valid and unchanged until xClose() is ds@1952: ** called. So the [sqlite3_file] can store a pointer to the ds@1952: ** filename if it needs to remember the filename for some reason. ds@1952: ** ds@1952: ** The flags argument to xOpen() is a copy of the flags argument ds@1952: ** to [sqlite3_open_v2()]. If [sqlite3_open()] or [sqlite3_open16()] ds@1952: ** is used, then flags is [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]. ds@1952: ** If xOpen() opens a file read-only then it sets *pOutFlags to ds@1952: ** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be ds@1952: ** set. ds@1952: ** ds@1952: ** SQLite will also add one of the following flags to the xOpen() ds@1952: ** call, depending on the object being opened: ds@1952: ** ds@1952: ** ds@1952: ** ds@1952: ** The file I/O implementation can use the object type flags to ds@1952: ** changes the way it deals with files. For example, an application ds@1952: ** that does not care about crash recovery or rollback, might make ds@1952: ** the open of a journal file a no-op. Writes to this journal are ds@1952: ** also a no-op. Any attempt to read the journal return SQLITE_IOERR. ds@1952: ** Or the implementation might recognize the a database file will ds@1952: ** be doing page-aligned sector reads and writes in a random order ds@1952: ** and set up its I/O subsystem accordingly. ds@1952: ** ds@1952: ** SQLite might also add one of the following flags to the xOpen ds@1952: ** method: ds@1952: ** ds@1952: ** ds@1952: ** ds@1952: ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be ds@1952: ** deleted when it is closed. This will always be set for TEMP ds@1952: ** databases and journals and for subjournals. The ds@1952: ** [SQLITE_OPEN_EXCLUSIVE] flag means the file should be opened ds@1952: ** for exclusive access. This flag is set for all files except ds@1952: ** for the main database file. ds@1952: ** ds@1952: ** Space to hold the [sqlite3_file] structure passed as the third ds@1952: ** argument to xOpen is allocated by caller (the SQLite core). ds@1952: ** szOsFile bytes are allocated for this object. The xOpen method ds@1952: ** fills in the allocated space. ds@1952: ** ds@1952: ** The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS] ds@1952: ** to test for the existance of a file, ds@1952: ** or [SQLITE_ACCESS_READWRITE] to test to see ds@1952: ** if a file is readable and writable, or [SQLITE_ACCESS_READ] ds@1952: ** to test to see if a file is at least readable. The file can be a ds@1952: ** directory. ds@1952: ** ds@1952: ** SQLite will always allocate at least mxPathname+1 byte for ds@1952: ** the output buffers for xGetTempname and xFullPathname. The exact ds@1952: ** size of the output buffer is also passed as a parameter to both ds@1952: ** methods. If the output buffer is not large enough, SQLITE_CANTOPEN ds@1952: ** should be returned. As this is handled as a fatal error by SQLite, ds@1952: ** vfs implementations should endevour to prevent this by setting ds@1952: ** mxPathname to a sufficiently large value. ds@1952: ** ds@1952: ** The xRandomness(), xSleep(), and xCurrentTime() interfaces ds@1952: ** are not strictly a part of the filesystem, but they are ds@1952: ** included in the VFS structure for completeness. ds@1952: ** The xRandomness() function attempts to return nBytes bytes ds@1952: ** of good-quality randomness into zOut. The return value is ds@1952: ** the actual number of bytes of randomness obtained. The ds@1952: ** xSleep() method cause the calling thread to sleep for at ds@1952: ** least the number of microseconds given. The xCurrentTime() ds@1952: ** method returns a Julian Day Number for the current date and ds@1952: ** time. ds@1952: */ ds@1952: typedef struct sqlite3_vfs sqlite3_vfs; ds@1952: struct sqlite3_vfs { ds@1952: int iVersion; /* Structure version number */ ds@1952: int szOsFile; /* Size of subclassed sqlite3_file */ ds@1952: int mxPathname; /* Maximum file pathname length */ ds@1952: sqlite3_vfs *pNext; /* Next registered VFS */ ds@1952: const char *zName; /* Name of this virtual file system */ ds@1952: void *pAppData; /* Pointer to application-specific data */ ds@1952: int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*, ds@1952: int flags, int *pOutFlags); ds@1952: int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir); ds@1952: int (*xAccess)(sqlite3_vfs*, const char *zName, int flags); ds@1952: int (*xGetTempname)(sqlite3_vfs*, int nOut, char *zOut); ds@1952: int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut); ds@1952: void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename); ds@1952: void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg); ds@1952: void *(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol); ds@1952: void (*xDlClose)(sqlite3_vfs*, void*); ds@1952: int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut); ds@1952: int (*xSleep)(sqlite3_vfs*, int microseconds); ds@1952: int (*xCurrentTime)(sqlite3_vfs*, double*); ds@1952: /* New fields may be appended in figure versions. The iVersion ds@1952: ** value will increment whenever this happens. */ ds@1952: }; ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Flags for the xAccess VFS method ds@1952: ** ds@1952: ** These integer constants can be used as the third parameter to ds@1952: ** the xAccess method of an [sqlite3_vfs] object. They determine ds@1952: ** the kind of what kind of permissions the xAccess method is ds@1952: ** looking for. With SQLITE_ACCESS_EXISTS, the xAccess method ds@1952: ** simply checks to see if the file exists. With SQLITE_ACCESS_READWRITE, ds@1952: ** the xAccess method checks to see if the file is both readable ds@1952: ** and writable. With SQLITE_ACCESS_READ the xAccess method ds@1952: ** checks to see if the file is readable. ds@1952: */ ds@1952: #define SQLITE_ACCESS_EXISTS 0 ds@1952: #define SQLITE_ACCESS_READWRITE 1 ds@1952: #define SQLITE_ACCESS_READ 2 ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Enable Or Disable Extended Result Codes ds@1952: ** ds@1952: ** This routine enables or disables the ds@1952: ** [SQLITE_IOERR_READ | extended result codes] feature. ds@1952: ** By default, SQLite API routines return one of only 26 integer ds@1952: ** [SQLITE_OK | result codes]. When extended result codes ds@1952: ** are enabled by this routine, the repetoire of result codes can be ds@1952: ** much larger and can (hopefully) provide more detailed information ds@1952: ** about the cause of an error. ds@1952: ** ds@1952: ** The second argument is a boolean value that turns extended result ds@1952: ** codes on and off. Extended result codes are off by default for ds@1952: ** backwards compatibility with older versions of SQLite. ds@1952: */ ds@1952: int sqlite3_extended_result_codes(sqlite3*, int onoff); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Last Insert Rowid ds@1952: ** ds@1952: ** Each entry in an SQLite table has a unique 64-bit signed integer key ds@1952: ** called the "rowid". The rowid is always available as an undeclared ds@1952: ** column named ROWID, OID, or _ROWID_. If the table has a column of ds@1952: ** type INTEGER PRIMARY KEY then that column is another an alias for the ds@1952: ** rowid. ds@1952: ** ds@1952: ** This routine returns the rowid of the most recent INSERT into ds@1952: ** the database from the database connection given in the first ds@1952: ** argument. If no inserts have ever occurred on this database ds@1952: ** connection, zero is returned. ds@1952: ** ds@1952: ** If an INSERT occurs within a trigger, then the rowid of the ds@1952: ** inserted row is returned by this routine as long as the trigger ds@1952: ** is running. But once the trigger terminates, the value returned ds@1952: ** by this routine reverts to the last value inserted before the ds@1952: ** trigger fired. ds@1952: ** ds@1952: ** If another thread does a new insert on the same database connection ds@1952: ** while this routine is running and thus changes the last insert rowid, ds@1952: ** then the return value of this routine is undefined. ds@1952: */ ds@1952: sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Count The Number Of Rows Modified ds@1952: ** ds@1952: ** This function returns the number of database rows that were changed ds@1952: ** (or inserted or deleted) by the most recent SQL statement. Only ds@1952: ** changes that are directly specified by the INSERT, UPDATE, or ds@1952: ** DELETE statement are counted. Auxiliary changes caused by ds@1952: ** triggers are not counted. Use the [sqlite3_total_changes()] function ds@1952: ** to find the total number of changes including changes caused by triggers. ds@1952: ** ds@1952: ** Within the body of a trigger, the sqlite3_changes() interface can be ds@1952: ** called to find the number of ds@1952: ** changes in the most recently completed INSERT, UPDATE, or DELETE ds@1952: ** statement within the body of the trigger. ds@1952: ** ds@1952: ** All changes are counted, even if they were later undone by a ds@1952: ** ROLLBACK or ABORT. Except, changes associated with creating and ds@1952: ** dropping tables are not counted. ds@1952: ** ds@1952: ** If a callback invokes [sqlite3_exec()] or [sqlite3_step()] recursively, ds@1952: ** then the changes in the inner, recursive call are counted together ds@1952: ** with the changes in the outer call. ds@1952: ** ds@1952: ** SQLite implements the command "DELETE FROM table" without a WHERE clause ds@1952: ** by dropping and recreating the table. (This is much faster than going ds@1952: ** through and deleting individual elements from the table.) Because of ds@1952: ** this optimization, the change count for "DELETE FROM table" will be ds@1952: ** zero regardless of the number of elements that were originally in the ds@1952: ** table. To get an accurate count of the number of rows deleted, use ds@1952: ** "DELETE FROM table WHERE 1" instead. ds@1952: ** ds@1952: ** If another thread makes changes on the same database connection ds@1952: ** while this routine is running then the return value of this routine ds@1952: ** is undefined. ds@1952: */ ds@1952: int sqlite3_changes(sqlite3*); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Total Number Of Rows Modified ds@1952: *** ds@1952: ** This function returns the number of database rows that have been ds@1952: ** modified by INSERT, UPDATE or DELETE statements since the database handle ds@1952: ** was opened. This includes UPDATE, INSERT and DELETE statements executed ds@1952: ** as part of trigger programs. All changes are counted as soon as the ds@1952: ** statement that makes them is completed (when the statement handle is ds@1952: ** passed to [sqlite3_reset()] or [sqlite3_finalize()]). ds@1952: ** ds@1952: ** See also the [sqlite3_change()] interface. ds@1952: ** ds@1952: ** SQLite implements the command "DELETE FROM table" without a WHERE clause ds@1952: ** by dropping and recreating the table. (This is much faster than going ds@1952: ** through and deleting individual elements form the table.) Because of ds@1952: ** this optimization, the change count for "DELETE FROM table" will be ds@1952: ** zero regardless of the number of elements that were originally in the ds@1952: ** table. To get an accurate count of the number of rows deleted, use ds@1952: ** "DELETE FROM table WHERE 1" instead. ds@1952: ** ds@1952: ** If another thread makes changes on the same database connection ds@1952: ** while this routine is running then the return value of this routine ds@1952: ** is undefined. ds@1952: */ ds@1952: int sqlite3_total_changes(sqlite3*); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Interrupt A Long-Running Query ds@1952: ** ds@1952: ** This function causes any pending database operation to abort and ds@1952: ** return at its earliest opportunity. This routine is typically ds@1952: ** called in response to a user action such as pressing "Cancel" ds@1952: ** or Ctrl-C where the user wants a long query operation to halt ds@1952: ** immediately. ds@1952: ** ds@1952: ** It is safe to call this routine from a thread different from the ds@1952: ** thread that is currently running the database operation. But it ds@1952: ** is not safe to call this routine with a database connection that ds@1952: ** is closed or might close before sqlite3_interrupt() returns. ds@1952: ** ds@1952: ** The SQL operation that is interrupted will return [SQLITE_INTERRUPT]. ds@1952: ** If an interrupted operation was an update that is inside an ds@1952: ** explicit transaction, then the entire transaction will be rolled ds@1952: ** back automatically. ds@1952: */ ds@1952: void sqlite3_interrupt(sqlite3*); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Determine If An SQL Statement Is Complete ds@1952: ** ds@1952: ** These functions return true if the given input string comprises ds@1952: ** one or more complete SQL statements. For the sqlite3_complete() call, ds@1952: ** the parameter must be a nul-terminated UTF-8 string. For ds@1952: ** sqlite3_complete16(), a nul-terminated machine byte order UTF-16 string ds@1952: ** is required. ds@1952: ** ds@1952: ** These routines are useful for command-line input to determine if the ds@1952: ** currently entered text forms one or more complete SQL statements or ds@1952: ** if additional input is needed before sending the statements into ds@1952: ** SQLite for parsing. The algorithm is simple. If the ds@1952: ** last token other than spaces and comments is a semicolon, then return ds@1952: ** true. Actually, the algorithm is a little more complicated than that ds@1952: ** in order to deal with triggers, but the basic idea is the same: the ds@1952: ** statement is not complete unless it ends in a semicolon. ds@1952: */ ds@1952: int sqlite3_complete(const char *sql); ds@1952: int sqlite3_complete16(const void *sql); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors ds@1952: ** ds@1952: ** This routine identifies a callback function that might be invoked ds@1952: ** whenever an attempt is made to open a database table ds@1952: ** that another thread or process has locked. ds@1952: ** If the busy callback is NULL, then [SQLITE_BUSY] ds@1952: ** (or sometimes [SQLITE_IOERR_BLOCKED]) ds@1952: ** is returned immediately upon encountering the lock. ds@1952: ** If the busy callback is not NULL, then the ds@1952: ** callback will be invoked with two arguments. The ds@1952: ** first argument to the handler is a copy of the void* pointer which ds@1952: ** is the third argument to this routine. The second argument to ds@1952: ** the handler is the number of times that the busy handler has ds@1952: ** been invoked for this locking event. If the ds@1952: ** busy callback returns 0, then no additional attempts are made to ds@1952: ** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned. ds@1952: ** If the callback returns non-zero, then another attempt is made to open the ds@1952: ** database for reading and the cycle repeats. ds@1952: ** ds@1952: ** The presence of a busy handler does not guarantee that ds@1952: ** it will be invoked when there is lock contention. ds@1952: ** If SQLite determines that invoking the busy handler could result in ds@1952: ** a deadlock, it will return [SQLITE_BUSY] instead. ds@1952: ** Consider a scenario where one process is holding a read lock that ds@1952: ** it is trying to promote to a reserved lock and ds@1952: ** a second process is holding a reserved lock that it is trying ds@1952: ** to promote to an exclusive lock. The first process cannot proceed ds@1952: ** because it is blocked by the second and the second process cannot ds@1952: ** proceed because it is blocked by the first. If both processes ds@1952: ** invoke the busy handlers, neither will make any progress. Therefore, ds@1952: ** SQLite returns [SQLITE_BUSY] for the first process, hoping that this ds@1952: ** will induce the first process to release its read lock and allow ds@1952: ** the second process to proceed. ds@1952: ** ds@1952: ** The default busy callback is NULL. ds@1952: ** ds@1952: ** The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED] when ds@1952: ** SQLite is in the middle of a large transaction where all the ds@1952: ** changes will not fit into the in-memory cache. SQLite will ds@1952: ** already hold a RESERVED lock on the database file, but it needs ds@1952: ** to promote this lock to EXCLUSIVE so that it can spill cache ds@1952: ** pages into the database file without harm to concurrent ds@1952: ** readers. If it is unable to promote the lock, then the in-memory ds@1952: ** cache will be left in an inconsistent state and so the error ds@1952: ** code is promoted from the relatively benign [SQLITE_BUSY] to ds@1952: ** the more severe [SQLITE_IOERR_BLOCKED]. This error code promotion ds@1952: ** forces an automatic rollback of the changes. See the ds@1952: ** ds@1952: ** CorruptionFollowingBusyError wiki page for a discussion of why ds@1952: ** this is important. ds@1952: ** ds@1952: ** Sqlite is re-entrant, so the busy handler may start a new query. ds@1952: ** (It is not clear why anyone would every want to do this, but it ds@1952: ** is allowed, in theory.) But the busy handler may not close the ds@1952: ** database. Closing the database from a busy handler will delete ds@1952: ** data structures out from under the executing query and will ds@1952: ** probably result in a segmentation fault or other runtime error. ds@1952: ** ds@1952: ** There can only be a single busy handler defined for each database ds@1952: ** connection. Setting a new busy handler clears any previous one. ds@1952: ** Note that calling [sqlite3_busy_timeout()] will also set or clear ds@1952: ** the busy handler. ds@1952: ** ds@1952: ** When operating in [sqlite3_enable_shared_cache | shared cache mode], ds@1952: ** only a single busy handler can be defined for each database file. ds@1952: ** So if two database connections share a single cache, then changing ds@1952: ** the busy handler on one connection will also change the busy ds@1952: ** handler in the other connection. The busy handler is invoked ds@1952: ** in the thread that was running when the SQLITE_BUSY was hit. ds@1952: */ ds@1952: int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Set A Busy Timeout ds@1952: ** ds@1952: ** This routine sets a busy handler that sleeps for a while when a ds@1952: ** table is locked. The handler will sleep multiple times until ds@1952: ** at least "ms" milliseconds of sleeping have been done. After ds@1952: ** "ms" milliseconds of sleeping, the handler returns 0 which ds@1952: ** causes [sqlite3_step()] to return [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]. ds@1952: ** ds@1952: ** Calling this routine with an argument less than or equal to zero ds@1952: ** turns off all busy handlers. ds@1952: ** ds@1952: ** There can only be a single busy handler for a particular database ds@1952: ** connection. If another busy handler was defined ds@1952: ** (using [sqlite3_busy_handler()]) prior to calling ds@1952: ** this routine, that other busy handler is cleared. ds@1952: */ ds@1952: int sqlite3_busy_timeout(sqlite3*, int ms); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Convenience Routines For Running Queries ds@1952: ** ds@1952: ** This next routine is a convenience wrapper around [sqlite3_exec()]. ds@1952: ** Instead of invoking a user-supplied callback for each row of the ds@1952: ** result, this routine remembers each row of the result in memory ds@1952: ** obtained from [sqlite3_malloc()], then returns all of the result after the ds@1952: ** query has finished. ds@1952: ** ds@1952: ** As an example, suppose the query result where this table: ds@1952: ** ds@1952: **
ds@1952: **        Name        | Age
ds@1952: **        -----------------------
ds@1952: **        Alice       | 43
ds@1952: **        Bob         | 28
ds@1952: **        Cindy       | 21
ds@1952: ** 
ds@1952: ** ds@1952: ** If the 3rd argument were &azResult then after the function returns ds@1952: ** azResult will contain the following data: ds@1952: ** ds@1952: **
ds@1952: **        azResult[0] = "Name";
ds@1952: **        azResult[1] = "Age";
ds@1952: **        azResult[2] = "Alice";
ds@1952: **        azResult[3] = "43";
ds@1952: **        azResult[4] = "Bob";
ds@1952: **        azResult[5] = "28";
ds@1952: **        azResult[6] = "Cindy";
ds@1952: **        azResult[7] = "21";
ds@1952: ** 
ds@1952: ** ds@1952: ** Notice that there is an extra row of data containing the column ds@1952: ** headers. But the *nrow return value is still 3. *ncolumn is ds@1952: ** set to 2. In general, the number of values inserted into azResult ds@1952: ** will be ((*nrow) + 1)*(*ncolumn). ds@1952: ** ds@1952: ** After the calling function has finished using the result, it should ds@1952: ** pass the result data pointer to sqlite3_free_table() in order to ds@1952: ** release the memory that was malloc-ed. Because of the way the ds@1952: ** [sqlite3_malloc()] happens, the calling function must not try to call ds@1952: ** [sqlite3_free()] directly. Only [sqlite3_free_table()] is able to release ds@1952: ** the memory properly and safely. ds@1952: ** ds@1952: ** The return value of this routine is the same as from [sqlite3_exec()]. ds@1952: */ ds@1952: int sqlite3_get_table( ds@1952: sqlite3*, /* An open database */ ds@1952: const char *sql, /* SQL to be executed */ ds@1952: char ***resultp, /* Result written to a char *[] that this points to */ ds@1952: int *nrow, /* Number of result rows written here */ ds@1952: int *ncolumn, /* Number of result columns written here */ ds@1952: char **errmsg /* Error msg written here */ ds@1952: ); ds@1952: void sqlite3_free_table(char **result); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Formatted String Printing Functions ds@1952: ** ds@1952: ** These routines are workalikes of the "printf()" family of functions ds@1952: ** from the standard C library. ds@1952: ** ds@1952: ** The sqlite3_mprintf() and sqlite3_vmprintf() routines write their ds@1952: ** results into memory obtained from [sqlite3_malloc()]. ds@1952: ** The strings returned by these two routines should be ds@1952: ** released by [sqlite3_free()]. Both routines return a ds@1952: ** NULL pointer if [sqlite3_malloc()] is unable to allocate enough ds@1952: ** memory to hold the resulting string. ds@1952: ** ds@1952: ** In sqlite3_snprintf() routine is similar to "snprintf()" from ds@1952: ** the standard C library. The result is written into the ds@1952: ** buffer supplied as the second parameter whose size is given by ds@1952: ** the first parameter. Note that the order of the ds@1952: ** first two parameters is reversed from snprintf(). This is an ds@1952: ** historical accident that cannot be fixed without breaking ds@1952: ** backwards compatibility. Note also that sqlite3_snprintf() ds@1952: ** returns a pointer to its buffer instead of the number of ds@1952: ** characters actually written into the buffer. We admit that ds@1952: ** the number of characters written would be a more useful return ds@1952: ** value but we cannot change the implementation of sqlite3_snprintf() ds@1952: ** now without breaking compatibility. ds@1952: ** ds@1952: ** As long as the buffer size is greater than zero, sqlite3_snprintf() ds@1952: ** guarantees that the buffer is always zero-terminated. The first ds@1952: ** parameter "n" is the total size of the buffer, including space for ds@1952: ** the zero terminator. So the longest string that can be completely ds@1952: ** written will be n-1 characters. ds@1952: ** ds@1952: ** These routines all implement some additional formatting ds@1952: ** options that are useful for constructing SQL statements. ds@1952: ** All of the usual printf formatting options apply. In addition, there ds@1952: ** is are "%q", "%Q", and "%z" options. ds@1952: ** ds@1952: ** The %q option works like %s in that it substitutes a null-terminated ds@1952: ** string from the argument list. But %q also doubles every '\'' character. ds@1952: ** %q is designed for use inside a string literal. By doubling each '\'' ds@1952: ** character it escapes that character and allows it to be inserted into ds@1952: ** the string. ds@1952: ** ds@1952: ** For example, so some string variable contains text as follows: ds@1952: ** ds@1952: **
ds@1952: **  char *zText = "It's a happy day!";
ds@1952: ** 
ds@1952: ** ds@1952: ** One can use this text in an SQL statement as follows: ds@1952: ** ds@1952: **
ds@1952: **  char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText);
ds@1952: **  sqlite3_exec(db, zSQL, 0, 0, 0);
ds@1952: **  sqlite3_free(zSQL);
ds@1952: ** 
ds@1952: ** ds@1952: ** Because the %q format string is used, the '\'' character in zText ds@1952: ** is escaped and the SQL generated is as follows: ds@1952: ** ds@1952: **
ds@1952: **  INSERT INTO table1 VALUES('It''s a happy day!')
ds@1952: ** 
ds@1952: ** ds@1952: ** This is correct. Had we used %s instead of %q, the generated SQL ds@1952: ** would have looked like this: ds@1952: ** ds@1952: **
ds@1952: **  INSERT INTO table1 VALUES('It's a happy day!');
ds@1952: ** 
ds@1952: ** ds@1952: ** This second example is an SQL syntax error. As a general rule you ds@1952: ** should always use %q instead of %s when inserting text into a string ds@1952: ** literal. ds@1952: ** ds@1952: ** The %Q option works like %q except it also adds single quotes around ds@1952: ** the outside of the total string. Or if the parameter in the argument ds@1952: ** list is a NULL pointer, %Q substitutes the text "NULL" (without single ds@1952: ** quotes) in place of the %Q option. So, for example, one could say: ds@1952: ** ds@1952: **
ds@1952: **  char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText);
ds@1952: **  sqlite3_exec(db, zSQL, 0, 0, 0);
ds@1952: **  sqlite3_free(zSQL);
ds@1952: ** 
ds@1952: ** ds@1952: ** The code above will render a correct SQL statement in the zSQL ds@1952: ** variable even if the zText variable is a NULL pointer. ds@1952: ** ds@1952: ** The "%z" formatting option works exactly like "%s" with the ds@1952: ** addition that after the string has been read and copied into ds@1952: ** the result, [sqlite3_free()] is called on the input string. ds@1952: */ ds@1952: char *sqlite3_mprintf(const char*,...); ds@1952: char *sqlite3_vmprintf(const char*, va_list); ds@1952: char *sqlite3_snprintf(int,char*,const char*, ...); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Memory Allocation Subsystem ds@1952: ** ds@1952: ** The SQLite core uses these three routines for all of its own ds@1952: ** internal memory allocation needs. (See the exception below.) ds@1952: ** The default implementation ds@1952: ** of the memory allocation subsystem uses the malloc(), realloc() ds@1952: ** and free() provided by the standard C library. However, if ds@1952: ** SQLite is compiled with the following C preprocessor macro ds@1952: ** ds@1952: **
SQLITE_OMIT_MEMORY_ALLOCATION
ds@1952: ** ds@1952: ** then no implementation is provided for these routines by ds@1952: ** SQLite. The application that links against SQLite is ds@1952: ** expected to provide its own implementation. If the application ds@1952: ** does provide its own implementation for these routines, then ds@1952: ** it must also provide an implementations for ds@1952: ** [sqlite3_memory_alarm()], [sqlite3_memory_used()], and ds@1952: ** [sqlite3_memory_highwater()]. The alternative implementations ds@1952: ** for these last three routines need not actually work, but ds@1952: ** stub functions at least are needed to statisfy the linker. ds@1952: ** SQLite never calls [sqlite3_memory_highwater()] itself, but ds@1952: ** the symbol is included in a table as part of the ds@1952: ** [sqlite3_load_extension()] interface. The ds@1952: ** [sqlite3_memory_alarm()] and [sqlite3_memory_used()] interfaces ds@1952: ** are called by [sqlite3_soft_heap_limit()] and working implementations ds@1952: ** of both routines must be provided if [sqlite3_soft_heap_limit()] ds@1952: ** is to operate correctly. ds@1952: ** ds@1952: ** Exception: The windows OS interface layer calls ds@1952: ** the system malloc() and free() directly when converting ds@1952: ** filenames between the UTF-8 encoding used by SQLite ds@1952: ** and whatever filename encoding is used by the particular windows ds@1952: ** installation. Memory allocation errors are detected, but ds@1952: ** they are reported back as [SQLITE_CANTOPEN] or ds@1952: ** [SQLITE_IOERR] rather than [SQLITE_NOMEM]. ds@1952: */ ds@1952: void *sqlite3_malloc(int); ds@1952: void *sqlite3_realloc(void*, int); ds@1952: void sqlite3_free(void*); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Memory Allocator Statistics ds@1952: ** ds@1952: ** In addition to the basic three allocation routines ds@1952: ** [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()], ds@1952: ** the memory allocation subsystem included with the SQLite ds@1952: ** sources provides the interfaces shown below. ds@1952: ** ds@1952: ** The first of these two routines returns the amount of memory ds@1952: ** currently outstanding (malloced but not freed). The second ds@1952: ** returns the largest instantaneous amount of outstanding ds@1952: ** memory. The highwater mark is reset if the argument is ds@1952: ** true. ds@1952: ** ds@1952: ** The implementation of these routines in the SQLite core ds@1952: ** is omitted if the application is compiled with the ds@1952: ** SQLITE_OMIT_MEMORY_ALLOCATION macro defined. In that case, ds@1952: ** the application that links SQLite must provide its own ds@1952: ** alternative implementation. See the documentation on ds@1952: ** [sqlite3_malloc()] for additional information. ds@1952: */ ds@1952: sqlite3_int64 sqlite3_memory_used(void); ds@1952: sqlite3_int64 sqlite3_memory_highwater(int resetFlag); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Memory Allocation Alarms ds@1952: ** ds@1952: ** The [sqlite3_memory_alarm] routine is used to register ds@1952: ** a callback on memory allocation events. ds@1952: ** ds@1952: ** This routine registers or clears a callbacks that fires when ds@1952: ** the amount of memory allocated exceeds iThreshold. Only ds@1952: ** a single callback can be registered at a time. Each call ds@1952: ** to [sqlite3_memory_alarm()] overwrites the previous callback. ds@1952: ** The callback is disabled by setting xCallback to a NULL ds@1952: ** pointer. ds@1952: ** ds@1952: ** The parameters to the callback are the pArg value, the ds@1952: ** amount of memory currently in use, and the size of the ds@1952: ** allocation that provoked the callback. The callback will ds@1952: ** presumably invoke [sqlite3_free()] to free up memory space. ds@1952: ** The callback may invoke [sqlite3_malloc()] or [sqlite3_realloc()] ds@1952: ** but if it does, no additional callbacks will be invoked by ds@1952: ** the recursive calls. ds@1952: ** ds@1952: ** The [sqlite3_soft_heap_limit()] interface works by registering ds@1952: ** a memory alarm at the soft heap limit and invoking ds@1952: ** [sqlite3_release_memory()] in the alarm callback. Application ds@1952: ** programs should not attempt to use the [sqlite3_memory_alarm()] ds@1952: ** interface because doing so will interfere with the ds@1952: ** [sqlite3_soft_heap_limit()] module. This interface is exposed ds@1952: ** only so that applications can provide their own ds@1952: ** alternative implementation when the SQLite core is ds@1952: ** compiled with SQLITE_OMIT_MEMORY_ALLOCATION. ds@1952: */ ds@1952: int sqlite3_memory_alarm( ds@1952: void(*xCallback)(void *pArg, sqlite3_int64 used, int N), ds@1952: void *pArg, ds@1952: sqlite3_int64 iThreshold ds@1952: ); ds@1952: ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Compile-Time Authorization Callbacks ds@1952: *** ds@1952: ** This routine registers a authorizer callback with the SQLite library. ds@1952: ** The authorizer callback is invoked as SQL statements are being compiled ds@1952: ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], ds@1952: ** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()]. At various ds@1952: ** points during the compilation process, as logic is being created ds@1952: ** to perform various actions, the authorizer callback is invoked to ds@1952: ** see if those actions are allowed. The authorizer callback should ds@1952: ** return SQLITE_OK to allow the action, [SQLITE_IGNORE] to disallow the ds@1952: ** specific action but allow the SQL statement to continue to be ds@1952: ** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be ds@1952: ** rejected with an error. ds@1952: ** ds@1952: ** Depending on the action, the [SQLITE_IGNORE] and [SQLITE_DENY] return ds@1952: ** codes might mean something different or they might mean the same ds@1952: ** thing. If the action is, for example, to perform a delete opertion, ds@1952: ** then [SQLITE_IGNORE] and [SQLITE_DENY] both cause the statement compilation ds@1952: ** to fail with an error. But if the action is to read a specific column ds@1952: ** from a specific table, then [SQLITE_DENY] will cause the entire ds@1952: ** statement to fail but [SQLITE_IGNORE] will cause a NULL value to be ds@1952: ** read instead of the actual column value. ds@1952: ** ds@1952: ** The first parameter to the authorizer callback is a copy of ds@1952: ** the third parameter to the sqlite3_set_authorizer() interface. ds@1952: ** The second parameter to the callback is an integer ds@1952: ** [SQLITE_COPY | action code] that specifies the particular action ds@1952: ** to be authorized. The available action codes are ds@1952: ** [SQLITE_COPY | documented separately]. The third through sixth ds@1952: ** parameters to the callback are strings that contain additional ds@1952: ** details about the action to be authorized. ds@1952: ** ds@1952: ** An authorizer is used when preparing SQL statements from an untrusted ds@1952: ** source, to ensure that the SQL statements do not try to access data ds@1952: ** that they are not allowed to see, or that they do not try to ds@1952: ** execute malicious statements that damage the database. For ds@1952: ** example, an application may allow a user to enter arbitrary ds@1952: ** SQL queries for evaluation by a database. But the application does ds@1952: ** not want the user to be able to make arbitrary changes to the ds@1952: ** database. An authorizer could then be put in place while the ds@1952: ** user-entered SQL is being prepared that disallows everything ds@1952: ** except SELECT statements. ds@1952: ** ds@1952: ** Only a single authorizer can be in place on a database connection ds@1952: ** at a time. Each call to sqlite3_set_authorizer overrides the ds@1952: ** previous call. A NULL authorizer means that no authorization ds@1952: ** callback is invoked. The default authorizer is NULL. ds@1952: ** ds@1952: ** Note that the authorizer callback is invoked only during ds@1952: ** [sqlite3_prepare()] or its variants. Authorization is not ds@1952: ** performed during statement evaluation in [sqlite3_step()]. ds@1952: */ ds@1952: int sqlite3_set_authorizer( ds@1952: sqlite3*, ds@1952: int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), ds@1952: void *pUserData ds@1952: ); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Authorizer Return Codes ds@1952: ** ds@1952: ** The [sqlite3_set_authorizer | authorizer callback function] must ds@1952: ** return either [SQLITE_OK] or one of these two constants in order ds@1952: ** to signal SQLite whether or not the action is permitted. See the ds@1952: ** [sqlite3_set_authorizer | authorizer documentation] for additional ds@1952: ** information. ds@1952: */ ds@1952: #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ ds@1952: #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Authorizer Action Codes ds@1952: ** ds@1952: ** The [sqlite3_set_authorizer()] interface registers a callback function ds@1952: ** that is invoked to authorizer certain SQL statement actions. The ds@1952: ** second parameter to the callback is an integer code that specifies ds@1952: ** what action is being authorized. These are the integer action codes that ds@1952: ** the authorizer callback may be passed. ds@1952: ** ds@1952: ** These action code values signify what kind of operation is to be ds@1952: ** authorized. The 3rd and 4th parameters to the authorization callback ds@1952: ** function will be parameters or NULL depending on which of these ds@1952: ** codes is used as the second parameter. The 5th parameter to the ds@1952: ** authorizer callback is the name of the database ("main", "temp", ds@1952: ** etc.) if applicable. The 6th parameter to the authorizer callback ds@1952: ** is the name of the inner-most trigger or view that is responsible for ds@1952: ** the access attempt or NULL if this access attempt is directly from ds@1952: ** top-level SQL code. ds@1952: */ ds@1952: /******************************************* 3rd ************ 4th ***********/ ds@1952: #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */ ds@1952: #define SQLITE_CREATE_TABLE 2 /* Table Name NULL */ ds@1952: #define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */ ds@1952: #define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */ ds@1952: #define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */ ds@1952: #define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */ ds@1952: #define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */ ds@1952: #define SQLITE_CREATE_VIEW 8 /* View Name NULL */ ds@1952: #define SQLITE_DELETE 9 /* Table Name NULL */ ds@1952: #define SQLITE_DROP_INDEX 10 /* Index Name Table Name */ ds@1952: #define SQLITE_DROP_TABLE 11 /* Table Name NULL */ ds@1952: #define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */ ds@1952: #define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */ ds@1952: #define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */ ds@1952: #define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */ ds@1952: #define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */ ds@1952: #define SQLITE_DROP_VIEW 17 /* View Name NULL */ ds@1952: #define SQLITE_INSERT 18 /* Table Name NULL */ ds@1952: #define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */ ds@1952: #define SQLITE_READ 20 /* Table Name Column Name */ ds@1952: #define SQLITE_SELECT 21 /* NULL NULL */ ds@1952: #define SQLITE_TRANSACTION 22 /* NULL NULL */ ds@1952: #define SQLITE_UPDATE 23 /* Table Name Column Name */ ds@1952: #define SQLITE_ATTACH 24 /* Filename NULL */ ds@1952: #define SQLITE_DETACH 25 /* Database Name NULL */ ds@1952: #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */ ds@1952: #define SQLITE_REINDEX 27 /* Index Name NULL */ ds@1952: #define SQLITE_ANALYZE 28 /* Table Name NULL */ ds@1952: #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */ ds@1952: #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */ ds@1952: #define SQLITE_FUNCTION 31 /* Function Name NULL */ ds@1952: #define SQLITE_COPY 0 /* No longer used */ ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Tracing And Profiling Functions ds@1952: ** ds@1952: ** These routines register callback functions that can be used for ds@1952: ** tracing and profiling the execution of SQL statements. ds@1952: ** The callback function registered by sqlite3_trace() is invoked ds@1952: ** at the first [sqlite3_step()] for the evaluation of an SQL statement. ds@1952: ** The callback function registered by sqlite3_profile() is invoked ds@1952: ** as each SQL statement finishes and includes ds@1952: ** information on how long that statement ran. ds@1952: ** ds@1952: ** The sqlite3_profile() API is currently considered experimental and ds@1952: ** is subject to change. ds@1952: */ ds@1952: void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*); ds@1952: void *sqlite3_profile(sqlite3*, ds@1952: void(*xProfile)(void*,const char*,sqlite3_uint64), void*); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Query Progress Callbacks ds@1952: ** ds@1952: ** This routine configures a callback function - the progress callback - that ds@1952: ** is invoked periodically during long running calls to [sqlite3_exec()], ds@1952: ** [sqlite3_step()] and [sqlite3_get_table()]. An example use for this ds@1952: ** interface is to keep a GUI updated during a large query. ds@1952: ** ds@1952: ** The progress callback is invoked once for every N virtual machine opcodes, ds@1952: ** where N is the second argument to this function. The progress callback ds@1952: ** itself is identified by the third argument to this function. The fourth ds@1952: ** argument to this function is a void pointer passed to the progress callback ds@1952: ** function each time it is invoked. ds@1952: ** ds@1952: ** If a call to [sqlite3_exec()], [sqlite3_step()], or [sqlite3_get_table()] ds@1952: ** results in fewer than N opcodes being executed, then the progress ds@1952: ** callback is never invoked. ds@1952: ** ds@1952: ** Only a single progress callback function may be registered for each ds@1952: ** open database connection. Every call to sqlite3_progress_handler() ds@1952: ** overwrites the results of the previous call. ds@1952: ** To remove the progress callback altogether, pass NULL as the third ds@1952: ** argument to this function. ds@1952: ** ds@1952: ** If the progress callback returns a result other than 0, then the current ds@1952: ** query is immediately terminated and any database changes rolled back. ds@1952: ** The containing [sqlite3_exec()], [sqlite3_step()], or ds@1952: ** [sqlite3_get_table()] call returns SQLITE_INTERRUPT. This feature ds@1952: ** can be used, for example, to implement the "Cancel" button on a ds@1952: ** progress dialog box in a GUI. ds@1952: */ ds@1952: void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Opening A New Database Connection ds@1952: ** ds@1952: ** Open the sqlite database file "filename". The "filename" is UTF-8 ds@1952: ** encoded for [sqlite3_open()] and [sqlite3_open_v2()] and UTF-16 encoded ds@1952: ** in the native byte order for [sqlite3_open16()]. ds@1952: ** An [sqlite3*] handle is returned in *ppDb, even ds@1952: ** if an error occurs. If the database is opened (or created) successfully, ds@1952: ** then [SQLITE_OK] is returned. Otherwise an error code is returned. The ds@1952: ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain ds@1952: ** an English language description of the error. ds@1952: ** ds@1952: ** The default encoding for the database will be UTF-8 if ds@1952: ** [sqlite3_open()] or [sqlite3_open_v2()] is called and ds@1952: ** UTF-16 if [sqlite3_open16()] is used. ds@1952: ** ds@1952: ** Whether or not an error occurs when it is opened, resources associated ds@1952: ** with the [sqlite3*] handle should be released by passing it to ds@1952: ** [sqlite3_close()] when it is no longer required. ds@1952: ** ds@1952: ** The [sqlite3_open_v2()] interface works like [sqlite3_open()] except that ds@1952: ** provides two additional parameters for additional control over the ds@1952: ** new database connection. The flags parameter can be one of: ds@1952: ** ds@1952: **
    ds@1952: **
  1. [SQLITE_OPEN_READONLY] ds@1952: **
  2. [SQLITE_OPEN_READWRITE] ds@1952: **
  3. [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE] ds@1952: **
ds@1952: ** ds@1952: ** The first value opens the database read-only. If the database does ds@1952: ** not previously exist, an error is returned. The second option opens ds@1952: ** the database for reading and writing if possible, or reading only if ds@1952: ** if the file is write protected. In either case the database must already ds@1952: ** exist or an error is returned. The third option opens the database ds@1952: ** for reading and writing and creates it if it does not already exist. ds@1952: ** The third options is behavior that is always used for [sqlite3_open()] ds@1952: ** and [sqlite3_open16()]. ds@1952: ** ds@1952: ** If the filename is ":memory:", then an private ds@1952: ** in-memory database is created for the connection. This in-memory ds@1952: ** database will vanish when the database connection is closed. Future ds@1952: ** version of SQLite might make use of additional special filenames ds@1952: ** that begin with the ":" character. It is recommended that ds@1952: ** when a database filename really does begin with ds@1952: ** ":" that you prefix the filename with a pathname like "./" to ds@1952: ** avoid ambiguity. ds@1952: ** ds@1952: ** If the filename is an empty string, then a private temporary ds@1952: ** on-disk database will be created. This private database will be ds@1952: ** automatically deleted as soon as the database connection is closed. ds@1952: ** ds@1952: ** The fourth parameter to sqlite3_open_v2() is the name of the ds@1952: ** [sqlite3_vfs] object that defines the operating system ds@1952: ** interface that the new database connection should use. If the ds@1952: ** fourth parameter is a NULL pointer then the default [sqlite3_vfs] ds@1952: ** object is used. ds@1952: ** ds@1952: ** Note to windows users: The encoding used for the filename argument ds@1952: ** of [sqlite3_open()] and [sqlite3_open_v2()] must be UTF-8, not whatever ds@1952: ** codepage is currently defined. Filenames containing international ds@1952: ** characters must be converted to UTF-8 prior to passing them into ds@1952: ** [sqlite3_open()] or [sqlite3_open_v2()]. ds@1952: */ ds@1952: int sqlite3_open( ds@1952: const char *filename, /* Database filename (UTF-8) */ ds@1952: sqlite3 **ppDb /* OUT: SQLite db handle */ ds@1952: ); ds@1952: int sqlite3_open16( ds@1952: const void *filename, /* Database filename (UTF-16) */ ds@1952: sqlite3 **ppDb /* OUT: SQLite db handle */ ds@1952: ); ds@1952: int sqlite3_open_v2( ds@1952: const char *filename, /* Database filename (UTF-8) */ ds@1952: sqlite3 **ppDb, /* OUT: SQLite db handle */ ds@1952: int flags, /* Flags */ ds@1952: const char *zVfs /* Name of VFS module to use */ ds@1952: ); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Error Codes And Messages ds@1952: ** ds@1952: ** The sqlite3_errcode() interface returns the numeric ds@1952: ** [SQLITE_OK | result code] or [SQLITE_IOERR_READ | extended result code] ds@1952: ** for the most recent failed sqlite3_* API call associated ds@1952: ** with [sqlite3] handle 'db'. If a prior API call failed but the ds@1952: ** most recent API call succeeded, the return value from sqlite3_errcode() ds@1952: ** is undefined. ds@1952: ** ds@1952: ** The sqlite3_errmsg() and sqlite3_errmsg16() return English-language ds@1952: ** text that describes the error, as either UTF8 or UTF16 respectively. ds@1952: ** Memory to hold the error message string is managed internally. The ds@1952: ** string may be overwritten or deallocated by subsequent calls to SQLite ds@1952: ** interface functions. ds@1952: ** ds@1952: ** Calls to many sqlite3_* functions set the error code and string returned ds@1952: ** by [sqlite3_errcode()], [sqlite3_errmsg()], and [sqlite3_errmsg16()] ds@1952: ** (overwriting the previous values). Note that calls to [sqlite3_errcode()], ds@1952: ** [sqlite3_errmsg()], and [sqlite3_errmsg16()] themselves do not affect the ds@1952: ** results of future invocations. Calls to API routines that do not return ds@1952: ** an error code (example: [sqlite3_data_count()]) do not ds@1952: ** change the error code returned by this routine. Interfaces that are ds@1952: ** not associated with a specific database connection (examples: ds@1952: ** [sqlite3_mprintf()] or [sqlite3_enable_shared_cache()] do not change ds@1952: ** the return code. ds@1952: ** ds@1952: ** Assuming no other intervening sqlite3_* API calls are made, the error ds@1952: ** code returned by this function is associated with the same error as ds@1952: ** the strings returned by [sqlite3_errmsg()] and [sqlite3_errmsg16()]. ds@1952: */ ds@1952: int sqlite3_errcode(sqlite3 *db); ds@1952: const char *sqlite3_errmsg(sqlite3*); ds@1952: const void *sqlite3_errmsg16(sqlite3*); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: SQL Statement Object ds@1952: ** ds@1952: ** Instance of this object represent single SQL statements. This ds@1952: ** is variously known as a "prepared statement" or a ds@1952: ** "compiled SQL statement" or simply as a "statement". ds@1952: ** ds@1952: ** The life of a statement object goes something like this: ds@1952: ** ds@1952: **
    ds@1952: **
  1. Create the object using [sqlite3_prepare_v2()] or a related ds@1952: ** function. ds@1952: **
  2. Bind values to host parameters using ds@1952: ** [sqlite3_bind_blob | sqlite3_bind_* interfaces]. ds@1952: **
  3. Run the SQL by calling [sqlite3_step()] one or more times. ds@1952: **
  4. Reset the statement using [sqlite3_reset()] then go back ds@1952: ** to step 2. Do this zero or more times. ds@1952: **
  5. Destroy the object using [sqlite3_finalize()]. ds@1952: **
ds@1952: ** ds@1952: ** Refer to documentation on individual methods above for additional ds@1952: ** information. ds@1952: */ ds@1952: typedef struct sqlite3_stmt sqlite3_stmt; ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Compiling An SQL Statement ds@1952: ** ds@1952: ** To execute an SQL query, it must first be compiled into a byte-code ds@1952: ** program using one of these routines. ds@1952: ** ds@1952: ** The first argument "db" is an [sqlite3 | SQLite database handle] ds@1952: ** obtained from a prior call to [sqlite3_open()], [sqlite3_open_v2()] ds@1952: ** or [sqlite3_open16()]. ds@1952: ** The second argument "zSql" is the statement to be compiled, encoded ds@1952: ** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2() ds@1952: ** interfaces uses UTF-8 and sqlite3_prepare16() and sqlite3_prepare16_v2() ds@1952: ** use UTF-16. ds@1952: ** ds@1952: ** If the nByte argument is less ds@1952: ** than zero, then zSql is read up to the first zero terminator. If ds@1952: ** nByte is non-negative, then it is the maximum number of ds@1952: ** bytes read from zSql. When nByte is non-negative, the ds@1952: ** zSql string ends at either the first '\000' character or ds@1952: ** until the nByte-th byte, whichever comes first. ds@1952: ** ds@1952: ** *pzTail is made to point to the first byte past the end of the first ds@1952: ** SQL statement in zSql. This routine only compiles the first statement ds@1952: ** in zSql, so *pzTail is left pointing to what remains uncompiled. ds@1952: ** ds@1952: ** *ppStmt is left pointing to a compiled ds@1952: ** [sqlite3_stmt | SQL statement structure] that can be ds@1952: ** executed using [sqlite3_step()]. Or if there is an error, *ppStmt may be ds@1952: ** set to NULL. If the input text contained no SQL (if the input is and ds@1952: ** empty string or a comment) then *ppStmt is set to NULL. The calling ds@1952: ** procedure is responsible for deleting the compiled SQL statement ds@1952: ** using [sqlite3_finalize()] after it has finished with it. ds@1952: ** ds@1952: ** On success, [SQLITE_OK] is returned. Otherwise an ds@1952: ** [SQLITE_ERROR | error code] is returned. ds@1952: ** ds@1952: ** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are ds@1952: ** recommended for all new programs. The two older interfaces are retained ds@1952: ** for backwards compatibility, but their use is discouraged. ds@1952: ** In the "v2" interfaces, the prepared statement ds@1952: ** that is returned (the [sqlite3_stmt] object) contains a copy of the ds@1952: ** original SQL text. This causes the [sqlite3_step()] interface to ds@1952: ** behave a differently in two ways: ds@1952: ** ds@1952: **
    ds@1952: **
  1. ds@1952: ** If the database schema changes, instead of returning [SQLITE_SCHEMA] as it ds@1952: ** always used to do, [sqlite3_step()] will automatically recompile the SQL ds@1952: ** statement and try to run it again. If the schema has changed in a way ds@1952: ** that makes the statement no longer valid, [sqlite3_step()] will still ds@1952: ** return [SQLITE_SCHEMA]. But unlike the legacy behavior, [SQLITE_SCHEMA] is ds@1952: ** now a fatal error. Calling [sqlite3_prepare_v2()] again will not make the ds@1952: ** error go away. Note: use [sqlite3_errmsg()] to find the text of the parsing ds@1952: ** error that results in an [SQLITE_SCHEMA] return. ds@1952: **
  2. ds@1952: ** ds@1952: **
  3. ds@1952: ** When an error occurs, ds@1952: ** [sqlite3_step()] will return one of the detailed ds@1952: ** [SQLITE_ERROR | result codes] or ds@1952: ** [SQLITE_IOERR_READ | extended result codes] such as directly. ds@1952: ** The legacy behavior was that [sqlite3_step()] would only return a generic ds@1952: ** [SQLITE_ERROR] result code and you would have to make a second call to ds@1952: ** [sqlite3_reset()] in order to find the underlying cause of the problem. ds@1952: ** With the "v2" prepare interfaces, the underlying reason for the error is ds@1952: ** returned immediately. ds@1952: **
  4. ds@1952: **
ds@1952: */ ds@1952: int sqlite3_prepare( ds@1952: sqlite3 *db, /* Database handle */ ds@1952: const char *zSql, /* SQL statement, UTF-8 encoded */ ds@1952: int nByte, /* Maximum length of zSql in bytes. */ ds@1952: sqlite3_stmt **ppStmt, /* OUT: Statement handle */ ds@1952: const char **pzTail /* OUT: Pointer to unused portion of zSql */ ds@1952: ); ds@1952: int sqlite3_prepare_v2( ds@1952: sqlite3 *db, /* Database handle */ ds@1952: const char *zSql, /* SQL statement, UTF-8 encoded */ ds@1952: int nByte, /* Maximum length of zSql in bytes. */ ds@1952: sqlite3_stmt **ppStmt, /* OUT: Statement handle */ ds@1952: const char **pzTail /* OUT: Pointer to unused portion of zSql */ ds@1952: ); ds@1952: int sqlite3_prepare16( ds@1952: sqlite3 *db, /* Database handle */ ds@1952: const void *zSql, /* SQL statement, UTF-16 encoded */ ds@1952: int nByte, /* Maximum length of zSql in bytes. */ ds@1952: sqlite3_stmt **ppStmt, /* OUT: Statement handle */ ds@1952: const void **pzTail /* OUT: Pointer to unused portion of zSql */ ds@1952: ); ds@1952: int sqlite3_prepare16_v2( ds@1952: sqlite3 *db, /* Database handle */ ds@1952: const void *zSql, /* SQL statement, UTF-16 encoded */ ds@1952: int nByte, /* Maximum length of zSql in bytes. */ ds@1952: sqlite3_stmt **ppStmt, /* OUT: Statement handle */ ds@1952: const void **pzTail /* OUT: Pointer to unused portion of zSql */ ds@1952: ); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Dynamically Typed Value Object ds@1952: ** ds@1952: ** SQLite uses dynamic typing for the values it stores. Values can ds@1952: ** be integers, floating point values, strings, BLOBs, or NULL. When ds@1952: ** passing around values internally, each value is represented as ds@1952: ** an instance of the sqlite3_value object. ds@1952: */ ds@1952: typedef struct Mem sqlite3_value; ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: SQL Function Context Object ds@1952: ** ds@1952: ** The context in which an SQL function executes is stored in an ds@1952: ** sqlite3_context object. A pointer to such an object is the ds@1952: ** first parameter to user-defined SQL functions. ds@1952: */ ds@1952: typedef struct sqlite3_context sqlite3_context; ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Binding Values To Prepared Statements ds@1952: ** ds@1952: ** In the SQL strings input to [sqlite3_prepare_v2()] and its variants, ds@1952: ** one or more literals can be replace by a parameter in one of these ds@1952: ** forms: ds@1952: ** ds@1952: ** ds@1952: ** ds@1952: ** In the parameter forms shown above NNN is an integer literal, ds@1952: ** AAA is an alphanumeric identifier and VVV is a variable name according ds@1952: ** to the syntax rules of the TCL programming language. ds@1952: ** The values of these parameters (also called "host parameter names") ds@1952: ** can be set using the sqlite3_bind_*() routines defined here. ds@1952: ** ds@1952: ** The first argument to the sqlite3_bind_*() routines always is a pointer ds@1952: ** to the [sqlite3_stmt] object returned from [sqlite3_prepare_v2()] or ds@1952: ** its variants. The second ds@1952: ** argument is the index of the parameter to be set. The first parameter has ds@1952: ** an index of 1. When the same named parameter is used more than once, second ds@1952: ** and subsequent ds@1952: ** occurrences have the same index as the first occurrence. The index for ds@1952: ** named parameters can be looked up using the ds@1952: ** [sqlite3_bind_parameter_name()] API if desired. The index for "?NNN" ds@1952: ** parametes is the value of NNN. ds@1952: ** The NNN value must be between 1 and the compile-time ds@1952: ** parameter SQLITE_MAX_VARIABLE_NUMBER (default value: 999). ds@1952: ** See limits.html for additional information. ds@1952: ** ds@1952: ** The third argument is the value to bind to the parameter. ds@1952: ** ds@1952: ** In those ds@1952: ** routines that have a fourth argument, its value is the number of bytes ds@1952: ** in the parameter. To be clear: the value is the number of bytes in the ds@1952: ** string, not the number of characters. The number ds@1952: ** of bytes does not include the zero-terminator at the end of strings. ds@1952: ** If the fourth parameter is negative, the length of the string is ds@1952: ** number of bytes up to the first zero terminator. ds@1952: ** ds@1952: ** The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and ds@1952: ** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or ds@1952: ** text after SQLite has finished with it. If the fifth argument is the ds@1952: ** special value [SQLITE_STATIC], then the library assumes that the information ds@1952: ** is in static, unmanaged space and does not need to be freed. If the ds@1952: ** fifth argument has the value [SQLITE_TRANSIENT], then SQLite makes its ds@1952: ** own private copy of the data immediately, before the sqlite3_bind_*() ds@1952: ** routine returns. ds@1952: ** ds@1952: ** The sqlite3_bind_zeroblob() routine binds a BLOB of length n that ds@1952: ** is filled with zeros. A zeroblob uses a fixed amount of memory ds@1952: ** (just an integer to hold it size) while it is being processed. ds@1952: ** Zeroblobs are intended to serve as place-holders for BLOBs whose ds@1952: ** content is later written using ds@1952: ** [sqlite3_blob_open | increment BLOB I/O] routines. A negative ds@1952: ** value for the zeroblob results in a zero-length BLOB. ds@1952: ** ds@1952: ** The sqlite3_bind_*() routines must be called after ds@1952: ** [sqlite3_prepare_v2()] (and its variants) or [sqlite3_reset()] and ds@1952: ** before [sqlite3_step()]. ds@1952: ** Bindings are not cleared by the [sqlite3_reset()] routine. ds@1952: ** Unbound parameters are interpreted as NULL. ds@1952: ** ds@1952: ** These routines return [SQLITE_OK] on success or an error code if ds@1952: ** anything goes wrong. [SQLITE_RANGE] is returned if the parameter ds@1952: ** index is out of range. [SQLITE_NOMEM] is returned if malloc fails. ds@1952: ** [SQLITE_MISUSE] is returned if these routines are called on a virtual ds@1952: ** machine that is the wrong state or which has already been finalized. ds@1952: */ ds@1952: int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); ds@1952: int sqlite3_bind_double(sqlite3_stmt*, int, double); ds@1952: int sqlite3_bind_int(sqlite3_stmt*, int, int); ds@1952: int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64); ds@1952: int sqlite3_bind_null(sqlite3_stmt*, int); ds@1952: int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*)); ds@1952: int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*)); ds@1952: int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); ds@1952: int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Number Of Host Parameters ds@1952: ** ds@1952: ** Return the largest host parameter index in the precompiled statement given ds@1952: ** as the argument. When the host parameters are of the forms like ":AAA" ds@1952: ** or "?", then they are assigned sequential increasing numbers beginning ds@1952: ** with one, so the value returned is the number of parameters. However ds@1952: ** if the same host parameter name is used multiple times, each occurrance ds@1952: ** is given the same number, so the value returned in that case is the number ds@1952: ** of unique host parameter names. If host parameters of the form "?NNN" ds@1952: ** are used (where NNN is an integer) then there might be gaps in the ds@1952: ** numbering and the value returned by this interface is the index of the ds@1952: ** host parameter with the largest index value. ds@1952: ** ds@1952: ** The prepared statement must not be [sqlite3_finalize | finalized] ds@1952: ** prior to this routine returnning. Otherwise the results are undefined ds@1952: ** and probably undesirable. ds@1952: */ ds@1952: int sqlite3_bind_parameter_count(sqlite3_stmt*); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Name Of A Host Parameter ds@1952: ** ds@1952: ** This routine returns a pointer to the name of the n-th parameter in a ds@1952: ** [sqlite3_stmt | prepared statement]. ds@1952: ** Host parameters of the form ":AAA" or "@AAA" or "$VVV" have a name ds@1952: ** which is the string ":AAA" or "@AAA" or "$VVV". ds@1952: ** In other words, the initial ":" or "$" or "@" ds@1952: ** is included as part of the name. ds@1952: ** Parameters of the form "?" or "?NNN" have no name. ds@1952: ** ds@1952: ** The first bound parameter has an index of 1, not 0. ds@1952: ** ds@1952: ** If the value n is out of range or if the n-th parameter is nameless, ds@1952: ** then NULL is returned. The returned string is always in the ds@1952: ** UTF-8 encoding even if the named parameter was originally specified ds@1952: ** as UTF-16 in [sqlite3_prepare16()] or [sqlite3_prepare16_v2()]. ds@1952: */ ds@1952: const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Index Of A Parameter With A Given Name ds@1952: ** ds@1952: ** This routine returns the index of a host parameter with the given name. ds@1952: ** The name must match exactly. If no parameter with the given name is ds@1952: ** found, return 0. Parameter names must be UTF8. ds@1952: */ ds@1952: int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Reset All Bindings On A Prepared Statement ds@1952: ** ds@1952: ** Contrary to the intuition of many, [sqlite3_reset()] does not ds@1952: ** reset the [sqlite3_bind_blob | bindings] on a ds@1952: ** [sqlite3_stmt | prepared statement]. Use this routine to ds@1952: ** reset all host parameters to NULL. ds@1952: */ ds@1952: int sqlite3_clear_bindings(sqlite3_stmt*); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Number Of Columns In A Result Set ds@1952: ** ds@1952: ** Return the number of columns in the result set returned by the ds@1952: ** [sqlite3_stmt | compiled SQL statement]. This routine returns 0 ds@1952: ** if pStmt is an SQL statement that does not return data (for ds@1952: ** example an UPDATE). ds@1952: */ ds@1952: int sqlite3_column_count(sqlite3_stmt *pStmt); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Column Names In A Result Set ds@1952: ** ds@1952: ** These routines return the name assigned to a particular column ds@1952: ** in the result set of a SELECT statement. The sqlite3_column_name() ds@1952: ** interface returns a pointer to a UTF8 string and sqlite3_column_name16() ds@1952: ** returns a pointer to a UTF16 string. The first parameter is the ds@1952: ** [sqlite3_stmt | prepared statement] that implements the SELECT statement. ds@1952: ** The second parameter is the column number. The left-most column is ds@1952: ** number 0. ds@1952: ** ds@1952: ** The returned string pointer is valid until either the ds@1952: ** [sqlite3_stmt | prepared statement] is destroyed by [sqlite3_finalize()] ds@1952: ** or until the next call sqlite3_column_name() or sqlite3_column_name16() ds@1952: ** on the same column. ds@1952: ** ds@1952: ** If sqlite3_malloc() fails during the processing of either routine ds@1952: ** (for example during a conversion from UTF-8 to UTF-16) then a ds@1952: ** NULL pointer is returned. ds@1952: */ ds@1952: const char *sqlite3_column_name(sqlite3_stmt*, int N); ds@1952: const void *sqlite3_column_name16(sqlite3_stmt*, int N); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Source Of Data In A Query Result ds@1952: ** ds@1952: ** These routines provide a means to determine what column of what ds@1952: ** table in which database a result of a SELECT statement comes from. ds@1952: ** The name of the database or table or column can be returned as ds@1952: ** either a UTF8 or UTF16 string. The _database_ routines return ds@1952: ** the database name, the _table_ routines return the table name, and ds@1952: ** the origin_ routines return the column name. ds@1952: ** The returned string is valid until ds@1952: ** the [sqlite3_stmt | prepared statement] is destroyed using ds@1952: ** [sqlite3_finalize()] or until the same information is requested ds@1952: ** again in a different encoding. ds@1952: ** ds@1952: ** The names returned are the original un-aliased names of the ds@1952: ** database, table, and column. ds@1952: ** ds@1952: ** The first argument to the following calls is a ds@1952: ** [sqlite3_stmt | compiled SQL statement]. ds@1952: ** These functions return information about the Nth column returned by ds@1952: ** the statement, where N is the second function argument. ds@1952: ** ds@1952: ** If the Nth column returned by the statement is an expression ds@1952: ** or subquery and is not a column value, then all of these functions ds@1952: ** return NULL. Otherwise, they return the ds@1952: ** name of the attached database, table and column that query result ds@1952: ** column was extracted from. ds@1952: ** ds@1952: ** As with all other SQLite APIs, those postfixed with "16" return UTF-16 ds@1952: ** encoded strings, the other functions return UTF-8. ds@1952: ** ds@1952: ** These APIs are only available if the library was compiled with the ds@1952: ** SQLITE_ENABLE_COLUMN_METADATA preprocessor symbol defined. ds@1952: ** ds@1952: ** If two or more threads call one or more of these routines against the same ds@1952: ** prepared statement and column at the same time then the results are ds@1952: ** undefined. ds@1952: */ ds@1952: const char *sqlite3_column_database_name(sqlite3_stmt*,int); ds@1952: const void *sqlite3_column_database_name16(sqlite3_stmt*,int); ds@1952: const char *sqlite3_column_table_name(sqlite3_stmt*,int); ds@1952: const void *sqlite3_column_table_name16(sqlite3_stmt*,int); ds@1952: const char *sqlite3_column_origin_name(sqlite3_stmt*,int); ds@1952: const void *sqlite3_column_origin_name16(sqlite3_stmt*,int); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Declared Datatype Of A Query Result ds@1952: ** ds@1952: ** The first parameter is a [sqlite3_stmt | compiled SQL statement]. ds@1952: ** If this statement is a SELECT statement and the Nth column of the ds@1952: ** returned result set of that SELECT is a table column (not an ds@1952: ** expression or subquery) then the declared type of the table ds@1952: ** column is returned. If the Nth column of the result set is an ds@1952: ** expression or subquery, then a NULL pointer is returned. ds@1952: ** The returned string is always UTF-8 encoded. For example, in ds@1952: ** the database schema: ds@1952: ** ds@1952: ** CREATE TABLE t1(c1 VARIANT); ds@1952: ** ds@1952: ** And the following statement compiled: ds@1952: ** ds@1952: ** SELECT c1 + 1, c1 FROM t1; ds@1952: ** ds@1952: ** Then this routine would return the string "VARIANT" for the second ds@1952: ** result column (i==1), and a NULL pointer for the first result column ds@1952: ** (i==0). ds@1952: ** ds@1952: ** SQLite uses dynamic run-time typing. So just because a column ds@1952: ** is declared to contain a particular type does not mean that the ds@1952: ** data stored in that column is of the declared type. SQLite is ds@1952: ** strongly typed, but the typing is dynamic not static. Type ds@1952: ** is associated with individual values, not with the containers ds@1952: ** used to hold those values. ds@1952: */ ds@1952: const char *sqlite3_column_decltype(sqlite3_stmt *, int i); ds@1952: const void *sqlite3_column_decltype16(sqlite3_stmt*,int); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Evaluate An SQL Statement ds@1952: ** ds@1952: ** After an [sqlite3_stmt | SQL statement] has been prepared with a call ds@1952: ** to either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or to one of ds@1952: ** the legacy interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], ds@1952: ** then this function must be called one or more times to evaluate the ds@1952: ** statement. ds@1952: ** ds@1952: ** The details of the behavior of this sqlite3_step() interface depend ds@1952: ** on whether the statement was prepared using the newer "v2" interface ds@1952: ** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy ds@1952: ** interface [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the ds@1952: ** new "v2" interface is recommended for new applications but the legacy ds@1952: ** interface will continue to be supported. ds@1952: ** ds@1952: ** In the lagacy interface, the return value will be either [SQLITE_BUSY], ds@1952: ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE]. ds@1952: ** With the "v2" interface, any of the other [SQLITE_OK | result code] ds@1952: ** or [SQLITE_IOERR_READ | extended result code] might be returned as ds@1952: ** well. ds@1952: ** ds@1952: ** [SQLITE_BUSY] means that the database engine was unable to acquire the ds@1952: ** database locks it needs to do its job. If the statement is a COMMIT ds@1952: ** or occurs outside of an explicit transaction, then you can retry the ds@1952: ** statement. If the statement is not a COMMIT and occurs within a ds@1952: ** explicit transaction then you should rollback the transaction before ds@1952: ** continuing. ds@1952: ** ds@1952: ** [SQLITE_DONE] means that the statement has finished executing ds@1952: ** successfully. sqlite3_step() should not be called again on this virtual ds@1952: ** machine without first calling [sqlite3_reset()] to reset the virtual ds@1952: ** machine back to its initial state. ds@1952: ** ds@1952: ** If the SQL statement being executed returns any data, then ds@1952: ** [SQLITE_ROW] is returned each time a new row of data is ready ds@1952: ** for processing by the caller. The values may be accessed using ds@1952: ** the [sqlite3_column_int | column access functions]. ds@1952: ** sqlite3_step() is called again to retrieve the next row of data. ds@1952: ** ds@1952: ** [SQLITE_ERROR] means that a run-time error (such as a constraint ds@1952: ** violation) has occurred. sqlite3_step() should not be called again on ds@1952: ** the VM. More information may be found by calling [sqlite3_errmsg()]. ds@1952: ** With the legacy interface, a more specific error code (example: ds@1952: ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth) ds@1952: ** can be obtained by calling [sqlite3_reset()] on the ds@1952: ** [sqlite3_stmt | prepared statement]. In the "v2" interface, ds@1952: ** the more specific error code is returned directly by sqlite3_step(). ds@1952: ** ds@1952: ** [SQLITE_MISUSE] means that the this routine was called inappropriately. ds@1952: ** Perhaps it was called on a [sqlite3_stmt | prepared statement] that has ds@1952: ** already been [sqlite3_finalize | finalized] or on one that had ds@1952: ** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could ds@1952: ** be the case that the same database connection is being used by two or ds@1952: ** more threads at the same moment in time. ds@1952: ** ds@1952: ** Goofy Interface Alert: ds@1952: ** In the legacy interface, ds@1952: ** the sqlite3_step() API always returns a generic error code, ds@1952: ** [SQLITE_ERROR], following any error other than [SQLITE_BUSY] ds@1952: ** and [SQLITE_MISUSE]. You must call [sqlite3_reset()] or ds@1952: ** [sqlite3_finalize()] in order to find one of the specific ds@1952: ** [SQLITE_ERROR | result codes] that better describes the error. ds@1952: ** We admit that this is a goofy design. The problem has been fixed ds@1952: ** with the "v2" interface. If you prepare all of your SQL statements ds@1952: ** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead ds@1952: ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()], then the ds@1952: ** more specific [SQLITE_ERROR | result codes] are returned directly ds@1952: ** by sqlite3_step(). The use of the "v2" interface is recommended. ds@1952: */ ds@1952: int sqlite3_step(sqlite3_stmt*); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: ds@1952: ** ds@1952: ** Return the number of values in the current row of the result set. ds@1952: ** ds@1952: ** After a call to [sqlite3_step()] that returns [SQLITE_ROW], this routine ds@1952: ** will return the same value as the [sqlite3_column_count()] function. ds@1952: ** After [sqlite3_step()] has returned an [SQLITE_DONE], [SQLITE_BUSY], or ds@1952: ** a [SQLITE_ERROR | error code], or before [sqlite3_step()] has been ds@1952: ** called on the [sqlite3_stmt | prepared statement] for the first time, ds@1952: ** this routine returns zero. ds@1952: */ ds@1952: int sqlite3_data_count(sqlite3_stmt *pStmt); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Fundamental Datatypes ds@1952: ** ds@1952: ** Every value in SQLite has one of five fundamental datatypes: ds@1952: ** ds@1952: ** ds@1952: ** ds@1952: ** These constants are codes for each of those types. ds@1952: ** ds@1952: ** Note that the SQLITE_TEXT constant was also used in SQLite version 2 ds@1952: ** for a completely different meaning. Software that links against both ds@1952: ** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT not ds@1952: ** SQLITE_TEXT. ds@1952: */ ds@1952: #define SQLITE_INTEGER 1 ds@1952: #define SQLITE_FLOAT 2 ds@1952: #define SQLITE_BLOB 4 ds@1952: #define SQLITE_NULL 5 ds@1952: #ifdef SQLITE_TEXT ds@1952: # undef SQLITE_TEXT ds@1952: #else ds@1952: # define SQLITE_TEXT 3 ds@1952: #endif ds@1952: #define SQLITE3_TEXT 3 ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Results Values From A Query ds@1952: ** ds@1952: ** These routines return information about ds@1952: ** a single column of the current result row of a query. In every ds@1952: ** case the first argument is a pointer to the ds@1952: ** [sqlite3_stmt | SQL statement] that is being ds@1952: ** evaluated (the [sqlite3_stmt*] that was returned from ds@1952: ** [sqlite3_prepare_v2()] or one of its variants) and ds@1952: ** the second argument is the index of the column for which information ds@1952: ** should be returned. The left-most column of the result set ds@1952: ** has an index of 0. ds@1952: ** ds@1952: ** If the SQL statement is not currently point to a valid row, or if the ds@1952: ** the column index is out of range, the result is undefined. ds@1952: ** These routines may only be called when the most recent call to ds@1952: ** [sqlite3_step()] has returned [SQLITE_ROW] and neither ds@1952: ** [sqlite3_reset()] nor [sqlite3_finalize()] has been call subsequently. ds@1952: ** If any of these routines are called after [sqlite3_reset()] or ds@1952: ** [sqlite3_finalize()] or after [sqlite3_step()] has returned ds@1952: ** something other than [SQLITE_ROW], the results are undefined. ds@1952: ** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()] ds@1952: ** are called from a different thread while any of these routines ds@1952: ** are pending, then the results are undefined. ds@1952: ** ds@1952: ** The sqlite3_column_type() routine returns ds@1952: ** [SQLITE_INTEGER | datatype code] for the initial data type ds@1952: ** of the result column. The returned value is one of [SQLITE_INTEGER], ds@1952: ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL]. The value ds@1952: ** returned by sqlite3_column_type() is only meaningful if no type ds@1952: ** conversions have occurred as described below. After a type conversion, ds@1952: ** the value returned by sqlite3_column_type() is undefined. Future ds@1952: ** versions of SQLite may change the behavior of sqlite3_column_type() ds@1952: ** following a type conversion. ds@1952: ** ds@1952: ** If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes() ds@1952: ** routine returns the number of bytes in that BLOB or string. ds@1952: ** If the result is a UTF-16 string, then sqlite3_column_bytes() converts ds@1952: ** the string to UTF-8 and then returns the number of bytes. ds@1952: ** If the result is a numeric value then sqlite3_column_bytes() uses ds@1952: ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns ds@1952: ** the number of bytes in that string. ds@1952: ** The value returned does not include the zero terminator at the end ds@1952: ** of the string. For clarity: the value returned is the number of ds@1952: ** bytes in the string, not the number of characters. ds@1952: ** ds@1952: ** Strings returned by sqlite3_column_text() and sqlite3_column_text16(), ds@1952: ** even zero-length strings, are always zero terminated. The return ds@1952: ** value from sqlite3_column_blob() for a zero-length blob is an arbitrary ds@1952: ** pointer, possibly even a NULL pointer. ds@1952: ** ds@1952: ** The sqlite3_column_bytes16() routine is similar to sqlite3_column_bytes() ds@1952: ** but leaves the result in UTF-16 instead of UTF-8. ds@1952: ** The zero terminator is not included in this count. ds@1952: ** ds@1952: ** These routines attempt to convert the value where appropriate. For ds@1952: ** example, if the internal representation is FLOAT and a text result ds@1952: ** is requested, [sqlite3_snprintf()] is used internally to do the conversion ds@1952: ** automatically. The following table details the conversions that ds@1952: ** are applied: ds@1952: ** ds@1952: **
ds@1952: ** ds@1952: **
Internal
Type
Requested
Type
Conversion ds@1952: ** ds@1952: **
NULL INTEGER Result is 0 ds@1952: **
NULL FLOAT Result is 0.0 ds@1952: **
NULL TEXT Result is NULL pointer ds@1952: **
NULL BLOB Result is NULL pointer ds@1952: **
INTEGER FLOAT Convert from integer to float ds@1952: **
INTEGER TEXT ASCII rendering of the integer ds@1952: **
INTEGER BLOB Same as for INTEGER->TEXT ds@1952: **
FLOAT INTEGER Convert from float to integer ds@1952: **
FLOAT TEXT ASCII rendering of the float ds@1952: **
FLOAT BLOB Same as FLOAT->TEXT ds@1952: **
TEXT INTEGER Use atoi() ds@1952: **
TEXT FLOAT Use atof() ds@1952: **
TEXT BLOB No change ds@1952: **
BLOB INTEGER Convert to TEXT then use atoi() ds@1952: **
BLOB FLOAT Convert to TEXT then use atof() ds@1952: **
BLOB TEXT Add a zero terminator if needed ds@1952: **
ds@1952: **
ds@1952: ** ds@1952: ** The table above makes reference to standard C library functions atoi() ds@1952: ** and atof(). SQLite does not really use these functions. It has its ds@1952: ** on equavalent internal routines. The atoi() and atof() names are ds@1952: ** used in the table for brevity and because they are familiar to most ds@1952: ** C programmers. ds@1952: ** ds@1952: ** Note that when type conversions occur, pointers returned by prior ds@1952: ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or ds@1952: ** sqlite3_column_text16() may be invalidated. ds@1952: ** Type conversions and pointer invalidations might occur ds@1952: ** in the following cases: ds@1952: ** ds@1952: ** ds@1952: ** ds@1952: ** Conversions between UTF-16be and UTF-16le are always done in place and do ds@1952: ** not invalidate a prior pointer, though of course the content of the buffer ds@1952: ** that the prior pointer points to will have been modified. Other kinds ds@1952: ** of conversion are done in place when it is possible, but sometime it is ds@1952: ** not possible and in those cases prior pointers are invalidated. ds@1952: ** ds@1952: ** The safest and easiest to remember policy is to invoke these routines ds@1952: ** in one of the following ways: ds@1952: ** ds@1952: ** ds@1952: ** ds@1952: ** In other words, you should call sqlite3_column_text(), sqlite3_column_blob(), ds@1952: ** or sqlite3_column_text16() first to force the result into the desired ds@1952: ** format, then invoke sqlite3_column_bytes() or sqlite3_column_bytes16() to ds@1952: ** find the size of the result. Do not mix call to sqlite3_column_text() or ds@1952: ** sqlite3_column_blob() with calls to sqlite3_column_bytes16(). And do not ds@1952: ** mix calls to sqlite3_column_text16() with calls to sqlite3_column_bytes(). ds@1952: ** ds@1952: ** The pointers returned are valid until a type conversion occurs as ds@1952: ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or ds@1952: ** [sqlite3_finalize()] is called. The memory space used to hold strings ds@1952: ** and blobs is freed automatically. Do not pass the pointers returned ds@1952: ** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into ds@1952: ** [sqlite3_free()]. ds@1952: ** ds@1952: ** If a memory allocation error occurs during the evaluation of any ds@1952: ** of these routines, a default value is returned. The default value ds@1952: ** is either the integer 0, the floating point number 0.0, or a NULL ds@1952: ** pointer. Subsequent calls to [sqlite3_errcode()] will return ds@1952: ** [SQLITE_NOMEM]. ds@1952: */ ds@1952: const void *sqlite3_column_blob(sqlite3_stmt*, int iCol); ds@1952: int sqlite3_column_bytes(sqlite3_stmt*, int iCol); ds@1952: int sqlite3_column_bytes16(sqlite3_stmt*, int iCol); ds@1952: double sqlite3_column_double(sqlite3_stmt*, int iCol); ds@1952: int sqlite3_column_int(sqlite3_stmt*, int iCol); ds@1952: sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol); ds@1952: const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol); ds@1952: const void *sqlite3_column_text16(sqlite3_stmt*, int iCol); ds@1952: int sqlite3_column_type(sqlite3_stmt*, int iCol); ds@1952: sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Destroy A Prepared Statement Object ds@1952: ** ds@1952: ** The sqlite3_finalize() function is called to delete a ds@1952: ** [sqlite3_stmt | compiled SQL statement]. If the statement was ds@1952: ** executed successfully, or not executed at all, then SQLITE_OK is returned. ds@1952: ** If execution of the statement failed then an ds@1952: ** [SQLITE_ERROR | error code] or [SQLITE_IOERR_READ | extended error code] ds@1952: ** is returned. ds@1952: ** ds@1952: ** This routine can be called at any point during the execution of the ds@1952: ** [sqlite3_stmt | virtual machine]. If the virtual machine has not ds@1952: ** completed execution when this routine is called, that is like ds@1952: ** encountering an error or an interrupt. (See [sqlite3_interrupt()].) ds@1952: ** Incomplete updates may be rolled back and transactions cancelled, ds@1952: ** depending on the circumstances, and the ds@1952: ** [SQLITE_ERROR | result code] returned will be [SQLITE_ABORT]. ds@1952: */ ds@1952: int sqlite3_finalize(sqlite3_stmt *pStmt); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Reset A Prepared Statement Object ds@1952: ** ds@1952: ** The sqlite3_reset() function is called to reset a ds@1952: ** [sqlite3_stmt | compiled SQL statement] object. ds@1952: ** back to it's initial state, ready to be re-executed. ds@1952: ** Any SQL statement variables that had values bound to them using ds@1952: ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values. ds@1952: ** Use [sqlite3_clear_bindings()] to reset the bindings. ds@1952: */ ds@1952: int sqlite3_reset(sqlite3_stmt *pStmt); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Create Or Redefine SQL Functions ds@1952: ** ds@1952: ** The following two functions are used to add SQL functions or aggregates ds@1952: ** or to redefine the behavior of existing SQL functions or aggregates. The ds@1952: ** difference only between the two is that the second parameter, the ds@1952: ** name of the (scalar) function or aggregate, is encoded in UTF-8 for ds@1952: ** sqlite3_create_function() and UTF-16 for sqlite3_create_function16(). ds@1952: ** ds@1952: ** The first argument is the [sqlite3 | database handle] that holds the ds@1952: ** SQL function or aggregate is to be added or redefined. If a single ds@1952: ** program uses more than one database handle internally, then SQL ds@1952: ** functions or aggregates must be added individually to each database ds@1952: ** handle with which they will be used. ds@1952: ** ds@1952: ** The second parameter is the name of the SQL function to be created ds@1952: ** or redefined. ds@1952: ** The length of the name is limited to 255 bytes, exclusive of the ds@1952: ** zero-terminator. Note that the name length limit is in bytes, not ds@1952: ** characters. Any attempt to create a function with a longer name ds@1952: ** will result in an SQLITE_ERROR error. ds@1952: ** ds@1952: ** The third parameter is the number of arguments that the SQL function or ds@1952: ** aggregate takes. If this parameter is negative, then the SQL function or ds@1952: ** aggregate may take any number of arguments. ds@1952: ** ds@1952: ** The fourth parameter, eTextRep, specifies what ds@1952: ** [SQLITE_UTF8 | text encoding] this SQL function prefers for ds@1952: ** its parameters. Any SQL function implementation should be able to work ds@1952: ** work with UTF-8, UTF-16le, or UTF-16be. But some implementations may be ds@1952: ** more efficient with one encoding than another. It is allowed to ds@1952: ** invoke sqlite3_create_function() or sqlite3_create_function16() multiple ds@1952: ** times with the same function but with different values of eTextRep. ds@1952: ** When multiple implementations of the same function are available, SQLite ds@1952: ** will pick the one that involves the least amount of data conversion. ds@1952: ** If there is only a single implementation which does not care what ds@1952: ** text encoding is used, then the fourth argument should be ds@1952: ** [SQLITE_ANY]. ds@1952: ** ds@1952: ** The fifth parameter is an arbitrary pointer. The implementation ds@1952: ** of the function can gain access to this pointer using ds@1952: ** [sqlite3_user_data()]. ds@1952: ** ds@1952: ** The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are ds@1952: ** pointers to C-language functions that implement the SQL ds@1952: ** function or aggregate. A scalar SQL function requires an implementation of ds@1952: ** the xFunc callback only, NULL pointers should be passed as the xStep ds@1952: ** and xFinal parameters. An aggregate SQL function requires an implementation ds@1952: ** of xStep and xFinal and NULL should be passed for xFunc. To delete an ds@1952: ** existing SQL function or aggregate, pass NULL for all three function ds@1952: ** callback. ds@1952: ** ds@1952: ** It is permitted to register multiple implementations of the same ds@1952: ** functions with the same name but with either differing numbers of ds@1952: ** arguments or differing perferred text encodings. SQLite will use ds@1952: ** the implementation most closely matches the way in which the ds@1952: ** SQL function is used. ds@1952: */ ds@1952: int sqlite3_create_function( ds@1952: sqlite3 *, ds@1952: const char *zFunctionName, ds@1952: int nArg, ds@1952: int eTextRep, ds@1952: void*, ds@1952: void (*xFunc)(sqlite3_context*,int,sqlite3_value**), ds@1952: void (*xStep)(sqlite3_context*,int,sqlite3_value**), ds@1952: void (*xFinal)(sqlite3_context*) ds@1952: ); ds@1952: int sqlite3_create_function16( ds@1952: sqlite3*, ds@1952: const void *zFunctionName, ds@1952: int nArg, ds@1952: int eTextRep, ds@1952: void*, ds@1952: void (*xFunc)(sqlite3_context*,int,sqlite3_value**), ds@1952: void (*xStep)(sqlite3_context*,int,sqlite3_value**), ds@1952: void (*xFinal)(sqlite3_context*) ds@1952: ); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Text Encodings ds@1952: ** ds@1952: ** These constant define integer codes that represent the various ds@1952: ** text encodings supported by SQLite. ds@1952: */ ds@1952: #define SQLITE_UTF8 1 ds@1952: #define SQLITE_UTF16LE 2 ds@1952: #define SQLITE_UTF16BE 3 ds@1952: #define SQLITE_UTF16 4 /* Use native byte order */ ds@1952: #define SQLITE_ANY 5 /* sqlite3_create_function only */ ds@1952: #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */ ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Obsolete Functions ds@1952: ** ds@1952: ** These functions are all now obsolete. In order to maintain ds@1952: ** backwards compatibility with older code, we continue to support ds@1952: ** these functions. However, new development projects should avoid ds@1952: ** the use of these functions. To help encourage people to avoid ds@1952: ** using these functions, we are not going to tell you want they do. ds@1952: */ ds@1952: int sqlite3_aggregate_count(sqlite3_context*); ds@1952: int sqlite3_expired(sqlite3_stmt*); ds@1952: int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*); ds@1952: int sqlite3_global_recover(void); ds@1952: void sqlite3_thread_cleanup(void); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Obtaining SQL Function Parameter Values ds@1952: ** ds@1952: ** The C-language implementation of SQL functions and aggregates uses ds@1952: ** this set of interface routines to access the parameter values on ds@1952: ** the function or aggregate. ds@1952: ** ds@1952: ** The xFunc (for scalar functions) or xStep (for aggregates) parameters ds@1952: ** to [sqlite3_create_function()] and [sqlite3_create_function16()] ds@1952: ** define callbacks that implement the SQL functions and aggregates. ds@1952: ** The 4th parameter to these callbacks is an array of pointers to ds@1952: ** [sqlite3_value] objects. There is one [sqlite3_value] object for ds@1952: ** each parameter to the SQL function. These routines are used to ds@1952: ** extract values from the [sqlite3_value] objects. ds@1952: ** ds@1952: ** These routines work just like the corresponding ds@1952: ** [sqlite3_column_blob | sqlite3_column_* routines] except that ds@1952: ** these routines take a single [sqlite3_value*] pointer instead ds@1952: ** of an [sqlite3_stmt*] pointer and an integer column number. ds@1952: ** ds@1952: ** The sqlite3_value_text16() interface extracts a UTF16 string ds@1952: ** in the native byte-order of the host machine. The ds@1952: ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces ds@1952: ** extract UTF16 strings as big-endian and little-endian respectively. ds@1952: ** ds@1952: ** The sqlite3_value_numeric_type() interface attempts to apply ds@1952: ** numeric affinity to the value. This means that an attempt is ds@1952: ** made to convert the value to an integer or floating point. If ds@1952: ** such a conversion is possible without loss of information (in order ds@1952: ** words if the value is original a string that looks like a number) ds@1952: ** then it is done. Otherwise no conversion occurs. The ds@1952: ** [SQLITE_INTEGER | datatype] after conversion is returned. ds@1952: ** ds@1952: ** Please pay particular attention to the fact that the pointer that ds@1952: ** is returned from [sqlite3_value_blob()], [sqlite3_value_text()], or ds@1952: ** [sqlite3_value_text16()] can be invalidated by a subsequent call to ds@1952: ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()], ds@1952: ** or [sqlite3_value_text16()]. ds@1952: ** ds@1952: ** These routines must be called from the same thread as ds@1952: ** the SQL function that supplied the sqlite3_value* parameters. ds@1952: ** Or, if the sqlite3_value* argument comes from the [sqlite3_column_value()] ds@1952: ** interface, then these routines should be called from the same thread ds@1952: ** that ran [sqlite3_column_value()]. ds@1952: */ ds@1952: const void *sqlite3_value_blob(sqlite3_value*); ds@1952: int sqlite3_value_bytes(sqlite3_value*); ds@1952: int sqlite3_value_bytes16(sqlite3_value*); ds@1952: double sqlite3_value_double(sqlite3_value*); ds@1952: int sqlite3_value_int(sqlite3_value*); ds@1952: sqlite3_int64 sqlite3_value_int64(sqlite3_value*); ds@1952: const unsigned char *sqlite3_value_text(sqlite3_value*); ds@1952: const void *sqlite3_value_text16(sqlite3_value*); ds@1952: const void *sqlite3_value_text16le(sqlite3_value*); ds@1952: const void *sqlite3_value_text16be(sqlite3_value*); ds@1952: int sqlite3_value_type(sqlite3_value*); ds@1952: int sqlite3_value_numeric_type(sqlite3_value*); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Obtain Aggregate Function Context ds@1952: ** ds@1952: ** The implementation of aggregate SQL functions use this routine to allocate ds@1952: ** a structure for storing their state. The first time this routine ds@1952: ** is called for a particular aggregate, a new structure of size nBytes ds@1952: ** is allocated, zeroed, and returned. On subsequent calls (for the ds@1952: ** same aggregate instance) the same buffer is returned. The implementation ds@1952: ** of the aggregate can use the returned buffer to accumulate data. ds@1952: ** ds@1952: ** The buffer allocated is freed automatically by SQLite whan the aggregate ds@1952: ** query concludes. ds@1952: ** ds@1952: ** The first parameter should be a copy of the ds@1952: ** [sqlite3_context | SQL function context] that is the first ds@1952: ** parameter to the callback routine that implements the aggregate ds@1952: ** function. ds@1952: ** ds@1952: ** This routine must be called from the same thread in which ds@1952: ** the aggregate SQL function is running. ds@1952: */ ds@1952: void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: User Data For Functions ds@1952: ** ds@1952: ** The pUserData parameter to the [sqlite3_create_function()] ds@1952: ** and [sqlite3_create_function16()] routines ds@1952: ** used to register user functions is available to ds@1952: ** the implementation of the function using this call. ds@1952: ** ds@1952: ** This routine must be called from the same thread in which ds@1952: ** the SQL function is running. ds@1952: */ ds@1952: void *sqlite3_user_data(sqlite3_context*); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Function Auxiliary Data ds@1952: ** ds@1952: ** The following two functions may be used by scalar SQL functions to ds@1952: ** associate meta-data with argument values. If the same value is passed to ds@1952: ** multiple invocations of the same SQL function during query execution, under ds@1952: ** some circumstances the associated meta-data may be preserved. This may ds@1952: ** be used, for example, to add a regular-expression matching scalar ds@1952: ** function. The compiled version of the regular expression is stored as ds@1952: ** meta-data associated with the SQL value passed as the regular expression ds@1952: ** pattern. The compiled regular expression can be reused on multiple ds@1952: ** invocations of the same function so that the original pattern string ds@1952: ** does not need to be recompiled on each invocation. ds@1952: ** ds@1952: ** The sqlite3_get_auxdata() interface returns a pointer to the meta-data ds@1952: ** associated with the Nth argument value to the current SQL function ds@1952: ** call, where N is the second parameter. If no meta-data has been set for ds@1952: ** that value, then a NULL pointer is returned. ds@1952: ** ds@1952: ** The sqlite3_set_auxdata() is used to associate meta-data with an SQL ds@1952: ** function argument. The third parameter is a pointer to the meta-data ds@1952: ** to be associated with the Nth user function argument value. The fourth ds@1952: ** parameter specifies a destructor that will be called on the meta- ds@1952: ** data pointer to release it when it is no longer required. If the ds@1952: ** destructor is NULL, it is not invoked. ds@1952: ** ds@1952: ** In practice, meta-data is preserved between function calls for ds@1952: ** expressions that are constant at compile time. This includes literal ds@1952: ** values and SQL variables. ds@1952: ** ds@1952: ** These routines must be called from the same thread in which ds@1952: ** the SQL function is running. ds@1952: */ ds@1952: void *sqlite3_get_auxdata(sqlite3_context*, int); ds@1952: void sqlite3_set_auxdata(sqlite3_context*, int, void*, void (*)(void*)); ds@1952: ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Constants Defining Special Destructor Behavior ds@1952: ** ds@1952: ** These are special value for the destructor that is passed in as the ds@1952: ** final argument to routines like [sqlite3_result_blob()]. If the destructor ds@1952: ** argument is SQLITE_STATIC, it means that the content pointer is constant ds@1952: ** and will never change. It does not need to be destroyed. The ds@1952: ** SQLITE_TRANSIENT value means that the content will likely change in ds@1952: ** the near future and that SQLite should make its own private copy of ds@1952: ** the content before returning. ds@1952: ** ds@1952: ** The typedef is necessary to work around problems in certain ds@1952: ** C++ compilers. See ticket #2191. ds@1952: */ ds@1952: typedef void (*sqlite3_destructor_type)(void*); ds@1952: #define SQLITE_STATIC ((sqlite3_destructor_type)0) ds@1952: #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Setting The Result Of An SQL Function ds@1952: ** ds@1952: ** These routines are used by the xFunc or xFinal callbacks that ds@1952: ** implement SQL functions and aggregates. See ds@1952: ** [sqlite3_create_function()] and [sqlite3_create_function16()] ds@1952: ** for additional information. ds@1952: ** ds@1952: ** These functions work very much like the ds@1952: ** [sqlite3_bind_blob | sqlite3_bind_*] family of functions used ds@1952: ** to bind values to host parameters in prepared statements. ds@1952: ** Refer to the ds@1952: ** [sqlite3_bind_blob | sqlite3_bind_* documentation] for ds@1952: ** additional information. ds@1952: ** ds@1952: ** The sqlite3_result_error() and sqlite3_result_error16() functions ds@1952: ** cause the implemented SQL function to throw an exception. The ds@1952: ** parameter to sqlite3_result_error() or sqlite3_result_error16() ds@1952: ** is the text of an error message. ds@1952: ** ds@1952: ** The sqlite3_result_toobig() cause the function implementation ds@1952: ** to throw and error indicating that a string or BLOB is to long ds@1952: ** to represent. ds@1952: ** ds@1952: ** These routines must be called from within the same thread as ds@1952: ** the SQL function associated with the [sqlite3_context] pointer. ds@1952: */ ds@1952: void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*)); ds@1952: void sqlite3_result_double(sqlite3_context*, double); ds@1952: void sqlite3_result_error(sqlite3_context*, const char*, int); ds@1952: void sqlite3_result_error16(sqlite3_context*, const void*, int); ds@1952: void sqlite3_result_error_toobig(sqlite3_context*); ds@1952: void sqlite3_result_error_nomem(sqlite3_context*); ds@1952: void sqlite3_result_int(sqlite3_context*, int); ds@1952: void sqlite3_result_int64(sqlite3_context*, sqlite3_int64); ds@1952: void sqlite3_result_null(sqlite3_context*); ds@1952: void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*)); ds@1952: void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*)); ds@1952: void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*)); ds@1952: void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*)); ds@1952: void sqlite3_result_value(sqlite3_context*, sqlite3_value*); ds@1952: void sqlite3_result_zeroblob(sqlite3_context*, int n); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Define New Collating Sequences ds@1952: ** ds@1952: ** These functions are used to add new collation sequences to the ds@1952: ** [sqlite3*] handle specified as the first argument. ds@1952: ** ds@1952: ** The name of the new collation sequence is specified as a UTF-8 string ds@1952: ** for sqlite3_create_collation() and sqlite3_create_collation_v2() ds@1952: ** and a UTF-16 string for sqlite3_create_collation16(). In all cases ds@1952: ** the name is passed as the second function argument. ds@1952: ** ds@1952: ** The third argument must be one of the constants [SQLITE_UTF8], ds@1952: ** [SQLITE_UTF16LE] or [SQLITE_UTF16BE], indicating that the user-supplied ds@1952: ** routine expects to be passed pointers to strings encoded using UTF-8, ds@1952: ** UTF-16 little-endian or UTF-16 big-endian respectively. ds@1952: ** ds@1952: ** A pointer to the user supplied routine must be passed as the fifth ds@1952: ** argument. If it is NULL, this is the same as deleting the collation ds@1952: ** sequence (so that SQLite cannot call it anymore). Each time the user ds@1952: ** supplied function is invoked, it is passed a copy of the void* passed as ds@1952: ** the fourth argument to sqlite3_create_collation() or ds@1952: ** sqlite3_create_collation16() as its first parameter. ds@1952: ** ds@1952: ** The remaining arguments to the user-supplied routine are two strings, ds@1952: ** each represented by a [length, data] pair and encoded in the encoding ds@1952: ** that was passed as the third argument when the collation sequence was ds@1952: ** registered. The user routine should return negative, zero or positive if ds@1952: ** the first string is less than, equal to, or greater than the second ds@1952: ** string. i.e. (STRING1 - STRING2). ds@1952: ** ds@1952: ** The sqlite3_create_collation_v2() works like sqlite3_create_collation() ds@1952: ** excapt that it takes an extra argument which is a destructor for ds@1952: ** the collation. The destructor is called when the collation is ds@1952: ** destroyed and is passed a copy of the fourth parameter void* pointer ds@1952: ** of the sqlite3_create_collation_v2(). Collations are destroyed when ds@1952: ** they are overridden by later calls to the collation creation functions ds@1952: ** or when the [sqlite3*] database handle is closed using [sqlite3_close()]. ds@1952: ** ds@1952: ** The sqlite3_create_collation_v2() interface is experimental and ds@1952: ** subject to change in future releases. The other collation creation ds@1952: ** functions are stable. ds@1952: */ ds@1952: int sqlite3_create_collation( ds@1952: sqlite3*, ds@1952: const char *zName, ds@1952: int eTextRep, ds@1952: void*, ds@1952: int(*xCompare)(void*,int,const void*,int,const void*) ds@1952: ); ds@1952: int sqlite3_create_collation_v2( ds@1952: sqlite3*, ds@1952: const char *zName, ds@1952: int eTextRep, ds@1952: void*, ds@1952: int(*xCompare)(void*,int,const void*,int,const void*), ds@1952: void(*xDestroy)(void*) ds@1952: ); ds@1952: int sqlite3_create_collation16( ds@1952: sqlite3*, ds@1952: const char *zName, ds@1952: int eTextRep, ds@1952: void*, ds@1952: int(*xCompare)(void*,int,const void*,int,const void*) ds@1952: ); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Collation Needed Callbacks ds@1952: ** ds@1952: ** To avoid having to register all collation sequences before a database ds@1952: ** can be used, a single callback function may be registered with the ds@1952: ** database handle to be called whenever an undefined collation sequence is ds@1952: ** required. ds@1952: ** ds@1952: ** If the function is registered using the sqlite3_collation_needed() API, ds@1952: ** then it is passed the names of undefined collation sequences as strings ds@1952: ** encoded in UTF-8. If sqlite3_collation_needed16() is used, the names ds@1952: ** are passed as UTF-16 in machine native byte order. A call to either ds@1952: ** function replaces any existing callback. ds@1952: ** ds@1952: ** When the callback is invoked, the first argument passed is a copy ds@1952: ** of the second argument to sqlite3_collation_needed() or ds@1952: ** sqlite3_collation_needed16(). The second argument is the database ds@1952: ** handle. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE], or ds@1952: ** [SQLITE_UTF16LE], indicating the most desirable form of the collation ds@1952: ** sequence function required. The fourth parameter is the name of the ds@1952: ** required collation sequence. ds@1952: ** ds@1952: ** The callback function should register the desired collation using ds@1952: ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or ds@1952: ** [sqlite3_create_collation_v2()]. ds@1952: */ ds@1952: int sqlite3_collation_needed( ds@1952: sqlite3*, ds@1952: void*, ds@1952: void(*)(void*,sqlite3*,int eTextRep,const char*) ds@1952: ); ds@1952: int sqlite3_collation_needed16( ds@1952: sqlite3*, ds@1952: void*, ds@1952: void(*)(void*,sqlite3*,int eTextRep,const void*) ds@1952: ); ds@1952: ds@1952: /* ds@1952: ** Specify the key for an encrypted database. This routine should be ds@1952: ** called right after sqlite3_open(). ds@1952: ** ds@1952: ** The code to implement this API is not available in the public release ds@1952: ** of SQLite. ds@1952: */ ds@1952: int sqlite3_key( ds@1952: sqlite3 *db, /* Database to be rekeyed */ ds@1952: const void *pKey, int nKey /* The key */ ds@1952: ); ds@1952: ds@1952: /* ds@1952: ** Change the key on an open database. If the current database is not ds@1952: ** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the ds@1952: ** database is decrypted. ds@1952: ** ds@1952: ** The code to implement this API is not available in the public release ds@1952: ** of SQLite. ds@1952: */ ds@1952: int sqlite3_rekey( ds@1952: sqlite3 *db, /* Database to be rekeyed */ ds@1952: const void *pKey, int nKey /* The new key */ ds@1952: ); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Suspend Execution For A Short Time ds@1952: ** ds@1952: ** This function causes the current thread to suspend execution ds@1952: ** a number of milliseconds specified in its parameter. ds@1952: ** ds@1952: ** If the operating system does not support sleep requests with ds@1952: ** millisecond time resolution, then the time will be rounded up to ds@1952: ** the nearest second. The number of milliseconds of sleep actually ds@1952: ** requested from the operating system is returned. ds@1952: ** ds@1952: ** SQLite implements this interface by calling the xSleep() ds@1952: ** method of the default [sqlite3_vfs] object. ds@1952: */ ds@1952: int sqlite3_sleep(int); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Name Of The Folder Holding Temporary Files ds@1952: ** ds@1952: ** If this global variable is made to point to a string which is ds@1952: ** the name of a folder (a.ka. directory), then all temporary files ds@1952: ** created by SQLite will be placed in that directory. If this variable ds@1952: ** is NULL pointer, then SQLite does a search for an appropriate temporary ds@1952: ** file directory. ds@1952: ** ds@1952: ** It is not safe to modify this variable once a database connection ds@1952: ** has been opened. It is intended that this variable be set once ds@1952: ** as part of process initialization and before any SQLite interface ds@1952: ** routines have been call and remain unchanged thereafter. ds@1952: */ ds@1952: SQLITE_EXTERN char *sqlite3_temp_directory; ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Test To See If The Database Is In Auto-Commit Mode ds@1952: ** ds@1952: ** Test to see whether or not the database connection is in autocommit ds@1952: ** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on ds@1952: ** by default. Autocommit is disabled by a BEGIN statement and reenabled ds@1952: ** by the next COMMIT or ROLLBACK. ds@1952: ** ds@1952: ** If certain kinds of errors occur on a statement within a multi-statement ds@1952: ** transactions (errors including [SQLITE_FULL], [SQLITE_IOERR], ds@1952: ** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the ds@1952: ** transaction might be rolled back automatically. The only way to ds@1952: ** find out if SQLite automatically rolled back the transaction after ds@1952: ** an error is to use this function. ds@1952: ** ds@1952: ** If another thread changes the autocommit status of the database ds@1952: ** connection while this routine is running, then the return value ds@1952: ** is undefined. ds@1952: */ ds@1952: int sqlite3_get_autocommit(sqlite3*); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Find The Database Handle Associated With A Prepared Statement ds@1952: ** ds@1952: ** Return the [sqlite3*] database handle to which a ds@1952: ** [sqlite3_stmt | prepared statement] belongs. ds@1952: ** This is the same database handle that was ds@1952: ** the first argument to the [sqlite3_prepare_v2()] or its variants ds@1952: ** that was used to create the statement in the first place. ds@1952: */ ds@1952: sqlite3 *sqlite3_db_handle(sqlite3_stmt*); ds@1952: ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Commit And Rollback Notification Callbacks ds@1952: ** ds@1952: ** These routines ds@1952: ** register callback functions to be invoked whenever a transaction ds@1952: ** is committed or rolled back. The pArg argument is passed through ds@1952: ** to the callback. If the callback on a commit hook function ds@1952: ** returns non-zero, then the commit is converted into a rollback. ds@1952: ** ds@1952: ** If another function was previously registered, its pArg value is returned. ds@1952: ** Otherwise NULL is returned. ds@1952: ** ds@1952: ** Registering a NULL function disables the callback. ds@1952: ** ds@1952: ** For the purposes of this API, a transaction is said to have been ds@1952: ** rolled back if an explicit "ROLLBACK" statement is executed, or ds@1952: ** an error or constraint causes an implicit rollback to occur. The ds@1952: ** callback is not invoked if a transaction is automatically rolled ds@1952: ** back because the database connection is closed. ds@1952: ** ds@1952: ** These are experimental interfaces and are subject to change. ds@1952: */ ds@1952: void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); ds@1952: void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Data Change Notification Callbacks ds@1952: ** ds@1952: ** Register a callback function with the database connection identified by the ds@1952: ** first argument to be invoked whenever a row is updated, inserted or deleted. ds@1952: ** Any callback set by a previous call to this function for the same ds@1952: ** database connection is overridden. ds@1952: ** ds@1952: ** The second argument is a pointer to the function to invoke when a ds@1952: ** row is updated, inserted or deleted. The first argument to the callback is ds@1952: ** a copy of the third argument to sqlite3_update_hook(). The second callback ds@1952: ** argument is one of SQLITE_INSERT, SQLITE_DELETE or SQLITE_UPDATE, depending ds@1952: ** on the operation that caused the callback to be invoked. The third and ds@1952: ** fourth arguments to the callback contain pointers to the database and ds@1952: ** table name containing the affected row. The final callback parameter is ds@1952: ** the rowid of the row. In the case of an update, this is the rowid after ds@1952: ** the update takes place. ds@1952: ** ds@1952: ** The update hook is not invoked when internal system tables are ds@1952: ** modified (i.e. sqlite_master and sqlite_sequence). ds@1952: ** ds@1952: ** If another function was previously registered, its pArg value is returned. ds@1952: ** Otherwise NULL is returned. ds@1952: */ ds@1952: void *sqlite3_update_hook( ds@1952: sqlite3*, ds@1952: void(*)(void *,int ,char const *,char const *,sqlite3_int64), ds@1952: void* ds@1952: ); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Enable Or Disable Shared Pager Cache ds@1952: ** ds@1952: ** This routine enables or disables the sharing of the database cache ds@1952: ** and schema data structures between connections to the same database. ds@1952: ** Sharing is enabled if the argument is true and disabled if the argument ds@1952: ** is false. ds@1952: ** ds@1952: ** Beginning in SQLite version 3.5.0, cache sharing is enabled and disabled ds@1952: ** for an entire process. In prior versions of SQLite, sharing was ds@1952: ** enabled or disabled for each thread separately. ds@1952: ** ds@1952: ** The cache sharing mode set by this interface effects all subsequent ds@1952: ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()]. ds@1952: ** Existing database connections continue use the sharing mode that was ds@1952: ** in effect at the time they were opened. ds@1952: ** ds@1952: ** Virtual tables cannot be used with a shared cache. When shared ds@1952: ** cache is enabled, the [sqlite3_create_module()] API used to register ds@1952: ** virtual tables will always return an error. ds@1952: ** ds@1952: ** This routine returns [SQLITE_OK] if shared cache was ds@1952: ** enabled or disabled successfully. An [SQLITE_ERROR | error code] ds@1952: ** is returned otherwise. ds@1952: ** ds@1952: ** Shared cache is disabled by default. But this might change in ds@1952: ** future releases of SQLite. Applications that care about shared ds@1952: ** cache setting should set it explicitly. ds@1952: */ ds@1952: int sqlite3_enable_shared_cache(int); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Attempt To Free Heap Memory ds@1952: ** ds@1952: ** Attempt to free N bytes of heap memory by deallocating non-essential ds@1952: ** memory allocations held by the database library (example: memory ds@1952: ** used to cache database pages to improve performance). ds@1952: */ ds@1952: int sqlite3_release_memory(int); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Impose A Limit On Heap Size ds@1952: ** ds@1952: ** Place a "soft" limit on the amount of heap memory that may be allocated ds@1952: ** by SQLite. If an internal allocation is requested ds@1952: ** that would exceed the specified limit, [sqlite3_release_memory()] is ds@1952: ** invoked one or more times to free up some space before the allocation ds@1952: ** is made. ds@1952: ** ds@1952: ** The limit is called "soft", because if [sqlite3_release_memory()] cannot ds@1952: ** free sufficient memory to prevent the limit from being exceeded, ds@1952: ** the memory is allocated anyway and the current operation proceeds. ds@1952: ** ds@1952: ** A negative or zero value for N means that there is no soft heap limit and ds@1952: ** [sqlite3_release_memory()] will only be called when memory is exhausted. ds@1952: ** The default value for the soft heap limit is zero. ds@1952: ** ds@1952: ** SQLite makes a best effort to honor the soft heap limit. But if it ds@1952: ** is unable to reduce memory usage below the soft limit, execution will ds@1952: ** continue without error or notification. This is why the limit is ds@1952: ** called a "soft" limit. It is advisory only. ds@1952: ** ds@1952: ** The soft heap limit is implemented using the [sqlite3_memory_alarm()] ds@1952: ** interface. Only a single memory alarm is available in the default ds@1952: ** implementation. This means that if the application also uses the ds@1952: ** memory alarm interface it will interfere with the operation of the ds@1952: ** soft heap limit and undefined behavior will result. ds@1952: ** ds@1952: ** Prior to SQLite version 3.5.0, this routine only constrained the memory ds@1952: ** allocated by a single thread - the same thread in which this routine ds@1952: ** runs. Beginning with SQLite version 3.5.0, the soft heap limit is ds@1952: ** applied to all threads. The value specified for the soft heap limit ds@1952: ** is an upper bound on the total memory allocation for all threads. In ds@1952: ** version 3.5.0 there is no mechanism for limiting the heap usage for ds@1952: ** individual threads. ds@1952: */ ds@1952: void sqlite3_soft_heap_limit(int); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Extract Metadata About A Column Of A Table ds@1952: ** ds@1952: ** This routine ds@1952: ** returns meta-data about a specific column of a specific database ds@1952: ** table accessible using the connection handle passed as the first function ds@1952: ** argument. ds@1952: ** ds@1952: ** The column is identified by the second, third and fourth parameters to ds@1952: ** this function. The second parameter is either the name of the database ds@1952: ** (i.e. "main", "temp" or an attached database) containing the specified ds@1952: ** table or NULL. If it is NULL, then all attached databases are searched ds@1952: ** for the table using the same algorithm as the database engine uses to ds@1952: ** resolve unqualified table references. ds@1952: ** ds@1952: ** The third and fourth parameters to this function are the table and column ds@1952: ** name of the desired column, respectively. Neither of these parameters ds@1952: ** may be NULL. ds@1952: ** ds@1952: ** Meta information is returned by writing to the memory locations passed as ds@1952: ** the 5th and subsequent parameters to this function. Any of these ds@1952: ** arguments may be NULL, in which case the corresponding element of meta ds@1952: ** information is ommitted. ds@1952: ** ds@1952: **
ds@1952: ** Parameter     Output Type      Description
ds@1952: ** -----------------------------------
ds@1952: **
ds@1952: **   5th         const char*      Data type
ds@1952: **   6th         const char*      Name of the default collation sequence 
ds@1952: **   7th         int              True if the column has a NOT NULL constraint
ds@1952: **   8th         int              True if the column is part of the PRIMARY KEY
ds@1952: **   9th         int              True if the column is AUTOINCREMENT
ds@1952: ** 
ds@1952: ** ds@1952: ** ds@1952: ** The memory pointed to by the character pointers returned for the ds@1952: ** declaration type and collation sequence is valid only until the next ds@1952: ** call to any sqlite API function. ds@1952: ** ds@1952: ** If the specified table is actually a view, then an error is returned. ds@1952: ** ds@1952: ** If the specified column is "rowid", "oid" or "_rowid_" and an ds@1952: ** INTEGER PRIMARY KEY column has been explicitly declared, then the output ds@1952: ** parameters are set for the explicitly declared column. If there is no ds@1952: ** explicitly declared IPK column, then the output parameters are set as ds@1952: ** follows: ds@1952: ** ds@1952: **
ds@1952: **     data type: "INTEGER"
ds@1952: **     collation sequence: "BINARY"
ds@1952: **     not null: 0
ds@1952: **     primary key: 1
ds@1952: **     auto increment: 0
ds@1952: ** 
ds@1952: ** ds@1952: ** This function may load one or more schemas from database files. If an ds@1952: ** error occurs during this process, or if the requested table or column ds@1952: ** cannot be found, an SQLITE error code is returned and an error message ds@1952: ** left in the database handle (to be retrieved using sqlite3_errmsg()). ds@1952: ** ds@1952: ** This API is only available if the library was compiled with the ds@1952: ** SQLITE_ENABLE_COLUMN_METADATA preprocessor symbol defined. ds@1952: */ ds@1952: int sqlite3_table_column_metadata( ds@1952: sqlite3 *db, /* Connection handle */ ds@1952: const char *zDbName, /* Database name or NULL */ ds@1952: const char *zTableName, /* Table name */ ds@1952: const char *zColumnName, /* Column name */ ds@1952: char const **pzDataType, /* OUTPUT: Declared data type */ ds@1952: char const **pzCollSeq, /* OUTPUT: Collation sequence name */ ds@1952: int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */ ds@1952: int *pPrimaryKey, /* OUTPUT: True if column part of PK */ ds@1952: int *pAutoinc /* OUTPUT: True if column is auto-increment */ ds@1952: ); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Load An Extension ds@1952: ** ds@1952: ** Attempt to load an SQLite extension library contained in the file ds@1952: ** zFile. The entry point is zProc. zProc may be 0 in which case the ds@1952: ** name of the entry point defaults to "sqlite3_extension_init". ds@1952: ** ds@1952: ** Return [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong. ds@1952: ** ds@1952: ** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with ds@1952: ** error message text. The calling function should free this memory ds@1952: ** by calling [sqlite3_free()]. ds@1952: ** ds@1952: ** Extension loading must be enabled using [sqlite3_enable_load_extension()] ds@1952: ** prior to calling this API or an error will be returned. ds@1952: */ ds@1952: int sqlite3_load_extension( ds@1952: sqlite3 *db, /* Load the extension into this database connection */ ds@1952: const char *zFile, /* Name of the shared library containing extension */ ds@1952: const char *zProc, /* Entry point. Derived from zFile if 0 */ ds@1952: char **pzErrMsg /* Put error message here if not 0 */ ds@1952: ); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Enable Or Disable Extension Loading ds@1952: ** ds@1952: ** So as not to open security holes in older applications that are ds@1952: ** unprepared to deal with extension loading, and as a means of disabling ds@1952: ** extension loading while evaluating user-entered SQL, the following ds@1952: ** API is provided to turn the [sqlite3_load_extension()] mechanism on and ds@1952: ** off. It is off by default. See ticket #1863. ds@1952: ** ds@1952: ** Call this routine with onoff==1 to turn extension loading on ds@1952: ** and call it with onoff==0 to turn it back off again. ds@1952: */ ds@1952: int sqlite3_enable_load_extension(sqlite3 *db, int onoff); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Make Arrangements To Automatically Load An Extension ds@1952: ** ds@1952: ** Register an extension entry point that is automatically invoked ds@1952: ** whenever a new database connection is opened using ds@1952: ** [sqlite3_open()], [sqlite3_open16()], or [sqlite3_open_v2()]. ds@1952: ** ds@1952: ** This API can be invoked at program startup in order to register ds@1952: ** one or more statically linked extensions that will be available ds@1952: ** to all new database connections. ds@1952: ** ds@1952: ** Duplicate extensions are detected so calling this routine multiple ds@1952: ** times with the same extension is harmless. ds@1952: ** ds@1952: ** This routine stores a pointer to the extension in an array ds@1952: ** that is obtained from malloc(). If you run a memory leak ds@1952: ** checker on your program and it reports a leak because of this ds@1952: ** array, then invoke [sqlite3_automatic_extension_reset()] prior ds@1952: ** to shutdown to free the memory. ds@1952: ** ds@1952: ** Automatic extensions apply across all threads. ds@1952: ** ds@1952: ** This interface is experimental and is subject to change or ds@1952: ** removal in future releases of SQLite. ds@1952: */ ds@1952: int sqlite3_auto_extension(void *xEntryPoint); ds@1952: ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Reset Automatic Extension Loading ds@1952: ** ds@1952: ** Disable all previously registered automatic extensions. This ds@1952: ** routine undoes the effect of all prior [sqlite3_automatic_extension()] ds@1952: ** calls. ds@1952: ** ds@1952: ** This call disabled automatic extensions in all threads. ds@1952: ** ds@1952: ** This interface is experimental and is subject to change or ds@1952: ** removal in future releases of SQLite. ds@1952: */ ds@1952: void sqlite3_reset_auto_extension(void); ds@1952: ds@1952: ds@1952: /* ds@1952: ****** EXPERIMENTAL - subject to change without notice ************** ds@1952: ** ds@1952: ** The interface to the virtual-table mechanism is currently considered ds@1952: ** to be experimental. The interface might change in incompatible ways. ds@1952: ** If this is a problem for you, do not use the interface at this time. ds@1952: ** ds@1952: ** When the virtual-table mechanism stablizes, we will declare the ds@1952: ** interface fixed, support it indefinitely, and remove this comment. ds@1952: */ ds@1952: ds@1952: /* ds@1952: ** Structures used by the virtual table interface ds@1952: */ ds@1952: typedef struct sqlite3_vtab sqlite3_vtab; ds@1952: typedef struct sqlite3_index_info sqlite3_index_info; ds@1952: typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor; ds@1952: typedef struct sqlite3_module sqlite3_module; ds@1952: ds@1952: /* ds@1952: ** A module is a class of virtual tables. Each module is defined ds@1952: ** by an instance of the following structure. This structure consists ds@1952: ** mostly of methods for the module. ds@1952: */ ds@1952: struct sqlite3_module { ds@1952: int iVersion; ds@1952: int (*xCreate)(sqlite3*, void *pAux, ds@1952: int argc, const char *const*argv, ds@1952: sqlite3_vtab **ppVTab, char**); ds@1952: int (*xConnect)(sqlite3*, void *pAux, ds@1952: int argc, const char *const*argv, ds@1952: sqlite3_vtab **ppVTab, char**); ds@1952: int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*); ds@1952: int (*xDisconnect)(sqlite3_vtab *pVTab); ds@1952: int (*xDestroy)(sqlite3_vtab *pVTab); ds@1952: int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor); ds@1952: int (*xClose)(sqlite3_vtab_cursor*); ds@1952: int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr, ds@1952: int argc, sqlite3_value **argv); ds@1952: int (*xNext)(sqlite3_vtab_cursor*); ds@1952: int (*xEof)(sqlite3_vtab_cursor*); ds@1952: int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int); ds@1952: int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid); ds@1952: int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *); ds@1952: int (*xBegin)(sqlite3_vtab *pVTab); ds@1952: int (*xSync)(sqlite3_vtab *pVTab); ds@1952: int (*xCommit)(sqlite3_vtab *pVTab); ds@1952: int (*xRollback)(sqlite3_vtab *pVTab); ds@1952: int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName, ds@1952: void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), ds@1952: void **ppArg); ds@1952: ds@1952: int (*xRename)(sqlite3_vtab *pVtab, const char *zNew); ds@1952: }; ds@1952: ds@1952: /* ds@1952: ** The sqlite3_index_info structure and its substructures is used to ds@1952: ** pass information into and receive the reply from the xBestIndex ds@1952: ** method of an sqlite3_module. The fields under **Inputs** are the ds@1952: ** inputs to xBestIndex and are read-only. xBestIndex inserts its ds@1952: ** results into the **Outputs** fields. ds@1952: ** ds@1952: ** The aConstraint[] array records WHERE clause constraints of the ds@1952: ** form: ds@1952: ** ds@1952: ** column OP expr ds@1952: ** ds@1952: ** Where OP is =, <, <=, >, or >=. The particular operator is stored ds@1952: ** in aConstraint[].op. The index of the column is stored in ds@1952: ** aConstraint[].iColumn. aConstraint[].usable is TRUE if the ds@1952: ** expr on the right-hand side can be evaluated (and thus the constraint ds@1952: ** is usable) and false if it cannot. ds@1952: ** ds@1952: ** The optimizer automatically inverts terms of the form "expr OP column" ds@1952: ** and makes other simplifications to the WHERE clause in an attempt to ds@1952: ** get as many WHERE clause terms into the form shown above as possible. ds@1952: ** The aConstraint[] array only reports WHERE clause terms in the correct ds@1952: ** form that refer to the particular virtual table being queried. ds@1952: ** ds@1952: ** Information about the ORDER BY clause is stored in aOrderBy[]. ds@1952: ** Each term of aOrderBy records a column of the ORDER BY clause. ds@1952: ** ds@1952: ** The xBestIndex method must fill aConstraintUsage[] with information ds@1952: ** about what parameters to pass to xFilter. If argvIndex>0 then ds@1952: ** the right-hand side of the corresponding aConstraint[] is evaluated ds@1952: ** and becomes the argvIndex-th entry in argv. If aConstraintUsage[].omit ds@1952: ** is true, then the constraint is assumed to be fully handled by the ds@1952: ** virtual table and is not checked again by SQLite. ds@1952: ** ds@1952: ** The idxNum and idxPtr values are recorded and passed into xFilter. ds@1952: ** sqlite3_free() is used to free idxPtr if needToFreeIdxPtr is true. ds@1952: ** ds@1952: ** The orderByConsumed means that output from xFilter will occur in ds@1952: ** the correct order to satisfy the ORDER BY clause so that no separate ds@1952: ** sorting step is required. ds@1952: ** ds@1952: ** The estimatedCost value is an estimate of the cost of doing the ds@1952: ** particular lookup. A full scan of a table with N entries should have ds@1952: ** a cost of N. A binary search of a table of N entries should have a ds@1952: ** cost of approximately log(N). ds@1952: */ ds@1952: struct sqlite3_index_info { ds@1952: /* Inputs */ ds@1952: int nConstraint; /* Number of entries in aConstraint */ ds@1952: struct sqlite3_index_constraint { ds@1952: int iColumn; /* Column on left-hand side of constraint */ ds@1952: unsigned char op; /* Constraint operator */ ds@1952: unsigned char usable; /* True if this constraint is usable */ ds@1952: int iTermOffset; /* Used internally - xBestIndex should ignore */ ds@1952: } *aConstraint; /* Table of WHERE clause constraints */ ds@1952: int nOrderBy; /* Number of terms in the ORDER BY clause */ ds@1952: struct sqlite3_index_orderby { ds@1952: int iColumn; /* Column number */ ds@1952: unsigned char desc; /* True for DESC. False for ASC. */ ds@1952: } *aOrderBy; /* The ORDER BY clause */ ds@1952: ds@1952: /* Outputs */ ds@1952: struct sqlite3_index_constraint_usage { ds@1952: int argvIndex; /* if >0, constraint is part of argv to xFilter */ ds@1952: unsigned char omit; /* Do not code a test for this constraint */ ds@1952: } *aConstraintUsage; ds@1952: int idxNum; /* Number used to identify the index */ ds@1952: char *idxStr; /* String, possibly obtained from sqlite3_malloc */ ds@1952: int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */ ds@1952: int orderByConsumed; /* True if output is already ordered */ ds@1952: double estimatedCost; /* Estimated cost of using this index */ ds@1952: }; ds@1952: #define SQLITE_INDEX_CONSTRAINT_EQ 2 ds@1952: #define SQLITE_INDEX_CONSTRAINT_GT 4 ds@1952: #define SQLITE_INDEX_CONSTRAINT_LE 8 ds@1952: #define SQLITE_INDEX_CONSTRAINT_LT 16 ds@1952: #define SQLITE_INDEX_CONSTRAINT_GE 32 ds@1952: #define SQLITE_INDEX_CONSTRAINT_MATCH 64 ds@1952: ds@1952: /* ds@1952: ** This routine is used to register a new module name with an SQLite ds@1952: ** connection. Module names must be registered before creating new ds@1952: ** virtual tables on the module, or before using preexisting virtual ds@1952: ** tables of the module. ds@1952: */ ds@1952: int sqlite3_create_module( ds@1952: sqlite3 *db, /* SQLite connection to register module with */ ds@1952: const char *zName, /* Name of the module */ ds@1952: const sqlite3_module *, /* Methods for the module */ ds@1952: void * /* Client data for xCreate/xConnect */ ds@1952: ); ds@1952: ds@1952: /* ds@1952: ** This routine is identical to the sqlite3_create_module() method above, ds@1952: ** except that it allows a destructor function to be specified. It is ds@1952: ** even more experimental than the rest of the virtual tables API. ds@1952: */ ds@1952: int sqlite3_create_module_v2( ds@1952: sqlite3 *db, /* SQLite connection to register module with */ ds@1952: const char *zName, /* Name of the module */ ds@1952: const sqlite3_module *, /* Methods for the module */ ds@1952: void *, /* Client data for xCreate/xConnect */ ds@1952: void(*xDestroy)(void*) /* Module destructor function */ ds@1952: ); ds@1952: ds@1952: /* ds@1952: ** Every module implementation uses a subclass of the following structure ds@1952: ** to describe a particular instance of the module. Each subclass will ds@1952: ** be tailored to the specific needs of the module implementation. The ds@1952: ** purpose of this superclass is to define certain fields that are common ds@1952: ** to all module implementations. ds@1952: ** ds@1952: ** Virtual tables methods can set an error message by assigning a ds@1952: ** string obtained from sqlite3_mprintf() to zErrMsg. The method should ds@1952: ** take care that any prior string is freed by a call to sqlite3_free() ds@1952: ** prior to assigning a new string to zErrMsg. After the error message ds@1952: ** is delivered up to the client application, the string will be automatically ds@1952: ** freed by sqlite3_free() and the zErrMsg field will be zeroed. Note ds@1952: ** that sqlite3_mprintf() and sqlite3_free() are used on the zErrMsg field ds@1952: ** since virtual tables are commonly implemented in loadable extensions which ds@1952: ** do not have access to sqlite3MPrintf() or sqlite3Free(). ds@1952: */ ds@1952: struct sqlite3_vtab { ds@1952: const sqlite3_module *pModule; /* The module for this virtual table */ ds@1952: int nRef; /* Used internally */ ds@1952: char *zErrMsg; /* Error message from sqlite3_mprintf() */ ds@1952: /* Virtual table implementations will typically add additional fields */ ds@1952: }; ds@1952: ds@1952: /* Every module implementation uses a subclass of the following structure ds@1952: ** to describe cursors that point into the virtual table and are used ds@1952: ** to loop through the virtual table. Cursors are created using the ds@1952: ** xOpen method of the module. Each module implementation will define ds@1952: ** the content of a cursor structure to suit its own needs. ds@1952: ** ds@1952: ** This superclass exists in order to define fields of the cursor that ds@1952: ** are common to all implementations. ds@1952: */ ds@1952: struct sqlite3_vtab_cursor { ds@1952: sqlite3_vtab *pVtab; /* Virtual table of this cursor */ ds@1952: /* Virtual table implementations will typically add additional fields */ ds@1952: }; ds@1952: ds@1952: /* ds@1952: ** The xCreate and xConnect methods of a module use the following API ds@1952: ** to declare the format (the names and datatypes of the columns) of ds@1952: ** the virtual tables they implement. ds@1952: */ ds@1952: int sqlite3_declare_vtab(sqlite3*, const char *zCreateTable); ds@1952: ds@1952: /* ds@1952: ** Virtual tables can provide alternative implementations of functions ds@1952: ** using the xFindFunction method. But global versions of those functions ds@1952: ** must exist in order to be overloaded. ds@1952: ** ds@1952: ** This API makes sure a global version of a function with a particular ds@1952: ** name and number of parameters exists. If no such function exists ds@1952: ** before this API is called, a new function is created. The implementation ds@1952: ** of the new function always causes an exception to be thrown. So ds@1952: ** the new function is not good for anything by itself. Its only ds@1952: ** purpose is to be a place-holder function that can be overloaded ds@1952: ** by virtual tables. ds@1952: ** ds@1952: ** This API should be considered part of the virtual table interface, ds@1952: ** which is experimental and subject to change. ds@1952: */ ds@1952: int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg); ds@1952: ds@1952: /* ds@1952: ** The interface to the virtual-table mechanism defined above (back up ds@1952: ** to a comment remarkably similar to this one) is currently considered ds@1952: ** to be experimental. The interface might change in incompatible ways. ds@1952: ** If this is a problem for you, do not use the interface at this time. ds@1952: ** ds@1952: ** When the virtual-table mechanism stabilizes, we will declare the ds@1952: ** interface fixed, support it indefinitely, and remove this comment. ds@1952: ** ds@1952: ****** EXPERIMENTAL - subject to change without notice ************** ds@1952: */ ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: A Handle To An Open BLOB ds@1952: ** ds@1952: ** An instance of the following opaque structure is used to ds@1952: ** represent an blob-handle. A blob-handle is created by ds@1952: ** [sqlite3_blob_open()] and destroyed by [sqlite3_blob_close()]. ds@1952: ** The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces ds@1952: ** can be used to read or write small subsections of the blob. ds@1952: ** The [sqlite3_blob_bytes()] interface returns the size of the ds@1952: ** blob in bytes. ds@1952: */ ds@1952: typedef struct sqlite3_blob sqlite3_blob; ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Open A BLOB For Incremental I/O ds@1952: ** ds@1952: ** Open a handle to the blob located in row iRow,, column zColumn, ds@1952: ** table zTable in database zDb. i.e. the same blob that would ds@1952: ** be selected by: ds@1952: ** ds@1952: **
ds@1952: **     SELECT zColumn FROM zDb.zTable WHERE rowid = iRow;
ds@1952: ** 
ds@1952: ** ds@1952: ** If the flags parameter is non-zero, the blob is opened for ds@1952: ** read and write access. If it is zero, the blob is opened for read ds@1952: ** access. ds@1952: ** ds@1952: ** On success, [SQLITE_OK] is returned and the new ds@1952: ** [sqlite3_blob | blob handle] is written to *ppBlob. ds@1952: ** Otherwise an error code is returned and ds@1952: ** any value written to *ppBlob should not be used by the caller. ds@1952: ** This function sets the database-handle error code and message ds@1952: ** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()]. ds@1952: */ ds@1952: int sqlite3_blob_open( ds@1952: sqlite3*, ds@1952: const char *zDb, ds@1952: const char *zTable, ds@1952: const char *zColumn, ds@1952: sqlite3_int64 iRow, ds@1952: int flags, ds@1952: sqlite3_blob **ppBlob ds@1952: ); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Close A BLOB Handle ds@1952: ** ds@1952: ** Close an open [sqlite3_blob | blob handle]. ds@1952: */ ds@1952: int sqlite3_blob_close(sqlite3_blob *); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Return The Size Of An Open BLOB ds@1952: ** ds@1952: ** Return the size in bytes of the blob accessible via the open ds@1952: ** [sqlite3_blob | blob-handle] passed as an argument. ds@1952: */ ds@1952: int sqlite3_blob_bytes(sqlite3_blob *); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Read Data From A BLOB Incrementally ds@1952: ** ds@1952: ** This function is used to read data from an open ds@1952: ** [sqlite3_blob | blob-handle] into a caller supplied buffer. ds@1952: ** n bytes of data are copied into buffer ds@1952: ** z from the open blob, starting at offset iOffset. ds@1952: ** ds@1952: ** On success, SQLITE_OK is returned. Otherwise, an ds@1952: ** [SQLITE_ERROR | SQLite error code] or an ds@1952: ** [SQLITE_IOERR_READ | extended error code] is returned. ds@1952: */ ds@1952: int sqlite3_blob_read(sqlite3_blob *, void *z, int n, int iOffset); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Write Data Into A BLOB Incrementally ds@1952: ** ds@1952: ** This function is used to write data into an open ds@1952: ** [sqlite3_blob | blob-handle] from a user supplied buffer. ds@1952: ** n bytes of data are copied from the buffer ds@1952: ** pointed to by z into the open blob, starting at offset iOffset. ds@1952: ** ds@1952: ** If the [sqlite3_blob | blob-handle] passed as the first argument ds@1952: ** was not opened for writing (the flags parameter to [sqlite3_blob_open()] ds@1952: *** was zero), this function returns [SQLITE_READONLY]. ds@1952: ** ds@1952: ** This function may only modify the contents of the blob, it is ds@1952: ** not possible to increase the size of a blob using this API. If ds@1952: ** offset iOffset is less than n bytes from the end of the blob, ds@1952: ** [SQLITE_ERROR] is returned and no data is written. ds@1952: ** ds@1952: ** On success, SQLITE_OK is returned. Otherwise, an ds@1952: ** [SQLITE_ERROR | SQLite error code] or an ds@1952: ** [SQLITE_IOERR_READ | extended error code] is returned. ds@1952: */ ds@1952: int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Virtual File System Objects ds@1952: ** ds@1952: ** A virtual filesystem (VFS) is an [sqlite3_vfs] object ds@1952: ** that SQLite uses to interact ds@1952: ** with the underlying operating system. Most builds come with a ds@1952: ** single default VFS that is appropriate for the host computer. ds@1952: ** New VFSes can be registered and existing VFSes can be unregistered. ds@1952: ** The following interfaces are provided. ds@1952: ** ds@1952: ** The sqlite3_vfs_find() interface returns a pointer to a VFS given its ds@1952: ** name. Names are case sensitive. If there is no match, a NULL ds@1952: ** pointer is returned. If zVfsName is NULL then the default ds@1952: ** VFS is returned. ds@1952: ** ds@1952: ** New VFSes are registered with sqlite3_vfs_register(). Each ds@1952: ** new VFS becomes the default VFS if the makeDflt flag is set. ds@1952: ** The same VFS can be registered multiple times without injury. ds@1952: ** To make an existing VFS into the default VFS, register it again ds@1952: ** with the makeDflt flag set. If two different VFSes with the ds@1952: ** same name are registered, the behavior is undefined. If a ds@1952: ** VFS is registered with a name that is NULL or an empty string, ds@1952: ** then the behavior is undefined. ds@1952: ** ds@1952: ** Unregister a VFS with the sqlite3_vfs_unregister() interface. ds@1952: ** If the default VFS is unregistered, another VFS is chosen as ds@1952: ** the default. The choice for the new VFS is arbitrary. ds@1952: */ ds@1952: sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName); ds@1952: int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt); ds@1952: int sqlite3_vfs_unregister(sqlite3_vfs*); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Mutexes ds@1952: ** ds@1952: ** The SQLite core uses these routines for thread ds@1952: ** synchronization. Though they are intended for internal ds@1952: ** use by SQLite, code that links against SQLite is ds@1952: ** permitted to use any of these routines. ds@1952: ** ds@1952: ** The SQLite source code contains multiple implementations ds@1952: ** of these mutex routines. An appropriate implementation ds@1952: ** is selected automatically at compile-time. The following ds@1952: ** implementations are available in the SQLite core: ds@1952: ** ds@1952: ** ds@1952: ** ds@1952: ** The SQLITE_MUTEX_NOOP implementation is a set of routines ds@1952: ** that does no real locking and is appropriate for use in ds@1952: ** a single-threaded application. The SQLITE_MUTEX_OS2, ds@1952: ** SQLITE_MUTEX_PTHREAD, and SQLITE_MUTEX_W32 implementations ds@1952: ** are appropriate for use on os/2, unix, and windows. ds@1952: ** ds@1952: ** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor ds@1952: ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex ds@1952: ** implementation is included with the library. The ds@1952: ** mutex interface routines defined here become external ds@1952: ** references in the SQLite library for which implementations ds@1952: ** must be provided by the application. This facility allows an ds@1952: ** application that links against SQLite to provide its own mutex ds@1952: ** implementation without having to modify the SQLite core. ds@1952: ** ds@1952: ** The sqlite3_mutex_alloc() routine allocates a new ds@1952: ** mutex and returns a pointer to it. If it returns NULL ds@1952: ** that means that a mutex could not be allocated. SQLite ds@1952: ** will unwind its stack and return an error. The argument ds@1952: ** to sqlite3_mutex_alloc() is one of these integer constants: ds@1952: ** ds@1952: ** ds@1952: ** ds@1952: ** The first two constants cause sqlite3_mutex_alloc() to create ds@1952: ** a new mutex. The new mutex is recursive when SQLITE_MUTEX_RECURSIVE ds@1952: ** is used but not necessarily so when SQLITE_MUTEX_FAST is used. ds@1952: ** The mutex implementation does not need to make a distinction ds@1952: ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does ds@1952: ** not want to. But SQLite will only request a recursive mutex in ds@1952: ** cases where it really needs one. If a faster non-recursive mutex ds@1952: ** implementation is available on the host platform, the mutex subsystem ds@1952: ** might return such a mutex in response to SQLITE_MUTEX_FAST. ds@1952: ** ds@1952: ** The other allowed parameters to sqlite3_mutex_alloc() each return ds@1952: ** a pointer to a static preexisting mutex. Four static mutexes are ds@1952: ** used by the current version of SQLite. Future versions of SQLite ds@1952: ** may add additional static mutexes. Static mutexes are for internal ds@1952: ** use by SQLite only. Applications that use SQLite mutexes should ds@1952: ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or ds@1952: ** SQLITE_MUTEX_RECURSIVE. ds@1952: ** ds@1952: ** Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST ds@1952: ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc() ds@1952: ** returns a different mutex on every call. But for the static ds@1952: ** mutex types, the same mutex is returned on every call that has ds@1952: ** the same type number. ds@1952: ** ds@1952: ** The sqlite3_mutex_free() routine deallocates a previously ds@1952: ** allocated dynamic mutex. SQLite is careful to deallocate every ds@1952: ** dynamic mutex that it allocates. The dynamic mutexes must not be in ds@1952: ** use when they are deallocated. Attempting to deallocate a static ds@1952: ** mutex results in undefined behavior. SQLite never deallocates ds@1952: ** a static mutex. ds@1952: ** ds@1952: ** The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt ds@1952: ** to enter a mutex. If another thread is already within the mutex, ds@1952: ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return ds@1952: ** SQLITE_BUSY. The sqlite3_mutex_try() interface returns SQLITE_OK ds@1952: ** upon successful entry. Mutexes created using SQLITE_MUTEX_RECURSIVE can ds@1952: ** be entered multiple times by the same thread. In such cases the, ds@1952: ** mutex must be exited an equal number of times before another thread ds@1952: ** can enter. If the same thread tries to enter any other kind of mutex ds@1952: ** more than once, the behavior is undefined. SQLite will never exhibit ds@1952: ** such behavior in its own use of mutexes. ds@1952: ** ds@1952: ** Some systems (ex: windows95) do not the operation implemented by ds@1952: ** sqlite3_mutex_try(). On those systems, sqlite3_mutex_try() will ds@1952: ** always return SQLITE_BUSY. The SQLite core only ever uses ds@1952: ** sqlite3_mutex_try() as an optimization so this is acceptable behavior. ds@1952: ** ds@1952: ** The sqlite3_mutex_leave() routine exits a mutex that was ds@1952: ** previously entered by the same thread. The behavior ds@1952: ** is undefined if the mutex is not currently entered by the ds@1952: ** calling thread or is not currently allocated. SQLite will ds@1952: ** never do either. ds@1952: ** ds@1952: ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()]. ds@1952: */ ds@1952: sqlite3_mutex *sqlite3_mutex_alloc(int); ds@1952: void sqlite3_mutex_free(sqlite3_mutex*); ds@1952: void sqlite3_mutex_enter(sqlite3_mutex*); ds@1952: int sqlite3_mutex_try(sqlite3_mutex*); ds@1952: void sqlite3_mutex_leave(sqlite3_mutex*); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Mutex Verifcation Routines ds@1952: ** ds@1952: ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines ds@1952: ** are intended for use inside assert() statements. The SQLite core ds@1952: ** never uses these routines except inside an assert() and applications ds@1952: ** are advised to follow the lead of the core. The core only ds@1952: ** provides implementations for these routines when it is compiled ds@1952: ** with the SQLITE_DEBUG flag. External mutex implementations ds@1952: ** are only required to provide these routines if SQLITE_DEBUG is ds@1952: ** defined and if NDEBUG is not defined. ds@1952: ** ds@1952: ** These routines should return true if the mutex in their argument ds@1952: ** is held or not held, respectively, by the calling thread. ds@1952: ** ds@1952: ** The implementation is not required to provided versions of these ds@1952: ** routines that actually work. ds@1952: ** If the implementation does not provide working ds@1952: ** versions of these routines, it should at least provide stubs ds@1952: ** that always return true so that one does not get spurious ds@1952: ** assertion failures. ds@1952: ** ds@1952: ** If the argument to sqlite3_mutex_held() is a NULL pointer then ds@1952: ** the routine should return 1. This seems counter-intuitive since ds@1952: ** clearly the mutex cannot be held if it does not exist. But the ds@1952: ** the reason the mutex does not exist is because the build is not ds@1952: ** using mutexes. And we do not want the assert() containing the ds@1952: ** call to sqlite3_mutex_held() to fail, so a non-zero return is ds@1952: ** the appropriate thing to do. The sqlite3_mutex_notheld() ds@1952: ** interface should also return 1 when given a NULL pointer. ds@1952: */ ds@1952: int sqlite3_mutex_held(sqlite3_mutex*); ds@1952: int sqlite3_mutex_notheld(sqlite3_mutex*); ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Mutex Types ds@1952: ** ds@1952: ** The [sqlite3_mutex_alloc()] interface takes a single argument ds@1952: ** which is one of these integer constants. ds@1952: */ ds@1952: #define SQLITE_MUTEX_FAST 0 ds@1952: #define SQLITE_MUTEX_RECURSIVE 1 ds@1952: #define SQLITE_MUTEX_STATIC_MASTER 2 ds@1952: #define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */ ds@1952: #define SQLITE_MUTEX_STATIC_MEM2 4 /* sqlite3_release_memory() */ ds@1952: #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_random() */ ds@1952: #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */ ds@1952: ds@1952: /* ds@1952: ** CAPI3REF: Low-Level Control Of Database Files ds@1952: ** ds@1952: ** The [sqlite3_file_control()] interface makes a direct call to the ds@1952: ** xFileControl method for the [sqlite3_io_methods] object associated ds@1952: ** with a particular database identified by the second argument. The ds@1952: ** name of the database is the name assigned to the database by the ds@1952: ** ATTACH SQL command that opened the ds@1952: ** database. To control the main database file, use the name "main" ds@1952: ** or a NULL pointer. The third and fourth parameters to this routine ds@1952: ** are passed directly through to the second and third parameters of ds@1952: ** the xFileControl method. The return value of the xFileControl ds@1952: ** method becomes the return value of this routine. ds@1952: ** ds@1952: ** If the second parameter (zDbName) does not match the name of any ds@1952: ** open database file, then SQLITE_ERROR is returned. This error ds@1952: ** code is not remembered and will not be recalled by [sqlite3_errcode()] ds@1952: ** or [sqlite3_errmsg()]. The underlying xFileControl method might ds@1952: ** also return SQLITE_ERROR. There is no way to distinguish between ds@1952: ** an incorrect zDbName and an SQLITE_ERROR return from the underlying ds@1952: ** xFileControl method. ds@1952: ** ds@1952: ** See also: [SQLITE_FCNTL_LOCKSTATE] ds@1952: */ ds@1952: int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*); ds@1952: ds@1952: /* ds@1952: ** Undo the hack that converts floating point types to integer for ds@1952: ** builds on processors without floating point support. ds@1952: */ ds@1952: #ifdef SQLITE_OMIT_FLOATING_POINT ds@1952: # undef double ds@1952: #endif ds@1952: ds@1952: #ifdef __cplusplus ds@1952: } /* End of the 'extern "C"' block */ ds@1952: #endif ds@1952: #endif