00001 /* 00002 ** 2001 September 15 00003 ** 00004 ** The author disclaims copyright to this source code. In place of 00005 ** a legal notice, here is a blessing: 00006 ** 00007 ** May you do good and not evil. 00008 ** May you find forgiveness for yourself and forgive others. 00009 ** May you share freely, never taking more than you give. 00010 ** 00011 ************************************************************************* 00012 ** This header file defines the interface that the SQLite library 00013 ** presents to client programs. If a C-function, structure, datatype, 00014 ** or constant definition does not appear in this file, then it is 00015 ** not a published API of SQLite, is subject to change without 00016 ** notice, and should not be referenced by programs that use SQLite. 00017 ** 00018 ** Some of the definitions that are in this file are marked as 00019 ** "experimental". Experimental interfaces are normally new 00020 ** features recently added to SQLite. We do not anticipate changes 00021 ** to experimental interfaces but reserve the right to make minor changes 00022 ** if experience from use "in the wild" suggest such changes are prudent. 00023 ** 00024 ** The official C-language API documentation for SQLite is derived 00025 ** from comments in this file. This file is the authoritative source 00026 ** on how SQLite interfaces are suppose to operate. 00027 ** 00028 ** The name of this file under configuration management is "sqlite.h.in". 00029 ** The makefile makes some minor changes to this file (such as inserting 00030 ** the version number) and changes its name to "sqlite3.h" as 00031 ** part of the build process. 00032 */ 00033 #ifndef _SQLITE3_H_ 00034 #define _SQLITE3_H_ 00035 #include <stdarg.h> /* Needed for the definition of va_list */ 00036 00037 /* 00038 ** Make sure we can call this stuff from C++. 00039 */ 00040 #ifdef __cplusplus 00041 extern "C" { 00042 #endif 00043 00044 00045 /* 00046 ** Add the ability to override 'extern' 00047 */ 00048 #ifndef SQLITE_EXTERN 00049 # define SQLITE_EXTERN extern 00050 #endif 00051 00052 #ifndef SQLITE_API 00053 # define SQLITE_API 00054 #endif 00055 00056 00057 /* 00058 ** These no-op macros are used in front of interfaces to mark those 00059 ** interfaces as either deprecated or experimental. New applications 00060 ** should not use deprecated interfaces - they are support for backwards 00061 ** compatibility only. Application writers should be aware that 00062 ** experimental interfaces are subject to change in point releases. 00063 ** 00064 ** These macros used to resolve to various kinds of compiler magic that 00065 ** would generate warning messages when they were used. But that 00066 ** compiler magic ended up generating such a flurry of bug reports 00067 ** that we have taken it all out and gone back to using simple 00068 ** noop macros. 00069 */ 00070 #define SQLITE_DEPRECATED 00071 #define SQLITE_EXPERIMENTAL 00072 00073 /* 00074 ** Ensure these symbols were not defined by some previous header file. 00075 */ 00076 #ifdef SQLITE_VERSION 00077 # undef SQLITE_VERSION 00078 #endif 00079 #ifdef SQLITE_VERSION_NUMBER 00080 # undef SQLITE_VERSION_NUMBER 00081 #endif 00082 00083 /* 00084 ** CAPI3REF: Compile-Time Library Version Numbers 00085 ** 00086 ** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header 00087 ** evaluates to a string literal that is the SQLite version in the 00088 ** format "X.Y.Z" where X is the major version number (always 3 for 00089 ** SQLite3) and Y is the minor version number and Z is the release number.)^ 00090 ** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer 00091 ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same 00092 ** numbers used in [SQLITE_VERSION].)^ 00093 ** The SQLITE_VERSION_NUMBER for any given release of SQLite will also 00094 ** be larger than the release from which it is derived. Either Y will 00095 ** be held constant and Z will be incremented or else Y will be incremented 00096 ** and Z will be reset to zero. 00097 ** 00098 ** Since version 3.6.18, SQLite source code has been stored in the 00099 ** <a href="http://www.fossil-scm.org/">Fossil configuration management 00100 ** system</a>. ^The SQLITE_SOURCE_ID macro evalutes to 00101 ** a string which identifies a particular check-in of SQLite 00102 ** within its configuration management system. ^The SQLITE_SOURCE_ID 00103 ** string contains the date and time of the check-in (UTC) and an SHA1 00104 ** hash of the entire source tree. 00105 ** 00106 ** See also: [sqlite3_libversion()], 00107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()], 00108 ** [sqlite_version()] and [sqlite_source_id()]. 00109 */ 00110 #define SQLITE_VERSION "3.6.23.1" 00111 #define SQLITE_VERSION_NUMBER 3006023 00112 #define SQLITE_SOURCE_ID "2010-03-26 22:28:06 b078b588d617e07886ad156e9f54ade6d823568e" 00113 00114 /* 00115 ** CAPI3REF: Run-Time Library Version Numbers 00116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid 00117 ** 00118 ** These interfaces provide the same information as the [SQLITE_VERSION], 00119 ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros 00120 ** but are associated with the library instead of the header file. ^(Cautious 00121 ** programmers might include assert() statements in their application to 00122 ** verify that values returned by these interfaces match the macros in 00123 ** the header, and thus insure that the application is 00124 ** compiled with matching library and header files. 00125 ** 00126 ** <blockquote><pre> 00127 ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER ); 00128 ** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 ); 00129 ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 ); 00130 ** </pre></blockquote>)^ 00131 ** 00132 ** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION] 00133 ** macro. ^The sqlite3_libversion() function returns a pointer to the 00134 ** to the sqlite3_version[] string constant. The sqlite3_libversion() 00135 ** function is provided for use in DLLs since DLL users usually do not have 00136 ** direct access to string constants within the DLL. ^The 00137 ** sqlite3_libversion_number() function returns an integer equal to 00138 ** [SQLITE_VERSION_NUMBER]. ^The sqlite3_sourceid() function returns 00139 ** a pointer to a string constant whose value is the same as the 00140 ** [SQLITE_SOURCE_ID] C preprocessor macro. 00141 ** 00142 ** See also: [sqlite_version()] and [sqlite_source_id()]. 00143 */ 00144 SQLITE_API SQLITE_EXTERN const char sqlite3_version[]; 00145 SQLITE_API const char *sqlite3_libversion(void); 00146 SQLITE_API const char *sqlite3_sourceid(void); 00147 SQLITE_API int sqlite3_libversion_number(void); 00148 00149 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS 00150 /* 00151 ** CAPI3REF: Run-Time Library Compilation Options Diagnostics 00152 ** 00153 ** ^The sqlite3_compileoption_used() function returns 0 or 1 00154 ** indicating whether the specified option was defined at 00155 ** compile time. ^The SQLITE_ prefix may be omitted from the 00156 ** option name passed to sqlite3_compileoption_used(). 00157 ** 00158 ** ^The sqlite3_compileoption_get() function allows interating 00159 ** over the list of options that were defined at compile time by 00160 ** returning the N-th compile time option string. ^If N is out of range, 00161 ** sqlite3_compileoption_get() returns a NULL pointer. ^The SQLITE_ 00162 ** prefix is omitted from any strings returned by 00163 ** sqlite3_compileoption_get(). 00164 ** 00165 ** ^Support for the diagnostic functions sqlite3_compileoption_used() 00166 ** and sqlite3_compileoption_get() may be omitted by specifing the 00167 ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time. 00168 ** 00169 ** See also: SQL functions [sqlite_compileoption_used()] and 00170 ** [sqlite_compileoption_get()] and the [compile_options pragma]. 00171 */ 00172 SQLITE_API int sqlite3_compileoption_used(const char *zOptName); 00173 SQLITE_API const char *sqlite3_compileoption_get(int N); 00174 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ 00175 00176 /* 00177 ** CAPI3REF: Test To See If The Library Is Threadsafe 00178 ** 00179 ** ^The sqlite3_threadsafe() function returns zero if and only if 00180 ** SQLite was compiled mutexing code omitted due to the 00181 ** [SQLITE_THREADSAFE] compile-time option being set to 0. 00182 ** 00183 ** SQLite can be compiled with or without mutexes. When 00184 ** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes 00185 ** are enabled and SQLite is threadsafe. When the 00186 ** [SQLITE_THREADSAFE] macro is 0, 00187 ** the mutexes are omitted. Without the mutexes, it is not safe 00188 ** to use SQLite concurrently from more than one thread. 00189 ** 00190 ** Enabling mutexes incurs a measurable performance penalty. 00191 ** So if speed is of utmost importance, it makes sense to disable 00192 ** the mutexes. But for maximum safety, mutexes should be enabled. 00193 ** ^The default behavior is for mutexes to be enabled. 00194 ** 00195 ** This interface can be used by an application to make sure that the 00196 ** version of SQLite that it is linking against was compiled with 00197 ** the desired setting of the [SQLITE_THREADSAFE] macro. 00198 ** 00199 ** This interface only reports on the compile-time mutex setting 00200 ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with 00201 ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but 00202 ** can be fully or partially disabled using a call to [sqlite3_config()] 00203 ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD], 00204 ** or [SQLITE_CONFIG_MUTEX]. ^(The return value of the 00205 ** sqlite3_threadsafe() function shows only the compile-time setting of 00206 ** thread safety, not any run-time changes to that setting made by 00207 ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe() 00208 ** is unchanged by calls to sqlite3_config().)^ 00209 ** 00210 ** See the [threading mode] documentation for additional information. 00211 */ 00212 SQLITE_API int sqlite3_threadsafe(void); 00213 00214 /* 00215 ** CAPI3REF: Database Connection Handle 00216 ** KEYWORDS: {database connection} {database connections} 00217 ** 00218 ** Each open SQLite database is represented by a pointer to an instance of 00219 ** the opaque structure named "sqlite3". It is useful to think of an sqlite3 00220 ** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and 00221 ** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()] 00222 ** is its destructor. There are many other interfaces (such as 00223 ** [sqlite3_prepare_v2()], [sqlite3_create_function()], and 00224 ** [sqlite3_busy_timeout()] to name but three) that are methods on an 00225 ** sqlite3 object. 00226 */ 00227 typedef struct sqlite3 sqlite3; 00228 00229 /* 00230 ** CAPI3REF: 64-Bit Integer Types 00231 ** KEYWORDS: sqlite_int64 sqlite_uint64 00232 ** 00233 ** Because there is no cross-platform way to specify 64-bit integer types 00234 ** SQLite includes typedefs for 64-bit signed and unsigned integers. 00235 ** 00236 ** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions. 00237 ** The sqlite_int64 and sqlite_uint64 types are supported for backwards 00238 ** compatibility only. 00239 ** 00240 ** ^The sqlite3_int64 and sqlite_int64 types can store integer values 00241 ** between -9223372036854775808 and +9223372036854775807 inclusive. ^The 00242 ** sqlite3_uint64 and sqlite_uint64 types can store integer values 00243 ** between 0 and +18446744073709551615 inclusive. 00244 */ 00245 #ifdef SQLITE_INT64_TYPE 00246 typedef SQLITE_INT64_TYPE sqlite_int64; 00247 typedef unsigned SQLITE_INT64_TYPE sqlite_uint64; 00248 #elif defined(_MSC_VER) || defined(__BORLANDC__) 00249 typedef __int64 sqlite_int64; 00250 typedef unsigned __int64 sqlite_uint64; 00251 #else 00252 typedef long long int sqlite_int64; 00253 typedef unsigned long long int sqlite_uint64; 00254 #endif 00255 typedef sqlite_int64 sqlite3_int64; 00256 typedef sqlite_uint64 sqlite3_uint64; 00257 00258 /* 00259 ** If compiling for a processor that lacks floating point support, 00260 ** substitute integer for floating-point. 00261 */ 00262 #ifdef SQLITE_OMIT_FLOATING_POINT 00263 # define double sqlite3_int64 00264 #endif 00265 00266 /* 00267 ** CAPI3REF: Closing A Database Connection 00268 ** 00269 ** ^The sqlite3_close() routine is the destructor for the [sqlite3] object. 00270 ** ^Calls to sqlite3_close() return SQLITE_OK if the [sqlite3] object is 00271 ** successfullly destroyed and all associated resources are deallocated. 00272 ** 00273 ** Applications must [sqlite3_finalize | finalize] all [prepared statements] 00274 ** and [sqlite3_blob_close | close] all [BLOB handles] associated with 00275 ** the [sqlite3] object prior to attempting to close the object. ^If 00276 ** sqlite3_close() is called on a [database connection] that still has 00277 ** outstanding [prepared statements] or [BLOB handles], then it returns 00278 ** SQLITE_BUSY. 00279 ** 00280 ** ^If [sqlite3_close()] is invoked while a transaction is open, 00281 ** the transaction is automatically rolled back. 00282 ** 00283 ** The C parameter to [sqlite3_close(C)] must be either a NULL 00284 ** pointer or an [sqlite3] object pointer obtained 00285 ** from [sqlite3_open()], [sqlite3_open16()], or 00286 ** [sqlite3_open_v2()], and not previously closed. 00287 ** ^Calling sqlite3_close() with a NULL pointer argument is a 00288 ** harmless no-op. 00289 */ 00290 SQLITE_API int sqlite3_close(sqlite3 *); 00291 00292 /* 00293 ** The type for a callback function. 00294 ** This is legacy and deprecated. It is included for historical 00295 ** compatibility and is not documented. 00296 */ 00297 typedef int (*sqlite3_callback)(void*,int,char**, char**); 00298 00299 /* 00300 ** CAPI3REF: One-Step Query Execution Interface 00301 ** 00302 ** The sqlite3_exec() interface is a convenience wrapper around 00303 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()], 00304 ** that allows an application to run multiple statements of SQL 00305 ** without having to use a lot of C code. 00306 ** 00307 ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded, 00308 ** semicolon-separate SQL statements passed into its 2nd argument, 00309 ** in the context of the [database connection] passed in as its 1st 00310 ** argument. ^If the callback function of the 3rd argument to 00311 ** sqlite3_exec() is not NULL, then it is invoked for each result row 00312 ** coming out of the evaluated SQL statements. ^The 4th argument to 00313 ** to sqlite3_exec() is relayed through to the 1st argument of each 00314 ** callback invocation. ^If the callback pointer to sqlite3_exec() 00315 ** is NULL, then no callback is ever invoked and result rows are 00316 ** ignored. 00317 ** 00318 ** ^If an error occurs while evaluating the SQL statements passed into 00319 ** sqlite3_exec(), then execution of the current statement stops and 00320 ** subsequent statements are skipped. ^If the 5th parameter to sqlite3_exec() 00321 ** is not NULL then any error message is written into memory obtained 00322 ** from [sqlite3_malloc()] and passed back through the 5th parameter. 00323 ** To avoid memory leaks, the application should invoke [sqlite3_free()] 00324 ** on error message strings returned through the 5th parameter of 00325 ** of sqlite3_exec() after the error message string is no longer needed. 00326 ** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors 00327 ** occur, then sqlite3_exec() sets the pointer in its 5th parameter to 00328 ** NULL before returning. 00329 ** 00330 ** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec() 00331 ** routine returns SQLITE_ABORT without invoking the callback again and 00332 ** without running any subsequent SQL statements. 00333 ** 00334 ** ^The 2nd argument to the sqlite3_exec() callback function is the 00335 ** number of columns in the result. ^The 3rd argument to the sqlite3_exec() 00336 ** callback is an array of pointers to strings obtained as if from 00337 ** [sqlite3_column_text()], one for each column. ^If an element of a 00338 ** result row is NULL then the corresponding string pointer for the 00339 ** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the 00340 ** sqlite3_exec() callback is an array of pointers to strings where each 00341 ** entry represents the name of corresponding result column as obtained 00342 ** from [sqlite3_column_name()]. 00343 ** 00344 ** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer 00345 ** to an empty string, or a pointer that contains only whitespace and/or 00346 ** SQL comments, then no SQL statements are evaluated and the database 00347 ** is not changed. 00348 ** 00349 ** Restrictions: 00350 ** 00351 ** <ul> 00352 ** <li> The application must insure that the 1st parameter to sqlite3_exec() 00353 ** is a valid and open [database connection]. 00354 ** <li> The application must not close [database connection] specified by 00355 ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running. 00356 ** <li> The application must not modify the SQL statement text passed into 00357 ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running. 00358 ** </ul> 00359 */ 00360 SQLITE_API int sqlite3_exec( 00361 sqlite3*, /* An open database */ 00362 const char *sql, /* SQL to be evaluated */ 00363 int (*callback)(void*,int,char**,char**), /* Callback function */ 00364 void *, /* 1st argument to callback */ 00365 char **errmsg /* Error msg written here */ 00366 ); 00367 00368 /* 00369 ** CAPI3REF: Result Codes 00370 ** KEYWORDS: SQLITE_OK {error code} {error codes} 00371 ** KEYWORDS: {result code} {result codes} 00372 ** 00373 ** Many SQLite functions return an integer result code from the set shown 00374 ** here in order to indicates success or failure. 00375 ** 00376 ** New error codes may be added in future versions of SQLite. 00377 ** 00378 ** See also: [SQLITE_IOERR_READ | extended result codes] 00379 */ 00380 #define SQLITE_OK 0 /* Successful result */ 00381 /* beginning-of-error-codes */ 00382 #define SQLITE_ERROR 1 /* SQL error or missing database */ 00383 #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ 00384 #define SQLITE_PERM 3 /* Access permission denied */ 00385 #define SQLITE_ABORT 4 /* Callback routine requested an abort */ 00386 #define SQLITE_BUSY 5 /* The database file is locked */ 00387 #define SQLITE_LOCKED 6 /* A table in the database is locked */ 00388 #define SQLITE_NOMEM 7 /* A malloc() failed */ 00389 #define SQLITE_READONLY 8 /* Attempt to write a readonly database */ 00390 #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/ 00391 #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */ 00392 #define SQLITE_CORRUPT 11 /* The database disk image is malformed */ 00393 #define SQLITE_NOTFOUND 12 /* NOT USED. Table or record not found */ 00394 #define SQLITE_FULL 13 /* Insertion failed because database is full */ 00395 #define SQLITE_CANTOPEN 14 /* Unable to open the database file */ 00396 #define SQLITE_PROTOCOL 15 /* NOT USED. Database lock protocol error */ 00397 #define SQLITE_EMPTY 16 /* Database is empty */ 00398 #define SQLITE_SCHEMA 17 /* The database schema changed */ 00399 #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */ 00400 #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */ 00401 #define SQLITE_MISMATCH 20 /* Data type mismatch */ 00402 #define SQLITE_MISUSE 21 /* Library used incorrectly */ 00403 #define SQLITE_NOLFS 22 /* Uses OS features not supported on host */ 00404 #define SQLITE_AUTH 23 /* Authorization denied */ 00405 #define SQLITE_FORMAT 24 /* Auxiliary database format error */ 00406 #define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */ 00407 #define SQLITE_NOTADB 26 /* File opened that is not a database file */ 00408 #define SQLITE_ROW 100 /* sqlite3_step() has another row ready */ 00409 #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */ 00410 /* end-of-error-codes */ 00411 00412 /* 00413 ** CAPI3REF: Extended Result Codes 00414 ** KEYWORDS: {extended error code} {extended error codes} 00415 ** KEYWORDS: {extended result code} {extended result codes} 00416 ** 00417 ** In its default configuration, SQLite API routines return one of 26 integer 00418 ** [SQLITE_OK | result codes]. However, experience has shown that many of 00419 ** these result codes are too coarse-grained. They do not provide as 00420 ** much information about problems as programmers might like. In an effort to 00421 ** address this, newer versions of SQLite (version 3.3.8 and later) include 00422 ** support for additional result codes that provide more detailed information 00423 ** about errors. The extended result codes are enabled or disabled 00424 ** on a per database connection basis using the 00425 ** [sqlite3_extended_result_codes()] API. 00426 ** 00427 ** Some of the available extended result codes are listed here. 00428 ** One may expect the number of extended result codes will be expand 00429 ** over time. Software that uses extended result codes should expect 00430 ** to see new result codes in future releases of SQLite. 00431 ** 00432 ** The SQLITE_OK result code will never be extended. It will always 00433 ** be exactly zero. 00434 */ 00435 #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) 00436 #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) 00437 #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) 00438 #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) 00439 #define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8)) 00440 #define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8)) 00441 #define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8)) 00442 #define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8)) 00443 #define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8)) 00444 #define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8)) 00445 #define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8)) 00446 #define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8)) 00447 #define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8)) 00448 #define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8)) 00449 #define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8)) 00450 #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8)) 00451 #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8)) 00452 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8) ) 00453 00454 /* 00455 ** CAPI3REF: Flags For File Open Operations 00456 ** 00457 ** These bit values are intended for use in the 00458 ** 3rd parameter to the [sqlite3_open_v2()] interface and 00459 ** in the 4th parameter to the xOpen method of the 00460 ** [sqlite3_vfs] object. 00461 */ 00462 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ 00463 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ 00464 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ 00465 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ 00466 #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */ 00467 #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */ 00468 #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */ 00469 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ 00470 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ 00471 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ 00472 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ 00473 #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */ 00474 #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */ 00475 #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */ 00476 #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */ 00477 #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ 00478 #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ 00479 00480 /* 00481 ** CAPI3REF: Device Characteristics 00482 ** 00483 ** The xDeviceCapabilities method of the [sqlite3_io_methods] 00484 ** object returns an integer which is a vector of the these 00485 ** bit values expressing I/O characteristics of the mass storage 00486 ** device that holds the file that the [sqlite3_io_methods] 00487 ** refers to. 00488 ** 00489 ** The SQLITE_IOCAP_ATOMIC property means that all writes of 00490 ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values 00491 ** mean that writes of blocks that are nnn bytes in size and 00492 ** are aligned to an address which is an integer multiple of 00493 ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means 00494 ** that when data is appended to a file, the data is appended 00495 ** first then the size of the file is extended, never the other 00496 ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that 00497 ** information is written to disk in the same order as calls 00498 ** to xWrite(). 00499 */ 00500 #define SQLITE_IOCAP_ATOMIC 0x00000001 00501 #define SQLITE_IOCAP_ATOMIC512 0x00000002 00502 #define SQLITE_IOCAP_ATOMIC1K 0x00000004 00503 #define SQLITE_IOCAP_ATOMIC2K 0x00000008 00504 #define SQLITE_IOCAP_ATOMIC4K 0x00000010 00505 #define SQLITE_IOCAP_ATOMIC8K 0x00000020 00506 #define SQLITE_IOCAP_ATOMIC16K 0x00000040 00507 #define SQLITE_IOCAP_ATOMIC32K 0x00000080 00508 #define SQLITE_IOCAP_ATOMIC64K 0x00000100 00509 #define SQLITE_IOCAP_SAFE_APPEND 0x00000200 00510 #define SQLITE_IOCAP_SEQUENTIAL 0x00000400 00511 00512 /* 00513 ** CAPI3REF: File Locking Levels 00514 ** 00515 ** SQLite uses one of these integer values as the second 00516 ** argument to calls it makes to the xLock() and xUnlock() methods 00517 ** of an [sqlite3_io_methods] object. 00518 */ 00519 #define SQLITE_LOCK_NONE 0 00520 #define SQLITE_LOCK_SHARED 1 00521 #define SQLITE_LOCK_RESERVED 2 00522 #define SQLITE_LOCK_PENDING 3 00523 #define SQLITE_LOCK_EXCLUSIVE 4 00524 00525 /* 00526 ** CAPI3REF: Synchronization Type Flags 00527 ** 00528 ** When SQLite invokes the xSync() method of an 00529 ** [sqlite3_io_methods] object it uses a combination of 00530 ** these integer values as the second argument. 00531 ** 00532 ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the 00533 ** sync operation only needs to flush data to mass storage. Inode 00534 ** information need not be flushed. If the lower four bits of the flag 00535 ** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics. 00536 ** If the lower four bits equal SQLITE_SYNC_FULL, that means 00537 ** to use Mac OS X style fullsync instead of fsync(). 00538 */ 00539 #define SQLITE_SYNC_NORMAL 0x00002 00540 #define SQLITE_SYNC_FULL 0x00003 00541 #define SQLITE_SYNC_DATAONLY 0x00010 00542 00543 /* 00544 ** CAPI3REF: OS Interface Open File Handle 00545 ** 00546 ** An [sqlite3_file] object represents an open file in the 00547 ** [sqlite3_vfs | OS interface layer]. Individual OS interface 00548 ** implementations will 00549 ** want to subclass this object by appending additional fields 00550 ** for their own use. The pMethods entry is a pointer to an 00551 ** [sqlite3_io_methods] object that defines methods for performing 00552 ** I/O operations on the open file. 00553 */ 00554 typedef struct sqlite3_file sqlite3_file; 00555 struct sqlite3_file { 00556 const struct sqlite3_io_methods *pMethods; /* Methods for an open file */ 00557 }; 00558 00559 /* 00560 ** CAPI3REF: OS Interface File Virtual Methods Object 00561 ** 00562 ** Every file opened by the [sqlite3_vfs] xOpen method populates an 00563 ** [sqlite3_file] object (or, more commonly, a subclass of the 00564 ** [sqlite3_file] object) with a pointer to an instance of this object. 00565 ** This object defines the methods used to perform various operations 00566 ** against the open file represented by the [sqlite3_file] object. 00567 ** 00568 ** If the xOpen method sets the sqlite3_file.pMethods element 00569 ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method 00570 ** may be invoked even if the xOpen reported that it failed. The 00571 ** only way to prevent a call to xClose following a failed xOpen 00572 ** is for the xOpen to set the sqlite3_file.pMethods element to NULL. 00573 ** 00574 ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or 00575 ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync(). 00576 ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY] 00577 ** flag may be ORed in to indicate that only the data of the file 00578 ** and not its inode needs to be synced. 00579 ** 00580 ** The integer values to xLock() and xUnlock() are one of 00581 ** <ul> 00582 ** <li> [SQLITE_LOCK_NONE], 00583 ** <li> [SQLITE_LOCK_SHARED], 00584 ** <li> [SQLITE_LOCK_RESERVED], 00585 ** <li> [SQLITE_LOCK_PENDING], or 00586 ** <li> [SQLITE_LOCK_EXCLUSIVE]. 00587 ** </ul> 00588 ** xLock() increases the lock. xUnlock() decreases the lock. 00589 ** The xCheckReservedLock() method checks whether any database connection, 00590 ** either in this process or in some other process, is holding a RESERVED, 00591 ** PENDING, or EXCLUSIVE lock on the file. It returns true 00592 ** if such a lock exists and false otherwise. 00593 ** 00594 ** The xFileControl() method is a generic interface that allows custom 00595 ** VFS implementations to directly control an open file using the 00596 ** [sqlite3_file_control()] interface. The second "op" argument is an 00597 ** integer opcode. The third argument is a generic pointer intended to 00598 ** point to a structure that may contain arguments or space in which to 00599 ** write return values. Potential uses for xFileControl() might be 00600 ** functions to enable blocking locks with timeouts, to change the 00601 ** locking strategy (for example to use dot-file locks), to inquire 00602 ** about the status of a lock, or to break stale locks. The SQLite 00603 ** core reserves all opcodes less than 100 for its own use. 00604 ** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available. 00605 ** Applications that define a custom xFileControl method should use opcodes 00606 ** greater than 100 to avoid conflicts. 00607 ** 00608 ** The xSectorSize() method returns the sector size of the 00609 ** device that underlies the file. The sector size is the 00610 ** minimum write that can be performed without disturbing 00611 ** other bytes in the file. The xDeviceCharacteristics() 00612 ** method returns a bit vector describing behaviors of the 00613 ** underlying device: 00614 ** 00615 ** <ul> 00616 ** <li> [SQLITE_IOCAP_ATOMIC] 00617 ** <li> [SQLITE_IOCAP_ATOMIC512] 00618 ** <li> [SQLITE_IOCAP_ATOMIC1K] 00619 ** <li> [SQLITE_IOCAP_ATOMIC2K] 00620 ** <li> [SQLITE_IOCAP_ATOMIC4K] 00621 ** <li> [SQLITE_IOCAP_ATOMIC8K] 00622 ** <li> [SQLITE_IOCAP_ATOMIC16K] 00623 ** <li> [SQLITE_IOCAP_ATOMIC32K] 00624 ** <li> [SQLITE_IOCAP_ATOMIC64K] 00625 ** <li> [SQLITE_IOCAP_SAFE_APPEND] 00626 ** <li> [SQLITE_IOCAP_SEQUENTIAL] 00627 ** </ul> 00628 ** 00629 ** The SQLITE_IOCAP_ATOMIC property means that all writes of 00630 ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values 00631 ** mean that writes of blocks that are nnn bytes in size and 00632 ** are aligned to an address which is an integer multiple of 00633 ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means 00634 ** that when data is appended to a file, the data is appended 00635 ** first then the size of the file is extended, never the other 00636 ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that 00637 ** information is written to disk in the same order as calls 00638 ** to xWrite(). 00639 ** 00640 ** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill 00641 ** in the unread portions of the buffer with zeros. A VFS that 00642 ** fails to zero-fill short reads might seem to work. However, 00643 ** failure to zero-fill short reads will eventually lead to 00644 ** database corruption. 00645 */ 00646 typedef struct sqlite3_io_methods sqlite3_io_methods; 00647 struct sqlite3_io_methods { 00648 int iVersion; 00649 int (*xClose)(sqlite3_file*); 00650 int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); 00651 int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst); 00652 int (*xTruncate)(sqlite3_file*, sqlite3_int64 size); 00653 int (*xSync)(sqlite3_file*, int flags); 00654 int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize); 00655 int (*xLock)(sqlite3_file*, int); 00656 int (*xUnlock)(sqlite3_file*, int); 00657 int (*xCheckReservedLock)(sqlite3_file*, int *pResOut); 00658 int (*xFileControl)(sqlite3_file*, int op, void *pArg); 00659 int (*xSectorSize)(sqlite3_file*); 00660 int (*xDeviceCharacteristics)(sqlite3_file*); 00661 /* Additional methods may be added in future releases */ 00662 }; 00663 00664 /* 00665 ** CAPI3REF: Standard File Control Opcodes 00666 ** 00667 ** These integer constants are opcodes for the xFileControl method 00668 ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()] 00669 ** interface. 00670 ** 00671 ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This 00672 ** opcode causes the xFileControl method to write the current state of 00673 ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED], 00674 ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE]) 00675 ** into an integer that the pArg argument points to. This capability 00676 ** is used during testing and only needs to be supported when SQLITE_TEST 00677 ** is defined. 00678 */ 00679 #define SQLITE_FCNTL_LOCKSTATE 1 00680 #define SQLITE_GET_LOCKPROXYFILE 2 00681 #define SQLITE_SET_LOCKPROXYFILE 3 00682 #define SQLITE_LAST_ERRNO 4 00683 00684 /* 00685 ** CAPI3REF: Mutex Handle 00686 ** 00687 ** The mutex module within SQLite defines [sqlite3_mutex] to be an 00688 ** abstract type for a mutex object. The SQLite core never looks 00689 ** at the internal representation of an [sqlite3_mutex]. It only 00690 ** deals with pointers to the [sqlite3_mutex] object. 00691 ** 00692 ** Mutexes are created using [sqlite3_mutex_alloc()]. 00693 */ 00694 typedef struct sqlite3_mutex sqlite3_mutex; 00695 00696 /* 00697 ** CAPI3REF: OS Interface Object 00698 ** 00699 ** An instance of the sqlite3_vfs object defines the interface between 00700 ** the SQLite core and the underlying operating system. The "vfs" 00701 ** in the name of the object stands for "virtual file system". 00702 ** 00703 ** The value of the iVersion field is initially 1 but may be larger in 00704 ** future versions of SQLite. Additional fields may be appended to this 00705 ** object when the iVersion value is increased. Note that the structure 00706 ** of the sqlite3_vfs object changes in the transaction between 00707 ** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not 00708 ** modified. 00709 ** 00710 ** The szOsFile field is the size of the subclassed [sqlite3_file] 00711 ** structure used by this VFS. mxPathname is the maximum length of 00712 ** a pathname in this VFS. 00713 ** 00714 ** Registered sqlite3_vfs objects are kept on a linked list formed by 00715 ** the pNext pointer. The [sqlite3_vfs_register()] 00716 ** and [sqlite3_vfs_unregister()] interfaces manage this list 00717 ** in a thread-safe way. The [sqlite3_vfs_find()] interface 00718 ** searches the list. Neither the application code nor the VFS 00719 ** implementation should use the pNext pointer. 00720 ** 00721 ** The pNext field is the only field in the sqlite3_vfs 00722 ** structure that SQLite will ever modify. SQLite will only access 00723 ** or modify this field while holding a particular static mutex. 00724 ** The application should never modify anything within the sqlite3_vfs 00725 ** object once the object has been registered. 00726 ** 00727 ** The zName field holds the name of the VFS module. The name must 00728 ** be unique across all VFS modules. 00729 ** 00730 ** SQLite will guarantee that the zFilename parameter to xOpen 00731 ** is either a NULL pointer or string obtained 00732 ** from xFullPathname(). SQLite further guarantees that 00733 ** the string will be valid and unchanged until xClose() is 00734 ** called. Because of the previous sentence, 00735 ** the [sqlite3_file] can safely store a pointer to the 00736 ** filename if it needs to remember the filename for some reason. 00737 ** If the zFilename parameter is xOpen is a NULL pointer then xOpen 00738 ** must invent its own temporary name for the file. Whenever the 00739 ** xFilename parameter is NULL it will also be the case that the 00740 ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE]. 00741 ** 00742 ** The flags argument to xOpen() includes all bits set in 00743 ** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()] 00744 ** or [sqlite3_open16()] is used, then flags includes at least 00745 ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]. 00746 ** If xOpen() opens a file read-only then it sets *pOutFlags to 00747 ** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set. 00748 ** 00749 ** SQLite will also add one of the following flags to the xOpen() 00750 ** call, depending on the object being opened: 00751 ** 00752 ** <ul> 00753 ** <li> [SQLITE_OPEN_MAIN_DB] 00754 ** <li> [SQLITE_OPEN_MAIN_JOURNAL] 00755 ** <li> [SQLITE_OPEN_TEMP_DB] 00756 ** <li> [SQLITE_OPEN_TEMP_JOURNAL] 00757 ** <li> [SQLITE_OPEN_TRANSIENT_DB] 00758 ** <li> [SQLITE_OPEN_SUBJOURNAL] 00759 ** <li> [SQLITE_OPEN_MASTER_JOURNAL] 00760 ** </ul> 00761 ** 00762 ** The file I/O implementation can use the object type flags to 00763 ** change the way it deals with files. For example, an application 00764 ** that does not care about crash recovery or rollback might make 00765 ** the open of a journal file a no-op. Writes to this journal would 00766 ** also be no-ops, and any attempt to read the journal would return 00767 ** SQLITE_IOERR. Or the implementation might recognize that a database 00768 ** file will be doing page-aligned sector reads and writes in a random 00769 ** order and set up its I/O subsystem accordingly. 00770 ** 00771 ** SQLite might also add one of the following flags to the xOpen method: 00772 ** 00773 ** <ul> 00774 ** <li> [SQLITE_OPEN_DELETEONCLOSE] 00775 ** <li> [SQLITE_OPEN_EXCLUSIVE] 00776 ** </ul> 00777 ** 00778 ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be 00779 ** deleted when it is closed. The [SQLITE_OPEN_DELETEONCLOSE] 00780 ** will be set for TEMP databases, journals and for subjournals. 00781 ** 00782 ** The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction 00783 ** with the [SQLITE_OPEN_CREATE] flag, which are both directly 00784 ** analogous to the O_EXCL and O_CREAT flags of the POSIX open() 00785 ** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the 00786 ** SQLITE_OPEN_CREATE, is used to indicate that file should always 00787 ** be created, and that it is an error if it already exists. 00788 ** It is <i>not</i> used to indicate the file should be opened 00789 ** for exclusive access. 00790 ** 00791 ** At least szOsFile bytes of memory are allocated by SQLite 00792 ** to hold the [sqlite3_file] structure passed as the third 00793 ** argument to xOpen. The xOpen method does not have to 00794 ** allocate the structure; it should just fill it in. Note that 00795 ** the xOpen method must set the sqlite3_file.pMethods to either 00796 ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do 00797 ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods 00798 ** element will be valid after xOpen returns regardless of the success 00799 ** or failure of the xOpen call. 00800 ** 00801 ** The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS] 00802 ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to 00803 ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ] 00804 ** to test whether a file is at least readable. The file can be a 00805 ** directory. 00806 ** 00807 ** SQLite will always allocate at least mxPathname+1 bytes for the 00808 ** output buffer xFullPathname. The exact size of the output buffer 00809 ** is also passed as a parameter to both methods. If the output buffer 00810 ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is 00811 ** handled as a fatal error by SQLite, vfs implementations should endeavor 00812 ** to prevent this by setting mxPathname to a sufficiently large value. 00813 ** 00814 ** The xRandomness(), xSleep(), and xCurrentTime() interfaces 00815 ** are not strictly a part of the filesystem, but they are 00816 ** included in the VFS structure for completeness. 00817 ** The xRandomness() function attempts to return nBytes bytes 00818 ** of good-quality randomness into zOut. The return value is 00819 ** the actual number of bytes of randomness obtained. 00820 ** The xSleep() method causes the calling thread to sleep for at 00821 ** least the number of microseconds given. The xCurrentTime() 00822 ** method returns a Julian Day Number for the current date and time. 00823 ** 00824 */ 00825 typedef struct sqlite3_vfs sqlite3_vfs; 00826 struct sqlite3_vfs { 00827 int iVersion; /* Structure version number */ 00828 int szOsFile; /* Size of subclassed sqlite3_file */ 00829 int mxPathname; /* Maximum file pathname length */ 00830 sqlite3_vfs *pNext; /* Next registered VFS */ 00831 const char *zName; /* Name of this virtual file system */ 00832 void *pAppData; /* Pointer to application-specific data */ 00833 int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*, 00834 int flags, int *pOutFlags); 00835 int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir); 00836 int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut); 00837 int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut); 00838 void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename); 00839 void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg); 00840 void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void); 00841 void (*xDlClose)(sqlite3_vfs*, void*); 00842 int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut); 00843 int (*xSleep)(sqlite3_vfs*, int microseconds); 00844 int (*xCurrentTime)(sqlite3_vfs*, double*); 00845 int (*xGetLastError)(sqlite3_vfs*, int, char *); 00846 /* New fields may be appended in figure versions. The iVersion 00847 ** value will increment whenever this happens. */ 00848 }; 00849 00850 /* 00851 ** CAPI3REF: Flags for the xAccess VFS method 00852 ** 00853 ** These integer constants can be used as the third parameter to 00854 ** the xAccess method of an [sqlite3_vfs] object. They determine 00855 ** what kind of permissions the xAccess method is looking for. 00856 ** With SQLITE_ACCESS_EXISTS, the xAccess method 00857 ** simply checks whether the file exists. 00858 ** With SQLITE_ACCESS_READWRITE, the xAccess method 00859 ** checks whether the file is both readable and writable. 00860 ** With SQLITE_ACCESS_READ, the xAccess method 00861 ** checks whether the file is readable. 00862 */ 00863 #define SQLITE_ACCESS_EXISTS 0 00864 #define SQLITE_ACCESS_READWRITE 1 00865 #define SQLITE_ACCESS_READ 2 00866 00867 /* 00868 ** CAPI3REF: Initialize The SQLite Library 00869 ** 00870 ** ^The sqlite3_initialize() routine initializes the 00871 ** SQLite library. ^The sqlite3_shutdown() routine 00872 ** deallocates any resources that were allocated by sqlite3_initialize(). 00873 ** These routines are designed to aid in process initialization and 00874 ** shutdown on embedded systems. Workstation applications using 00875 ** SQLite normally do not need to invoke either of these routines. 00876 ** 00877 ** A call to sqlite3_initialize() is an "effective" call if it is 00878 ** the first time sqlite3_initialize() is invoked during the lifetime of 00879 ** the process, or if it is the first time sqlite3_initialize() is invoked 00880 ** following a call to sqlite3_shutdown(). ^(Only an effective call 00881 ** of sqlite3_initialize() does any initialization. All other calls 00882 ** are harmless no-ops.)^ 00883 ** 00884 ** A call to sqlite3_shutdown() is an "effective" call if it is the first 00885 ** call to sqlite3_shutdown() since the last sqlite3_initialize(). ^(Only 00886 ** an effective call to sqlite3_shutdown() does any deinitialization. 00887 ** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^ 00888 ** 00889 ** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown() 00890 ** is not. The sqlite3_shutdown() interface must only be called from a 00891 ** single thread. All open [database connections] must be closed and all 00892 ** other SQLite resources must be deallocated prior to invoking 00893 ** sqlite3_shutdown(). 00894 ** 00895 ** Among other things, ^sqlite3_initialize() will invoke 00896 ** sqlite3_os_init(). Similarly, ^sqlite3_shutdown() 00897 ** will invoke sqlite3_os_end(). 00898 ** 00899 ** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success. 00900 ** ^If for some reason, sqlite3_initialize() is unable to initialize 00901 ** the library (perhaps it is unable to allocate a needed resource such 00902 ** as a mutex) it returns an [error code] other than [SQLITE_OK]. 00903 ** 00904 ** ^The sqlite3_initialize() routine is called internally by many other 00905 ** SQLite interfaces so that an application usually does not need to 00906 ** invoke sqlite3_initialize() directly. For example, [sqlite3_open()] 00907 ** calls sqlite3_initialize() so the SQLite library will be automatically 00908 ** initialized when [sqlite3_open()] is called if it has not be initialized 00909 ** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT] 00910 ** compile-time option, then the automatic calls to sqlite3_initialize() 00911 ** are omitted and the application must call sqlite3_initialize() directly 00912 ** prior to using any other SQLite interface. For maximum portability, 00913 ** it is recommended that applications always invoke sqlite3_initialize() 00914 ** directly prior to using any other SQLite interface. Future releases 00915 ** of SQLite may require this. In other words, the behavior exhibited 00916 ** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the 00917 ** default behavior in some future release of SQLite. 00918 ** 00919 ** The sqlite3_os_init() routine does operating-system specific 00920 ** initialization of the SQLite library. The sqlite3_os_end() 00921 ** routine undoes the effect of sqlite3_os_init(). Typical tasks 00922 ** performed by these routines include allocation or deallocation 00923 ** of static resources, initialization of global variables, 00924 ** setting up a default [sqlite3_vfs] module, or setting up 00925 ** a default configuration using [sqlite3_config()]. 00926 ** 00927 ** The application should never invoke either sqlite3_os_init() 00928 ** or sqlite3_os_end() directly. The application should only invoke 00929 ** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init() 00930 ** interface is called automatically by sqlite3_initialize() and 00931 ** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate 00932 ** implementations for sqlite3_os_init() and sqlite3_os_end() 00933 ** are built into SQLite when it is compiled for Unix, Windows, or OS/2. 00934 ** When [custom builds | built for other platforms] 00935 ** (using the [SQLITE_OS_OTHER=1] compile-time 00936 ** option) the application must supply a suitable implementation for 00937 ** sqlite3_os_init() and sqlite3_os_end(). An application-supplied 00938 ** implementation of sqlite3_os_init() or sqlite3_os_end() 00939 ** must return [SQLITE_OK] on success and some other [error code] upon 00940 ** failure. 00941 */ 00942 SQLITE_API int sqlite3_initialize(void); 00943 SQLITE_API int sqlite3_shutdown(void); 00944 SQLITE_API int sqlite3_os_init(void); 00945 SQLITE_API int sqlite3_os_end(void); 00946 00947 /* 00948 ** CAPI3REF: Configuring The SQLite Library 00949 ** 00950 ** The sqlite3_config() interface is used to make global configuration 00951 ** changes to SQLite in order to tune SQLite to the specific needs of 00952 ** the application. The default configuration is recommended for most 00953 ** applications and so this routine is usually not necessary. It is 00954 ** provided to support rare applications with unusual needs. 00955 ** 00956 ** The sqlite3_config() interface is not threadsafe. The application 00957 ** must insure that no other SQLite interfaces are invoked by other 00958 ** threads while sqlite3_config() is running. Furthermore, sqlite3_config() 00959 ** may only be invoked prior to library initialization using 00960 ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. 00961 ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before 00962 ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE. 00963 ** Note, however, that ^sqlite3_config() can be called as part of the 00964 ** implementation of an application-defined [sqlite3_os_init()]. 00965 ** 00966 ** The first argument to sqlite3_config() is an integer 00967 ** [SQLITE_CONFIG_SINGLETHREAD | configuration option] that determines 00968 ** what property of SQLite is to be configured. Subsequent arguments 00969 ** vary depending on the [SQLITE_CONFIG_SINGLETHREAD | configuration option] 00970 ** in the first argument. 00971 ** 00972 ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. 00973 ** ^If the option is unknown or SQLite is unable to set the option 00974 ** then this routine returns a non-zero [error code]. 00975 */ 00976 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_config(int, ...); 00977 00978 /* 00979 ** CAPI3REF: Configure database connections 00980 ** EXPERIMENTAL 00981 ** 00982 ** The sqlite3_db_config() interface is used to make configuration 00983 ** changes to a [database connection]. The interface is similar to 00984 ** [sqlite3_config()] except that the changes apply to a single 00985 ** [database connection] (specified in the first argument). The 00986 ** sqlite3_db_config() interface should only be used immediately after 00987 ** the database connection is created using [sqlite3_open()], 00988 ** [sqlite3_open16()], or [sqlite3_open_v2()]. 00989 ** 00990 ** The second argument to sqlite3_db_config(D,V,...) is the 00991 ** configuration verb - an integer code that indicates what 00992 ** aspect of the [database connection] is being configured. 00993 ** The only choice for this value is [SQLITE_DBCONFIG_LOOKASIDE]. 00994 ** New verbs are likely to be added in future releases of SQLite. 00995 ** Additional arguments depend on the verb. 00996 ** 00997 ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if 00998 ** the call is considered successful. 00999 */ 01000 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_db_config(sqlite3*, int op, ...); 01001 01002 /* 01003 ** CAPI3REF: Memory Allocation Routines 01004 ** EXPERIMENTAL 01005 ** 01006 ** An instance of this object defines the interface between SQLite 01007 ** and low-level memory allocation routines. 01008 ** 01009 ** This object is used in only one place in the SQLite interface. 01010 ** A pointer to an instance of this object is the argument to 01011 ** [sqlite3_config()] when the configuration option is 01012 ** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC]. 01013 ** By creating an instance of this object 01014 ** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC]) 01015 ** during configuration, an application can specify an alternative 01016 ** memory allocation subsystem for SQLite to use for all of its 01017 ** dynamic memory needs. 01018 ** 01019 ** Note that SQLite comes with several [built-in memory allocators] 01020 ** that are perfectly adequate for the overwhelming majority of applications 01021 ** and that this object is only useful to a tiny minority of applications 01022 ** with specialized memory allocation requirements. This object is 01023 ** also used during testing of SQLite in order to specify an alternative 01024 ** memory allocator that simulates memory out-of-memory conditions in 01025 ** order to verify that SQLite recovers gracefully from such 01026 ** conditions. 01027 ** 01028 ** The xMalloc and xFree methods must work like the 01029 ** malloc() and free() functions from the standard C library. 01030 ** The xRealloc method must work like realloc() from the standard C library 01031 ** with the exception that if the second argument to xRealloc is zero, 01032 ** xRealloc must be a no-op - it must not perform any allocation or 01033 ** deallocation. ^SQLite guarantees that the second argument to 01034 ** xRealloc is always a value returned by a prior call to xRoundup. 01035 ** And so in cases where xRoundup always returns a positive number, 01036 ** xRealloc can perform exactly as the standard library realloc() and 01037 ** still be in compliance with this specification. 01038 ** 01039 ** xSize should return the allocated size of a memory allocation 01040 ** previously obtained from xMalloc or xRealloc. The allocated size 01041 ** is always at least as big as the requested size but may be larger. 01042 ** 01043 ** The xRoundup method returns what would be the allocated size of 01044 ** a memory allocation given a particular requested size. Most memory 01045 ** allocators round up memory allocations at least to the next multiple 01046 ** of 8. Some allocators round up to a larger multiple or to a power of 2. 01047 ** Every memory allocation request coming in through [sqlite3_malloc()] 01048 ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0, 01049 ** that causes the corresponding memory allocation to fail. 01050 ** 01051 ** The xInit method initializes the memory allocator. (For example, 01052 ** it might allocate any require mutexes or initialize internal data 01053 ** structures. The xShutdown method is invoked (indirectly) by 01054 ** [sqlite3_shutdown()] and should deallocate any resources acquired 01055 ** by xInit. The pAppData pointer is used as the only parameter to 01056 ** xInit and xShutdown. 01057 ** 01058 ** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes 01059 ** the xInit method, so the xInit method need not be threadsafe. The 01060 ** xShutdown method is only called from [sqlite3_shutdown()] so it does 01061 ** not need to be threadsafe either. For all other methods, SQLite 01062 ** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the 01063 ** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which 01064 ** it is by default) and so the methods are automatically serialized. 01065 ** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other 01066 ** methods must be threadsafe or else make their own arrangements for 01067 ** serialization. 01068 ** 01069 ** SQLite will never invoke xInit() more than once without an intervening 01070 ** call to xShutdown(). 01071 */ 01072 typedef struct sqlite3_mem_methods sqlite3_mem_methods; 01073 struct sqlite3_mem_methods { 01074 void *(*xMalloc)(int); /* Memory allocation function */ 01075 void (*xFree)(void*); /* Free a prior allocation */ 01076 void *(*xRealloc)(void*,int); /* Resize an allocation */ 01077 int (*xSize)(void*); /* Return the size of an allocation */ 01078 int (*xRoundup)(int); /* Round up request size to allocation size */ 01079 int (*xInit)(void*); /* Initialize the memory allocator */ 01080 void (*xShutdown)(void*); /* Deinitialize the memory allocator */ 01081 void *pAppData; /* Argument to xInit() and xShutdown() */ 01082 }; 01083 01084 /* 01085 ** CAPI3REF: Configuration Options 01086 ** EXPERIMENTAL 01087 ** 01088 ** These constants are the available integer configuration options that 01089 ** can be passed as the first argument to the [sqlite3_config()] interface. 01090 ** 01091 ** New configuration options may be added in future releases of SQLite. 01092 ** Existing configuration options might be discontinued. Applications 01093 ** should check the return code from [sqlite3_config()] to make sure that 01094 ** the call worked. The [sqlite3_config()] interface will return a 01095 ** non-zero [error code] if a discontinued or unsupported configuration option 01096 ** is invoked. 01097 ** 01098 ** <dl> 01099 ** <dt>SQLITE_CONFIG_SINGLETHREAD</dt> 01100 ** <dd>There are no arguments to this option. ^This option sets the 01101 ** [threading mode] to Single-thread. In other words, it disables 01102 ** all mutexing and puts SQLite into a mode where it can only be used 01103 ** by a single thread. ^If SQLite is compiled with 01104 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 01105 ** it is not possible to change the [threading mode] from its default 01106 ** value of Single-thread and so [sqlite3_config()] will return 01107 ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD 01108 ** configuration option.</dd> 01109 ** 01110 ** <dt>SQLITE_CONFIG_MULTITHREAD</dt> 01111 ** <dd>There are no arguments to this option. ^This option sets the 01112 ** [threading mode] to Multi-thread. In other words, it disables 01113 ** mutexing on [database connection] and [prepared statement] objects. 01114 ** The application is responsible for serializing access to 01115 ** [database connections] and [prepared statements]. But other mutexes 01116 ** are enabled so that SQLite will be safe to use in a multi-threaded 01117 ** environment as long as no two threads attempt to use the same 01118 ** [database connection] at the same time. ^If SQLite is compiled with 01119 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 01120 ** it is not possible to set the Multi-thread [threading mode] and 01121 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the 01122 ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd> 01123 ** 01124 ** <dt>SQLITE_CONFIG_SERIALIZED</dt> 01125 ** <dd>There are no arguments to this option. ^This option sets the 01126 ** [threading mode] to Serialized. In other words, this option enables 01127 ** all mutexes including the recursive 01128 ** mutexes on [database connection] and [prepared statement] objects. 01129 ** In this mode (which is the default when SQLite is compiled with 01130 ** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access 01131 ** to [database connections] and [prepared statements] so that the 01132 ** application is free to use the same [database connection] or the 01133 ** same [prepared statement] in different threads at the same time. 01134 ** ^If SQLite is compiled with 01135 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 01136 ** it is not possible to set the Serialized [threading mode] and 01137 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the 01138 ** SQLITE_CONFIG_SERIALIZED configuration option.</dd> 01139 ** 01140 ** <dt>SQLITE_CONFIG_MALLOC</dt> 01141 ** <dd> ^(This option takes a single argument which is a pointer to an 01142 ** instance of the [sqlite3_mem_methods] structure. The argument specifies 01143 ** alternative low-level memory allocation routines to be used in place of 01144 ** the memory allocation routines built into SQLite.)^ ^SQLite makes 01145 ** its own private copy of the content of the [sqlite3_mem_methods] structure 01146 ** before the [sqlite3_config()] call returns.</dd> 01147 ** 01148 ** <dt>SQLITE_CONFIG_GETMALLOC</dt> 01149 ** <dd> ^(This option takes a single argument which is a pointer to an 01150 ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods] 01151 ** structure is filled with the currently defined memory allocation routines.)^ 01152 ** This option can be used to overload the default memory allocation 01153 ** routines with a wrapper that simulations memory allocation failure or 01154 ** tracks memory usage, for example. </dd> 01155 ** 01156 ** <dt>SQLITE_CONFIG_MEMSTATUS</dt> 01157 ** <dd> ^This option takes single argument of type int, interpreted as a 01158 ** boolean, which enables or disables the collection of memory allocation 01159 ** statistics. ^(When memory allocation statistics are disabled, the 01160 ** following SQLite interfaces become non-operational: 01161 ** <ul> 01162 ** <li> [sqlite3_memory_used()] 01163 ** <li> [sqlite3_memory_highwater()] 01164 ** <li> [sqlite3_soft_heap_limit()] 01165 ** <li> [sqlite3_status()] 01166 ** </ul>)^ 01167 ** ^Memory allocation statistics are enabled by default unless SQLite is 01168 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory 01169 ** allocation statistics are disabled by default. 01170 ** </dd> 01171 ** 01172 ** <dt>SQLITE_CONFIG_SCRATCH</dt> 01173 ** <dd> ^This option specifies a static memory buffer that SQLite can use for 01174 ** scratch memory. There are three arguments: A pointer an 8-byte 01175 ** aligned memory buffer from which the scrach allocations will be 01176 ** drawn, the size of each scratch allocation (sz), 01177 ** and the maximum number of scratch allocations (N). The sz 01178 ** argument must be a multiple of 16. The sz parameter should be a few bytes 01179 ** larger than the actual scratch space required due to internal overhead. 01180 ** The first argument must be a pointer to an 8-byte aligned buffer 01181 ** of at least sz*N bytes of memory. 01182 ** ^SQLite will use no more than one scratch buffer per thread. So 01183 ** N should be set to the expected maximum number of threads. ^SQLite will 01184 ** never require a scratch buffer that is more than 6 times the database 01185 ** page size. ^If SQLite needs needs additional scratch memory beyond 01186 ** what is provided by this configuration option, then 01187 ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd> 01188 ** 01189 ** <dt>SQLITE_CONFIG_PAGECACHE</dt> 01190 ** <dd> ^This option specifies a static memory buffer that SQLite can use for 01191 ** the database page cache with the default page cache implemenation. 01192 ** This configuration should not be used if an application-define page 01193 ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option. 01194 ** There are three arguments to this option: A pointer to 8-byte aligned 01195 ** memory, the size of each page buffer (sz), and the number of pages (N). 01196 ** The sz argument should be the size of the largest database page 01197 ** (a power of two between 512 and 32768) plus a little extra for each 01198 ** page header. ^The page header size is 20 to 40 bytes depending on 01199 ** the host architecture. ^It is harmless, apart from the wasted memory, 01200 ** to make sz a little too large. The first 01201 ** argument should point to an allocation of at least sz*N bytes of memory. 01202 ** ^SQLite will use the memory provided by the first argument to satisfy its 01203 ** memory needs for the first N pages that it adds to cache. ^If additional 01204 ** page cache memory is needed beyond what is provided by this option, then 01205 ** SQLite goes to [sqlite3_malloc()] for the additional storage space. 01206 ** ^The implementation might use one or more of the N buffers to hold 01207 ** memory accounting information. The pointer in the first argument must 01208 ** be aligned to an 8-byte boundary or subsequent behavior of SQLite 01209 ** will be undefined.</dd> 01210 ** 01211 ** <dt>SQLITE_CONFIG_HEAP</dt> 01212 ** <dd> ^This option specifies a static memory buffer that SQLite will use 01213 ** for all of its dynamic memory allocation needs beyond those provided 01214 ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. 01215 ** There are three arguments: An 8-byte aligned pointer to the memory, 01216 ** the number of bytes in the memory buffer, and the minimum allocation size. 01217 ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts 01218 ** to using its default memory allocator (the system malloc() implementation), 01219 ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the 01220 ** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or 01221 ** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory 01222 ** allocator is engaged to handle all of SQLites memory allocation needs. 01223 ** The first pointer (the memory pointer) must be aligned to an 8-byte 01224 ** boundary or subsequent behavior of SQLite will be undefined.</dd> 01225 ** 01226 ** <dt>SQLITE_CONFIG_MUTEX</dt> 01227 ** <dd> ^(This option takes a single argument which is a pointer to an 01228 ** instance of the [sqlite3_mutex_methods] structure. The argument specifies 01229 ** alternative low-level mutex routines to be used in place 01230 ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the 01231 ** content of the [sqlite3_mutex_methods] structure before the call to 01232 ** [sqlite3_config()] returns. ^If SQLite is compiled with 01233 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 01234 ** the entire mutexing subsystem is omitted from the build and hence calls to 01235 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will 01236 ** return [SQLITE_ERROR].</dd> 01237 ** 01238 ** <dt>SQLITE_CONFIG_GETMUTEX</dt> 01239 ** <dd> ^(This option takes a single argument which is a pointer to an 01240 ** instance of the [sqlite3_mutex_methods] structure. The 01241 ** [sqlite3_mutex_methods] 01242 ** structure is filled with the currently defined mutex routines.)^ 01243 ** This option can be used to overload the default mutex allocation 01244 ** routines with a wrapper used to track mutex usage for performance 01245 ** profiling or testing, for example. ^If SQLite is compiled with 01246 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 01247 ** the entire mutexing subsystem is omitted from the build and hence calls to 01248 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will 01249 ** return [SQLITE_ERROR].</dd> 01250 ** 01251 ** <dt>SQLITE_CONFIG_LOOKASIDE</dt> 01252 ** <dd> ^(This option takes two arguments that determine the default 01253 ** memory allocation for the lookaside memory allocator on each 01254 ** [database connection]. The first argument is the 01255 ** size of each lookaside buffer slot and the second is the number of 01256 ** slots allocated to each database connection.)^ ^(This option sets the 01257 ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] 01258 ** verb to [sqlite3_db_config()] can be used to change the lookaside 01259 ** configuration on individual connections.)^ </dd> 01260 ** 01261 ** <dt>SQLITE_CONFIG_PCACHE</dt> 01262 ** <dd> ^(This option takes a single argument which is a pointer to 01263 ** an [sqlite3_pcache_methods] object. This object specifies the interface 01264 ** to a custom page cache implementation.)^ ^SQLite makes a copy of the 01265 ** object and uses it for page cache memory allocations.</dd> 01266 ** 01267 ** <dt>SQLITE_CONFIG_GETPCACHE</dt> 01268 ** <dd> ^(This option takes a single argument which is a pointer to an 01269 ** [sqlite3_pcache_methods] object. SQLite copies of the current 01270 ** page cache implementation into that object.)^ </dd> 01271 ** 01272 ** </dl> 01273 */ 01274 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ 01275 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ 01276 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ 01277 #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ 01278 #define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */ 01279 #define SQLITE_CONFIG_SCRATCH 6 /* void*, int sz, int N */ 01280 #define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */ 01281 #define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */ 01282 #define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */ 01283 #define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */ 01284 #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */ 01285 /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ 01286 #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ 01287 #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */ 01288 #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */ 01289 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ 01290 01291 /* 01292 ** CAPI3REF: Configuration Options 01293 ** EXPERIMENTAL 01294 ** 01295 ** These constants are the available integer configuration options that 01296 ** can be passed as the second argument to the [sqlite3_db_config()] interface. 01297 ** 01298 ** New configuration options may be added in future releases of SQLite. 01299 ** Existing configuration options might be discontinued. Applications 01300 ** should check the return code from [sqlite3_db_config()] to make sure that 01301 ** the call worked. ^The [sqlite3_db_config()] interface will return a 01302 ** non-zero [error code] if a discontinued or unsupported configuration option 01303 ** is invoked. 01304 ** 01305 ** <dl> 01306 ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt> 01307 ** <dd> ^This option takes three additional arguments that determine the 01308 ** [lookaside memory allocator] configuration for the [database connection]. 01309 ** ^The first argument (the third parameter to [sqlite3_db_config()] is a 01310 ** pointer to an memory buffer to use for lookaside memory. 01311 ** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb 01312 ** may be NULL in which case SQLite will allocate the 01313 ** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the 01314 ** size of each lookaside buffer slot. ^The third argument is the number of 01315 ** slots. The size of the buffer in the first argument must be greater than 01316 ** or equal to the product of the second and third arguments. The buffer 01317 ** must be aligned to an 8-byte boundary. ^If the second argument to 01318 ** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally 01319 ** rounded down to the next smaller 01320 ** multiple of 8. See also: [SQLITE_CONFIG_LOOKASIDE]</dd> 01321 ** 01322 ** </dl> 01323 */ 01324 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */ 01325 01326 01327 /* 01328 ** CAPI3REF: Enable Or Disable Extended Result Codes 01329 ** 01330 ** ^The sqlite3_extended_result_codes() routine enables or disables the 01331 ** [extended result codes] feature of SQLite. ^The extended result 01332 ** codes are disabled by default for historical compatibility. 01333 */ 01334 SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff); 01335 01336 /* 01337 ** CAPI3REF: Last Insert Rowid 01338 ** 01339 ** ^Each entry in an SQLite table has a unique 64-bit signed 01340 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available 01341 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those 01342 ** names are not also used by explicitly declared columns. ^If 01343 ** the table has a column of type [INTEGER PRIMARY KEY] then that column 01344 ** is another alias for the rowid. 01345 ** 01346 ** ^This routine returns the [rowid] of the most recent 01347 ** successful [INSERT] into the database from the [database connection] 01348 ** in the first argument. ^If no successful [INSERT]s 01349 ** have ever occurred on that database connection, zero is returned. 01350 ** 01351 ** ^(If an [INSERT] occurs within a trigger, then the [rowid] of the inserted 01352 ** row is returned by this routine as long as the trigger is running. 01353 ** But once the trigger terminates, the value returned by this routine 01354 ** reverts to the last value inserted before the trigger fired.)^ 01355 ** 01356 ** ^An [INSERT] that fails due to a constraint violation is not a 01357 ** successful [INSERT] and does not change the value returned by this 01358 ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK, 01359 ** and INSERT OR ABORT make no changes to the return value of this 01360 ** routine when their insertion fails. ^(When INSERT OR REPLACE 01361 ** encounters a constraint violation, it does not fail. The 01362 ** INSERT continues to completion after deleting rows that caused 01363 ** the constraint problem so INSERT OR REPLACE will always change 01364 ** the return value of this interface.)^ 01365 ** 01366 ** ^For the purposes of this routine, an [INSERT] is considered to 01367 ** be successful even if it is subsequently rolled back. 01368 ** 01369 ** This function is accessible to SQL statements via the 01370 ** [last_insert_rowid() SQL function]. 01371 ** 01372 ** If a separate thread performs a new [INSERT] on the same 01373 ** database connection while the [sqlite3_last_insert_rowid()] 01374 ** function is running and thus changes the last insert [rowid], 01375 ** then the value returned by [sqlite3_last_insert_rowid()] is 01376 ** unpredictable and might not equal either the old or the new 01377 ** last insert [rowid]. 01378 */ 01379 SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); 01380 01381 /* 01382 ** CAPI3REF: Count The Number Of Rows Modified 01383 ** 01384 ** ^This function returns the number of database rows that were changed 01385 ** or inserted or deleted by the most recently completed SQL statement 01386 ** on the [database connection] specified by the first parameter. 01387 ** ^(Only changes that are directly specified by the [INSERT], [UPDATE], 01388 ** or [DELETE] statement are counted. Auxiliary changes caused by 01389 ** triggers or [foreign key actions] are not counted.)^ Use the 01390 ** [sqlite3_total_changes()] function to find the total number of changes 01391 ** including changes caused by triggers and foreign key actions. 01392 ** 01393 ** ^Changes to a view that are simulated by an [INSTEAD OF trigger] 01394 ** are not counted. Only real table changes are counted. 01395 ** 01396 ** ^(A "row change" is a change to a single row of a single table 01397 ** caused by an INSERT, DELETE, or UPDATE statement. Rows that 01398 ** are changed as side effects of [REPLACE] constraint resolution, 01399 ** rollback, ABORT processing, [DROP TABLE], or by any other 01400 ** mechanisms do not count as direct row changes.)^ 01401 ** 01402 ** A "trigger context" is a scope of execution that begins and 01403 ** ends with the script of a [CREATE TRIGGER | trigger]. 01404 ** Most SQL statements are 01405 ** evaluated outside of any trigger. This is the "top level" 01406 ** trigger context. If a trigger fires from the top level, a 01407 ** new trigger context is entered for the duration of that one 01408 ** trigger. Subtriggers create subcontexts for their duration. 01409 ** 01410 ** ^Calling [sqlite3_exec()] or [sqlite3_step()] recursively does 01411 ** not create a new trigger context. 01412 ** 01413 ** ^This function returns the number of direct row changes in the 01414 ** most recent INSERT, UPDATE, or DELETE statement within the same 01415 ** trigger context. 01416 ** 01417 ** ^Thus, when called from the top level, this function returns the 01418 ** number of changes in the most recent INSERT, UPDATE, or DELETE 01419 ** that also occurred at the top level. ^(Within the body of a trigger, 01420 ** the sqlite3_changes() interface can be called to find the number of 01421 ** changes in the most recently completed INSERT, UPDATE, or DELETE 01422 ** statement within the body of the same trigger. 01423 ** However, the number returned does not include changes 01424 ** caused by subtriggers since those have their own context.)^ 01425 ** 01426 ** See also the [sqlite3_total_changes()] interface, the 01427 ** [count_changes pragma], and the [changes() SQL function]. 01428 ** 01429 ** If a separate thread makes changes on the same database connection 01430 ** while [sqlite3_changes()] is running then the value returned 01431 ** is unpredictable and not meaningful. 01432 */ 01433 SQLITE_API int sqlite3_changes(sqlite3*); 01434 01435 /* 01436 ** CAPI3REF: Total Number Of Rows Modified 01437 ** 01438 ** ^This function returns the number of row changes caused by [INSERT], 01439 ** [UPDATE] or [DELETE] statements since the [database connection] was opened. 01440 ** ^(The count returned by sqlite3_total_changes() includes all changes 01441 ** from all [CREATE TRIGGER | trigger] contexts and changes made by 01442 ** [foreign key actions]. However, 01443 ** the count does not include changes used to implement [REPLACE] constraints, 01444 ** do rollbacks or ABORT processing, or [DROP TABLE] processing. The 01445 ** count does not include rows of views that fire an [INSTEAD OF trigger], 01446 ** though if the INSTEAD OF trigger makes changes of its own, those changes 01447 ** are counted.)^ 01448 ** ^The sqlite3_total_changes() function counts the changes as soon as 01449 ** the statement that makes them is completed (when the statement handle 01450 ** is passed to [sqlite3_reset()] or [sqlite3_finalize()]). 01451 ** 01452 ** See also the [sqlite3_changes()] interface, the 01453 ** [count_changes pragma], and the [total_changes() SQL function]. 01454 ** 01455 ** If a separate thread makes changes on the same database connection 01456 ** while [sqlite3_total_changes()] is running then the value 01457 ** returned is unpredictable and not meaningful. 01458 */ 01459 SQLITE_API int sqlite3_total_changes(sqlite3*); 01460 01461 /* 01462 ** CAPI3REF: Interrupt A Long-Running Query 01463 ** 01464 ** ^This function causes any pending database operation to abort and 01465 ** return at its earliest opportunity. This routine is typically 01466 ** called in response to a user action such as pressing "Cancel" 01467 ** or Ctrl-C where the user wants a long query operation to halt 01468 ** immediately. 01469 ** 01470 ** ^It is safe to call this routine from a thread different from the 01471 ** thread that is currently running the database operation. But it 01472 ** is not safe to call this routine with a [database connection] that 01473 ** is closed or might close before sqlite3_interrupt() returns. 01474 ** 01475 ** ^If an SQL operation is very nearly finished at the time when 01476 ** sqlite3_interrupt() is called, then it might not have an opportunity 01477 ** to be interrupted and might continue to completion. 01478 ** 01479 ** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT]. 01480 ** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE 01481 ** that is inside an explicit transaction, then the entire transaction 01482 ** will be rolled back automatically. 01483 ** 01484 ** ^The sqlite3_interrupt(D) call is in effect until all currently running 01485 ** SQL statements on [database connection] D complete. ^Any new SQL statements 01486 ** that are started after the sqlite3_interrupt() call and before the 01487 ** running statements reaches zero are interrupted as if they had been 01488 ** running prior to the sqlite3_interrupt() call. ^New SQL statements 01489 ** that are started after the running statement count reaches zero are 01490 ** not effected by the sqlite3_interrupt(). 01491 ** ^A call to sqlite3_interrupt(D) that occurs when there are no running 01492 ** SQL statements is a no-op and has no effect on SQL statements 01493 ** that are started after the sqlite3_interrupt() call returns. 01494 ** 01495 ** If the database connection closes while [sqlite3_interrupt()] 01496 ** is running then bad things will likely happen. 01497 */ 01498 SQLITE_API void sqlite3_interrupt(sqlite3*); 01499 01500 /* 01501 ** CAPI3REF: Determine If An SQL Statement Is Complete 01502 ** 01503 ** These routines are useful during command-line input to determine if the 01504 ** currently entered text seems to form a complete SQL statement or 01505 ** if additional input is needed before sending the text into 01506 ** SQLite for parsing. ^These routines return 1 if the input string 01507 ** appears to be a complete SQL statement. ^A statement is judged to be 01508 ** complete if it ends with a semicolon token and is not a prefix of a 01509 ** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within 01510 ** string literals or quoted identifier names or comments are not 01511 ** independent tokens (they are part of the token in which they are 01512 ** embedded) and thus do not count as a statement terminator. ^Whitespace 01513 ** and comments that follow the final semicolon are ignored. 01514 ** 01515 ** ^These routines return 0 if the statement is incomplete. ^If a 01516 ** memory allocation fails, then SQLITE_NOMEM is returned. 01517 ** 01518 ** ^These routines do not parse the SQL statements thus 01519 ** will not detect syntactically incorrect SQL. 01520 ** 01521 ** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior 01522 ** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked 01523 ** automatically by sqlite3_complete16(). If that initialization fails, 01524 ** then the return value from sqlite3_complete16() will be non-zero 01525 ** regardless of whether or not the input SQL is complete.)^ 01526 ** 01527 ** The input to [sqlite3_complete()] must be a zero-terminated 01528 ** UTF-8 string. 01529 ** 01530 ** The input to [sqlite3_complete16()] must be a zero-terminated 01531 ** UTF-16 string in native byte order. 01532 */ 01533 SQLITE_API int sqlite3_complete(const char *sql); 01534 SQLITE_API int sqlite3_complete16(const void *sql); 01535 01536 /* 01537 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors 01538 ** 01539 ** ^This routine sets a callback function that might be invoked whenever 01540 ** an attempt is made to open a database table that another thread 01541 ** or process has locked. 01542 ** 01543 ** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] 01544 ** is returned immediately upon encountering the lock. ^If the busy callback 01545 ** is not NULL, then the callback might be invoked with two arguments. 01546 ** 01547 ** ^The first argument to the busy handler is a copy of the void* pointer which 01548 ** is the third argument to sqlite3_busy_handler(). ^The second argument to 01549 ** the busy handler callback is the number of times that the busy handler has 01550 ** been invoked for this locking event. ^If the 01551 ** busy callback returns 0, then no additional attempts are made to 01552 ** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned. 01553 ** ^If the callback returns non-zero, then another attempt 01554 ** is made to open the database for reading and the cycle repeats. 01555 ** 01556 ** The presence of a busy handler does not guarantee that it will be invoked 01557 ** when there is lock contention. ^If SQLite determines that invoking the busy 01558 ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY] 01559 ** or [SQLITE_IOERR_BLOCKED] instead of invoking the busy handler. 01560 ** Consider a scenario where one process is holding a read lock that 01561 ** it is trying to promote to a reserved lock and 01562 ** a second process is holding a reserved lock that it is trying 01563 ** to promote to an exclusive lock. The first process cannot proceed 01564 ** because it is blocked by the second and the second process cannot 01565 ** proceed because it is blocked by the first. If both processes 01566 ** invoke the busy handlers, neither will make any progress. Therefore, 01567 ** SQLite returns [SQLITE_BUSY] for the first process, hoping that this 01568 ** will induce the first process to release its read lock and allow 01569 ** the second process to proceed. 01570 ** 01571 ** ^The default busy callback is NULL. 01572 ** 01573 ** ^The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED] 01574 ** when SQLite is in the middle of a large transaction where all the 01575 ** changes will not fit into the in-memory cache. SQLite will 01576 ** already hold a RESERVED lock on the database file, but it needs 01577 ** to promote this lock to EXCLUSIVE so that it can spill cache 01578 ** pages into the database file without harm to concurrent 01579 ** readers. ^If it is unable to promote the lock, then the in-memory 01580 ** cache will be left in an inconsistent state and so the error 01581 ** code is promoted from the relatively benign [SQLITE_BUSY] to 01582 ** the more severe [SQLITE_IOERR_BLOCKED]. ^This error code promotion 01583 ** forces an automatic rollback of the changes. See the 01584 ** <a href="/cvstrac/wiki?p=CorruptionFollowingBusyError"> 01585 ** CorruptionFollowingBusyError</a> wiki page for a discussion of why 01586 ** this is important. 01587 ** 01588 ** ^(There can only be a single busy handler defined for each 01589 ** [database connection]. Setting a new busy handler clears any 01590 ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()] 01591 ** will also set or clear the busy handler. 01592 ** 01593 ** The busy callback should not take any actions which modify the 01594 ** database connection that invoked the busy handler. Any such actions 01595 ** result in undefined behavior. 01596 ** 01597 ** A busy handler must not close the database connection 01598 ** or [prepared statement] that invoked the busy handler. 01599 */ 01600 SQLITE_API int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*); 01601 01602 /* 01603 ** CAPI3REF: Set A Busy Timeout 01604 ** 01605 ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps 01606 ** for a specified amount of time when a table is locked. ^The handler 01607 ** will sleep multiple times until at least "ms" milliseconds of sleeping 01608 ** have accumulated. ^After at least "ms" milliseconds of sleeping, 01609 ** the handler returns 0 which causes [sqlite3_step()] to return 01610 ** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]. 01611 ** 01612 ** ^Calling this routine with an argument less than or equal to zero 01613 ** turns off all busy handlers. 01614 ** 01615 ** ^(There can only be a single busy handler for a particular 01616 ** [database connection] any any given moment. If another busy handler 01617 ** was defined (using [sqlite3_busy_handler()]) prior to calling 01618 ** this routine, that other busy handler is cleared.)^ 01619 */ 01620 SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms); 01621 01622 /* 01623 ** CAPI3REF: Convenience Routines For Running Queries 01624 ** 01625 ** Definition: A <b>result table</b> is memory data structure created by the 01626 ** [sqlite3_get_table()] interface. A result table records the 01627 ** complete query results from one or more queries. 01628 ** 01629 ** The table conceptually has a number of rows and columns. But 01630 ** these numbers are not part of the result table itself. These 01631 ** numbers are obtained separately. Let N be the number of rows 01632 ** and M be the number of columns. 01633 ** 01634 ** A result table is an array of pointers to zero-terminated UTF-8 strings. 01635 ** There are (N+1)*M elements in the array. The first M pointers point 01636 ** to zero-terminated strings that contain the names of the columns. 01637 ** The remaining entries all point to query results. NULL values result 01638 ** in NULL pointers. All other values are in their UTF-8 zero-terminated 01639 ** string representation as returned by [sqlite3_column_text()]. 01640 ** 01641 ** A result table might consist of one or more memory allocations. 01642 ** It is not safe to pass a result table directly to [sqlite3_free()]. 01643 ** A result table should be deallocated using [sqlite3_free_table()]. 01644 ** 01645 ** As an example of the result table format, suppose a query result 01646 ** is as follows: 01647 ** 01648 ** <blockquote><pre> 01649 ** Name | Age 01650 ** ----------------------- 01651 ** Alice | 43 01652 ** Bob | 28 01653 ** Cindy | 21 01654 ** </pre></blockquote> 01655 ** 01656 ** There are two column (M==2) and three rows (N==3). Thus the 01657 ** result table has 8 entries. Suppose the result table is stored 01658 ** in an array names azResult. Then azResult holds this content: 01659 ** 01660 ** <blockquote><pre> 01661 ** azResult[0] = "Name"; 01662 ** azResult[1] = "Age"; 01663 ** azResult[2] = "Alice"; 01664 ** azResult[3] = "43"; 01665 ** azResult[4] = "Bob"; 01666 ** azResult[5] = "28"; 01667 ** azResult[6] = "Cindy"; 01668 ** azResult[7] = "21"; 01669 ** </pre></blockquote> 01670 ** 01671 ** ^The sqlite3_get_table() function evaluates one or more 01672 ** semicolon-separated SQL statements in the zero-terminated UTF-8 01673 ** string of its 2nd parameter and returns a result table to the 01674 ** pointer given in its 3rd parameter. 01675 ** 01676 ** After the application has finished with the result from sqlite3_get_table(), 01677 ** it should pass the result table pointer to sqlite3_free_table() in order to 01678 ** release the memory that was malloced. Because of the way the 01679 ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling 01680 ** function must not try to call [sqlite3_free()] directly. Only 01681 ** [sqlite3_free_table()] is able to release the memory properly and safely. 01682 ** 01683 ** ^(The sqlite3_get_table() interface is implemented as a wrapper around 01684 ** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access 01685 ** to any internal data structures of SQLite. It uses only the public 01686 ** interface defined here. As a consequence, errors that occur in the 01687 ** wrapper layer outside of the internal [sqlite3_exec()] call are not 01688 ** reflected in subsequent calls to [sqlite3_errcode()] or 01689 ** [sqlite3_errmsg()].)^ 01690 */ 01691 SQLITE_API int sqlite3_get_table( 01692 sqlite3 *db, /* An open database */ 01693 const char *zSql, /* SQL to be evaluated */ 01694 char ***pazResult, /* Results of the query */ 01695 int *pnRow, /* Number of result rows written here */ 01696 int *pnColumn, /* Number of result columns written here */ 01697 char **pzErrmsg /* Error msg written here */ 01698 ); 01699 SQLITE_API void sqlite3_free_table(char **result); 01700 01701 /* 01702 ** CAPI3REF: Formatted String Printing Functions 01703 ** 01704 ** These routines are work-alikes of the "printf()" family of functions 01705 ** from the standard C library. 01706 ** 01707 ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their 01708 ** results into memory obtained from [sqlite3_malloc()]. 01709 ** The strings returned by these two routines should be 01710 ** released by [sqlite3_free()]. ^Both routines return a 01711 ** NULL pointer if [sqlite3_malloc()] is unable to allocate enough 01712 ** memory to hold the resulting string. 01713 ** 01714 ** ^(In sqlite3_snprintf() routine is similar to "snprintf()" from 01715 ** the standard C library. The result is written into the 01716 ** buffer supplied as the second parameter whose size is given by 01717 ** the first parameter. Note that the order of the 01718 ** first two parameters is reversed from snprintf().)^ This is an 01719 ** historical accident that cannot be fixed without breaking 01720 ** backwards compatibility. ^(Note also that sqlite3_snprintf() 01721 ** returns a pointer to its buffer instead of the number of 01722 ** characters actually written into the buffer.)^ We admit that 01723 ** the number of characters written would be a more useful return 01724 ** value but we cannot change the implementation of sqlite3_snprintf() 01725 ** now without breaking compatibility. 01726 ** 01727 ** ^As long as the buffer size is greater than zero, sqlite3_snprintf() 01728 ** guarantees that the buffer is always zero-terminated. ^The first 01729 ** parameter "n" is the total size of the buffer, including space for 01730 ** the zero terminator. So the longest string that can be completely 01731 ** written will be n-1 characters. 01732 ** 01733 ** These routines all implement some additional formatting 01734 ** options that are useful for constructing SQL statements. 01735 ** All of the usual printf() formatting options apply. In addition, there 01736 ** is are "%q", "%Q", and "%z" options. 01737 ** 01738 ** ^(The %q option works like %s in that it substitutes a null-terminated 01739 ** string from the argument list. But %q also doubles every '\'' character. 01740 ** %q is designed for use inside a string literal.)^ By doubling each '\'' 01741 ** character it escapes that character and allows it to be inserted into 01742 ** the string. 01743 ** 01744 ** For example, assume the string variable zText contains text as follows: 01745 ** 01746 ** <blockquote><pre> 01747 ** char *zText = "It's a happy day!"; 01748 ** </pre></blockquote> 01749 ** 01750 ** One can use this text in an SQL statement as follows: 01751 ** 01752 ** <blockquote><pre> 01753 ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText); 01754 ** sqlite3_exec(db, zSQL, 0, 0, 0); 01755 ** sqlite3_free(zSQL); 01756 ** </pre></blockquote> 01757 ** 01758 ** Because the %q format string is used, the '\'' character in zText 01759 ** is escaped and the SQL generated is as follows: 01760 ** 01761 ** <blockquote><pre> 01762 ** INSERT INTO table1 VALUES('It''s a happy day!') 01763 ** </pre></blockquote> 01764 ** 01765 ** This is correct. Had we used %s instead of %q, the generated SQL 01766 ** would have looked like this: 01767 ** 01768 ** <blockquote><pre> 01769 ** INSERT INTO table1 VALUES('It's a happy day!'); 01770 ** </pre></blockquote> 01771 ** 01772 ** This second example is an SQL syntax error. As a general rule you should 01773 ** always use %q instead of %s when inserting text into a string literal. 01774 ** 01775 ** ^(The %Q option works like %q except it also adds single quotes around 01776 ** the outside of the total string. Additionally, if the parameter in the 01777 ** argument list is a NULL pointer, %Q substitutes the text "NULL" (without 01778 ** single quotes).)^ So, for example, one could say: 01779 ** 01780 ** <blockquote><pre> 01781 ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText); 01782 ** sqlite3_exec(db, zSQL, 0, 0, 0); 01783 ** sqlite3_free(zSQL); 01784 ** </pre></blockquote> 01785 ** 01786 ** The code above will render a correct SQL statement in the zSQL 01787 ** variable even if the zText variable is a NULL pointer. 01788 ** 01789 ** ^(The "%z" formatting option works like "%s" but with the 01790 ** addition that after the string has been read and copied into 01791 ** the result, [sqlite3_free()] is called on the input string.)^ 01792 */ 01793 SQLITE_API char *sqlite3_mprintf(const char*,...); 01794 SQLITE_API char *sqlite3_vmprintf(const char*, va_list); 01795 SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...); 01796 01797 /* 01798 ** CAPI3REF: Memory Allocation Subsystem 01799 ** 01800 ** The SQLite core uses these three routines for all of its own 01801 ** internal memory allocation needs. "Core" in the previous sentence 01802 ** does not include operating-system specific VFS implementation. The 01803 ** Windows VFS uses native malloc() and free() for some operations. 01804 ** 01805 ** ^The sqlite3_malloc() routine returns a pointer to a block 01806 ** of memory at least N bytes in length, where N is the parameter. 01807 ** ^If sqlite3_malloc() is unable to obtain sufficient free 01808 ** memory, it returns a NULL pointer. ^If the parameter N to 01809 ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns 01810 ** a NULL pointer. 01811 ** 01812 ** ^Calling sqlite3_free() with a pointer previously returned 01813 ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so 01814 ** that it might be reused. ^The sqlite3_free() routine is 01815 ** a no-op if is called with a NULL pointer. Passing a NULL pointer 01816 ** to sqlite3_free() is harmless. After being freed, memory 01817 ** should neither be read nor written. Even reading previously freed 01818 ** memory might result in a segmentation fault or other severe error. 01819 ** Memory corruption, a segmentation fault, or other severe error 01820 ** might result if sqlite3_free() is called with a non-NULL pointer that 01821 ** was not obtained from sqlite3_malloc() or sqlite3_realloc(). 01822 ** 01823 ** ^(The sqlite3_realloc() interface attempts to resize a 01824 ** prior memory allocation to be at least N bytes, where N is the 01825 ** second parameter. The memory allocation to be resized is the first 01826 ** parameter.)^ ^ If the first parameter to sqlite3_realloc() 01827 ** is a NULL pointer then its behavior is identical to calling 01828 ** sqlite3_malloc(N) where N is the second parameter to sqlite3_realloc(). 01829 ** ^If the second parameter to sqlite3_realloc() is zero or 01830 ** negative then the behavior is exactly the same as calling 01831 ** sqlite3_free(P) where P is the first parameter to sqlite3_realloc(). 01832 ** ^sqlite3_realloc() returns a pointer to a memory allocation 01833 ** of at least N bytes in size or NULL if sufficient memory is unavailable. 01834 ** ^If M is the size of the prior allocation, then min(N,M) bytes 01835 ** of the prior allocation are copied into the beginning of buffer returned 01836 ** by sqlite3_realloc() and the prior allocation is freed. 01837 ** ^If sqlite3_realloc() returns NULL, then the prior allocation 01838 ** is not freed. 01839 ** 01840 ** ^The memory returned by sqlite3_malloc() and sqlite3_realloc() 01841 ** is always aligned to at least an 8 byte boundary. 01842 ** 01843 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define 01844 ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in 01845 ** implementation of these routines to be omitted. That capability 01846 ** is no longer provided. Only built-in memory allocators can be used. 01847 ** 01848 ** The Windows OS interface layer calls 01849 ** the system malloc() and free() directly when converting 01850 ** filenames between the UTF-8 encoding used by SQLite 01851 ** and whatever filename encoding is used by the particular Windows 01852 ** installation. Memory allocation errors are detected, but 01853 ** they are reported back as [SQLITE_CANTOPEN] or 01854 ** [SQLITE_IOERR] rather than [SQLITE_NOMEM]. 01855 ** 01856 ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()] 01857 ** must be either NULL or else pointers obtained from a prior 01858 ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have 01859 ** not yet been released. 01860 ** 01861 ** The application must not read or write any part of 01862 ** a block of memory after it has been released using 01863 ** [sqlite3_free()] or [sqlite3_realloc()]. 01864 */ 01865 SQLITE_API void *sqlite3_malloc(int); 01866 SQLITE_API void *sqlite3_realloc(void*, int); 01867 SQLITE_API void sqlite3_free(void*); 01868 01869 /* 01870 ** CAPI3REF: Memory Allocator Statistics 01871 ** 01872 ** SQLite provides these two interfaces for reporting on the status 01873 ** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()] 01874 ** routines, which form the built-in memory allocation subsystem. 01875 ** 01876 ** ^The [sqlite3_memory_used()] routine returns the number of bytes 01877 ** of memory currently outstanding (malloced but not freed). 01878 ** ^The [sqlite3_memory_highwater()] routine returns the maximum 01879 ** value of [sqlite3_memory_used()] since the high-water mark 01880 ** was last reset. ^The values returned by [sqlite3_memory_used()] and 01881 ** [sqlite3_memory_highwater()] include any overhead 01882 ** added by SQLite in its implementation of [sqlite3_malloc()], 01883 ** but not overhead added by the any underlying system library 01884 ** routines that [sqlite3_malloc()] may call. 01885 ** 01886 ** ^The memory high-water mark is reset to the current value of 01887 ** [sqlite3_memory_used()] if and only if the parameter to 01888 ** [sqlite3_memory_highwater()] is true. ^The value returned 01889 ** by [sqlite3_memory_highwater(1)] is the high-water mark 01890 ** prior to the reset. 01891 */ 01892 SQLITE_API sqlite3_int64 sqlite3_memory_used(void); 01893 SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag); 01894 01895 /* 01896 ** CAPI3REF: Pseudo-Random Number Generator 01897 ** 01898 ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to 01899 ** select random [ROWID | ROWIDs] when inserting new records into a table that 01900 ** already uses the largest possible [ROWID]. The PRNG is also used for 01901 ** the build-in random() and randomblob() SQL functions. This interface allows 01902 ** applications to access the same PRNG for other purposes. 01903 ** 01904 ** ^A call to this routine stores N bytes of randomness into buffer P. 01905 ** 01906 ** ^The first time this routine is invoked (either internally or by 01907 ** the application) the PRNG is seeded using randomness obtained 01908 ** from the xRandomness method of the default [sqlite3_vfs] object. 01909 ** ^On all subsequent invocations, the pseudo-randomness is generated 01910 ** internally and without recourse to the [sqlite3_vfs] xRandomness 01911 ** method. 01912 */ 01913 SQLITE_API void sqlite3_randomness(int N, void *P); 01914 01915 /* 01916 ** CAPI3REF: Compile-Time Authorization Callbacks 01917 ** 01918 ** ^This routine registers a authorizer callback with a particular 01919 ** [database connection], supplied in the first argument. 01920 ** ^The authorizer callback is invoked as SQL statements are being compiled 01921 ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], 01922 ** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()]. ^At various 01923 ** points during the compilation process, as logic is being created 01924 ** to perform various actions, the authorizer callback is invoked to 01925 ** see if those actions are allowed. ^The authorizer callback should 01926 ** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the 01927 ** specific action but allow the SQL statement to continue to be 01928 ** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be 01929 ** rejected with an error. ^If the authorizer callback returns 01930 ** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY] 01931 ** then the [sqlite3_prepare_v2()] or equivalent call that triggered 01932 ** the authorizer will fail with an error message. 01933 ** 01934 ** When the callback returns [SQLITE_OK], that means the operation 01935 ** requested is ok. ^When the callback returns [SQLITE_DENY], the 01936 ** [sqlite3_prepare_v2()] or equivalent call that triggered the 01937 ** authorizer will fail with an error message explaining that 01938 ** access is denied. 01939 ** 01940 ** ^The first parameter to the authorizer callback is a copy of the third 01941 ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter 01942 ** to the callback is an integer [SQLITE_COPY | action code] that specifies 01943 ** the particular action to be authorized. ^The third through sixth parameters 01944 ** to the callback are zero-terminated strings that contain additional 01945 ** details about the action to be authorized. 01946 ** 01947 ** ^If the action code is [SQLITE_READ] 01948 ** and the callback returns [SQLITE_IGNORE] then the 01949 ** [prepared statement] statement is constructed to substitute 01950 ** a NULL value in place of the table column that would have 01951 ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE] 01952 ** return can be used to deny an untrusted user access to individual 01953 ** columns of a table. 01954 ** ^If the action code is [SQLITE_DELETE] and the callback returns 01955 ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the 01956 ** [truncate optimization] is disabled and all rows are deleted individually. 01957 ** 01958 ** An authorizer is used when [sqlite3_prepare | preparing] 01959 ** SQL statements from an untrusted source, to ensure that the SQL statements 01960 ** do not try to access data they are not allowed to see, or that they do not 01961 ** try to execute malicious statements that damage the database. For 01962 ** example, an application may allow a user to enter arbitrary 01963 ** SQL queries for evaluation by a database. But the application does 01964 ** not want the user to be able to make arbitrary changes to the 01965 ** database. An authorizer could then be put in place while the 01966 ** user-entered SQL is being [sqlite3_prepare | prepared] that 01967 ** disallows everything except [SELECT] statements. 01968 ** 01969 ** Applications that need to process SQL from untrusted sources 01970 ** might also consider lowering resource limits using [sqlite3_limit()] 01971 ** and limiting database size using the [max_page_count] [PRAGMA] 01972 ** in addition to using an authorizer. 01973 ** 01974 ** ^(Only a single authorizer can be in place on a database connection 01975 ** at a time. Each call to sqlite3_set_authorizer overrides the 01976 ** previous call.)^ ^Disable the authorizer by installing a NULL callback. 01977 ** The authorizer is disabled by default. 01978 ** 01979 ** The authorizer callback must not do anything that will modify 01980 ** the database connection that invoked the authorizer callback. 01981 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 01982 ** database connections for the meaning of "modify" in this paragraph. 01983 ** 01984 ** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the 01985 ** statement might be re-prepared during [sqlite3_step()] due to a 01986 ** schema change. Hence, the application should ensure that the 01987 ** correct authorizer callback remains in place during the [sqlite3_step()]. 01988 ** 01989 ** ^Note that the authorizer callback is invoked only during 01990 ** [sqlite3_prepare()] or its variants. Authorization is not 01991 ** performed during statement evaluation in [sqlite3_step()], unless 01992 ** as stated in the previous paragraph, sqlite3_step() invokes 01993 ** sqlite3_prepare_v2() to reprepare a statement after a schema change. 01994 */ 01995 SQLITE_API int sqlite3_set_authorizer( 01996 sqlite3*, 01997 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), 01998 void *pUserData 01999 ); 02000 02001 /* 02002 ** CAPI3REF: Authorizer Return Codes 02003 ** 02004 ** The [sqlite3_set_authorizer | authorizer callback function] must 02005 ** return either [SQLITE_OK] or one of these two constants in order 02006 ** to signal SQLite whether or not the action is permitted. See the 02007 ** [sqlite3_set_authorizer | authorizer documentation] for additional 02008 ** information. 02009 */ 02010 #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ 02011 #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ 02012 02013 /* 02014 ** CAPI3REF: Authorizer Action Codes 02015 ** 02016 ** The [sqlite3_set_authorizer()] interface registers a callback function 02017 ** that is invoked to authorize certain SQL statement actions. The 02018 ** second parameter to the callback is an integer code that specifies 02019 ** what action is being authorized. These are the integer action codes that 02020 ** the authorizer callback may be passed. 02021 ** 02022 ** These action code values signify what kind of operation is to be 02023 ** authorized. The 3rd and 4th parameters to the authorization 02024 ** callback function will be parameters or NULL depending on which of these 02025 ** codes is used as the second parameter. ^(The 5th parameter to the 02026 ** authorizer callback is the name of the database ("main", "temp", 02027 ** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback 02028 ** is the name of the inner-most trigger or view that is responsible for 02029 ** the access attempt or NULL if this access attempt is directly from 02030 ** top-level SQL code. 02031 */ 02032 /******************************************* 3rd ************ 4th ***********/ 02033 #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */ 02034 #define SQLITE_CREATE_TABLE 2 /* Table Name NULL */ 02035 #define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */ 02036 #define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */ 02037 #define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */ 02038 #define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */ 02039 #define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */ 02040 #define SQLITE_CREATE_VIEW 8 /* View Name NULL */ 02041 #define SQLITE_DELETE 9 /* Table Name NULL */ 02042 #define SQLITE_DROP_INDEX 10 /* Index Name Table Name */ 02043 #define SQLITE_DROP_TABLE 11 /* Table Name NULL */ 02044 #define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */ 02045 #define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */ 02046 #define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */ 02047 #define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */ 02048 #define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */ 02049 #define SQLITE_DROP_VIEW 17 /* View Name NULL */ 02050 #define SQLITE_INSERT 18 /* Table Name NULL */ 02051 #define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */ 02052 #define SQLITE_READ 20 /* Table Name Column Name */ 02053 #define SQLITE_SELECT 21 /* NULL NULL */ 02054 #define SQLITE_TRANSACTION 22 /* Operation NULL */ 02055 #define SQLITE_UPDATE 23 /* Table Name Column Name */ 02056 #define SQLITE_ATTACH 24 /* Filename NULL */ 02057 #define SQLITE_DETACH 25 /* Database Name NULL */ 02058 #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */ 02059 #define SQLITE_REINDEX 27 /* Index Name NULL */ 02060 #define SQLITE_ANALYZE 28 /* Table Name NULL */ 02061 #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */ 02062 #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */ 02063 #define SQLITE_FUNCTION 31 /* NULL Function Name */ 02064 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */ 02065 #define SQLITE_COPY 0 /* No longer used */ 02066 02067 /* 02068 ** CAPI3REF: Tracing And Profiling Functions 02069 ** EXPERIMENTAL 02070 ** 02071 ** These routines register callback functions that can be used for 02072 ** tracing and profiling the execution of SQL statements. 02073 ** 02074 ** ^The callback function registered by sqlite3_trace() is invoked at 02075 ** various times when an SQL statement is being run by [sqlite3_step()]. 02076 ** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the 02077 ** SQL statement text as the statement first begins executing. 02078 ** ^(Additional sqlite3_trace() callbacks might occur 02079 ** as each triggered subprogram is entered. The callbacks for triggers 02080 ** contain a UTF-8 SQL comment that identifies the trigger.)^ 02081 ** 02082 ** ^The callback function registered by sqlite3_profile() is invoked 02083 ** as each SQL statement finishes. ^The profile callback contains 02084 ** the original statement text and an estimate of wall-clock time 02085 ** of how long that statement took to run. 02086 */ 02087 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*); 02088 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*, 02089 void(*xProfile)(void*,const char*,sqlite3_uint64), void*); 02090 02091 /* 02092 ** CAPI3REF: Query Progress Callbacks 02093 ** 02094 ** ^This routine configures a callback function - the 02095 ** progress callback - that is invoked periodically during long 02096 ** running calls to [sqlite3_exec()], [sqlite3_step()] and 02097 ** [sqlite3_get_table()]. An example use for this 02098 ** interface is to keep a GUI updated during a large query. 02099 ** 02100 ** ^If the progress callback returns non-zero, the operation is 02101 ** interrupted. This feature can be used to implement a 02102 ** "Cancel" button on a GUI progress dialog box. 02103 ** 02104 ** The progress handler must not do anything that will modify 02105 ** the database connection that invoked the progress handler. 02106 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 02107 ** database connections for the meaning of "modify" in this paragraph. 02108 ** 02109 */ 02110 SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); 02111 02112 /* 02113 ** CAPI3REF: Opening A New Database Connection 02114 ** 02115 ** ^These routines open an SQLite database file whose name is given by the 02116 ** filename argument. ^The filename argument is interpreted as UTF-8 for 02117 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte 02118 ** order for sqlite3_open16(). ^(A [database connection] handle is usually 02119 ** returned in *ppDb, even if an error occurs. The only exception is that 02120 ** if SQLite is unable to allocate memory to hold the [sqlite3] object, 02121 ** a NULL will be written into *ppDb instead of a pointer to the [sqlite3] 02122 ** object.)^ ^(If the database is opened (and/or created) successfully, then 02123 ** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The 02124 ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain 02125 ** an English language description of the error following a failure of any 02126 ** of the sqlite3_open() routines. 02127 ** 02128 ** ^The default encoding for the database will be UTF-8 if 02129 ** sqlite3_open() or sqlite3_open_v2() is called and 02130 ** UTF-16 in the native byte order if sqlite3_open16() is used. 02131 ** 02132 ** Whether or not an error occurs when it is opened, resources 02133 ** associated with the [database connection] handle should be released by 02134 ** passing it to [sqlite3_close()] when it is no longer required. 02135 ** 02136 ** The sqlite3_open_v2() interface works like sqlite3_open() 02137 ** except that it accepts two additional parameters for additional control 02138 ** over the new database connection. ^(The flags parameter to 02139 ** sqlite3_open_v2() can take one of 02140 ** the following three values, optionally combined with the 02141 ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE], 02142 ** and/or [SQLITE_OPEN_PRIVATECACHE] flags:)^ 02143 ** 02144 ** <dl> 02145 ** ^(<dt>[SQLITE_OPEN_READONLY]</dt> 02146 ** <dd>The database is opened in read-only mode. If the database does not 02147 ** already exist, an error is returned.</dd>)^ 02148 ** 02149 ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt> 02150 ** <dd>The database is opened for reading and writing if possible, or reading 02151 ** only if the file is write protected by the operating system. In either 02152 ** case the database must already exist, otherwise an error is returned.</dd>)^ 02153 ** 02154 ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt> 02155 ** <dd>The database is opened for reading and writing, and is creates it if 02156 ** it does not already exist. This is the behavior that is always used for 02157 ** sqlite3_open() and sqlite3_open16().</dd>)^ 02158 ** </dl> 02159 ** 02160 ** If the 3rd parameter to sqlite3_open_v2() is not one of the 02161 ** combinations shown above or one of the combinations shown above combined 02162 ** with the [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], 02163 ** [SQLITE_OPEN_SHAREDCACHE] and/or [SQLITE_OPEN_SHAREDCACHE] flags, 02164 ** then the behavior is undefined. 02165 ** 02166 ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection 02167 ** opens in the multi-thread [threading mode] as long as the single-thread 02168 ** mode has not been set at compile-time or start-time. ^If the 02169 ** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens 02170 ** in the serialized [threading mode] unless single-thread was 02171 ** previously selected at compile-time or start-time. 02172 ** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be 02173 ** eligible to use [shared cache mode], regardless of whether or not shared 02174 ** cache is enabled using [sqlite3_enable_shared_cache()]. ^The 02175 ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not 02176 ** participate in [shared cache mode] even if it is enabled. 02177 ** 02178 ** ^If the filename is ":memory:", then a private, temporary in-memory database 02179 ** is created for the connection. ^This in-memory database will vanish when 02180 ** the database connection is closed. Future versions of SQLite might 02181 ** make use of additional special filenames that begin with the ":" character. 02182 ** It is recommended that when a database filename actually does begin with 02183 ** a ":" character you should prefix the filename with a pathname such as 02184 ** "./" to avoid ambiguity. 02185 ** 02186 ** ^If the filename is an empty string, then a private, temporary 02187 ** on-disk database will be created. ^This private database will be 02188 ** automatically deleted as soon as the database connection is closed. 02189 ** 02190 ** ^The fourth parameter to sqlite3_open_v2() is the name of the 02191 ** [sqlite3_vfs] object that defines the operating system interface that 02192 ** the new database connection should use. ^If the fourth parameter is 02193 ** a NULL pointer then the default [sqlite3_vfs] object is used. 02194 ** 02195 ** <b>Note to Windows users:</b> The encoding used for the filename argument 02196 ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever 02197 ** codepage is currently defined. Filenames containing international 02198 ** characters must be converted to UTF-8 prior to passing them into 02199 ** sqlite3_open() or sqlite3_open_v2(). 02200 */ 02201 SQLITE_API int sqlite3_open( 02202 const char *filename, /* Database filename (UTF-8) */ 02203 sqlite3 **ppDb /* OUT: SQLite db handle */ 02204 ); 02205 SQLITE_API int sqlite3_open16( 02206 const void *filename, /* Database filename (UTF-16) */ 02207 sqlite3 **ppDb /* OUT: SQLite db handle */ 02208 ); 02209 SQLITE_API int sqlite3_open_v2( 02210 const char *filename, /* Database filename (UTF-8) */ 02211 sqlite3 **ppDb, /* OUT: SQLite db handle */ 02212 int flags, /* Flags */ 02213 const char *zVfs /* Name of VFS module to use */ 02214 ); 02215 02216 /* 02217 ** CAPI3REF: Error Codes And Messages 02218 ** 02219 ** ^The sqlite3_errcode() interface returns the numeric [result code] or 02220 ** [extended result code] for the most recent failed sqlite3_* API call 02221 ** associated with a [database connection]. If a prior API call failed 02222 ** but the most recent API call succeeded, the return value from 02223 ** sqlite3_errcode() is undefined. ^The sqlite3_extended_errcode() 02224 ** interface is the same except that it always returns the 02225 ** [extended result code] even when extended result codes are 02226 ** disabled. 02227 ** 02228 ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language 02229 ** text that describes the error, as either UTF-8 or UTF-16 respectively. 02230 ** ^(Memory to hold the error message string is managed internally. 02231 ** The application does not need to worry about freeing the result. 02232 ** However, the error string might be overwritten or deallocated by 02233 ** subsequent calls to other SQLite interface functions.)^ 02234 ** 02235 ** When the serialized [threading mode] is in use, it might be the 02236 ** case that a second error occurs on a separate thread in between 02237 ** the time of the first error and the call to these interfaces. 02238 ** When that happens, the second error will be reported since these 02239 ** interfaces always report the most recent result. To avoid 02240 ** this, each thread can obtain exclusive use of the [database connection] D 02241 ** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning 02242 ** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after 02243 ** all calls to the interfaces listed here are completed. 02244 ** 02245 ** If an interface fails with SQLITE_MISUSE, that means the interface 02246 ** was invoked incorrectly by the application. In that case, the 02247 ** error code and message may or may not be set. 02248 */ 02249 SQLITE_API int sqlite3_errcode(sqlite3 *db); 02250 SQLITE_API int sqlite3_extended_errcode(sqlite3 *db); 02251 SQLITE_API const char *sqlite3_errmsg(sqlite3*); 02252 SQLITE_API const void *sqlite3_errmsg16(sqlite3*); 02253 02254 /* 02255 ** CAPI3REF: SQL Statement Object 02256 ** KEYWORDS: {prepared statement} {prepared statements} 02257 ** 02258 ** An instance of this object represents a single SQL statement. 02259 ** This object is variously known as a "prepared statement" or a 02260 ** "compiled SQL statement" or simply as a "statement". 02261 ** 02262 ** The life of a statement object goes something like this: 02263 ** 02264 ** <ol> 02265 ** <li> Create the object using [sqlite3_prepare_v2()] or a related 02266 ** function. 02267 ** <li> Bind values to [host parameters] using the sqlite3_bind_*() 02268 ** interfaces. 02269 ** <li> Run the SQL by calling [sqlite3_step()] one or more times. 02270 ** <li> Reset the statement using [sqlite3_reset()] then go back 02271 ** to step 2. Do this zero or more times. 02272 ** <li> Destroy the object using [sqlite3_finalize()]. 02273 ** </ol> 02274 ** 02275 ** Refer to documentation on individual methods above for additional 02276 ** information. 02277 */ 02278 typedef struct sqlite3_stmt sqlite3_stmt; 02279 02280 /* 02281 ** CAPI3REF: Run-time Limits 02282 ** 02283 ** ^(This interface allows the size of various constructs to be limited 02284 ** on a connection by connection basis. The first parameter is the 02285 ** [database connection] whose limit is to be set or queried. The 02286 ** second parameter is one of the [limit categories] that define a 02287 ** class of constructs to be size limited. The third parameter is the 02288 ** new limit for that construct. The function returns the old limit.)^ 02289 ** 02290 ** ^If the new limit is a negative number, the limit is unchanged. 02291 ** ^(For the limit category of SQLITE_LIMIT_XYZ there is a 02292 ** [limits | hard upper bound] 02293 ** set by a compile-time C preprocessor macro named 02294 ** [limits | SQLITE_MAX_XYZ]. 02295 ** (The "_LIMIT_" in the name is changed to "_MAX_".))^ 02296 ** ^Attempts to increase a limit above its hard upper bound are 02297 ** silently truncated to the hard upper bound. 02298 ** 02299 ** Run-time limits are intended for use in applications that manage 02300 ** both their own internal database and also databases that are controlled 02301 ** by untrusted external sources. An example application might be a 02302 ** web browser that has its own databases for storing history and 02303 ** separate databases controlled by JavaScript applications downloaded 02304 ** off the Internet. The internal databases can be given the 02305 ** large, default limits. Databases managed by external sources can 02306 ** be given much smaller limits designed to prevent a denial of service 02307 ** attack. Developers might also want to use the [sqlite3_set_authorizer()] 02308 ** interface to further control untrusted SQL. The size of the database 02309 ** created by an untrusted script can be contained using the 02310 ** [max_page_count] [PRAGMA]. 02311 ** 02312 ** New run-time limit categories may be added in future releases. 02313 */ 02314 SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal); 02315 02316 /* 02317 ** CAPI3REF: Run-Time Limit Categories 02318 ** KEYWORDS: {limit category} {*limit categories} 02319 ** 02320 ** These constants define various performance limits 02321 ** that can be lowered at run-time using [sqlite3_limit()]. 02322 ** The synopsis of the meanings of the various limits is shown below. 02323 ** Additional information is available at [limits | Limits in SQLite]. 02324 ** 02325 ** <dl> 02326 ** ^(<dt>SQLITE_LIMIT_LENGTH</dt> 02327 ** <dd>The maximum size of any string or BLOB or table row.<dd>)^ 02328 ** 02329 ** ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt> 02330 ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^ 02331 ** 02332 ** ^(<dt>SQLITE_LIMIT_COLUMN</dt> 02333 ** <dd>The maximum number of columns in a table definition or in the 02334 ** result set of a [SELECT] or the maximum number of columns in an index 02335 ** or in an ORDER BY or GROUP BY clause.</dd>)^ 02336 ** 02337 ** ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> 02338 ** <dd>The maximum depth of the parse tree on any expression.</dd>)^ 02339 ** 02340 ** ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt> 02341 ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^ 02342 ** 02343 ** ^(<dt>SQLITE_LIMIT_VDBE_OP</dt> 02344 ** <dd>The maximum number of instructions in a virtual machine program 02345 ** used to implement an SQL statement.</dd>)^ 02346 ** 02347 ** ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt> 02348 ** <dd>The maximum number of arguments on a function.</dd>)^ 02349 ** 02350 ** ^(<dt>SQLITE_LIMIT_ATTACHED</dt> 02351 ** <dd>The maximum number of [ATTACH | attached databases].)^</dd> 02352 ** 02353 ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt> 02354 ** <dd>The maximum length of the pattern argument to the [LIKE] or 02355 ** [GLOB] operators.</dd>)^ 02356 ** 02357 ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt> 02358 ** <dd>The maximum number of variables in an SQL statement that can 02359 ** be bound.</dd>)^ 02360 ** 02361 ** ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> 02362 ** <dd>The maximum depth of recursion for triggers.</dd>)^ 02363 ** </dl> 02364 */ 02365 #define SQLITE_LIMIT_LENGTH 0 02366 #define SQLITE_LIMIT_SQL_LENGTH 1 02367 #define SQLITE_LIMIT_COLUMN 2 02368 #define SQLITE_LIMIT_EXPR_DEPTH 3 02369 #define SQLITE_LIMIT_COMPOUND_SELECT 4 02370 #define SQLITE_LIMIT_VDBE_OP 5 02371 #define SQLITE_LIMIT_FUNCTION_ARG 6 02372 #define SQLITE_LIMIT_ATTACHED 7 02373 #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8 02374 #define SQLITE_LIMIT_VARIABLE_NUMBER 9 02375 #define SQLITE_LIMIT_TRIGGER_DEPTH 10 02376 02377 /* 02378 ** CAPI3REF: Compiling An SQL Statement 02379 ** KEYWORDS: {SQL statement compiler} 02380 ** 02381 ** To execute an SQL query, it must first be compiled into a byte-code 02382 ** program using one of these routines. 02383 ** 02384 ** The first argument, "db", is a [database connection] obtained from a 02385 ** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or 02386 ** [sqlite3_open16()]. The database connection must not have been closed. 02387 ** 02388 ** The second argument, "zSql", is the statement to be compiled, encoded 02389 ** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2() 02390 ** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2() 02391 ** use UTF-16. 02392 ** 02393 ** ^If the nByte argument is less than zero, then zSql is read up to the 02394 ** first zero terminator. ^If nByte is non-negative, then it is the maximum 02395 ** number of bytes read from zSql. ^When nByte is non-negative, the 02396 ** zSql string ends at either the first '\000' or '\u0000' character or 02397 ** the nByte-th byte, whichever comes first. If the caller knows 02398 ** that the supplied string is nul-terminated, then there is a small 02399 ** performance advantage to be gained by passing an nByte parameter that 02400 ** is equal to the number of bytes in the input string <i>including</i> 02401 ** the nul-terminator bytes. 02402 ** 02403 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte 02404 ** past the end of the first SQL statement in zSql. These routines only 02405 ** compile the first statement in zSql, so *pzTail is left pointing to 02406 ** what remains uncompiled. 02407 ** 02408 ** ^*ppStmt is left pointing to a compiled [prepared statement] that can be 02409 ** executed using [sqlite3_step()]. ^If there is an error, *ppStmt is set 02410 ** to NULL. ^If the input text contains no SQL (if the input is an empty 02411 ** string or a comment) then *ppStmt is set to NULL. 02412 ** The calling procedure is responsible for deleting the compiled 02413 ** SQL statement using [sqlite3_finalize()] after it has finished with it. 02414 ** ppStmt may not be NULL. 02415 ** 02416 ** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK]; 02417 ** otherwise an [error code] is returned. 02418 ** 02419 ** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are 02420 ** recommended for all new programs. The two older interfaces are retained 02421 ** for backwards compatibility, but their use is discouraged. 02422 ** ^In the "v2" interfaces, the prepared statement 02423 ** that is returned (the [sqlite3_stmt] object) contains a copy of the 02424 ** original SQL text. This causes the [sqlite3_step()] interface to 02425 ** behave differently in three ways: 02426 ** 02427 ** <ol> 02428 ** <li> 02429 ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it 02430 ** always used to do, [sqlite3_step()] will automatically recompile the SQL 02431 ** statement and try to run it again. ^If the schema has changed in 02432 ** a way that makes the statement no longer valid, [sqlite3_step()] will still 02433 ** return [SQLITE_SCHEMA]. But unlike the legacy behavior, [SQLITE_SCHEMA] is 02434 ** now a fatal error. Calling [sqlite3_prepare_v2()] again will not make the 02435 ** error go away. Note: use [sqlite3_errmsg()] to find the text 02436 ** of the parsing error that results in an [SQLITE_SCHEMA] return. 02437 ** </li> 02438 ** 02439 ** <li> 02440 ** ^When an error occurs, [sqlite3_step()] will return one of the detailed 02441 ** [error codes] or [extended error codes]. ^The legacy behavior was that 02442 ** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code 02443 ** and the application would have to make a second call to [sqlite3_reset()] 02444 ** in order to find the underlying cause of the problem. With the "v2" prepare 02445 ** interfaces, the underlying reason for the error is returned immediately. 02446 ** </li> 02447 ** 02448 ** <li> 02449 ** ^If the value of a [parameter | host parameter] in the WHERE clause might 02450 ** change the query plan for a statement, then the statement may be 02451 ** automatically recompiled (as if there had been a schema change) on the first 02452 ** [sqlite3_step()] call following any change to the 02453 ** [sqlite3_bind_text | bindings] of the [parameter]. 02454 ** </li> 02455 ** </ol> 02456 */ 02457 SQLITE_API int sqlite3_prepare( 02458 sqlite3 *db, /* Database handle */ 02459 const char *zSql, /* SQL statement, UTF-8 encoded */ 02460 int nByte, /* Maximum length of zSql in bytes. */ 02461 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 02462 const char **pzTail /* OUT: Pointer to unused portion of zSql */ 02463 ); 02464 SQLITE_API int sqlite3_prepare_v2( 02465 sqlite3 *db, /* Database handle */ 02466 const char *zSql, /* SQL statement, UTF-8 encoded */ 02467 int nByte, /* Maximum length of zSql in bytes. */ 02468 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 02469 const char **pzTail /* OUT: Pointer to unused portion of zSql */ 02470 ); 02471 SQLITE_API int sqlite3_prepare16( 02472 sqlite3 *db, /* Database handle */ 02473 const void *zSql, /* SQL statement, UTF-16 encoded */ 02474 int nByte, /* Maximum length of zSql in bytes. */ 02475 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 02476 const void **pzTail /* OUT: Pointer to unused portion of zSql */ 02477 ); 02478 SQLITE_API int sqlite3_prepare16_v2( 02479 sqlite3 *db, /* Database handle */ 02480 const void *zSql, /* SQL statement, UTF-16 encoded */ 02481 int nByte, /* Maximum length of zSql in bytes. */ 02482 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 02483 const void **pzTail /* OUT: Pointer to unused portion of zSql */ 02484 ); 02485 02486 /* 02487 ** CAPI3REF: Retrieving Statement SQL 02488 ** 02489 ** ^This interface can be used to retrieve a saved copy of the original 02490 ** SQL text used to create a [prepared statement] if that statement was 02491 ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()]. 02492 */ 02493 SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt); 02494 02495 /* 02496 ** CAPI3REF: Dynamically Typed Value Object 02497 ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value} 02498 ** 02499 ** SQLite uses the sqlite3_value object to represent all values 02500 ** that can be stored in a database table. SQLite uses dynamic typing 02501 ** for the values it stores. ^Values stored in sqlite3_value objects 02502 ** can be integers, floating point values, strings, BLOBs, or NULL. 02503 ** 02504 ** An sqlite3_value object may be either "protected" or "unprotected". 02505 ** Some interfaces require a protected sqlite3_value. Other interfaces 02506 ** will accept either a protected or an unprotected sqlite3_value. 02507 ** Every interface that accepts sqlite3_value arguments specifies 02508 ** whether or not it requires a protected sqlite3_value. 02509 ** 02510 ** The terms "protected" and "unprotected" refer to whether or not 02511 ** a mutex is held. A internal mutex is held for a protected 02512 ** sqlite3_value object but no mutex is held for an unprotected 02513 ** sqlite3_value object. If SQLite is compiled to be single-threaded 02514 ** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0) 02515 ** or if SQLite is run in one of reduced mutex modes 02516 ** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD] 02517 ** then there is no distinction between protected and unprotected 02518 ** sqlite3_value objects and they can be used interchangeably. However, 02519 ** for maximum code portability it is recommended that applications 02520 ** still make the distinction between between protected and unprotected 02521 ** sqlite3_value objects even when not strictly required. 02522 ** 02523 ** ^The sqlite3_value objects that are passed as parameters into the 02524 ** implementation of [application-defined SQL functions] are protected. 02525 ** ^The sqlite3_value object returned by 02526 ** [sqlite3_column_value()] is unprotected. 02527 ** Unprotected sqlite3_value objects may only be used with 02528 ** [sqlite3_result_value()] and [sqlite3_bind_value()]. 02529 ** The [sqlite3_value_blob | sqlite3_value_type()] family of 02530 ** interfaces require protected sqlite3_value objects. 02531 */ 02532 typedef struct Mem sqlite3_value; 02533 02534 /* 02535 ** CAPI3REF: SQL Function Context Object 02536 ** 02537 ** The context in which an SQL function executes is stored in an 02538 ** sqlite3_context object. ^A pointer to an sqlite3_context object 02539 ** is always first parameter to [application-defined SQL functions]. 02540 ** The application-defined SQL function implementation will pass this 02541 ** pointer through into calls to [sqlite3_result_int | sqlite3_result()], 02542 ** [sqlite3_aggregate_context()], [sqlite3_user_data()], 02543 ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()], 02544 ** and/or [sqlite3_set_auxdata()]. 02545 */ 02546 typedef struct sqlite3_context sqlite3_context; 02547 02548 /* 02549 ** CAPI3REF: Binding Values To Prepared Statements 02550 ** KEYWORDS: {host parameter} {host parameters} {host parameter name} 02551 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding} 02552 ** 02553 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants, 02554 ** literals may be replaced by a [parameter] that matches one of following 02555 ** templates: 02556 ** 02557 ** <ul> 02558 ** <li> ? 02559 ** <li> ?NNN 02560 ** <li> :VVV 02561 ** <li> @VVV 02562 ** <li> $VVV 02563 ** </ul> 02564 ** 02565 ** In the templates above, NNN represents an integer literal, 02566 ** and VVV represents an alphanumeric identifer.)^ ^The values of these 02567 ** parameters (also called "host parameter names" or "SQL parameters") 02568 ** can be set using the sqlite3_bind_*() routines defined here. 02569 ** 02570 ** ^The first argument to the sqlite3_bind_*() routines is always 02571 ** a pointer to the [sqlite3_stmt] object returned from 02572 ** [sqlite3_prepare_v2()] or its variants. 02573 ** 02574 ** ^The second argument is the index of the SQL parameter to be set. 02575 ** ^The leftmost SQL parameter has an index of 1. ^When the same named 02576 ** SQL parameter is used more than once, second and subsequent 02577 ** occurrences have the same index as the first occurrence. 02578 ** ^The index for named parameters can be looked up using the 02579 ** [sqlite3_bind_parameter_index()] API if desired. ^The index 02580 ** for "?NNN" parameters is the value of NNN. 02581 ** ^The NNN value must be between 1 and the [sqlite3_limit()] 02582 ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999). 02583 ** 02584 ** ^The third argument is the value to bind to the parameter. 02585 ** 02586 ** ^(In those routines that have a fourth argument, its value is the 02587 ** number of bytes in the parameter. To be clear: the value is the 02588 ** number of <u>bytes</u> in the value, not the number of characters.)^ 02589 ** ^If the fourth parameter is negative, the length of the string is 02590 ** the number of bytes up to the first zero terminator. 02591 ** 02592 ** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and 02593 ** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or 02594 ** string after SQLite has finished with it. ^If the fifth argument is 02595 ** the special value [SQLITE_STATIC], then SQLite assumes that the 02596 ** information is in static, unmanaged space and does not need to be freed. 02597 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then 02598 ** SQLite makes its own private copy of the data immediately, before 02599 ** the sqlite3_bind_*() routine returns. 02600 ** 02601 ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that 02602 ** is filled with zeroes. ^A zeroblob uses a fixed amount of memory 02603 ** (just an integer to hold its size) while it is being processed. 02604 ** Zeroblobs are intended to serve as placeholders for BLOBs whose 02605 ** content is later written using 02606 ** [sqlite3_blob_open | incremental BLOB I/O] routines. 02607 ** ^A negative value for the zeroblob results in a zero-length BLOB. 02608 ** 02609 ** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer 02610 ** for the [prepared statement] or with a prepared statement for which 02611 ** [sqlite3_step()] has been called more recently than [sqlite3_reset()], 02612 ** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_() 02613 ** routine is passed a [prepared statement] that has been finalized, the 02614 ** result is undefined and probably harmful. 02615 ** 02616 ** ^Bindings are not cleared by the [sqlite3_reset()] routine. 02617 ** ^Unbound parameters are interpreted as NULL. 02618 ** 02619 ** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an 02620 ** [error code] if anything goes wrong. 02621 ** ^[SQLITE_RANGE] is returned if the parameter 02622 ** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails. 02623 ** 02624 ** See also: [sqlite3_bind_parameter_count()], 02625 ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()]. 02626 */ 02627 SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); 02628 SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double); 02629 SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int); 02630 SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64); 02631 SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int); 02632 SQLITE_API int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*)); 02633 SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*)); 02634 SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); 02635 SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); 02636 02637 /* 02638 ** CAPI3REF: Number Of SQL Parameters 02639 ** 02640 ** ^This routine can be used to find the number of [SQL parameters] 02641 ** in a [prepared statement]. SQL parameters are tokens of the 02642 ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as 02643 ** placeholders for values that are [sqlite3_bind_blob | bound] 02644 ** to the parameters at a later time. 02645 ** 02646 ** ^(This routine actually returns the index of the largest (rightmost) 02647 ** parameter. For all forms except ?NNN, this will correspond to the 02648 ** number of unique parameters. If parameters of the ?NNN form are used, 02649 ** there may be gaps in the list.)^ 02650 ** 02651 ** See also: [sqlite3_bind_blob|sqlite3_bind()], 02652 ** [sqlite3_bind_parameter_name()], and 02653 ** [sqlite3_bind_parameter_index()]. 02654 */ 02655 SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*); 02656 02657 /* 02658 ** CAPI3REF: Name Of A Host Parameter 02659 ** 02660 ** ^The sqlite3_bind_parameter_name(P,N) interface returns 02661 ** the name of the N-th [SQL parameter] in the [prepared statement] P. 02662 ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA" 02663 ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA" 02664 ** respectively. 02665 ** In other words, the initial ":" or "$" or "@" or "?" 02666 ** is included as part of the name.)^ 02667 ** ^Parameters of the form "?" without a following integer have no name 02668 ** and are referred to as "nameless" or "anonymous parameters". 02669 ** 02670 ** ^The first host parameter has an index of 1, not 0. 02671 ** 02672 ** ^If the value N is out of range or if the N-th parameter is 02673 ** nameless, then NULL is returned. ^The returned string is 02674 ** always in UTF-8 encoding even if the named parameter was 02675 ** originally specified as UTF-16 in [sqlite3_prepare16()] or 02676 ** [sqlite3_prepare16_v2()]. 02677 ** 02678 ** See also: [sqlite3_bind_blob|sqlite3_bind()], 02679 ** [sqlite3_bind_parameter_count()], and 02680 ** [sqlite3_bind_parameter_index()]. 02681 */ 02682 SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int); 02683 02684 /* 02685 ** CAPI3REF: Index Of A Parameter With A Given Name 02686 ** 02687 ** ^Return the index of an SQL parameter given its name. ^The 02688 ** index value returned is suitable for use as the second 02689 ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero 02690 ** is returned if no matching parameter is found. ^The parameter 02691 ** name must be given in UTF-8 even if the original statement 02692 ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()]. 02693 ** 02694 ** See also: [sqlite3_bind_blob|sqlite3_bind()], 02695 ** [sqlite3_bind_parameter_count()], and 02696 ** [sqlite3_bind_parameter_index()]. 02697 */ 02698 SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); 02699 02700 /* 02701 ** CAPI3REF: Reset All Bindings On A Prepared Statement 02702 ** 02703 ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset 02704 ** the [sqlite3_bind_blob | bindings] on a [prepared statement]. 02705 ** ^Use this routine to reset all host parameters to NULL. 02706 */ 02707 SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*); 02708 02709 /* 02710 ** CAPI3REF: Number Of Columns In A Result Set 02711 ** 02712 ** ^Return the number of columns in the result set returned by the 02713 ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL 02714 ** statement that does not return data (for example an [UPDATE]). 02715 */ 02716 SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt); 02717 02718 /* 02719 ** CAPI3REF: Column Names In A Result Set 02720 ** 02721 ** ^These routines return the name assigned to a particular column 02722 ** in the result set of a [SELECT] statement. ^The sqlite3_column_name() 02723 ** interface returns a pointer to a zero-terminated UTF-8 string 02724 ** and sqlite3_column_name16() returns a pointer to a zero-terminated 02725 ** UTF-16 string. ^The first parameter is the [prepared statement] 02726 ** that implements the [SELECT] statement. ^The second parameter is the 02727 ** column number. ^The leftmost column is number 0. 02728 ** 02729 ** ^The returned string pointer is valid until either the [prepared statement] 02730 ** is destroyed by [sqlite3_finalize()] or until the next call to 02731 ** sqlite3_column_name() or sqlite3_column_name16() on the same column. 02732 ** 02733 ** ^If sqlite3_malloc() fails during the processing of either routine 02734 ** (for example during a conversion from UTF-8 to UTF-16) then a 02735 ** NULL pointer is returned. 02736 ** 02737 ** ^The name of a result column is the value of the "AS" clause for 02738 ** that column, if there is an AS clause. If there is no AS clause 02739 ** then the name of the column is unspecified and may change from 02740 ** one release of SQLite to the next. 02741 */ 02742 SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N); 02743 SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N); 02744 02745 /* 02746 ** CAPI3REF: Source Of Data In A Query Result 02747 ** 02748 ** ^These routines provide a means to determine the database, table, and 02749 ** table column that is the origin of a particular result column in 02750 ** [SELECT] statement. 02751 ** ^The name of the database or table or column can be returned as 02752 ** either a UTF-8 or UTF-16 string. ^The _database_ routines return 02753 ** the database name, the _table_ routines return the table name, and 02754 ** the origin_ routines return the column name. 02755 ** ^The returned string is valid until the [prepared statement] is destroyed 02756 ** using [sqlite3_finalize()] or until the same information is requested 02757 ** again in a different encoding. 02758 ** 02759 ** ^The names returned are the original un-aliased names of the 02760 ** database, table, and column. 02761 ** 02762 ** ^The first argument to these interfaces is a [prepared statement]. 02763 ** ^These functions return information about the Nth result column returned by 02764 ** the statement, where N is the second function argument. 02765 ** ^The left-most column is column 0 for these routines. 02766 ** 02767 ** ^If the Nth column returned by the statement is an expression or 02768 ** subquery and is not a column value, then all of these functions return 02769 ** NULL. ^These routine might also return NULL if a memory allocation error 02770 ** occurs. ^Otherwise, they return the name of the attached database, table, 02771 ** or column that query result column was extracted from. 02772 ** 02773 ** ^As with all other SQLite APIs, those whose names end with "16" return 02774 ** UTF-16 encoded strings and the other functions return UTF-8. 02775 ** 02776 ** ^These APIs are only available if the library was compiled with the 02777 ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol. 02778 ** 02779 ** If two or more threads call one or more of these routines against the same 02780 ** prepared statement and column at the same time then the results are 02781 ** undefined. 02782 ** 02783 ** If two or more threads call one or more 02784 ** [sqlite3_column_database_name | column metadata interfaces] 02785 ** for the same [prepared statement] and result column 02786 ** at the same time then the results are undefined. 02787 */ 02788 SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int); 02789 SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int); 02790 SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int); 02791 SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int); 02792 SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int); 02793 SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int); 02794 02795 /* 02796 ** CAPI3REF: Declared Datatype Of A Query Result 02797 ** 02798 ** ^(The first parameter is a [prepared statement]. 02799 ** If this statement is a [SELECT] statement and the Nth column of the 02800 ** returned result set of that [SELECT] is a table column (not an 02801 ** expression or subquery) then the declared type of the table 02802 ** column is returned.)^ ^If the Nth column of the result set is an 02803 ** expression or subquery, then a NULL pointer is returned. 02804 ** ^The returned string is always UTF-8 encoded. 02805 ** 02806 ** ^(For example, given the database schema: 02807 ** 02808 ** CREATE TABLE t1(c1 VARIANT); 02809 ** 02810 ** and the following statement to be compiled: 02811 ** 02812 ** SELECT c1 + 1, c1 FROM t1; 02813 ** 02814 ** this routine would return the string "VARIANT" for the second result 02815 ** column (i==1), and a NULL pointer for the first result column (i==0).)^ 02816 ** 02817 ** ^SQLite uses dynamic run-time typing. ^So just because a column 02818 ** is declared to contain a particular type does not mean that the 02819 ** data stored in that column is of the declared type. SQLite is 02820 ** strongly typed, but the typing is dynamic not static. ^Type 02821 ** is associated with individual values, not with the containers 02822 ** used to hold those values. 02823 */ 02824 SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int); 02825 SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int); 02826 02827 /* 02828 ** CAPI3REF: Evaluate An SQL Statement 02829 ** 02830 ** After a [prepared statement] has been prepared using either 02831 ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy 02832 ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function 02833 ** must be called one or more times to evaluate the statement. 02834 ** 02835 ** The details of the behavior of the sqlite3_step() interface depend 02836 ** on whether the statement was prepared using the newer "v2" interface 02837 ** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy 02838 ** interface [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the 02839 ** new "v2" interface is recommended for new applications but the legacy 02840 ** interface will continue to be supported. 02841 ** 02842 ** ^In the legacy interface, the return value will be either [SQLITE_BUSY], 02843 ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE]. 02844 ** ^With the "v2" interface, any of the other [result codes] or 02845 ** [extended result codes] might be returned as well. 02846 ** 02847 ** ^[SQLITE_BUSY] means that the database engine was unable to acquire the 02848 ** database locks it needs to do its job. ^If the statement is a [COMMIT] 02849 ** or occurs outside of an explicit transaction, then you can retry the 02850 ** statement. If the statement is not a [COMMIT] and occurs within a 02851 ** explicit transaction then you should rollback the transaction before 02852 ** continuing. 02853 ** 02854 ** ^[SQLITE_DONE] means that the statement has finished executing 02855 ** successfully. sqlite3_step() should not be called again on this virtual 02856 ** machine without first calling [sqlite3_reset()] to reset the virtual 02857 ** machine back to its initial state. 02858 ** 02859 ** ^If the SQL statement being executed returns any data, then [SQLITE_ROW] 02860 ** is returned each time a new row of data is ready for processing by the 02861 ** caller. The values may be accessed using the [column access functions]. 02862 ** sqlite3_step() is called again to retrieve the next row of data. 02863 ** 02864 ** ^[SQLITE_ERROR] means that a run-time error (such as a constraint 02865 ** violation) has occurred. sqlite3_step() should not be called again on 02866 ** the VM. More information may be found by calling [sqlite3_errmsg()]. 02867 ** ^With the legacy interface, a more specific error code (for example, 02868 ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth) 02869 ** can be obtained by calling [sqlite3_reset()] on the 02870 ** [prepared statement]. ^In the "v2" interface, 02871 ** the more specific error code is returned directly by sqlite3_step(). 02872 ** 02873 ** [SQLITE_MISUSE] means that the this routine was called inappropriately. 02874 ** Perhaps it was called on a [prepared statement] that has 02875 ** already been [sqlite3_finalize | finalized] or on one that had 02876 ** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could 02877 ** be the case that the same database connection is being used by two or 02878 ** more threads at the same moment in time. 02879 ** 02880 ** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step() 02881 ** API always returns a generic error code, [SQLITE_ERROR], following any 02882 ** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call 02883 ** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the 02884 ** specific [error codes] that better describes the error. 02885 ** We admit that this is a goofy design. The problem has been fixed 02886 ** with the "v2" interface. If you prepare all of your SQL statements 02887 ** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead 02888 ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces, 02889 ** then the more specific [error codes] are returned directly 02890 ** by sqlite3_step(). The use of the "v2" interface is recommended. 02891 */ 02892 SQLITE_API int sqlite3_step(sqlite3_stmt*); 02893 02894 /* 02895 ** CAPI3REF: Number of columns in a result set 02896 ** 02897 ** ^The sqlite3_data_count(P) the number of columns in the 02898 ** of the result set of [prepared statement] P. 02899 */ 02900 SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt); 02901 02902 /* 02903 ** CAPI3REF: Fundamental Datatypes 02904 ** KEYWORDS: SQLITE_TEXT 02905 ** 02906 ** ^(Every value in SQLite has one of five fundamental datatypes: 02907 ** 02908 ** <ul> 02909 ** <li> 64-bit signed integer 02910 ** <li> 64-bit IEEE floating point number 02911 ** <li> string 02912 ** <li> BLOB 02913 ** <li> NULL 02914 ** </ul>)^ 02915 ** 02916 ** These constants are codes for each of those types. 02917 ** 02918 ** Note that the SQLITE_TEXT constant was also used in SQLite version 2 02919 ** for a completely different meaning. Software that links against both 02920 ** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not 02921 ** SQLITE_TEXT. 02922 */ 02923 #define SQLITE_INTEGER 1 02924 #define SQLITE_FLOAT 2 02925 #define SQLITE_BLOB 4 02926 #define SQLITE_NULL 5 02927 #ifdef SQLITE_TEXT 02928 # undef SQLITE_TEXT 02929 #else 02930 # define SQLITE_TEXT 3 02931 #endif 02932 #define SQLITE3_TEXT 3 02933 02934 /* 02935 ** CAPI3REF: Result Values From A Query 02936 ** KEYWORDS: {column access functions} 02937 ** 02938 ** These routines form the "result set" interface. 02939 ** 02940 ** ^These routines return information about a single column of the current 02941 ** result row of a query. ^In every case the first argument is a pointer 02942 ** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*] 02943 ** that was returned from [sqlite3_prepare_v2()] or one of its variants) 02944 ** and the second argument is the index of the column for which information 02945 ** should be returned. ^The leftmost column of the result set has the index 0. 02946 ** ^The number of columns in the result can be determined using 02947 ** [sqlite3_column_count()]. 02948 ** 02949 ** If the SQL statement does not currently point to a valid row, or if the 02950 ** column index is out of range, the result is undefined. 02951 ** These routines may only be called when the most recent call to 02952 ** [sqlite3_step()] has returned [SQLITE_ROW] and neither 02953 ** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently. 02954 ** If any of these routines are called after [sqlite3_reset()] or 02955 ** [sqlite3_finalize()] or after [sqlite3_step()] has returned 02956 ** something other than [SQLITE_ROW], the results are undefined. 02957 ** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()] 02958 ** are called from a different thread while any of these routines 02959 ** are pending, then the results are undefined. 02960 ** 02961 ** ^The sqlite3_column_type() routine returns the 02962 ** [SQLITE_INTEGER | datatype code] for the initial data type 02963 ** of the result column. ^The returned value is one of [SQLITE_INTEGER], 02964 ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL]. The value 02965 ** returned by sqlite3_column_type() is only meaningful if no type 02966 ** conversions have occurred as described below. After a type conversion, 02967 ** the value returned by sqlite3_column_type() is undefined. Future 02968 ** versions of SQLite may change the behavior of sqlite3_column_type() 02969 ** following a type conversion. 02970 ** 02971 ** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes() 02972 ** routine returns the number of bytes in that BLOB or string. 02973 ** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts 02974 ** the string to UTF-8 and then returns the number of bytes. 02975 ** ^If the result is a numeric value then sqlite3_column_bytes() uses 02976 ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns 02977 ** the number of bytes in that string. 02978 ** ^The value returned does not include the zero terminator at the end 02979 ** of the string. ^For clarity: the value returned is the number of 02980 ** bytes in the string, not the number of characters. 02981 ** 02982 ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(), 02983 ** even empty strings, are always zero terminated. ^The return 02984 ** value from sqlite3_column_blob() for a zero-length BLOB is an arbitrary 02985 ** pointer, possibly even a NULL pointer. 02986 ** 02987 ** ^The sqlite3_column_bytes16() routine is similar to sqlite3_column_bytes() 02988 ** but leaves the result in UTF-16 in native byte order instead of UTF-8. 02989 ** ^The zero terminator is not included in this count. 02990 ** 02991 ** ^The object returned by [sqlite3_column_value()] is an 02992 ** [unprotected sqlite3_value] object. An unprotected sqlite3_value object 02993 ** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()]. 02994 ** If the [unprotected sqlite3_value] object returned by 02995 ** [sqlite3_column_value()] is used in any other way, including calls 02996 ** to routines like [sqlite3_value_int()], [sqlite3_value_text()], 02997 ** or [sqlite3_value_bytes()], then the behavior is undefined. 02998 ** 02999 ** These routines attempt to convert the value where appropriate. ^For 03000 ** example, if the internal representation is FLOAT and a text result 03001 ** is requested, [sqlite3_snprintf()] is used internally to perform the 03002 ** conversion automatically. ^(The following table details the conversions 03003 ** that are applied: 03004 ** 03005 ** <blockquote> 03006 ** <table border="1"> 03007 ** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion 03008 ** 03009 ** <tr><td> NULL <td> INTEGER <td> Result is 0 03010 ** <tr><td> NULL <td> FLOAT <td> Result is 0.0 03011 ** <tr><td> NULL <td> TEXT <td> Result is NULL pointer 03012 ** <tr><td> NULL <td> BLOB <td> Result is NULL pointer 03013 ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float 03014 ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer 03015 ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT 03016 ** <tr><td> FLOAT <td> INTEGER <td> Convert from float to integer 03017 ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float 03018 ** <tr><td> FLOAT <td> BLOB <td> Same as FLOAT->TEXT 03019 ** <tr><td> TEXT <td> INTEGER <td> Use atoi() 03020 ** <tr><td> TEXT <td> FLOAT <td> Use atof() 03021 ** <tr><td> TEXT <td> BLOB <td> No change 03022 ** <tr><td> BLOB <td> INTEGER <td> Convert to TEXT then use atoi() 03023 ** <tr><td> BLOB <td> FLOAT <td> Convert to TEXT then use atof() 03024 ** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed 03025 ** </table> 03026 ** </blockquote>)^ 03027 ** 03028 ** The table above makes reference to standard C library functions atoi() 03029 ** and atof(). SQLite does not really use these functions. It has its 03030 ** own equivalent internal routines. The atoi() and atof() names are 03031 ** used in the table for brevity and because they are familiar to most 03032 ** C programmers. 03033 ** 03034 ** ^Note that when type conversions occur, pointers returned by prior 03035 ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or 03036 ** sqlite3_column_text16() may be invalidated. 03037 ** ^(Type conversions and pointer invalidations might occur 03038 ** in the following cases: 03039 ** 03040 ** <ul> 03041 ** <li> The initial content is a BLOB and sqlite3_column_text() or 03042 ** sqlite3_column_text16() is called. A zero-terminator might 03043 ** need to be added to the string.</li> 03044 ** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or 03045 ** sqlite3_column_text16() is called. The content must be converted 03046 ** to UTF-16.</li> 03047 ** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or 03048 ** sqlite3_column_text() is called. The content must be converted 03049 ** to UTF-8.</li> 03050 ** </ul>)^ 03051 ** 03052 ** ^Conversions between UTF-16be and UTF-16le are always done in place and do 03053 ** not invalidate a prior pointer, though of course the content of the buffer 03054 ** that the prior pointer points to will have been modified. Other kinds 03055 ** of conversion are done in place when it is possible, but sometimes they 03056 ** are not possible and in those cases prior pointers are invalidated. 03057 ** 03058 ** ^(The safest and easiest to remember policy is to invoke these routines 03059 ** in one of the following ways: 03060 ** 03061 ** <ul> 03062 ** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li> 03063 ** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li> 03064 ** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li> 03065 ** </ul>)^ 03066 ** 03067 ** In other words, you should call sqlite3_column_text(), 03068 ** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result 03069 ** into the desired format, then invoke sqlite3_column_bytes() or 03070 ** sqlite3_column_bytes16() to find the size of the result. Do not mix calls 03071 ** to sqlite3_column_text() or sqlite3_column_blob() with calls to 03072 ** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16() 03073 ** with calls to sqlite3_column_bytes(). 03074 ** 03075 ** ^The pointers returned are valid until a type conversion occurs as 03076 ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or 03077 ** [sqlite3_finalize()] is called. ^The memory space used to hold strings 03078 ** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned 03079 ** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into 03080 ** [sqlite3_free()]. 03081 ** 03082 ** ^(If a memory allocation error occurs during the evaluation of any 03083 ** of these routines, a default value is returned. The default value 03084 ** is either the integer 0, the floating point number 0.0, or a NULL 03085 ** pointer. Subsequent calls to [sqlite3_errcode()] will return 03086 ** [SQLITE_NOMEM].)^ 03087 */ 03088 SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol); 03089 SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol); 03090 SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol); 03091 SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol); 03092 SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol); 03093 SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol); 03094 SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol); 03095 SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol); 03096 SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol); 03097 SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol); 03098 03099 /* 03100 ** CAPI3REF: Destroy A Prepared Statement Object 03101 ** 03102 ** ^The sqlite3_finalize() function is called to delete a [prepared statement]. 03103 ** ^If the statement was executed successfully or not executed at all, then 03104 ** SQLITE_OK is returned. ^If execution of the statement failed then an 03105 ** [error code] or [extended error code] is returned. 03106 ** 03107 ** ^This routine can be called at any point during the execution of the 03108 ** [prepared statement]. ^If the virtual machine has not 03109 ** completed execution when this routine is called, that is like 03110 ** encountering an error or an [sqlite3_interrupt | interrupt]. 03111 ** ^Incomplete updates may be rolled back and transactions canceled, 03112 ** depending on the circumstances, and the 03113 ** [error code] returned will be [SQLITE_ABORT]. 03114 */ 03115 SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt); 03116 03117 /* 03118 ** CAPI3REF: Reset A Prepared Statement Object 03119 ** 03120 ** The sqlite3_reset() function is called to reset a [prepared statement] 03121 ** object back to its initial state, ready to be re-executed. 03122 ** ^Any SQL statement variables that had values bound to them using 03123 ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values. 03124 ** Use [sqlite3_clear_bindings()] to reset the bindings. 03125 ** 03126 ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S 03127 ** back to the beginning of its program. 03128 ** 03129 ** ^If the most recent call to [sqlite3_step(S)] for the 03130 ** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE], 03131 ** or if [sqlite3_step(S)] has never before been called on S, 03132 ** then [sqlite3_reset(S)] returns [SQLITE_OK]. 03133 ** 03134 ** ^If the most recent call to [sqlite3_step(S)] for the 03135 ** [prepared statement] S indicated an error, then 03136 ** [sqlite3_reset(S)] returns an appropriate [error code]. 03137 ** 03138 ** ^The [sqlite3_reset(S)] interface does not change the values 03139 ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S. 03140 */ 03141 SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt); 03142 03143 /* 03144 ** CAPI3REF: Create Or Redefine SQL Functions 03145 ** KEYWORDS: {function creation routines} 03146 ** KEYWORDS: {application-defined SQL function} 03147 ** KEYWORDS: {application-defined SQL functions} 03148 ** 03149 ** ^These two functions (collectively known as "function creation routines") 03150 ** are used to add SQL functions or aggregates or to redefine the behavior 03151 ** of existing SQL functions or aggregates. The only difference between the 03152 ** two is that the second parameter, the name of the (scalar) function or 03153 ** aggregate, is encoded in UTF-8 for sqlite3_create_function() and UTF-16 03154 ** for sqlite3_create_function16(). 03155 ** 03156 ** ^The first parameter is the [database connection] to which the SQL 03157 ** function is to be added. ^If an application uses more than one database 03158 ** connection then application-defined SQL functions must be added 03159 ** to each database connection separately. 03160 ** 03161 ** The second parameter is the name of the SQL function to be created or 03162 ** redefined. ^The length of the name is limited to 255 bytes, exclusive of 03163 ** the zero-terminator. Note that the name length limit is in bytes, not 03164 ** characters. ^Any attempt to create a function with a longer name 03165 ** will result in [SQLITE_ERROR] being returned. 03166 ** 03167 ** ^The third parameter (nArg) 03168 ** is the number of arguments that the SQL function or 03169 ** aggregate takes. ^If this parameter is -1, then the SQL function or 03170 ** aggregate may take any number of arguments between 0 and the limit 03171 ** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third 03172 ** parameter is less than -1 or greater than 127 then the behavior is 03173 ** undefined. 03174 ** 03175 ** The fourth parameter, eTextRep, specifies what 03176 ** [SQLITE_UTF8 | text encoding] this SQL function prefers for 03177 ** its parameters. Any SQL function implementation should be able to work 03178 ** work with UTF-8, UTF-16le, or UTF-16be. But some implementations may be 03179 ** more efficient with one encoding than another. ^An application may 03180 ** invoke sqlite3_create_function() or sqlite3_create_function16() multiple 03181 ** times with the same function but with different values of eTextRep. 03182 ** ^When multiple implementations of the same function are available, SQLite 03183 ** will pick the one that involves the least amount of data conversion. 03184 ** If there is only a single implementation which does not care what text 03185 ** encoding is used, then the fourth argument should be [SQLITE_ANY]. 03186 ** 03187 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the 03188 ** function can gain access to this pointer using [sqlite3_user_data()].)^ 03189 ** 03190 ** The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are 03191 ** pointers to C-language functions that implement the SQL function or 03192 ** aggregate. ^A scalar SQL function requires an implementation of the xFunc 03193 ** callback only; NULL pointers should be passed as the xStep and xFinal 03194 ** parameters. ^An aggregate SQL function requires an implementation of xStep 03195 ** and xFinal and NULL should be passed for xFunc. ^To delete an existing 03196 ** SQL function or aggregate, pass NULL for all three function callbacks. 03197 ** 03198 ** ^It is permitted to register multiple implementations of the same 03199 ** functions with the same name but with either differing numbers of 03200 ** arguments or differing preferred text encodings. ^SQLite will use 03201 ** the implementation that most closely matches the way in which the 03202 ** SQL function is used. ^A function implementation with a non-negative 03203 ** nArg parameter is a better match than a function implementation with 03204 ** a negative nArg. ^A function where the preferred text encoding 03205 ** matches the database encoding is a better 03206 ** match than a function where the encoding is different. 03207 ** ^A function where the encoding difference is between UTF16le and UTF16be 03208 ** is a closer match than a function where the encoding difference is 03209 ** between UTF8 and UTF16. 03210 ** 03211 ** ^Built-in functions may be overloaded by new application-defined functions. 03212 ** ^The first application-defined function with a given name overrides all 03213 ** built-in functions in the same [database connection] with the same name. 03214 ** ^Subsequent application-defined functions of the same name only override 03215 ** prior application-defined functions that are an exact match for the 03216 ** number of parameters and preferred encoding. 03217 ** 03218 ** ^An application-defined function is permitted to call other 03219 ** SQLite interfaces. However, such calls must not 03220 ** close the database connection nor finalize or reset the prepared 03221 ** statement in which the function is running. 03222 */ 03223 SQLITE_API int sqlite3_create_function( 03224 sqlite3 *db, 03225 const char *zFunctionName, 03226 int nArg, 03227 int eTextRep, 03228 void *pApp, 03229 void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 03230 void (*xStep)(sqlite3_context*,int,sqlite3_value**), 03231 void (*xFinal)(sqlite3_context*) 03232 ); 03233 SQLITE_API int sqlite3_create_function16( 03234 sqlite3 *db, 03235 const void *zFunctionName, 03236 int nArg, 03237 int eTextRep, 03238 void *pApp, 03239 void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 03240 void (*xStep)(sqlite3_context*,int,sqlite3_value**), 03241 void (*xFinal)(sqlite3_context*) 03242 ); 03243 03244 /* 03245 ** CAPI3REF: Text Encodings 03246 ** 03247 ** These constant define integer codes that represent the various 03248 ** text encodings supported by SQLite. 03249 */ 03250 #define SQLITE_UTF8 1 03251 #define SQLITE_UTF16LE 2 03252 #define SQLITE_UTF16BE 3 03253 #define SQLITE_UTF16 4 /* Use native byte order */ 03254 #define SQLITE_ANY 5 /* sqlite3_create_function only */ 03255 #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */ 03256 03257 /* 03258 ** CAPI3REF: Deprecated Functions 03259 ** DEPRECATED 03260 ** 03261 ** These functions are [deprecated]. In order to maintain 03262 ** backwards compatibility with older code, these functions continue 03263 ** to be supported. However, new applications should avoid 03264 ** the use of these functions. To help encourage people to avoid 03265 ** using these functions, we are not going to tell you what they do. 03266 */ 03267 #ifndef SQLITE_OMIT_DEPRECATED 03268 SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*); 03269 SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*); 03270 SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*); 03271 SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void); 03272 SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void); 03273 SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),void*,sqlite3_int64); 03274 #endif 03275 03276 /* 03277 ** CAPI3REF: Obtaining SQL Function Parameter Values 03278 ** 03279 ** The C-language implementation of SQL functions and aggregates uses 03280 ** this set of interface routines to access the parameter values on 03281 ** the function or aggregate. 03282 ** 03283 ** The xFunc (for scalar functions) or xStep (for aggregates) parameters 03284 ** to [sqlite3_create_function()] and [sqlite3_create_function16()] 03285 ** define callbacks that implement the SQL functions and aggregates. 03286 ** The 4th parameter to these callbacks is an array of pointers to 03287 ** [protected sqlite3_value] objects. There is one [sqlite3_value] object for 03288 ** each parameter to the SQL function. These routines are used to 03289 ** extract values from the [sqlite3_value] objects. 03290 ** 03291 ** These routines work only with [protected sqlite3_value] objects. 03292 ** Any attempt to use these routines on an [unprotected sqlite3_value] 03293 ** object results in undefined behavior. 03294 ** 03295 ** ^These routines work just like the corresponding [column access functions] 03296 ** except that these routines take a single [protected sqlite3_value] object 03297 ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number. 03298 ** 03299 ** ^The sqlite3_value_text16() interface extracts a UTF-16 string 03300 ** in the native byte-order of the host machine. ^The 03301 ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces 03302 ** extract UTF-16 strings as big-endian and little-endian respectively. 03303 ** 03304 ** ^(The sqlite3_value_numeric_type() interface attempts to apply 03305 ** numeric affinity to the value. This means that an attempt is 03306 ** made to convert the value to an integer or floating point. If 03307 ** such a conversion is possible without loss of information (in other 03308 ** words, if the value is a string that looks like a number) 03309 ** then the conversion is performed. Otherwise no conversion occurs. 03310 ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^ 03311 ** 03312 ** Please pay particular attention to the fact that the pointer returned 03313 ** from [sqlite3_value_blob()], [sqlite3_value_text()], or 03314 ** [sqlite3_value_text16()] can be invalidated by a subsequent call to 03315 ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()], 03316 ** or [sqlite3_value_text16()]. 03317 ** 03318 ** These routines must be called from the same thread as 03319 ** the SQL function that supplied the [sqlite3_value*] parameters. 03320 */ 03321 SQLITE_API const void *sqlite3_value_blob(sqlite3_value*); 03322 SQLITE_API int sqlite3_value_bytes(sqlite3_value*); 03323 SQLITE_API int sqlite3_value_bytes16(sqlite3_value*); 03324 SQLITE_API double sqlite3_value_double(sqlite3_value*); 03325 SQLITE_API int sqlite3_value_int(sqlite3_value*); 03326 SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*); 03327 SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*); 03328 SQLITE_API const void *sqlite3_value_text16(sqlite3_value*); 03329 SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*); 03330 SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*); 03331 SQLITE_API int sqlite3_value_type(sqlite3_value*); 03332 SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*); 03333 03334 /* 03335 ** CAPI3REF: Obtain Aggregate Function Context 03336 ** 03337 ** Implementions of aggregate SQL functions use this 03338 ** routine to allocate memory for storing their state. 03339 ** 03340 ** ^The first time the sqlite3_aggregate_context(C,N) routine is called 03341 ** for a particular aggregate function, SQLite 03342 ** allocates N of memory, zeroes out that memory, and returns a pointer 03343 ** to the new memory. ^On second and subsequent calls to 03344 ** sqlite3_aggregate_context() for the same aggregate function instance, 03345 ** the same buffer is returned. Sqlite3_aggregate_context() is normally 03346 ** called once for each invocation of the xStep callback and then one 03347 ** last time when the xFinal callback is invoked. ^(When no rows match 03348 ** an aggregate query, the xStep() callback of the aggregate function 03349 ** implementation is never called and xFinal() is called exactly once. 03350 ** In those cases, sqlite3_aggregate_context() might be called for the 03351 ** first time from within xFinal().)^ 03352 ** 03353 ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer if N is 03354 ** less than or equal to zero or if a memory allocate error occurs. 03355 ** 03356 ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is 03357 ** determined by the N parameter on first successful call. Changing the 03358 ** value of N in subsequent call to sqlite3_aggregate_context() within 03359 ** the same aggregate function instance will not resize the memory 03360 ** allocation.)^ 03361 ** 03362 ** ^SQLite automatically frees the memory allocated by 03363 ** sqlite3_aggregate_context() when the aggregate query concludes. 03364 ** 03365 ** The first parameter must be a copy of the 03366 ** [sqlite3_context | SQL function context] that is the first parameter 03367 ** to the xStep or xFinal callback routine that implements the aggregate 03368 ** function. 03369 ** 03370 ** This routine must be called from the same thread in which 03371 ** the aggregate SQL function is running. 03372 */ 03373 SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); 03374 03375 /* 03376 ** CAPI3REF: User Data For Functions 03377 ** 03378 ** ^The sqlite3_user_data() interface returns a copy of 03379 ** the pointer that was the pUserData parameter (the 5th parameter) 03380 ** of the [sqlite3_create_function()] 03381 ** and [sqlite3_create_function16()] routines that originally 03382 ** registered the application defined function. 03383 ** 03384 ** This routine must be called from the same thread in which 03385 ** the application-defined function is running. 03386 */ 03387 SQLITE_API void *sqlite3_user_data(sqlite3_context*); 03388 03389 /* 03390 ** CAPI3REF: Database Connection For Functions 03391 ** 03392 ** ^The sqlite3_context_db_handle() interface returns a copy of 03393 ** the pointer to the [database connection] (the 1st parameter) 03394 ** of the [sqlite3_create_function()] 03395 ** and [sqlite3_create_function16()] routines that originally 03396 ** registered the application defined function. 03397 */ 03398 SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*); 03399 03400 /* 03401 ** CAPI3REF: Function Auxiliary Data 03402 ** 03403 ** The following two functions may be used by scalar SQL functions to 03404 ** associate metadata with argument values. If the same value is passed to 03405 ** multiple invocations of the same SQL function during query execution, under 03406 ** some circumstances the associated metadata may be preserved. This may 03407 ** be used, for example, to add a regular-expression matching scalar 03408 ** function. The compiled version of the regular expression is stored as 03409 ** metadata associated with the SQL value passed as the regular expression 03410 ** pattern. The compiled regular expression can be reused on multiple 03411 ** invocations of the same function so that the original pattern string 03412 ** does not need to be recompiled on each invocation. 03413 ** 03414 ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata 03415 ** associated by the sqlite3_set_auxdata() function with the Nth argument 03416 ** value to the application-defined function. ^If no metadata has been ever 03417 ** been set for the Nth argument of the function, or if the corresponding 03418 ** function parameter has changed since the meta-data was set, 03419 ** then sqlite3_get_auxdata() returns a NULL pointer. 03420 ** 03421 ** ^The sqlite3_set_auxdata() interface saves the metadata 03422 ** pointed to by its 3rd parameter as the metadata for the N-th 03423 ** argument of the application-defined function. Subsequent 03424 ** calls to sqlite3_get_auxdata() might return this data, if it has 03425 ** not been destroyed. 03426 ** ^If it is not NULL, SQLite will invoke the destructor 03427 ** function given by the 4th parameter to sqlite3_set_auxdata() on 03428 ** the metadata when the corresponding function parameter changes 03429 ** or when the SQL statement completes, whichever comes first. 03430 ** 03431 ** SQLite is free to call the destructor and drop metadata on any 03432 ** parameter of any function at any time. ^The only guarantee is that 03433 ** the destructor will be called before the metadata is dropped. 03434 ** 03435 ** ^(In practice, metadata is preserved between function calls for 03436 ** expressions that are constant at compile time. This includes literal 03437 ** values and [parameters].)^ 03438 ** 03439 ** These routines must be called from the same thread in which 03440 ** the SQL function is running. 03441 */ 03442 SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N); 03443 SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*)); 03444 03445 03446 /* 03447 ** CAPI3REF: Constants Defining Special Destructor Behavior 03448 ** 03449 ** These are special values for the destructor that is passed in as the 03450 ** final argument to routines like [sqlite3_result_blob()]. ^If the destructor 03451 ** argument is SQLITE_STATIC, it means that the content pointer is constant 03452 ** and will never change. It does not need to be destroyed. ^The 03453 ** SQLITE_TRANSIENT value means that the content will likely change in 03454 ** the near future and that SQLite should make its own private copy of 03455 ** the content before returning. 03456 ** 03457 ** The typedef is necessary to work around problems in certain 03458 ** C++ compilers. See ticket #2191. 03459 */ 03460 typedef void (*sqlite3_destructor_type)(void*); 03461 #define SQLITE_STATIC ((sqlite3_destructor_type)0) 03462 #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) 03463 03464 /* 03465 ** CAPI3REF: Setting The Result Of An SQL Function 03466 ** 03467 ** These routines are used by the xFunc or xFinal callbacks that 03468 ** implement SQL functions and aggregates. See 03469 ** [sqlite3_create_function()] and [sqlite3_create_function16()] 03470 ** for additional information. 03471 ** 03472 ** These functions work very much like the [parameter binding] family of 03473 ** functions used to bind values to host parameters in prepared statements. 03474 ** Refer to the [SQL parameter] documentation for additional information. 03475 ** 03476 ** ^The sqlite3_result_blob() interface sets the result from 03477 ** an application-defined function to be the BLOB whose content is pointed 03478 ** to by the second parameter and which is N bytes long where N is the 03479 ** third parameter. 03480 ** 03481 ** ^The sqlite3_result_zeroblob() interfaces set the result of 03482 ** the application-defined function to be a BLOB containing all zero 03483 ** bytes and N bytes in size, where N is the value of the 2nd parameter. 03484 ** 03485 ** ^The sqlite3_result_double() interface sets the result from 03486 ** an application-defined function to be a floating point value specified 03487 ** by its 2nd argument. 03488 ** 03489 ** ^The sqlite3_result_error() and sqlite3_result_error16() functions 03490 ** cause the implemented SQL function to throw an exception. 03491 ** ^SQLite uses the string pointed to by the 03492 ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16() 03493 ** as the text of an error message. ^SQLite interprets the error 03494 ** message string from sqlite3_result_error() as UTF-8. ^SQLite 03495 ** interprets the string from sqlite3_result_error16() as UTF-16 in native 03496 ** byte order. ^If the third parameter to sqlite3_result_error() 03497 ** or sqlite3_result_error16() is negative then SQLite takes as the error 03498 ** message all text up through the first zero character. 03499 ** ^If the third parameter to sqlite3_result_error() or 03500 ** sqlite3_result_error16() is non-negative then SQLite takes that many 03501 ** bytes (not characters) from the 2nd parameter as the error message. 03502 ** ^The sqlite3_result_error() and sqlite3_result_error16() 03503 ** routines make a private copy of the error message text before 03504 ** they return. Hence, the calling function can deallocate or 03505 ** modify the text after they return without harm. 03506 ** ^The sqlite3_result_error_code() function changes the error code 03507 ** returned by SQLite as a result of an error in a function. ^By default, 03508 ** the error code is SQLITE_ERROR. ^A subsequent call to sqlite3_result_error() 03509 ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR. 03510 ** 03511 ** ^The sqlite3_result_toobig() interface causes SQLite to throw an error 03512 ** indicating that a string or BLOB is too long to represent. 03513 ** 03514 ** ^The sqlite3_result_nomem() interface causes SQLite to throw an error 03515 ** indicating that a memory allocation failed. 03516 ** 03517 ** ^The sqlite3_result_int() interface sets the return value 03518 ** of the application-defined function to be the 32-bit signed integer 03519 ** value given in the 2nd argument. 03520 ** ^The sqlite3_result_int64() interface sets the return value 03521 ** of the application-defined function to be the 64-bit signed integer 03522 ** value given in the 2nd argument. 03523 ** 03524 ** ^The sqlite3_result_null() interface sets the return value 03525 ** of the application-defined function to be NULL. 03526 ** 03527 ** ^The sqlite3_result_text(), sqlite3_result_text16(), 03528 ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces 03529 ** set the return value of the application-defined function to be 03530 ** a text string which is represented as UTF-8, UTF-16 native byte order, 03531 ** UTF-16 little endian, or UTF-16 big endian, respectively. 03532 ** ^SQLite takes the text result from the application from 03533 ** the 2nd parameter of the sqlite3_result_text* interfaces. 03534 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces 03535 ** is negative, then SQLite takes result text from the 2nd parameter 03536 ** through the first zero character. 03537 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces 03538 ** is non-negative, then as many bytes (not characters) of the text 03539 ** pointed to by the 2nd parameter are taken as the application-defined 03540 ** function result. 03541 ** ^If the 4th parameter to the sqlite3_result_text* interfaces 03542 ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that 03543 ** function as the destructor on the text or BLOB result when it has 03544 ** finished using that result. 03545 ** ^If the 4th parameter to the sqlite3_result_text* interfaces or to 03546 ** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite 03547 ** assumes that the text or BLOB result is in constant space and does not 03548 ** copy the content of the parameter nor call a destructor on the content 03549 ** when it has finished using that result. 03550 ** ^If the 4th parameter to the sqlite3_result_text* interfaces 03551 ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT 03552 ** then SQLite makes a copy of the result into space obtained from 03553 ** from [sqlite3_malloc()] before it returns. 03554 ** 03555 ** ^The sqlite3_result_value() interface sets the result of 03556 ** the application-defined function to be a copy the 03557 ** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The 03558 ** sqlite3_result_value() interface makes a copy of the [sqlite3_value] 03559 ** so that the [sqlite3_value] specified in the parameter may change or 03560 ** be deallocated after sqlite3_result_value() returns without harm. 03561 ** ^A [protected sqlite3_value] object may always be used where an 03562 ** [unprotected sqlite3_value] object is required, so either 03563 ** kind of [sqlite3_value] object can be used with this interface. 03564 ** 03565 ** If these routines are called from within the different thread 03566 ** than the one containing the application-defined function that received 03567 ** the [sqlite3_context] pointer, the results are undefined. 03568 */ 03569 SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*)); 03570 SQLITE_API void sqlite3_result_double(sqlite3_context*, double); 03571 SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int); 03572 SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int); 03573 SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*); 03574 SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*); 03575 SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int); 03576 SQLITE_API void sqlite3_result_int(sqlite3_context*, int); 03577 SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64); 03578 SQLITE_API void sqlite3_result_null(sqlite3_context*); 03579 SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*)); 03580 SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*)); 03581 SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*)); 03582 SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*)); 03583 SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*); 03584 SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n); 03585 03586 /* 03587 ** CAPI3REF: Define New Collating Sequences 03588 ** 03589 ** These functions are used to add new collation sequences to the 03590 ** [database connection] specified as the first argument. 03591 ** 03592 ** ^The name of the new collation sequence is specified as a UTF-8 string 03593 ** for sqlite3_create_collation() and sqlite3_create_collation_v2() 03594 ** and a UTF-16 string for sqlite3_create_collation16(). ^In all cases 03595 ** the name is passed as the second function argument. 03596 ** 03597 ** ^The third argument may be one of the constants [SQLITE_UTF8], 03598 ** [SQLITE_UTF16LE], or [SQLITE_UTF16BE], indicating that the user-supplied 03599 ** routine expects to be passed pointers to strings encoded using UTF-8, 03600 ** UTF-16 little-endian, or UTF-16 big-endian, respectively. ^The 03601 ** third argument might also be [SQLITE_UTF16] to indicate that the routine 03602 ** expects pointers to be UTF-16 strings in the native byte order, or the 03603 ** argument can be [SQLITE_UTF16_ALIGNED] if the 03604 ** the routine expects pointers to 16-bit word aligned strings 03605 ** of UTF-16 in the native byte order. 03606 ** 03607 ** A pointer to the user supplied routine must be passed as the fifth 03608 ** argument. ^If it is NULL, this is the same as deleting the collation 03609 ** sequence (so that SQLite cannot call it anymore). 03610 ** ^Each time the application supplied function is invoked, it is passed 03611 ** as its first parameter a copy of the void* passed as the fourth argument 03612 ** to sqlite3_create_collation() or sqlite3_create_collation16(). 03613 ** 03614 ** ^The remaining arguments to the application-supplied routine are two strings, 03615 ** each represented by a (length, data) pair and encoded in the encoding 03616 ** that was passed as the third argument when the collation sequence was 03617 ** registered. The application defined collation routine should 03618 ** return negative, zero or positive if the first string is less than, 03619 ** equal to, or greater than the second string. i.e. (STRING1 - STRING2). 03620 ** 03621 ** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation() 03622 ** except that it takes an extra argument which is a destructor for 03623 ** the collation. ^The destructor is called when the collation is 03624 ** destroyed and is passed a copy of the fourth parameter void* pointer 03625 ** of the sqlite3_create_collation_v2(). 03626 ** ^Collations are destroyed when they are overridden by later calls to the 03627 ** collation creation functions or when the [database connection] is closed 03628 ** using [sqlite3_close()]. 03629 ** 03630 ** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()]. 03631 */ 03632 SQLITE_API int sqlite3_create_collation( 03633 sqlite3*, 03634 const char *zName, 03635 int eTextRep, 03636 void*, 03637 int(*xCompare)(void*,int,const void*,int,const void*) 03638 ); 03639 SQLITE_API int sqlite3_create_collation_v2( 03640 sqlite3*, 03641 const char *zName, 03642 int eTextRep, 03643 void*, 03644 int(*xCompare)(void*,int,const void*,int,const void*), 03645 void(*xDestroy)(void*) 03646 ); 03647 SQLITE_API int sqlite3_create_collation16( 03648 sqlite3*, 03649 const void *zName, 03650 int eTextRep, 03651 void*, 03652 int(*xCompare)(void*,int,const void*,int,const void*) 03653 ); 03654 03655 /* 03656 ** CAPI3REF: Collation Needed Callbacks 03657 ** 03658 ** ^To avoid having to register all collation sequences before a database 03659 ** can be used, a single callback function may be registered with the 03660 ** [database connection] to be invoked whenever an undefined collation 03661 ** sequence is required. 03662 ** 03663 ** ^If the function is registered using the sqlite3_collation_needed() API, 03664 ** then it is passed the names of undefined collation sequences as strings 03665 ** encoded in UTF-8. ^If sqlite3_collation_needed16() is used, 03666 ** the names are passed as UTF-16 in machine native byte order. 03667 ** ^A call to either function replaces the existing collation-needed callback. 03668 ** 03669 ** ^(When the callback is invoked, the first argument passed is a copy 03670 ** of the second argument to sqlite3_collation_needed() or 03671 ** sqlite3_collation_needed16(). The second argument is the database 03672 ** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE], 03673 ** or [SQLITE_UTF16LE], indicating the most desirable form of the collation 03674 ** sequence function required. The fourth parameter is the name of the 03675 ** required collation sequence.)^ 03676 ** 03677 ** The callback function should register the desired collation using 03678 ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or 03679 ** [sqlite3_create_collation_v2()]. 03680 */ 03681 SQLITE_API int sqlite3_collation_needed( 03682 sqlite3*, 03683 void*, 03684 void(*)(void*,sqlite3*,int eTextRep,const char*) 03685 ); 03686 SQLITE_API int sqlite3_collation_needed16( 03687 sqlite3*, 03688 void*, 03689 void(*)(void*,sqlite3*,int eTextRep,const void*) 03690 ); 03691 03692 #if SQLITE_HAS_CODEC 03693 /* 03694 ** Specify the key for an encrypted database. This routine should be 03695 ** called right after sqlite3_open(). 03696 ** 03697 ** The code to implement this API is not available in the public release 03698 ** of SQLite. 03699 */ 03700 SQLITE_API int sqlite3_key( 03701 sqlite3 *db, /* Database to be rekeyed */ 03702 const void *pKey, int nKey /* The key */ 03703 ); 03704 03705 /* 03706 ** Change the key on an open database. If the current database is not 03707 ** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the 03708 ** database is decrypted. 03709 ** 03710 ** The code to implement this API is not available in the public release 03711 ** of SQLite. 03712 */ 03713 SQLITE_API int sqlite3_rekey( 03714 sqlite3 *db, /* Database to be rekeyed */ 03715 const void *pKey, int nKey /* The new key */ 03716 ); 03717 03718 /* 03719 ** Specify the activation key for a SEE database. Unless 03720 ** activated, none of the SEE routines will work. 03721 */ 03722 SQLITE_API void sqlite3_activate_see( 03723 const char *zPassPhrase /* Activation phrase */ 03724 ); 03725 #endif 03726 03727 #ifdef SQLITE_ENABLE_CEROD 03728 /* 03729 ** Specify the activation key for a CEROD database. Unless 03730 ** activated, none of the CEROD routines will work. 03731 */ 03732 SQLITE_API void sqlite3_activate_cerod( 03733 const char *zPassPhrase /* Activation phrase */ 03734 ); 03735 #endif 03736 03737 /* 03738 ** CAPI3REF: Suspend Execution For A Short Time 03739 ** 03740 ** ^The sqlite3_sleep() function causes the current thread to suspend execution 03741 ** for at least a number of milliseconds specified in its parameter. 03742 ** 03743 ** ^If the operating system does not support sleep requests with 03744 ** millisecond time resolution, then the time will be rounded up to 03745 ** the nearest second. ^The number of milliseconds of sleep actually 03746 ** requested from the operating system is returned. 03747 ** 03748 ** ^SQLite implements this interface by calling the xSleep() 03749 ** method of the default [sqlite3_vfs] object. 03750 */ 03751 SQLITE_API int sqlite3_sleep(int); 03752 03753 /* 03754 ** CAPI3REF: Name Of The Folder Holding Temporary Files 03755 ** 03756 ** ^(If this global variable is made to point to a string which is 03757 ** the name of a folder (a.k.a. directory), then all temporary files 03758 ** created by SQLite when using a built-in [sqlite3_vfs | VFS] 03759 ** will be placed in that directory.)^ ^If this variable 03760 ** is a NULL pointer, then SQLite performs a search for an appropriate 03761 ** temporary file directory. 03762 ** 03763 ** It is not safe to read or modify this variable in more than one 03764 ** thread at a time. It is not safe to read or modify this variable 03765 ** if a [database connection] is being used at the same time in a separate 03766 ** thread. 03767 ** It is intended that this variable be set once 03768 ** as part of process initialization and before any SQLite interface 03769 ** routines have been called and that this variable remain unchanged 03770 ** thereafter. 03771 ** 03772 ** ^The [temp_store_directory pragma] may modify this variable and cause 03773 ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore, 03774 ** the [temp_store_directory pragma] always assumes that any string 03775 ** that this variable points to is held in memory obtained from 03776 ** [sqlite3_malloc] and the pragma may attempt to free that memory 03777 ** using [sqlite3_free]. 03778 ** Hence, if this variable is modified directly, either it should be 03779 ** made NULL or made to point to memory obtained from [sqlite3_malloc] 03780 ** or else the use of the [temp_store_directory pragma] should be avoided. 03781 */ 03782 SQLITE_API SQLITE_EXTERN char *sqlite3_temp_directory; 03783 03784 /* 03785 ** CAPI3REF: Test For Auto-Commit Mode 03786 ** KEYWORDS: {autocommit mode} 03787 ** 03788 ** ^The sqlite3_get_autocommit() interface returns non-zero or 03789 ** zero if the given database connection is or is not in autocommit mode, 03790 ** respectively. ^Autocommit mode is on by default. 03791 ** ^Autocommit mode is disabled by a [BEGIN] statement. 03792 ** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK]. 03793 ** 03794 ** If certain kinds of errors occur on a statement within a multi-statement 03795 ** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR], 03796 ** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the 03797 ** transaction might be rolled back automatically. The only way to 03798 ** find out whether SQLite automatically rolled back the transaction after 03799 ** an error is to use this function. 03800 ** 03801 ** If another thread changes the autocommit status of the database 03802 ** connection while this routine is running, then the return value 03803 ** is undefined. 03804 */ 03805 SQLITE_API int sqlite3_get_autocommit(sqlite3*); 03806 03807 /* 03808 ** CAPI3REF: Find The Database Handle Of A Prepared Statement 03809 ** 03810 ** ^The sqlite3_db_handle interface returns the [database connection] handle 03811 ** to which a [prepared statement] belongs. ^The [database connection] 03812 ** returned by sqlite3_db_handle is the same [database connection] 03813 ** that was the first argument 03814 ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to 03815 ** create the statement in the first place. 03816 */ 03817 SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*); 03818 03819 /* 03820 ** CAPI3REF: Find the next prepared statement 03821 ** 03822 ** ^This interface returns a pointer to the next [prepared statement] after 03823 ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL 03824 ** then this interface returns a pointer to the first prepared statement 03825 ** associated with the database connection pDb. ^If no prepared statement 03826 ** satisfies the conditions of this routine, it returns NULL. 03827 ** 03828 ** The [database connection] pointer D in a call to 03829 ** [sqlite3_next_stmt(D,S)] must refer to an open database 03830 ** connection and in particular must not be a NULL pointer. 03831 */ 03832 SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); 03833 03834 /* 03835 ** CAPI3REF: Commit And Rollback Notification Callbacks 03836 ** 03837 ** ^The sqlite3_commit_hook() interface registers a callback 03838 ** function to be invoked whenever a transaction is [COMMIT | committed]. 03839 ** ^Any callback set by a previous call to sqlite3_commit_hook() 03840 ** for the same database connection is overridden. 03841 ** ^The sqlite3_rollback_hook() interface registers a callback 03842 ** function to be invoked whenever a transaction is [ROLLBACK | rolled back]. 03843 ** ^Any callback set by a previous call to sqlite3_rollback_hook() 03844 ** for the same database connection is overridden. 03845 ** ^The pArg argument is passed through to the callback. 03846 ** ^If the callback on a commit hook function returns non-zero, 03847 ** then the commit is converted into a rollback. 03848 ** 03849 ** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions 03850 ** return the P argument from the previous call of the same function 03851 ** on the same [database connection] D, or NULL for 03852 ** the first call for each function on D. 03853 ** 03854 ** The callback implementation must not do anything that will modify 03855 ** the database connection that invoked the callback. Any actions 03856 ** to modify the database connection must be deferred until after the 03857 ** completion of the [sqlite3_step()] call that triggered the commit 03858 ** or rollback hook in the first place. 03859 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 03860 ** database connections for the meaning of "modify" in this paragraph. 03861 ** 03862 ** ^Registering a NULL function disables the callback. 03863 ** 03864 ** ^When the commit hook callback routine returns zero, the [COMMIT] 03865 ** operation is allowed to continue normally. ^If the commit hook 03866 ** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK]. 03867 ** ^The rollback hook is invoked on a rollback that results from a commit 03868 ** hook returning non-zero, just as it would be with any other rollback. 03869 ** 03870 ** ^For the purposes of this API, a transaction is said to have been 03871 ** rolled back if an explicit "ROLLBACK" statement is executed, or 03872 ** an error or constraint causes an implicit rollback to occur. 03873 ** ^The rollback callback is not invoked if a transaction is 03874 ** automatically rolled back because the database connection is closed. 03875 ** ^The rollback callback is not invoked if a transaction is 03876 ** rolled back because a commit callback returned non-zero. 03877 ** 03878 ** See also the [sqlite3_update_hook()] interface. 03879 */ 03880 SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); 03881 SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); 03882 03883 /* 03884 ** CAPI3REF: Data Change Notification Callbacks 03885 ** 03886 ** ^The sqlite3_update_hook() interface registers a callback function 03887 ** with the [database connection] identified by the first argument 03888 ** to be invoked whenever a row is updated, inserted or deleted. 03889 ** ^Any callback set by a previous call to this function 03890 ** for the same database connection is overridden. 03891 ** 03892 ** ^The second argument is a pointer to the function to invoke when a 03893 ** row is updated, inserted or deleted. 03894 ** ^The first argument to the callback is a copy of the third argument 03895 ** to sqlite3_update_hook(). 03896 ** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE], 03897 ** or [SQLITE_UPDATE], depending on the operation that caused the callback 03898 ** to be invoked. 03899 ** ^The third and fourth arguments to the callback contain pointers to the 03900 ** database and table name containing the affected row. 03901 ** ^The final callback parameter is the [rowid] of the row. 03902 ** ^In the case of an update, this is the [rowid] after the update takes place. 03903 ** 03904 ** ^(The update hook is not invoked when internal system tables are 03905 ** modified (i.e. sqlite_master and sqlite_sequence).)^ 03906 ** 03907 ** ^In the current implementation, the update hook 03908 ** is not invoked when duplication rows are deleted because of an 03909 ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook 03910 ** invoked when rows are deleted using the [truncate optimization]. 03911 ** The exceptions defined in this paragraph might change in a future 03912 ** release of SQLite. 03913 ** 03914 ** The update hook implementation must not do anything that will modify 03915 ** the database connection that invoked the update hook. Any actions 03916 ** to modify the database connection must be deferred until after the 03917 ** completion of the [sqlite3_step()] call that triggered the update hook. 03918 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 03919 ** database connections for the meaning of "modify" in this paragraph. 03920 ** 03921 ** ^The sqlite3_update_hook(D,C,P) function 03922 ** returns the P argument from the previous call 03923 ** on the same [database connection] D, or NULL for 03924 ** the first call on D. 03925 ** 03926 ** See also the [sqlite3_commit_hook()] and [sqlite3_rollback_hook()] 03927 ** interfaces. 03928 */ 03929 SQLITE_API void *sqlite3_update_hook( 03930 sqlite3*, 03931 void(*)(void *,int ,char const *,char const *,sqlite3_int64), 03932 void* 03933 ); 03934 03935 /* 03936 ** CAPI3REF: Enable Or Disable Shared Pager Cache 03937 ** KEYWORDS: {shared cache} 03938 ** 03939 ** ^(This routine enables or disables the sharing of the database cache 03940 ** and schema data structures between [database connection | connections] 03941 ** to the same database. Sharing is enabled if the argument is true 03942 ** and disabled if the argument is false.)^ 03943 ** 03944 ** ^Cache sharing is enabled and disabled for an entire process. 03945 ** This is a change as of SQLite version 3.5.0. In prior versions of SQLite, 03946 ** sharing was enabled or disabled for each thread separately. 03947 ** 03948 ** ^(The cache sharing mode set by this interface effects all subsequent 03949 ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()]. 03950 ** Existing database connections continue use the sharing mode 03951 ** that was in effect at the time they were opened.)^ 03952 ** 03953 ** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled 03954 ** successfully. An [error code] is returned otherwise.)^ 03955 ** 03956 ** ^Shared cache is disabled by default. But this might change in 03957 ** future releases of SQLite. Applications that care about shared 03958 ** cache setting should set it explicitly. 03959 ** 03960 ** See Also: [SQLite Shared-Cache Mode] 03961 */ 03962 SQLITE_API int sqlite3_enable_shared_cache(int); 03963 03964 /* 03965 ** CAPI3REF: Attempt To Free Heap Memory 03966 ** 03967 ** ^The sqlite3_release_memory() interface attempts to free N bytes 03968 ** of heap memory by deallocating non-essential memory allocations 03969 ** held by the database library. Memory used to cache database 03970 ** pages to improve performance is an example of non-essential memory. 03971 ** ^sqlite3_release_memory() returns the number of bytes actually freed, 03972 ** which might be more or less than the amount requested. 03973 */ 03974 SQLITE_API int sqlite3_release_memory(int); 03975 03976 /* 03977 ** CAPI3REF: Impose A Limit On Heap Size 03978 ** 03979 ** ^The sqlite3_soft_heap_limit() interface places a "soft" limit 03980 ** on the amount of heap memory that may be allocated by SQLite. 03981 ** ^If an internal allocation is requested that would exceed the 03982 ** soft heap limit, [sqlite3_release_memory()] is invoked one or 03983 ** more times to free up some space before the allocation is performed. 03984 ** 03985 ** ^The limit is called "soft" because if [sqlite3_release_memory()] 03986 ** cannot free sufficient memory to prevent the limit from being exceeded, 03987 ** the memory is allocated anyway and the current operation proceeds. 03988 ** 03989 ** ^A negative or zero value for N means that there is no soft heap limit and 03990 ** [sqlite3_release_memory()] will only be called when memory is exhausted. 03991 ** ^The default value for the soft heap limit is zero. 03992 ** 03993 ** ^(SQLite makes a best effort to honor the soft heap limit. 03994 ** But if the soft heap limit cannot be honored, execution will 03995 ** continue without error or notification.)^ This is why the limit is 03996 ** called a "soft" limit. It is advisory only. 03997 ** 03998 ** Prior to SQLite version 3.5.0, this routine only constrained the memory 03999 ** allocated by a single thread - the same thread in which this routine 04000 ** runs. Beginning with SQLite version 3.5.0, the soft heap limit is 04001 ** applied to all threads. The value specified for the soft heap limit 04002 ** is an upper bound on the total memory allocation for all threads. In 04003 ** version 3.5.0 there is no mechanism for limiting the heap usage for 04004 ** individual threads. 04005 */ 04006 SQLITE_API void sqlite3_soft_heap_limit(int); 04007 04008 /* 04009 ** CAPI3REF: Extract Metadata About A Column Of A Table 04010 ** 04011 ** ^This routine returns metadata about a specific column of a specific 04012 ** database table accessible using the [database connection] handle 04013 ** passed as the first function argument. 04014 ** 04015 ** ^The column is identified by the second, third and fourth parameters to 04016 ** this function. ^The second parameter is either the name of the database 04017 ** (i.e. "main", "temp", or an attached database) containing the specified 04018 ** table or NULL. ^If it is NULL, then all attached databases are searched 04019 ** for the table using the same algorithm used by the database engine to 04020 ** resolve unqualified table references. 04021 ** 04022 ** ^The third and fourth parameters to this function are the table and column 04023 ** name of the desired column, respectively. Neither of these parameters 04024 ** may be NULL. 04025 ** 04026 ** ^Metadata is returned by writing to the memory locations passed as the 5th 04027 ** and subsequent parameters to this function. ^Any of these arguments may be 04028 ** NULL, in which case the corresponding element of metadata is omitted. 04029 ** 04030 ** ^(<blockquote> 04031 ** <table border="1"> 04032 ** <tr><th> Parameter <th> Output<br>Type <th> Description 04033 ** 04034 ** <tr><td> 5th <td> const char* <td> Data type 04035 ** <tr><td> 6th <td> const char* <td> Name of default collation sequence 04036 ** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint 04037 ** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY 04038 ** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT] 04039 ** </table> 04040 ** </blockquote>)^ 04041 ** 04042 ** ^The memory pointed to by the character pointers returned for the 04043 ** declaration type and collation sequence is valid only until the next 04044 ** call to any SQLite API function. 04045 ** 04046 ** ^If the specified table is actually a view, an [error code] is returned. 04047 ** 04048 ** ^If the specified column is "rowid", "oid" or "_rowid_" and an 04049 ** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output 04050 ** parameters are set for the explicitly declared column. ^(If there is no 04051 ** explicitly declared [INTEGER PRIMARY KEY] column, then the output 04052 ** parameters are set as follows: 04053 ** 04054 ** <pre> 04055 ** data type: "INTEGER" 04056 ** collation sequence: "BINARY" 04057 ** not null: 0 04058 ** primary key: 1 04059 ** auto increment: 0 04060 ** </pre>)^ 04061 ** 04062 ** ^(This function may load one or more schemas from database files. If an 04063 ** error occurs during this process, or if the requested table or column 04064 ** cannot be found, an [error code] is returned and an error message left 04065 ** in the [database connection] (to be retrieved using sqlite3_errmsg()).)^ 04066 ** 04067 ** ^This API is only available if the library was compiled with the 04068 ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined. 04069 */ 04070 SQLITE_API int sqlite3_table_column_metadata( 04071 sqlite3 *db, /* Connection handle */ 04072 const char *zDbName, /* Database name or NULL */ 04073 const char *zTableName, /* Table name */ 04074 const char *zColumnName, /* Column name */ 04075 char const **pzDataType, /* OUTPUT: Declared data type */ 04076 char const **pzCollSeq, /* OUTPUT: Collation sequence name */ 04077 int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */ 04078 int *pPrimaryKey, /* OUTPUT: True if column part of PK */ 04079 int *pAutoinc /* OUTPUT: True if column is auto-increment */ 04080 ); 04081 04082 /* 04083 ** CAPI3REF: Load An Extension 04084 ** 04085 ** ^This interface loads an SQLite extension library from the named file. 04086 ** 04087 ** ^The sqlite3_load_extension() interface attempts to load an 04088 ** SQLite extension library contained in the file zFile. 04089 ** 04090 ** ^The entry point is zProc. 04091 ** ^zProc may be 0, in which case the name of the entry point 04092 ** defaults to "sqlite3_extension_init". 04093 ** ^The sqlite3_load_extension() interface returns 04094 ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong. 04095 ** ^If an error occurs and pzErrMsg is not 0, then the 04096 ** [sqlite3_load_extension()] interface shall attempt to 04097 ** fill *pzErrMsg with error message text stored in memory 04098 ** obtained from [sqlite3_malloc()]. The calling function 04099 ** should free this memory by calling [sqlite3_free()]. 04100 ** 04101 ** ^Extension loading must be enabled using 04102 ** [sqlite3_enable_load_extension()] prior to calling this API, 04103 ** otherwise an error will be returned. 04104 ** 04105 ** See also the [load_extension() SQL function]. 04106 */ 04107 SQLITE_API int sqlite3_load_extension( 04108 sqlite3 *db, /* Load the extension into this database connection */ 04109 const char *zFile, /* Name of the shared library containing extension */ 04110 const char *zProc, /* Entry point. Derived from zFile if 0 */ 04111 char **pzErrMsg /* Put error message here if not 0 */ 04112 ); 04113 04114 /* 04115 ** CAPI3REF: Enable Or Disable Extension Loading 04116 ** 04117 ** ^So as not to open security holes in older applications that are 04118 ** unprepared to deal with extension loading, and as a means of disabling 04119 ** extension loading while evaluating user-entered SQL, the following API 04120 ** is provided to turn the [sqlite3_load_extension()] mechanism on and off. 04121 ** 04122 ** ^Extension loading is off by default. See ticket #1863. 04123 ** ^Call the sqlite3_enable_load_extension() routine with onoff==1 04124 ** to turn extension loading on and call it with onoff==0 to turn 04125 ** it back off again. 04126 */ 04127 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff); 04128 04129 /* 04130 ** CAPI3REF: Automatically Load An Extensions 04131 ** 04132 ** ^This API can be invoked at program startup in order to register 04133 ** one or more statically linked extensions that will be available 04134 ** to all new [database connections]. 04135 ** 04136 ** ^(This routine stores a pointer to the extension entry point 04137 ** in an array that is obtained from [sqlite3_malloc()]. That memory 04138 ** is deallocated by [sqlite3_reset_auto_extension()].)^ 04139 ** 04140 ** ^This function registers an extension entry point that is 04141 ** automatically invoked whenever a new [database connection] 04142 ** is opened using [sqlite3_open()], [sqlite3_open16()], 04143 ** or [sqlite3_open_v2()]. 04144 ** ^Duplicate extensions are detected so calling this routine 04145 ** multiple times with the same extension is harmless. 04146 ** ^Automatic extensions apply across all threads. 04147 */ 04148 SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void)); 04149 04150 /* 04151 ** CAPI3REF: Reset Automatic Extension Loading 04152 ** 04153 ** ^(This function disables all previously registered automatic 04154 ** extensions. It undoes the effect of all prior 04155 ** [sqlite3_auto_extension()] calls.)^ 04156 ** 04157 ** ^This function disables automatic extensions in all threads. 04158 */ 04159 SQLITE_API void sqlite3_reset_auto_extension(void); 04160 04161 /* 04162 ****** EXPERIMENTAL - subject to change without notice ************** 04163 ** 04164 ** The interface to the virtual-table mechanism is currently considered 04165 ** to be experimental. The interface might change in incompatible ways. 04166 ** If this is a problem for you, do not use the interface at this time. 04167 ** 04168 ** When the virtual-table mechanism stabilizes, we will declare the 04169 ** interface fixed, support it indefinitely, and remove this comment. 04170 */ 04171 04172 /* 04173 ** Structures used by the virtual table interface 04174 */ 04175 typedef struct sqlite3_vtab sqlite3_vtab; 04176 typedef struct sqlite3_index_info sqlite3_index_info; 04177 typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor; 04178 typedef struct sqlite3_module sqlite3_module; 04179 04180 /* 04181 ** CAPI3REF: Virtual Table Object 04182 ** KEYWORDS: sqlite3_module {virtual table module} 04183 ** EXPERIMENTAL 04184 ** 04185 ** This structure, sometimes called a a "virtual table module", 04186 ** defines the implementation of a [virtual tables]. 04187 ** This structure consists mostly of methods for the module. 04188 ** 04189 ** ^A virtual table module is created by filling in a persistent 04190 ** instance of this structure and passing a pointer to that instance 04191 ** to [sqlite3_create_module()] or [sqlite3_create_module_v2()]. 04192 ** ^The registration remains valid until it is replaced by a different 04193 ** module or until the [database connection] closes. The content 04194 ** of this structure must not change while it is registered with 04195 ** any database connection. 04196 */ 04197 struct sqlite3_module { 04198 int iVersion; 04199 int (*xCreate)(sqlite3*, void *pAux, 04200 int argc, const char *const*argv, 04201 sqlite3_vtab **ppVTab, char**); 04202 int (*xConnect)(sqlite3*, void *pAux, 04203 int argc, const char *const*argv, 04204 sqlite3_vtab **ppVTab, char**); 04205 int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*); 04206 int (*xDisconnect)(sqlite3_vtab *pVTab); 04207 int (*xDestroy)(sqlite3_vtab *pVTab); 04208 int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor); 04209 int (*xClose)(sqlite3_vtab_cursor*); 04210 int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr, 04211 int argc, sqlite3_value **argv); 04212 int (*xNext)(sqlite3_vtab_cursor*); 04213 int (*xEof)(sqlite3_vtab_cursor*); 04214 int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int); 04215 int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid); 04216 int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *); 04217 int (*xBegin)(sqlite3_vtab *pVTab); 04218 int (*xSync)(sqlite3_vtab *pVTab); 04219 int (*xCommit)(sqlite3_vtab *pVTab); 04220 int (*xRollback)(sqlite3_vtab *pVTab); 04221 int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName, 04222 void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), 04223 void **ppArg); 04224 int (*xRename)(sqlite3_vtab *pVtab, const char *zNew); 04225 }; 04226 04227 /* 04228 ** CAPI3REF: Virtual Table Indexing Information 04229 ** KEYWORDS: sqlite3_index_info 04230 ** EXPERIMENTAL 04231 ** 04232 ** The sqlite3_index_info structure and its substructures is used to 04233 ** pass information into and receive the reply from the [xBestIndex] 04234 ** method of a [virtual table module]. The fields under **Inputs** are the 04235 ** inputs to xBestIndex and are read-only. xBestIndex inserts its 04236 ** results into the **Outputs** fields. 04237 ** 04238 ** ^(The aConstraint[] array records WHERE clause constraints of the form: 04239 ** 04240 ** <pre>column OP expr</pre> 04241 ** 04242 ** where OP is =, <, <=, >, or >=.)^ ^(The particular operator is 04243 ** stored in aConstraint[].op.)^ ^(The index of the column is stored in 04244 ** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the 04245 ** expr on the right-hand side can be evaluated (and thus the constraint 04246 ** is usable) and false if it cannot.)^ 04247 ** 04248 ** ^The optimizer automatically inverts terms of the form "expr OP column" 04249 ** and makes other simplifications to the WHERE clause in an attempt to 04250 ** get as many WHERE clause terms into the form shown above as possible. 04251 ** ^The aConstraint[] array only reports WHERE clause terms that are 04252 ** relevant to the particular virtual table being queried. 04253 ** 04254 ** ^Information about the ORDER BY clause is stored in aOrderBy[]. 04255 ** ^Each term of aOrderBy records a column of the ORDER BY clause. 04256 ** 04257 ** The [xBestIndex] method must fill aConstraintUsage[] with information 04258 ** about what parameters to pass to xFilter. ^If argvIndex>0 then 04259 ** the right-hand side of the corresponding aConstraint[] is evaluated 04260 ** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit 04261 ** is true, then the constraint is assumed to be fully handled by the 04262 ** virtual table and is not checked again by SQLite.)^ 04263 ** 04264 ** ^The idxNum and idxPtr values are recorded and passed into the 04265 ** [xFilter] method. 04266 ** ^[sqlite3_free()] is used to free idxPtr if and only if 04267 ** needToFreeIdxPtr is true. 04268 ** 04269 ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in 04270 ** the correct order to satisfy the ORDER BY clause so that no separate 04271 ** sorting step is required. 04272 ** 04273 ** ^The estimatedCost value is an estimate of the cost of doing the 04274 ** particular lookup. A full scan of a table with N entries should have 04275 ** a cost of N. A binary search of a table of N entries should have a 04276 ** cost of approximately log(N). 04277 */ 04278 struct sqlite3_index_info { 04279 /* Inputs */ 04280 int nConstraint; /* Number of entries in aConstraint */ 04281 struct sqlite3_index_constraint { 04282 int iColumn; /* Column on left-hand side of constraint */ 04283 unsigned char op; /* Constraint operator */ 04284 unsigned char usable; /* True if this constraint is usable */ 04285 int iTermOffset; /* Used internally - xBestIndex should ignore */ 04286 } *aConstraint; /* Table of WHERE clause constraints */ 04287 int nOrderBy; /* Number of terms in the ORDER BY clause */ 04288 struct sqlite3_index_orderby { 04289 int iColumn; /* Column number */ 04290 unsigned char desc; /* True for DESC. False for ASC. */ 04291 } *aOrderBy; /* The ORDER BY clause */ 04292 /* Outputs */ 04293 struct sqlite3_index_constraint_usage { 04294 int argvIndex; /* if >0, constraint is part of argv to xFilter */ 04295 unsigned char omit; /* Do not code a test for this constraint */ 04296 } *aConstraintUsage; 04297 int idxNum; /* Number used to identify the index */ 04298 char *idxStr; /* String, possibly obtained from sqlite3_malloc */ 04299 int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */ 04300 int orderByConsumed; /* True if output is already ordered */ 04301 double estimatedCost; /* Estimated cost of using this index */ 04302 }; 04303 #define SQLITE_INDEX_CONSTRAINT_EQ 2 04304 #define SQLITE_INDEX_CONSTRAINT_GT 4 04305 #define SQLITE_INDEX_CONSTRAINT_LE 8 04306 #define SQLITE_INDEX_CONSTRAINT_LT 16 04307 #define SQLITE_INDEX_CONSTRAINT_GE 32 04308 #define SQLITE_INDEX_CONSTRAINT_MATCH 64 04309 04310 /* 04311 ** CAPI3REF: Register A Virtual Table Implementation 04312 ** EXPERIMENTAL 04313 ** 04314 ** ^These routines are used to register a new [virtual table module] name. 04315 ** ^Module names must be registered before 04316 ** creating a new [virtual table] using the module and before using a 04317 ** preexisting [virtual table] for the module. 04318 ** 04319 ** ^The module name is registered on the [database connection] specified 04320 ** by the first parameter. ^The name of the module is given by the 04321 ** second parameter. ^The third parameter is a pointer to 04322 ** the implementation of the [virtual table module]. ^The fourth 04323 ** parameter is an arbitrary client data pointer that is passed through 04324 ** into the [xCreate] and [xConnect] methods of the virtual table module 04325 ** when a new virtual table is be being created or reinitialized. 04326 ** 04327 ** ^The sqlite3_create_module_v2() interface has a fifth parameter which 04328 ** is a pointer to a destructor for the pClientData. ^SQLite will 04329 ** invoke the destructor function (if it is not NULL) when SQLite 04330 ** no longer needs the pClientData pointer. ^The sqlite3_create_module() 04331 ** interface is equivalent to sqlite3_create_module_v2() with a NULL 04332 ** destructor. 04333 */ 04334 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module( 04335 sqlite3 *db, /* SQLite connection to register module with */ 04336 const char *zName, /* Name of the module */ 04337 const sqlite3_module *p, /* Methods for the module */ 04338 void *pClientData /* Client data for xCreate/xConnect */ 04339 ); 04340 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_create_module_v2( 04341 sqlite3 *db, /* SQLite connection to register module with */ 04342 const char *zName, /* Name of the module */ 04343 const sqlite3_module *p, /* Methods for the module */ 04344 void *pClientData, /* Client data for xCreate/xConnect */ 04345 void(*xDestroy)(void*) /* Module destructor function */ 04346 ); 04347 04348 /* 04349 ** CAPI3REF: Virtual Table Instance Object 04350 ** KEYWORDS: sqlite3_vtab 04351 ** EXPERIMENTAL 04352 ** 04353 ** Every [virtual table module] implementation uses a subclass 04354 ** of this object to describe a particular instance 04355 ** of the [virtual table]. Each subclass will 04356 ** be tailored to the specific needs of the module implementation. 04357 ** The purpose of this superclass is to define certain fields that are 04358 ** common to all module implementations. 04359 ** 04360 ** ^Virtual tables methods can set an error message by assigning a 04361 ** string obtained from [sqlite3_mprintf()] to zErrMsg. The method should 04362 ** take care that any prior string is freed by a call to [sqlite3_free()] 04363 ** prior to assigning a new string to zErrMsg. ^After the error message 04364 ** is delivered up to the client application, the string will be automatically 04365 ** freed by sqlite3_free() and the zErrMsg field will be zeroed. 04366 */ 04367 struct sqlite3_vtab { 04368 const sqlite3_module *pModule; /* The module for this virtual table */ 04369 int nRef; /* NO LONGER USED */ 04370 char *zErrMsg; /* Error message from sqlite3_mprintf() */ 04371 /* Virtual table implementations will typically add additional fields */ 04372 }; 04373 04374 /* 04375 ** CAPI3REF: Virtual Table Cursor Object 04376 ** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor} 04377 ** EXPERIMENTAL 04378 ** 04379 ** Every [virtual table module] implementation uses a subclass of the 04380 ** following structure to describe cursors that point into the 04381 ** [virtual table] and are used 04382 ** to loop through the virtual table. Cursors are created using the 04383 ** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed 04384 ** by the [sqlite3_module.xClose | xClose] method. Cursors are used 04385 ** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods 04386 ** of the module. Each module implementation will define 04387 ** the content of a cursor structure to suit its own needs. 04388 ** 04389 ** This superclass exists in order to define fields of the cursor that 04390 ** are common to all implementations. 04391 */ 04392 struct sqlite3_vtab_cursor { 04393 sqlite3_vtab *pVtab; /* Virtual table of this cursor */ 04394 /* Virtual table implementations will typically add additional fields */ 04395 }; 04396 04397 /* 04398 ** CAPI3REF: Declare The Schema Of A Virtual Table 04399 ** EXPERIMENTAL 04400 ** 04401 ** ^The [xCreate] and [xConnect] methods of a 04402 ** [virtual table module] call this interface 04403 ** to declare the format (the names and datatypes of the columns) of 04404 ** the virtual tables they implement. 04405 */ 04406 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_declare_vtab(sqlite3*, const char *zSQL); 04407 04408 /* 04409 ** CAPI3REF: Overload A Function For A Virtual Table 04410 ** EXPERIMENTAL 04411 ** 04412 ** ^(Virtual tables can provide alternative implementations of functions 04413 ** using the [xFindFunction] method of the [virtual table module]. 04414 ** But global versions of those functions 04415 ** must exist in order to be overloaded.)^ 04416 ** 04417 ** ^(This API makes sure a global version of a function with a particular 04418 ** name and number of parameters exists. If no such function exists 04419 ** before this API is called, a new function is created.)^ ^The implementation 04420 ** of the new function always causes an exception to be thrown. So 04421 ** the new function is not good for anything by itself. Its only 04422 ** purpose is to be a placeholder function that can be overloaded 04423 ** by a [virtual table]. 04424 */ 04425 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg); 04426 04427 /* 04428 ** The interface to the virtual-table mechanism defined above (back up 04429 ** to a comment remarkably similar to this one) is currently considered 04430 ** to be experimental. The interface might change in incompatible ways. 04431 ** If this is a problem for you, do not use the interface at this time. 04432 ** 04433 ** When the virtual-table mechanism stabilizes, we will declare the 04434 ** interface fixed, support it indefinitely, and remove this comment. 04435 ** 04436 ****** EXPERIMENTAL - subject to change without notice ************** 04437 */ 04438 04439 /* 04440 ** CAPI3REF: A Handle To An Open BLOB 04441 ** KEYWORDS: {BLOB handle} {BLOB handles} 04442 ** 04443 ** An instance of this object represents an open BLOB on which 04444 ** [sqlite3_blob_open | incremental BLOB I/O] can be performed. 04445 ** ^Objects of this type are created by [sqlite3_blob_open()] 04446 ** and destroyed by [sqlite3_blob_close()]. 04447 ** ^The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces 04448 ** can be used to read or write small subsections of the BLOB. 04449 ** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes. 04450 */ 04451 typedef struct sqlite3_blob sqlite3_blob; 04452 04453 /* 04454 ** CAPI3REF: Open A BLOB For Incremental I/O 04455 ** 04456 ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located 04457 ** in row iRow, column zColumn, table zTable in database zDb; 04458 ** in other words, the same BLOB that would be selected by: 04459 ** 04460 ** <pre> 04461 ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow; 04462 ** </pre>)^ 04463 ** 04464 ** ^If the flags parameter is non-zero, then the BLOB is opened for read 04465 ** and write access. ^If it is zero, the BLOB is opened for read access. 04466 ** ^It is not possible to open a column that is part of an index or primary 04467 ** key for writing. ^If [foreign key constraints] are enabled, it is 04468 ** not possible to open a column that is part of a [child key] for writing. 04469 ** 04470 ** ^Note that the database name is not the filename that contains 04471 ** the database but rather the symbolic name of the database that 04472 ** appears after the AS keyword when the database is connected using [ATTACH]. 04473 ** ^For the main database file, the database name is "main". 04474 ** ^For TEMP tables, the database name is "temp". 04475 ** 04476 ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is written 04477 ** to *ppBlob. Otherwise an [error code] is returned and *ppBlob is set 04478 ** to be a null pointer.)^ 04479 ** ^This function sets the [database connection] error code and message 04480 ** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()] and related 04481 ** functions. ^Note that the *ppBlob variable is always initialized in a 04482 ** way that makes it safe to invoke [sqlite3_blob_close()] on *ppBlob 04483 ** regardless of the success or failure of this routine. 04484 ** 04485 ** ^(If the row that a BLOB handle points to is modified by an 04486 ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects 04487 ** then the BLOB handle is marked as "expired". 04488 ** This is true if any column of the row is changed, even a column 04489 ** other than the one the BLOB handle is open on.)^ 04490 ** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for 04491 ** a expired BLOB handle fail with an return code of [SQLITE_ABORT]. 04492 ** ^(Changes written into a BLOB prior to the BLOB expiring are not 04493 ** rolled back by the expiration of the BLOB. Such changes will eventually 04494 ** commit if the transaction continues to completion.)^ 04495 ** 04496 ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of 04497 ** the opened blob. ^The size of a blob may not be changed by this 04498 ** interface. Use the [UPDATE] SQL command to change the size of a 04499 ** blob. 04500 ** 04501 ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces 04502 ** and the built-in [zeroblob] SQL function can be used, if desired, 04503 ** to create an empty, zero-filled blob in which to read or write using 04504 ** this interface. 04505 ** 04506 ** To avoid a resource leak, every open [BLOB handle] should eventually 04507 ** be released by a call to [sqlite3_blob_close()]. 04508 */ 04509 SQLITE_API int sqlite3_blob_open( 04510 sqlite3*, 04511 const char *zDb, 04512 const char *zTable, 04513 const char *zColumn, 04514 sqlite3_int64 iRow, 04515 int flags, 04516 sqlite3_blob **ppBlob 04517 ); 04518 04519 /* 04520 ** CAPI3REF: Close A BLOB Handle 04521 ** 04522 ** ^Closes an open [BLOB handle]. 04523 ** 04524 ** ^Closing a BLOB shall cause the current transaction to commit 04525 ** if there are no other BLOBs, no pending prepared statements, and the 04526 ** database connection is in [autocommit mode]. 04527 ** ^If any writes were made to the BLOB, they might be held in cache 04528 ** until the close operation if they will fit. 04529 ** 04530 ** ^(Closing the BLOB often forces the changes 04531 ** out to disk and so if any I/O errors occur, they will likely occur 04532 ** at the time when the BLOB is closed. Any errors that occur during 04533 ** closing are reported as a non-zero return value.)^ 04534 ** 04535 ** ^(The BLOB is closed unconditionally. Even if this routine returns 04536 ** an error code, the BLOB is still closed.)^ 04537 ** 04538 ** ^Calling this routine with a null pointer (such as would be returned 04539 ** by a failed call to [sqlite3_blob_open()]) is a harmless no-op. 04540 */ 04541 SQLITE_API int sqlite3_blob_close(sqlite3_blob *); 04542 04543 /* 04544 ** CAPI3REF: Return The Size Of An Open BLOB 04545 ** 04546 ** ^Returns the size in bytes of the BLOB accessible via the 04547 ** successfully opened [BLOB handle] in its only argument. ^The 04548 ** incremental blob I/O routines can only read or overwriting existing 04549 ** blob content; they cannot change the size of a blob. 04550 ** 04551 ** This routine only works on a [BLOB handle] which has been created 04552 ** by a prior successful call to [sqlite3_blob_open()] and which has not 04553 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in 04554 ** to this routine results in undefined and probably undesirable behavior. 04555 */ 04556 SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *); 04557 04558 /* 04559 ** CAPI3REF: Read Data From A BLOB Incrementally 04560 ** 04561 ** ^(This function is used to read data from an open [BLOB handle] into a 04562 ** caller-supplied buffer. N bytes of data are copied into buffer Z 04563 ** from the open BLOB, starting at offset iOffset.)^ 04564 ** 04565 ** ^If offset iOffset is less than N bytes from the end of the BLOB, 04566 ** [SQLITE_ERROR] is returned and no data is read. ^If N or iOffset is 04567 ** less than zero, [SQLITE_ERROR] is returned and no data is read. 04568 ** ^The size of the blob (and hence the maximum value of N+iOffset) 04569 ** can be determined using the [sqlite3_blob_bytes()] interface. 04570 ** 04571 ** ^An attempt to read from an expired [BLOB handle] fails with an 04572 ** error code of [SQLITE_ABORT]. 04573 ** 04574 ** ^(On success, sqlite3_blob_read() returns SQLITE_OK. 04575 ** Otherwise, an [error code] or an [extended error code] is returned.)^ 04576 ** 04577 ** This routine only works on a [BLOB handle] which has been created 04578 ** by a prior successful call to [sqlite3_blob_open()] and which has not 04579 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in 04580 ** to this routine results in undefined and probably undesirable behavior. 04581 ** 04582 ** See also: [sqlite3_blob_write()]. 04583 */ 04584 SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); 04585 04586 /* 04587 ** CAPI3REF: Write Data Into A BLOB Incrementally 04588 ** 04589 ** ^This function is used to write data into an open [BLOB handle] from a 04590 ** caller-supplied buffer. ^N bytes of data are copied from the buffer Z 04591 ** into the open BLOB, starting at offset iOffset. 04592 ** 04593 ** ^If the [BLOB handle] passed as the first argument was not opened for 04594 ** writing (the flags parameter to [sqlite3_blob_open()] was zero), 04595 ** this function returns [SQLITE_READONLY]. 04596 ** 04597 ** ^This function may only modify the contents of the BLOB; it is 04598 ** not possible to increase the size of a BLOB using this API. 04599 ** ^If offset iOffset is less than N bytes from the end of the BLOB, 04600 ** [SQLITE_ERROR] is returned and no data is written. ^If N is 04601 ** less than zero [SQLITE_ERROR] is returned and no data is written. 04602 ** The size of the BLOB (and hence the maximum value of N+iOffset) 04603 ** can be determined using the [sqlite3_blob_bytes()] interface. 04604 ** 04605 ** ^An attempt to write to an expired [BLOB handle] fails with an 04606 ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred 04607 ** before the [BLOB handle] expired are not rolled back by the 04608 ** expiration of the handle, though of course those changes might 04609 ** have been overwritten by the statement that expired the BLOB handle 04610 ** or by other independent statements. 04611 ** 04612 ** ^(On success, sqlite3_blob_write() returns SQLITE_OK. 04613 ** Otherwise, an [error code] or an [extended error code] is returned.)^ 04614 ** 04615 ** This routine only works on a [BLOB handle] which has been created 04616 ** by a prior successful call to [sqlite3_blob_open()] and which has not 04617 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in 04618 ** to this routine results in undefined and probably undesirable behavior. 04619 ** 04620 ** See also: [sqlite3_blob_read()]. 04621 */ 04622 SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset); 04623 04624 /* 04625 ** CAPI3REF: Virtual File System Objects 04626 ** 04627 ** A virtual filesystem (VFS) is an [sqlite3_vfs] object 04628 ** that SQLite uses to interact 04629 ** with the underlying operating system. Most SQLite builds come with a 04630 ** single default VFS that is appropriate for the host computer. 04631 ** New VFSes can be registered and existing VFSes can be unregistered. 04632 ** The following interfaces are provided. 04633 ** 04634 ** ^The sqlite3_vfs_find() interface returns a pointer to a VFS given its name. 04635 ** ^Names are case sensitive. 04636 ** ^Names are zero-terminated UTF-8 strings. 04637 ** ^If there is no match, a NULL pointer is returned. 04638 ** ^If zVfsName is NULL then the default VFS is returned. 04639 ** 04640 ** ^New VFSes are registered with sqlite3_vfs_register(). 04641 ** ^Each new VFS becomes the default VFS if the makeDflt flag is set. 04642 ** ^The same VFS can be registered multiple times without injury. 04643 ** ^To make an existing VFS into the default VFS, register it again 04644 ** with the makeDflt flag set. If two different VFSes with the 04645 ** same name are registered, the behavior is undefined. If a 04646 ** VFS is registered with a name that is NULL or an empty string, 04647 ** then the behavior is undefined. 04648 ** 04649 ** ^Unregister a VFS with the sqlite3_vfs_unregister() interface. 04650 ** ^(If the default VFS is unregistered, another VFS is chosen as 04651 ** the default. The choice for the new VFS is arbitrary.)^ 04652 */ 04653 SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName); 04654 SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt); 04655 SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*); 04656 04657 /* 04658 ** CAPI3REF: Mutexes 04659 ** 04660 ** The SQLite core uses these routines for thread 04661 ** synchronization. Though they are intended for internal 04662 ** use by SQLite, code that links against SQLite is 04663 ** permitted to use any of these routines. 04664 ** 04665 ** The SQLite source code contains multiple implementations 04666 ** of these mutex routines. An appropriate implementation 04667 ** is selected automatically at compile-time. ^(The following 04668 ** implementations are available in the SQLite core: 04669 ** 04670 ** <ul> 04671 ** <li> SQLITE_MUTEX_OS2 04672 ** <li> SQLITE_MUTEX_PTHREAD 04673 ** <li> SQLITE_MUTEX_W32 04674 ** <li> SQLITE_MUTEX_NOOP 04675 ** </ul>)^ 04676 ** 04677 ** ^The SQLITE_MUTEX_NOOP implementation is a set of routines 04678 ** that does no real locking and is appropriate for use in 04679 ** a single-threaded application. ^The SQLITE_MUTEX_OS2, 04680 ** SQLITE_MUTEX_PTHREAD, and SQLITE_MUTEX_W32 implementations 04681 ** are appropriate for use on OS/2, Unix, and Windows. 04682 ** 04683 ** ^(If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor 04684 ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex 04685 ** implementation is included with the library. In this case the 04686 ** application must supply a custom mutex implementation using the 04687 ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function 04688 ** before calling sqlite3_initialize() or any other public sqlite3_ 04689 ** function that calls sqlite3_initialize().)^ 04690 ** 04691 ** ^The sqlite3_mutex_alloc() routine allocates a new 04692 ** mutex and returns a pointer to it. ^If it returns NULL 04693 ** that means that a mutex could not be allocated. ^SQLite 04694 ** will unwind its stack and return an error. ^(The argument 04695 ** to sqlite3_mutex_alloc() is one of these integer constants: 04696 ** 04697 ** <ul> 04698 ** <li> SQLITE_MUTEX_FAST 04699 ** <li> SQLITE_MUTEX_RECURSIVE 04700 ** <li> SQLITE_MUTEX_STATIC_MASTER 04701 ** <li> SQLITE_MUTEX_STATIC_MEM 04702 ** <li> SQLITE_MUTEX_STATIC_MEM2 04703 ** <li> SQLITE_MUTEX_STATIC_PRNG 04704 ** <li> SQLITE_MUTEX_STATIC_LRU 04705 ** <li> SQLITE_MUTEX_STATIC_LRU2 04706 ** </ul>)^ 04707 ** 04708 ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) 04709 ** cause sqlite3_mutex_alloc() to create 04710 ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE 04711 ** is used but not necessarily so when SQLITE_MUTEX_FAST is used. 04712 ** The mutex implementation does not need to make a distinction 04713 ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does 04714 ** not want to. ^SQLite will only request a recursive mutex in 04715 ** cases where it really needs one. ^If a faster non-recursive mutex 04716 ** implementation is available on the host platform, the mutex subsystem 04717 ** might return such a mutex in response to SQLITE_MUTEX_FAST. 04718 ** 04719 ** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other 04720 ** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return 04721 ** a pointer to a static preexisting mutex. ^Six static mutexes are 04722 ** used by the current version of SQLite. Future versions of SQLite 04723 ** may add additional static mutexes. Static mutexes are for internal 04724 ** use by SQLite only. Applications that use SQLite mutexes should 04725 ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or 04726 ** SQLITE_MUTEX_RECURSIVE. 04727 ** 04728 ** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST 04729 ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc() 04730 ** returns a different mutex on every call. ^But for the static 04731 ** mutex types, the same mutex is returned on every call that has 04732 ** the same type number. 04733 ** 04734 ** ^The sqlite3_mutex_free() routine deallocates a previously 04735 ** allocated dynamic mutex. ^SQLite is careful to deallocate every 04736 ** dynamic mutex that it allocates. The dynamic mutexes must not be in 04737 ** use when they are deallocated. Attempting to deallocate a static 04738 ** mutex results in undefined behavior. ^SQLite never deallocates 04739 ** a static mutex. 04740 ** 04741 ** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt 04742 ** to enter a mutex. ^If another thread is already within the mutex, 04743 ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return 04744 ** SQLITE_BUSY. ^The sqlite3_mutex_try() interface returns [SQLITE_OK] 04745 ** upon successful entry. ^(Mutexes created using 04746 ** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread. 04747 ** In such cases the, 04748 ** mutex must be exited an equal number of times before another thread 04749 ** can enter.)^ ^(If the same thread tries to enter any other 04750 ** kind of mutex more than once, the behavior is undefined. 04751 ** SQLite will never exhibit 04752 ** such behavior in its own use of mutexes.)^ 04753 ** 04754 ** ^(Some systems (for example, Windows 95) do not support the operation 04755 ** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try() 04756 ** will always return SQLITE_BUSY. The SQLite core only ever uses 04757 ** sqlite3_mutex_try() as an optimization so this is acceptable behavior.)^ 04758 ** 04759 ** ^The sqlite3_mutex_leave() routine exits a mutex that was 04760 ** previously entered by the same thread. ^(The behavior 04761 ** is undefined if the mutex is not currently entered by the 04762 ** calling thread or is not currently allocated. SQLite will 04763 ** never do either.)^ 04764 ** 04765 ** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or 04766 ** sqlite3_mutex_leave() is a NULL pointer, then all three routines 04767 ** behave as no-ops. 04768 ** 04769 ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()]. 04770 */ 04771 SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int); 04772 SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*); 04773 SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*); 04774 SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*); 04775 SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*); 04776 04777 /* 04778 ** CAPI3REF: Mutex Methods Object 04779 ** EXPERIMENTAL 04780 ** 04781 ** An instance of this structure defines the low-level routines 04782 ** used to allocate and use mutexes. 04783 ** 04784 ** Usually, the default mutex implementations provided by SQLite are 04785 ** sufficient, however the user has the option of substituting a custom 04786 ** implementation for specialized deployments or systems for which SQLite 04787 ** does not provide a suitable implementation. In this case, the user 04788 ** creates and populates an instance of this structure to pass 04789 ** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option. 04790 ** Additionally, an instance of this structure can be used as an 04791 ** output variable when querying the system for the current mutex 04792 ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option. 04793 ** 04794 ** ^The xMutexInit method defined by this structure is invoked as 04795 ** part of system initialization by the sqlite3_initialize() function. 04796 ** ^The xMutexInit routine is calle by SQLite exactly once for each 04797 ** effective call to [sqlite3_initialize()]. 04798 ** 04799 ** ^The xMutexEnd method defined by this structure is invoked as 04800 ** part of system shutdown by the sqlite3_shutdown() function. The 04801 ** implementation of this method is expected to release all outstanding 04802 ** resources obtained by the mutex methods implementation, especially 04803 ** those obtained by the xMutexInit method. ^The xMutexEnd() 04804 ** interface is invoked exactly once for each call to [sqlite3_shutdown()]. 04805 ** 04806 ** ^(The remaining seven methods defined by this structure (xMutexAlloc, 04807 ** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and 04808 ** xMutexNotheld) implement the following interfaces (respectively): 04809 ** 04810 ** <ul> 04811 ** <li> [sqlite3_mutex_alloc()] </li> 04812 ** <li> [sqlite3_mutex_free()] </li> 04813 ** <li> [sqlite3_mutex_enter()] </li> 04814 ** <li> [sqlite3_mutex_try()] </li> 04815 ** <li> [sqlite3_mutex_leave()] </li> 04816 ** <li> [sqlite3_mutex_held()] </li> 04817 ** <li> [sqlite3_mutex_notheld()] </li> 04818 ** </ul>)^ 04819 ** 04820 ** The only difference is that the public sqlite3_XXX functions enumerated 04821 ** above silently ignore any invocations that pass a NULL pointer instead 04822 ** of a valid mutex handle. The implementations of the methods defined 04823 ** by this structure are not required to handle this case, the results 04824 ** of passing a NULL pointer instead of a valid mutex handle are undefined 04825 ** (i.e. it is acceptable to provide an implementation that segfaults if 04826 ** it is passed a NULL pointer). 04827 ** 04828 ** The xMutexInit() method must be threadsafe. ^It must be harmless to 04829 ** invoke xMutexInit() mutiple times within the same process and without 04830 ** intervening calls to xMutexEnd(). Second and subsequent calls to 04831 ** xMutexInit() must be no-ops. 04832 ** 04833 ** ^xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()] 04834 ** and its associates). ^Similarly, xMutexAlloc() must not use SQLite memory 04835 ** allocation for a static mutex. ^However xMutexAlloc() may use SQLite 04836 ** memory allocation for a fast or recursive mutex. 04837 ** 04838 ** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is 04839 ** called, but only if the prior call to xMutexInit returned SQLITE_OK. 04840 ** If xMutexInit fails in any way, it is expected to clean up after itself 04841 ** prior to returning. 04842 */ 04843 typedef struct sqlite3_mutex_methods sqlite3_mutex_methods; 04844 struct sqlite3_mutex_methods { 04845 int (*xMutexInit)(void); 04846 int (*xMutexEnd)(void); 04847 sqlite3_mutex *(*xMutexAlloc)(int); 04848 void (*xMutexFree)(sqlite3_mutex *); 04849 void (*xMutexEnter)(sqlite3_mutex *); 04850 int (*xMutexTry)(sqlite3_mutex *); 04851 void (*xMutexLeave)(sqlite3_mutex *); 04852 int (*xMutexHeld)(sqlite3_mutex *); 04853 int (*xMutexNotheld)(sqlite3_mutex *); 04854 }; 04855 04856 /* 04857 ** CAPI3REF: Mutex Verification Routines 04858 ** 04859 ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines 04860 ** are intended for use inside assert() statements. ^The SQLite core 04861 ** never uses these routines except inside an assert() and applications 04862 ** are advised to follow the lead of the core. ^The SQLite core only 04863 ** provides implementations for these routines when it is compiled 04864 ** with the SQLITE_DEBUG flag. ^External mutex implementations 04865 ** are only required to provide these routines if SQLITE_DEBUG is 04866 ** defined and if NDEBUG is not defined. 04867 ** 04868 ** ^These routines should return true if the mutex in their argument 04869 ** is held or not held, respectively, by the calling thread. 04870 ** 04871 ** ^The implementation is not required to provided versions of these 04872 ** routines that actually work. If the implementation does not provide working 04873 ** versions of these routines, it should at least provide stubs that always 04874 ** return true so that one does not get spurious assertion failures. 04875 ** 04876 ** ^If the argument to sqlite3_mutex_held() is a NULL pointer then 04877 ** the routine should return 1. This seems counter-intuitive since 04878 ** clearly the mutex cannot be held if it does not exist. But the 04879 ** the reason the mutex does not exist is because the build is not 04880 ** using mutexes. And we do not want the assert() containing the 04881 ** call to sqlite3_mutex_held() to fail, so a non-zero return is 04882 ** the appropriate thing to do. ^The sqlite3_mutex_notheld() 04883 ** interface should also return 1 when given a NULL pointer. 04884 */ 04885 #ifndef NDEBUG 04886 SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*); 04887 SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*); 04888 #endif 04889 04890 /* 04891 ** CAPI3REF: Mutex Types 04892 ** 04893 ** The [sqlite3_mutex_alloc()] interface takes a single argument 04894 ** which is one of these integer constants. 04895 ** 04896 ** The set of static mutexes may change from one SQLite release to the 04897 ** next. Applications that override the built-in mutex logic must be 04898 ** prepared to accommodate additional static mutexes. 04899 */ 04900 #define SQLITE_MUTEX_FAST 0 04901 #define SQLITE_MUTEX_RECURSIVE 1 04902 #define SQLITE_MUTEX_STATIC_MASTER 2 04903 #define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */ 04904 #define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */ 04905 #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */ 04906 #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_random() */ 04907 #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */ 04908 #define SQLITE_MUTEX_STATIC_LRU2 7 /* lru page list */ 04909 04910 /* 04911 ** CAPI3REF: Retrieve the mutex for a database connection 04912 ** 04913 ** ^This interface returns a pointer the [sqlite3_mutex] object that 04914 ** serializes access to the [database connection] given in the argument 04915 ** when the [threading mode] is Serialized. 04916 ** ^If the [threading mode] is Single-thread or Multi-thread then this 04917 ** routine returns a NULL pointer. 04918 */ 04919 SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*); 04920 04921 /* 04922 ** CAPI3REF: Low-Level Control Of Database Files 04923 ** 04924 ** ^The [sqlite3_file_control()] interface makes a direct call to the 04925 ** xFileControl method for the [sqlite3_io_methods] object associated 04926 ** with a particular database identified by the second argument. ^The 04927 ** name of the database "main" for the main database or "temp" for the 04928 ** TEMP database, or the name that appears after the AS keyword for 04929 ** databases that are added using the [ATTACH] SQL command. 04930 ** ^A NULL pointer can be used in place of "main" to refer to the 04931 ** main database file. 04932 ** ^The third and fourth parameters to this routine 04933 ** are passed directly through to the second and third parameters of 04934 ** the xFileControl method. ^The return value of the xFileControl 04935 ** method becomes the return value of this routine. 04936 ** 04937 ** ^If the second parameter (zDbName) does not match the name of any 04938 ** open database file, then SQLITE_ERROR is returned. ^This error 04939 ** code is not remembered and will not be recalled by [sqlite3_errcode()] 04940 ** or [sqlite3_errmsg()]. The underlying xFileControl method might 04941 ** also return SQLITE_ERROR. There is no way to distinguish between 04942 ** an incorrect zDbName and an SQLITE_ERROR return from the underlying 04943 ** xFileControl method. 04944 ** 04945 ** See also: [SQLITE_FCNTL_LOCKSTATE] 04946 */ 04947 SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*); 04948 04949 /* 04950 ** CAPI3REF: Testing Interface 04951 ** 04952 ** ^The sqlite3_test_control() interface is used to read out internal 04953 ** state of SQLite and to inject faults into SQLite for testing 04954 ** purposes. ^The first parameter is an operation code that determines 04955 ** the number, meaning, and operation of all subsequent parameters. 04956 ** 04957 ** This interface is not for use by applications. It exists solely 04958 ** for verifying the correct operation of the SQLite library. Depending 04959 ** on how the SQLite library is compiled, this interface might not exist. 04960 ** 04961 ** The details of the operation codes, their meanings, the parameters 04962 ** they take, and what they do are all subject to change without notice. 04963 ** Unlike most of the SQLite API, this function is not guaranteed to 04964 ** operate consistently from one release to the next. 04965 */ 04966 SQLITE_API int sqlite3_test_control(int op, ...); 04967 04968 /* 04969 ** CAPI3REF: Testing Interface Operation Codes 04970 ** 04971 ** These constants are the valid operation code parameters used 04972 ** as the first argument to [sqlite3_test_control()]. 04973 ** 04974 ** These parameters and their meanings are subject to change 04975 ** without notice. These values are for testing purposes only. 04976 ** Applications should not use any of these parameters or the 04977 ** [sqlite3_test_control()] interface. 04978 */ 04979 #define SQLITE_TESTCTRL_FIRST 5 04980 #define SQLITE_TESTCTRL_PRNG_SAVE 5 04981 #define SQLITE_TESTCTRL_PRNG_RESTORE 6 04982 #define SQLITE_TESTCTRL_PRNG_RESET 7 04983 #define SQLITE_TESTCTRL_BITVEC_TEST 8 04984 #define SQLITE_TESTCTRL_FAULT_INSTALL 9 04985 #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10 04986 #define SQLITE_TESTCTRL_PENDING_BYTE 11 04987 #define SQLITE_TESTCTRL_ASSERT 12 04988 #define SQLITE_TESTCTRL_ALWAYS 13 04989 #define SQLITE_TESTCTRL_RESERVE 14 04990 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15 04991 #define SQLITE_TESTCTRL_ISKEYWORD 16 04992 #define SQLITE_TESTCTRL_LAST 16 04993 04994 /* 04995 ** CAPI3REF: SQLite Runtime Status 04996 ** EXPERIMENTAL 04997 ** 04998 ** ^This interface is used to retrieve runtime status information 04999 ** about the preformance of SQLite, and optionally to reset various 05000 ** highwater marks. ^The first argument is an integer code for 05001 ** the specific parameter to measure. ^(Recognized integer codes 05002 ** are of the form [SQLITE_STATUS_MEMORY_USED | SQLITE_STATUS_...].)^ 05003 ** ^The current value of the parameter is returned into *pCurrent. 05004 ** ^The highest recorded value is returned in *pHighwater. ^If the 05005 ** resetFlag is true, then the highest record value is reset after 05006 ** *pHighwater is written. ^(Some parameters do not record the highest 05007 ** value. For those parameters 05008 ** nothing is written into *pHighwater and the resetFlag is ignored.)^ 05009 ** ^(Other parameters record only the highwater mark and not the current 05010 ** value. For these latter parameters nothing is written into *pCurrent.)^ 05011 ** 05012 ** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a 05013 ** non-zero [error code] on failure. 05014 ** 05015 ** This routine is threadsafe but is not atomic. This routine can be 05016 ** called while other threads are running the same or different SQLite 05017 ** interfaces. However the values returned in *pCurrent and 05018 ** *pHighwater reflect the status of SQLite at different points in time 05019 ** and it is possible that another thread might change the parameter 05020 ** in between the times when *pCurrent and *pHighwater are written. 05021 ** 05022 ** See also: [sqlite3_db_status()] 05023 */ 05024 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag); 05025 05026 05027 /* 05028 ** CAPI3REF: Status Parameters 05029 ** EXPERIMENTAL 05030 ** 05031 ** These integer constants designate various run-time status parameters 05032 ** that can be returned by [sqlite3_status()]. 05033 ** 05034 ** <dl> 05035 ** ^(<dt>SQLITE_STATUS_MEMORY_USED</dt> 05036 ** <dd>This parameter is the current amount of memory checked out 05037 ** using [sqlite3_malloc()], either directly or indirectly. The 05038 ** figure includes calls made to [sqlite3_malloc()] by the application 05039 ** and internal memory usage by the SQLite library. Scratch memory 05040 ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache 05041 ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in 05042 ** this parameter. The amount returned is the sum of the allocation 05043 ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^ 05044 ** 05045 ** ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt> 05046 ** <dd>This parameter records the largest memory allocation request 05047 ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their 05048 ** internal equivalents). Only the value returned in the 05049 ** *pHighwater parameter to [sqlite3_status()] is of interest. 05050 ** The value written into the *pCurrent parameter is undefined.</dd>)^ 05051 ** 05052 ** ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt> 05053 ** <dd>This parameter returns the number of pages used out of the 05054 ** [pagecache memory allocator] that was configured using 05055 ** [SQLITE_CONFIG_PAGECACHE]. The 05056 ** value returned is in pages, not in bytes.</dd>)^ 05057 ** 05058 ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt> 05059 ** <dd>This parameter returns the number of bytes of page cache 05060 ** allocation which could not be statisfied by the [SQLITE_CONFIG_PAGECACHE] 05061 ** buffer and where forced to overflow to [sqlite3_malloc()]. The 05062 ** returned value includes allocations that overflowed because they 05063 ** where too large (they were larger than the "sz" parameter to 05064 ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because 05065 ** no space was left in the page cache.</dd>)^ 05066 ** 05067 ** ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt> 05068 ** <dd>This parameter records the largest memory allocation request 05069 ** handed to [pagecache memory allocator]. Only the value returned in the 05070 ** *pHighwater parameter to [sqlite3_status()] is of interest. 05071 ** The value written into the *pCurrent parameter is undefined.</dd>)^ 05072 ** 05073 ** ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt> 05074 ** <dd>This parameter returns the number of allocations used out of the 05075 ** [scratch memory allocator] configured using 05076 ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not 05077 ** in bytes. Since a single thread may only have one scratch allocation 05078 ** outstanding at time, this parameter also reports the number of threads 05079 ** using scratch memory at the same time.</dd>)^ 05080 ** 05081 ** ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt> 05082 ** <dd>This parameter returns the number of bytes of scratch memory 05083 ** allocation which could not be statisfied by the [SQLITE_CONFIG_SCRATCH] 05084 ** buffer and where forced to overflow to [sqlite3_malloc()]. The values 05085 ** returned include overflows because the requested allocation was too 05086 ** larger (that is, because the requested allocation was larger than the 05087 ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer 05088 ** slots were available. 05089 ** </dd>)^ 05090 ** 05091 ** ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt> 05092 ** <dd>This parameter records the largest memory allocation request 05093 ** handed to [scratch memory allocator]. Only the value returned in the 05094 ** *pHighwater parameter to [sqlite3_status()] is of interest. 05095 ** The value written into the *pCurrent parameter is undefined.</dd>)^ 05096 ** 05097 ** ^(<dt>SQLITE_STATUS_PARSER_STACK</dt> 05098 ** <dd>This parameter records the deepest parser stack. It is only 05099 ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^ 05100 ** </dl> 05101 ** 05102 ** New status parameters may be added from time to time. 05103 */ 05104 #define SQLITE_STATUS_MEMORY_USED 0 05105 #define SQLITE_STATUS_PAGECACHE_USED 1 05106 #define SQLITE_STATUS_PAGECACHE_OVERFLOW 2 05107 #define SQLITE_STATUS_SCRATCH_USED 3 05108 #define SQLITE_STATUS_SCRATCH_OVERFLOW 4 05109 #define SQLITE_STATUS_MALLOC_SIZE 5 05110 #define SQLITE_STATUS_PARSER_STACK 6 05111 #define SQLITE_STATUS_PAGECACHE_SIZE 7 05112 #define SQLITE_STATUS_SCRATCH_SIZE 8 05113 05114 /* 05115 ** CAPI3REF: Database Connection Status 05116 ** EXPERIMENTAL 05117 ** 05118 ** ^This interface is used to retrieve runtime status information 05119 ** about a single [database connection]. ^The first argument is the 05120 ** database connection object to be interrogated. ^The second argument 05121 ** is the parameter to interrogate. ^Currently, the only allowed value 05122 ** for the second parameter is [SQLITE_DBSTATUS_LOOKASIDE_USED]. 05123 ** Additional options will likely appear in future releases of SQLite. 05124 ** 05125 ** ^The current value of the requested parameter is written into *pCur 05126 ** and the highest instantaneous value is written into *pHiwtr. ^If 05127 ** the resetFlg is true, then the highest instantaneous value is 05128 ** reset back down to the current value. 05129 ** 05130 ** See also: [sqlite3_status()] and [sqlite3_stmt_status()]. 05131 */ 05132 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); 05133 05134 /* 05135 ** CAPI3REF: Status Parameters for database connections 05136 ** EXPERIMENTAL 05137 ** 05138 ** These constants are the available integer "verbs" that can be passed as 05139 ** the second argument to the [sqlite3_db_status()] interface. 05140 ** 05141 ** New verbs may be added in future releases of SQLite. Existing verbs 05142 ** might be discontinued. Applications should check the return code from 05143 ** [sqlite3_db_status()] to make sure that the call worked. 05144 ** The [sqlite3_db_status()] interface will return a non-zero error code 05145 ** if a discontinued or unsupported verb is invoked. 05146 ** 05147 ** <dl> 05148 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt> 05149 ** <dd>This parameter returns the number of lookaside memory slots currently 05150 ** checked out.</dd>)^ 05151 ** </dl> 05152 */ 05153 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0 05154 05155 05156 /* 05157 ** CAPI3REF: Prepared Statement Status 05158 ** EXPERIMENTAL 05159 ** 05160 ** ^(Each prepared statement maintains various 05161 ** [SQLITE_STMTSTATUS_SORT | counters] that measure the number 05162 ** of times it has performed specific operations.)^ These counters can 05163 ** be used to monitor the performance characteristics of the prepared 05164 ** statements. For example, if the number of table steps greatly exceeds 05165 ** the number of table searches or result rows, that would tend to indicate 05166 ** that the prepared statement is using a full table scan rather than 05167 ** an index. 05168 ** 05169 ** ^(This interface is used to retrieve and reset counter values from 05170 ** a [prepared statement]. The first argument is the prepared statement 05171 ** object to be interrogated. The second argument 05172 ** is an integer code for a specific [SQLITE_STMTSTATUS_SORT | counter] 05173 ** to be interrogated.)^ 05174 ** ^The current value of the requested counter is returned. 05175 ** ^If the resetFlg is true, then the counter is reset to zero after this 05176 ** interface call returns. 05177 ** 05178 ** See also: [sqlite3_status()] and [sqlite3_db_status()]. 05179 */ 05180 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); 05181 05182 /* 05183 ** CAPI3REF: Status Parameters for prepared statements 05184 ** EXPERIMENTAL 05185 ** 05186 ** These preprocessor macros define integer codes that name counter 05187 ** values associated with the [sqlite3_stmt_status()] interface. 05188 ** The meanings of the various counters are as follows: 05189 ** 05190 ** <dl> 05191 ** <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt> 05192 ** <dd>^This is the number of times that SQLite has stepped forward in 05193 ** a table as part of a full table scan. Large numbers for this counter 05194 ** may indicate opportunities for performance improvement through 05195 ** careful use of indices.</dd> 05196 ** 05197 ** <dt>SQLITE_STMTSTATUS_SORT</dt> 05198 ** <dd>^This is the number of sort operations that have occurred. 05199 ** A non-zero value in this counter may indicate an opportunity to 05200 ** improvement performance through careful use of indices.</dd> 05201 ** 05202 ** </dl> 05203 */ 05204 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1 05205 #define SQLITE_STMTSTATUS_SORT 2 05206 05207 /* 05208 ** CAPI3REF: Custom Page Cache Object 05209 ** EXPERIMENTAL 05210 ** 05211 ** The sqlite3_pcache type is opaque. It is implemented by 05212 ** the pluggable module. The SQLite core has no knowledge of 05213 ** its size or internal structure and never deals with the 05214 ** sqlite3_pcache object except by holding and passing pointers 05215 ** to the object. 05216 ** 05217 ** See [sqlite3_pcache_methods] for additional information. 05218 */ 05219 typedef struct sqlite3_pcache sqlite3_pcache; 05220 05221 /* 05222 ** CAPI3REF: Application Defined Page Cache. 05223 ** KEYWORDS: {page cache} 05224 ** EXPERIMENTAL 05225 ** 05226 ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can 05227 ** register an alternative page cache implementation by passing in an 05228 ** instance of the sqlite3_pcache_methods structure.)^ The majority of the 05229 ** heap memory used by SQLite is used by the page cache to cache data read 05230 ** from, or ready to be written to, the database file. By implementing a 05231 ** custom page cache using this API, an application can control more 05232 ** precisely the amount of memory consumed by SQLite, the way in which 05233 ** that memory is allocated and released, and the policies used to 05234 ** determine exactly which parts of a database file are cached and for 05235 ** how long. 05236 ** 05237 ** ^(The contents of the sqlite3_pcache_methods structure are copied to an 05238 ** internal buffer by SQLite within the call to [sqlite3_config]. Hence 05239 ** the application may discard the parameter after the call to 05240 ** [sqlite3_config()] returns.)^ 05241 ** 05242 ** ^The xInit() method is called once for each call to [sqlite3_initialize()] 05243 ** (usually only once during the lifetime of the process). ^(The xInit() 05244 ** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^ 05245 ** ^The xInit() method can set up up global structures and/or any mutexes 05246 ** required by the custom page cache implementation. 05247 ** 05248 ** ^The xShutdown() method is called from within [sqlite3_shutdown()], 05249 ** if the application invokes this API. It can be used to clean up 05250 ** any outstanding resources before process shutdown, if required. 05251 ** 05252 ** ^SQLite holds a [SQLITE_MUTEX_RECURSIVE] mutex when it invokes 05253 ** the xInit method, so the xInit method need not be threadsafe. ^The 05254 ** xShutdown method is only called from [sqlite3_shutdown()] so it does 05255 ** not need to be threadsafe either. All other methods must be threadsafe 05256 ** in multithreaded applications. 05257 ** 05258 ** ^SQLite will never invoke xInit() more than once without an intervening 05259 ** call to xShutdown(). 05260 ** 05261 ** ^The xCreate() method is used to construct a new cache instance. SQLite 05262 ** will typically create one cache instance for each open database file, 05263 ** though this is not guaranteed. ^The 05264 ** first parameter, szPage, is the size in bytes of the pages that must 05265 ** be allocated by the cache. ^szPage will not be a power of two. ^szPage 05266 ** will the page size of the database file that is to be cached plus an 05267 ** increment (here called "R") of about 100 or 200. ^SQLite will use the 05268 ** extra R bytes on each page to store metadata about the underlying 05269 ** database page on disk. The value of R depends 05270 ** on the SQLite version, the target platform, and how SQLite was compiled. 05271 ** ^R is constant for a particular build of SQLite. ^The second argument to 05272 ** xCreate(), bPurgeable, is true if the cache being created will 05273 ** be used to cache database pages of a file stored on disk, or 05274 ** false if it is used for an in-memory database. ^The cache implementation 05275 ** does not have to do anything special based with the value of bPurgeable; 05276 ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will 05277 ** never invoke xUnpin() except to deliberately delete a page. 05278 ** ^In other words, a cache created with bPurgeable set to false will 05279 ** never contain any unpinned pages. 05280 ** 05281 ** ^(The xCachesize() method may be called at any time by SQLite to set the 05282 ** suggested maximum cache-size (number of pages stored by) the cache 05283 ** instance passed as the first argument. This is the value configured using 05284 ** the SQLite "[PRAGMA cache_size]" command.)^ ^As with the bPurgeable 05285 ** parameter, the implementation is not required to do anything with this 05286 ** value; it is advisory only. 05287 ** 05288 ** ^The xPagecount() method should return the number of pages currently 05289 ** stored in the cache. 05290 ** 05291 ** ^The xFetch() method is used to fetch a page and return a pointer to it. 05292 ** ^A 'page', in this context, is a buffer of szPage bytes aligned at an 05293 ** 8-byte boundary. ^The page to be fetched is determined by the key. ^The 05294 ** mimimum key value is 1. After it has been retrieved using xFetch, the page 05295 ** is considered to be "pinned". 05296 ** 05297 ** ^If the requested page is already in the page cache, then the page cache 05298 ** implementation must return a pointer to the page buffer with its content 05299 ** intact. ^(If the requested page is not already in the cache, then the 05300 ** behavior of the cache implementation is determined by the value of the 05301 ** createFlag parameter passed to xFetch, according to the following table: 05302 ** 05303 ** <table border=1 width=85% align=center> 05304 ** <tr><th> createFlag <th> Behaviour when page is not already in cache 05305 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL. 05306 ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so. 05307 ** Otherwise return NULL. 05308 ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return 05309 ** NULL if allocating a new page is effectively impossible. 05310 ** </table>)^ 05311 ** 05312 ** SQLite will normally invoke xFetch() with a createFlag of 0 or 1. If 05313 ** a call to xFetch() with createFlag==1 returns NULL, then SQLite will 05314 ** attempt to unpin one or more cache pages by spilling the content of 05315 ** pinned pages to disk and synching the operating system disk cache. After 05316 ** attempting to unpin pages, the xFetch() method will be invoked again with 05317 ** a createFlag of 2. 05318 ** 05319 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page 05320 ** as its second argument. ^(If the third parameter, discard, is non-zero, 05321 ** then the page should be evicted from the cache. In this case SQLite 05322 ** assumes that the next time the page is retrieved from the cache using 05323 ** the xFetch() method, it will be zeroed.)^ ^If the discard parameter is 05324 ** zero, then the page is considered to be unpinned. ^The cache implementation 05325 ** may choose to evict unpinned pages at any time. 05326 ** 05327 ** ^(The cache is not required to perform any reference counting. A single 05328 ** call to xUnpin() unpins the page regardless of the number of prior calls 05329 ** to xFetch().)^ 05330 ** 05331 ** ^The xRekey() method is used to change the key value associated with the 05332 ** page passed as the second argument from oldKey to newKey. ^If the cache 05333 ** previously contains an entry associated with newKey, it should be 05334 ** discarded. ^Any prior cache entry associated with newKey is guaranteed not 05335 ** to be pinned. 05336 ** 05337 ** ^When SQLite calls the xTruncate() method, the cache must discard all 05338 ** existing cache entries with page numbers (keys) greater than or equal 05339 ** to the value of the iLimit parameter passed to xTruncate(). ^If any 05340 ** of these pages are pinned, they are implicitly unpinned, meaning that 05341 ** they can be safely discarded. 05342 ** 05343 ** ^The xDestroy() method is used to delete a cache allocated by xCreate(). 05344 ** All resources associated with the specified cache should be freed. ^After 05345 ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*] 05346 ** handle invalid, and will not use it with any other sqlite3_pcache_methods 05347 ** functions. 05348 */ 05349 typedef struct sqlite3_pcache_methods sqlite3_pcache_methods; 05350 struct sqlite3_pcache_methods { 05351 void *pArg; 05352 int (*xInit)(void*); 05353 void (*xShutdown)(void*); 05354 sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable); 05355 void (*xCachesize)(sqlite3_pcache*, int nCachesize); 05356 int (*xPagecount)(sqlite3_pcache*); 05357 void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag); 05358 void (*xUnpin)(sqlite3_pcache*, void*, int discard); 05359 void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey); 05360 void (*xTruncate)(sqlite3_pcache*, unsigned iLimit); 05361 void (*xDestroy)(sqlite3_pcache*); 05362 }; 05363 05364 /* 05365 ** CAPI3REF: Online Backup Object 05366 ** EXPERIMENTAL 05367 ** 05368 ** The sqlite3_backup object records state information about an ongoing 05369 ** online backup operation. ^The sqlite3_backup object is created by 05370 ** a call to [sqlite3_backup_init()] and is destroyed by a call to 05371 ** [sqlite3_backup_finish()]. 05372 ** 05373 ** See Also: [Using the SQLite Online Backup API] 05374 */ 05375 typedef struct sqlite3_backup sqlite3_backup; 05376 05377 /* 05378 ** CAPI3REF: Online Backup API. 05379 ** EXPERIMENTAL 05380 ** 05381 ** The backup API copies the content of one database into another. 05382 ** It is useful either for creating backups of databases or 05383 ** for copying in-memory databases to or from persistent files. 05384 ** 05385 ** See Also: [Using the SQLite Online Backup API] 05386 ** 05387 ** ^Exclusive access is required to the destination database for the 05388 ** duration of the operation. ^However the source database is only 05389 ** read-locked while it is actually being read; it is not locked 05390 ** continuously for the entire backup operation. ^Thus, the backup may be 05391 ** performed on a live source database without preventing other users from 05392 ** reading or writing to the source database while the backup is underway. 05393 ** 05394 ** ^(To perform a backup operation: 05395 ** <ol> 05396 ** <li><b>sqlite3_backup_init()</b> is called once to initialize the 05397 ** backup, 05398 ** <li><b>sqlite3_backup_step()</b> is called one or more times to transfer 05399 ** the data between the two databases, and finally 05400 ** <li><b>sqlite3_backup_finish()</b> is called to release all resources 05401 ** associated with the backup operation. 05402 ** </ol>)^ 05403 ** There should be exactly one call to sqlite3_backup_finish() for each 05404 ** successful call to sqlite3_backup_init(). 05405 ** 05406 ** <b>sqlite3_backup_init()</b> 05407 ** 05408 ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the 05409 ** [database connection] associated with the destination database 05410 ** and the database name, respectively. 05411 ** ^The database name is "main" for the main database, "temp" for the 05412 ** temporary database, or the name specified after the AS keyword in 05413 ** an [ATTACH] statement for an attached database. 05414 ** ^The S and M arguments passed to 05415 ** sqlite3_backup_init(D,N,S,M) identify the [database connection] 05416 ** and database name of the source database, respectively. 05417 ** ^The source and destination [database connections] (parameters S and D) 05418 ** must be different or else sqlite3_backup_init(D,N,S,M) will file with 05419 ** an error. 05420 ** 05421 ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is 05422 ** returned and an error code and error message are store3d in the 05423 ** destination [database connection] D. 05424 ** ^The error code and message for the failed call to sqlite3_backup_init() 05425 ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or 05426 ** [sqlite3_errmsg16()] functions. 05427 ** ^A successful call to sqlite3_backup_init() returns a pointer to an 05428 ** [sqlite3_backup] object. 05429 ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and 05430 ** sqlite3_backup_finish() functions to perform the specified backup 05431 ** operation. 05432 ** 05433 ** <b>sqlite3_backup_step()</b> 05434 ** 05435 ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between 05436 ** the source and destination databases specified by [sqlite3_backup] object B. 05437 ** ^If N is negative, all remaining source pages are copied. 05438 ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there 05439 ** are still more pages to be copied, then the function resturns [SQLITE_OK]. 05440 ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages 05441 ** from source to destination, then it returns [SQLITE_DONE]. 05442 ** ^If an error occurs while running sqlite3_backup_step(B,N), 05443 ** then an [error code] is returned. ^As well as [SQLITE_OK] and 05444 ** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY], 05445 ** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an 05446 ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code. 05447 ** 05448 ** ^The sqlite3_backup_step() might return [SQLITE_READONLY] if the destination 05449 ** database was opened read-only or if 05450 ** the destination is an in-memory database with a different page size 05451 ** from the source database. 05452 ** 05453 ** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then 05454 ** the [sqlite3_busy_handler | busy-handler function] 05455 ** is invoked (if one is specified). ^If the 05456 ** busy-handler returns non-zero before the lock is available, then 05457 ** [SQLITE_BUSY] is returned to the caller. ^In this case the call to 05458 ** sqlite3_backup_step() can be retried later. ^If the source 05459 ** [database connection] 05460 ** is being used to write to the source database when sqlite3_backup_step() 05461 ** is called, then [SQLITE_LOCKED] is returned immediately. ^Again, in this 05462 ** case the call to sqlite3_backup_step() can be retried later on. ^(If 05463 ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or 05464 ** [SQLITE_READONLY] is returned, then 05465 ** there is no point in retrying the call to sqlite3_backup_step(). These 05466 ** errors are considered fatal.)^ The application must accept 05467 ** that the backup operation has failed and pass the backup operation handle 05468 ** to the sqlite3_backup_finish() to release associated resources. 05469 ** 05470 ** ^The first call to sqlite3_backup_step() obtains an exclusive lock 05471 ** on the destination file. ^The exclusive lock is not released until either 05472 ** sqlite3_backup_finish() is called or the backup operation is complete 05473 ** and sqlite3_backup_step() returns [SQLITE_DONE]. ^Every call to 05474 ** sqlite3_backup_step() obtains a [shared lock] on the source database that 05475 ** lasts for the duration of the sqlite3_backup_step() call. 05476 ** ^Because the source database is not locked between calls to 05477 ** sqlite3_backup_step(), the source database may be modified mid-way 05478 ** through the backup process. ^If the source database is modified by an 05479 ** external process or via a database connection other than the one being 05480 ** used by the backup operation, then the backup will be automatically 05481 ** restarted by the next call to sqlite3_backup_step(). ^If the source 05482 ** database is modified by the using the same database connection as is used 05483 ** by the backup operation, then the backup database is automatically 05484 ** updated at the same time. 05485 ** 05486 ** <b>sqlite3_backup_finish()</b> 05487 ** 05488 ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the 05489 ** application wishes to abandon the backup operation, the application 05490 ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish(). 05491 ** ^The sqlite3_backup_finish() interfaces releases all 05492 ** resources associated with the [sqlite3_backup] object. 05493 ** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any 05494 ** active write-transaction on the destination database is rolled back. 05495 ** The [sqlite3_backup] object is invalid 05496 ** and may not be used following a call to sqlite3_backup_finish(). 05497 ** 05498 ** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no 05499 ** sqlite3_backup_step() errors occurred, regardless or whether or not 05500 ** sqlite3_backup_step() completed. 05501 ** ^If an out-of-memory condition or IO error occurred during any prior 05502 ** sqlite3_backup_step() call on the same [sqlite3_backup] object, then 05503 ** sqlite3_backup_finish() returns the corresponding [error code]. 05504 ** 05505 ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step() 05506 ** is not a permanent error and does not affect the return value of 05507 ** sqlite3_backup_finish(). 05508 ** 05509 ** <b>sqlite3_backup_remaining(), sqlite3_backup_pagecount()</b> 05510 ** 05511 ** ^Each call to sqlite3_backup_step() sets two values inside 05512 ** the [sqlite3_backup] object: the number of pages still to be backed 05513 ** up and the total number of pages in the source databae file. 05514 ** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces 05515 ** retrieve these two values, respectively. 05516 ** 05517 ** ^The values returned by these functions are only updated by 05518 ** sqlite3_backup_step(). ^If the source database is modified during a backup 05519 ** operation, then the values are not updated to account for any extra 05520 ** pages that need to be updated or the size of the source database file 05521 ** changing. 05522 ** 05523 ** <b>Concurrent Usage of Database Handles</b> 05524 ** 05525 ** ^The source [database connection] may be used by the application for other 05526 ** purposes while a backup operation is underway or being initialized. 05527 ** ^If SQLite is compiled and configured to support threadsafe database 05528 ** connections, then the source database connection may be used concurrently 05529 ** from within other threads. 05530 ** 05531 ** However, the application must guarantee that the destination 05532 ** [database connection] is not passed to any other API (by any thread) after 05533 ** sqlite3_backup_init() is called and before the corresponding call to 05534 ** sqlite3_backup_finish(). SQLite does not currently check to see 05535 ** if the application incorrectly accesses the destination [database connection] 05536 ** and so no error code is reported, but the operations may malfunction 05537 ** nevertheless. Use of the destination database connection while a 05538 ** backup is in progress might also also cause a mutex deadlock. 05539 ** 05540 ** If running in [shared cache mode], the application must 05541 ** guarantee that the shared cache used by the destination database 05542 ** is not accessed while the backup is running. In practice this means 05543 ** that the application must guarantee that the disk file being 05544 ** backed up to is not accessed by any connection within the process, 05545 ** not just the specific connection that was passed to sqlite3_backup_init(). 05546 ** 05547 ** The [sqlite3_backup] object itself is partially threadsafe. Multiple 05548 ** threads may safely make multiple concurrent calls to sqlite3_backup_step(). 05549 ** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount() 05550 ** APIs are not strictly speaking threadsafe. If they are invoked at the 05551 ** same time as another thread is invoking sqlite3_backup_step() it is 05552 ** possible that they return invalid values. 05553 */ 05554 SQLITE_API sqlite3_backup *sqlite3_backup_init( 05555 sqlite3 *pDest, /* Destination database handle */ 05556 const char *zDestName, /* Destination database name */ 05557 sqlite3 *pSource, /* Source database handle */ 05558 const char *zSourceName /* Source database name */ 05559 ); 05560 SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage); 05561 SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p); 05562 SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p); 05563 SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p); 05564 05565 /* 05566 ** CAPI3REF: Unlock Notification 05567 ** EXPERIMENTAL 05568 ** 05569 ** ^When running in shared-cache mode, a database operation may fail with 05570 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or 05571 ** individual tables within the shared-cache cannot be obtained. See 05572 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking. 05573 ** ^This API may be used to register a callback that SQLite will invoke 05574 ** when the connection currently holding the required lock relinquishes it. 05575 ** ^This API is only available if the library was compiled with the 05576 ** [SQLITE_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined. 05577 ** 05578 ** See Also: [Using the SQLite Unlock Notification Feature]. 05579 ** 05580 ** ^Shared-cache locks are released when a database connection concludes 05581 ** its current transaction, either by committing it or rolling it back. 05582 ** 05583 ** ^When a connection (known as the blocked connection) fails to obtain a 05584 ** shared-cache lock and SQLITE_LOCKED is returned to the caller, the 05585 ** identity of the database connection (the blocking connection) that 05586 ** has locked the required resource is stored internally. ^After an 05587 ** application receives an SQLITE_LOCKED error, it may call the 05588 ** sqlite3_unlock_notify() method with the blocked connection handle as 05589 ** the first argument to register for a callback that will be invoked 05590 ** when the blocking connections current transaction is concluded. ^The 05591 ** callback is invoked from within the [sqlite3_step] or [sqlite3_close] 05592 ** call that concludes the blocking connections transaction. 05593 ** 05594 ** ^(If sqlite3_unlock_notify() is called in a multi-threaded application, 05595 ** there is a chance that the blocking connection will have already 05596 ** concluded its transaction by the time sqlite3_unlock_notify() is invoked. 05597 ** If this happens, then the specified callback is invoked immediately, 05598 ** from within the call to sqlite3_unlock_notify().)^ 05599 ** 05600 ** ^If the blocked connection is attempting to obtain a write-lock on a 05601 ** shared-cache table, and more than one other connection currently holds 05602 ** a read-lock on the same table, then SQLite arbitrarily selects one of 05603 ** the other connections to use as the blocking connection. 05604 ** 05605 ** ^(There may be at most one unlock-notify callback registered by a 05606 ** blocked connection. If sqlite3_unlock_notify() is called when the 05607 ** blocked connection already has a registered unlock-notify callback, 05608 ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is 05609 ** called with a NULL pointer as its second argument, then any existing 05610 ** unlock-notify callback is cancelled. ^The blocked connections 05611 ** unlock-notify callback may also be canceled by closing the blocked 05612 ** connection using [sqlite3_close()]. 05613 ** 05614 ** The unlock-notify callback is not reentrant. If an application invokes 05615 ** any sqlite3_xxx API functions from within an unlock-notify callback, a 05616 ** crash or deadlock may be the result. 05617 ** 05618 ** ^Unless deadlock is detected (see below), sqlite3_unlock_notify() always 05619 ** returns SQLITE_OK. 05620 ** 05621 ** <b>Callback Invocation Details</b> 05622 ** 05623 ** When an unlock-notify callback is registered, the application provides a 05624 ** single void* pointer that is passed to the callback when it is invoked. 05625 ** However, the signature of the callback function allows SQLite to pass 05626 ** it an array of void* context pointers. The first argument passed to 05627 ** an unlock-notify callback is a pointer to an array of void* pointers, 05628 ** and the second is the number of entries in the array. 05629 ** 05630 ** When a blocking connections transaction is concluded, there may be 05631 ** more than one blocked connection that has registered for an unlock-notify 05632 ** callback. ^If two or more such blocked connections have specified the 05633 ** same callback function, then instead of invoking the callback function 05634 ** multiple times, it is invoked once with the set of void* context pointers 05635 ** specified by the blocked connections bundled together into an array. 05636 ** This gives the application an opportunity to prioritize any actions 05637 ** related to the set of unblocked database connections. 05638 ** 05639 ** <b>Deadlock Detection</b> 05640 ** 05641 ** Assuming that after registering for an unlock-notify callback a 05642 ** database waits for the callback to be issued before taking any further 05643 ** action (a reasonable assumption), then using this API may cause the 05644 ** application to deadlock. For example, if connection X is waiting for 05645 ** connection Y's transaction to be concluded, and similarly connection 05646 ** Y is waiting on connection X's transaction, then neither connection 05647 ** will proceed and the system may remain deadlocked indefinitely. 05648 ** 05649 ** To avoid this scenario, the sqlite3_unlock_notify() performs deadlock 05650 ** detection. ^If a given call to sqlite3_unlock_notify() would put the 05651 ** system in a deadlocked state, then SQLITE_LOCKED is returned and no 05652 ** unlock-notify callback is registered. The system is said to be in 05653 ** a deadlocked state if connection A has registered for an unlock-notify 05654 ** callback on the conclusion of connection B's transaction, and connection 05655 ** B has itself registered for an unlock-notify callback when connection 05656 ** A's transaction is concluded. ^Indirect deadlock is also detected, so 05657 ** the system is also considered to be deadlocked if connection B has 05658 ** registered for an unlock-notify callback on the conclusion of connection 05659 ** C's transaction, where connection C is waiting on connection A. ^Any 05660 ** number of levels of indirection are allowed. 05661 ** 05662 ** <b>The "DROP TABLE" Exception</b> 05663 ** 05664 ** When a call to [sqlite3_step()] returns SQLITE_LOCKED, it is almost 05665 ** always appropriate to call sqlite3_unlock_notify(). There is however, 05666 ** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement, 05667 ** SQLite checks if there are any currently executing SELECT statements 05668 ** that belong to the same connection. If there are, SQLITE_LOCKED is 05669 ** returned. In this case there is no "blocking connection", so invoking 05670 ** sqlite3_unlock_notify() results in the unlock-notify callback being 05671 ** invoked immediately. If the application then re-attempts the "DROP TABLE" 05672 ** or "DROP INDEX" query, an infinite loop might be the result. 05673 ** 05674 ** One way around this problem is to check the extended error code returned 05675 ** by an sqlite3_step() call. ^(If there is a blocking connection, then the 05676 ** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in 05677 ** the special "DROP TABLE/INDEX" case, the extended error code is just 05678 ** SQLITE_LOCKED.)^ 05679 */ 05680 SQLITE_API int sqlite3_unlock_notify( 05681 sqlite3 *pBlocked, /* Waiting connection */ 05682 void (*xNotify)(void **apArg, int nArg), /* Callback function to invoke */ 05683 void *pNotifyArg /* Argument to pass to xNotify */ 05684 ); 05685 05686 05687 /* 05688 ** CAPI3REF: String Comparison 05689 ** EXPERIMENTAL 05690 ** 05691 ** ^The [sqlite3_strnicmp()] API allows applications and extensions to 05692 ** compare the contents of two buffers containing UTF-8 strings in a 05693 ** case-indendent fashion, using the same definition of case independence 05694 ** that SQLite uses internally when comparing identifiers. 05695 */ 05696 SQLITE_API int sqlite3_strnicmp(const char *, const char *, int); 05697 05698 /* 05699 ** CAPI3REF: Error Logging Interface 05700 ** EXPERIMENTAL 05701 ** 05702 ** ^The [sqlite3_log()] interface writes a message into the error log 05703 ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()]. 05704 ** ^If logging is enabled, the zFormat string and subsequent arguments are 05705 ** passed through to [sqlite3_vmprintf()] to generate the final output string. 05706 ** 05707 ** The sqlite3_log() interface is intended for use by extensions such as 05708 ** virtual tables, collating functions, and SQL functions. While there is 05709 ** nothing to prevent an application from calling sqlite3_log(), doing so 05710 ** is considered bad form. 05711 ** 05712 ** The zFormat string must not be NULL. 05713 ** 05714 ** To avoid deadlocks and other threading problems, the sqlite3_log() routine 05715 ** will not use dynamically allocated memory. The log message is stored in 05716 ** a fixed-length buffer on the stack. If the log message is longer than 05717 ** a few hundred characters, it will be truncated to the length of the 05718 ** buffer. 05719 */ 05720 SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...); 05721 05722 /* 05723 ** Undo the hack that converts floating point types to integer for 05724 ** builds on processors without floating point support. 05725 */ 05726 #ifdef SQLITE_OMIT_FLOATING_POINT 05727 # undef double 05728 #endif 05729 05730 #ifdef __cplusplus 05731 } /* End of the 'extern "C"' block */ 05732 #endif 05733 #endif 05734
1.7.1