00001 /****************************************************************************** 00002 ** This file is an amalgamation of many separate C source files from SQLite 00003 ** version 3.7.9. By combining all the individual C code files into this 00004 ** single large file, the entire code can be compiled as a single translation 00005 ** unit. This allows many compilers to do optimizations that would not be 00006 ** possible if the files were compiled separately. Performance improvements 00007 ** of 5% or more are commonly seen when SQLite is compiled as a single 00008 ** translation unit. 00009 ** 00010 ** This file is all you need to compile SQLite. To use SQLite in other 00011 ** programs, you need this file and the "sqlite3.h" header file that defines 00012 ** the programming interface to the SQLite library. (If you do not have 00013 ** the "sqlite3.h" header file at hand, you will find a copy embedded within 00014 ** the text of this file. Search for "Begin file sqlite3.h" to find the start 00015 ** of the embedded sqlite3.h header file.) Additional code files may be needed 00016 ** if you want a wrapper to interface SQLite with your choice of programming 00017 ** language. The code for the "sqlite3" command-line shell is also in a 00018 ** separate file. This file contains only code for the core SQLite library. 00019 */ 00020 #define SQLITE_CORE 1 00021 #define SQLITE_AMALGAMATION 1 00022 #ifndef SQLITE_PRIVATE 00023 # define SQLITE_PRIVATE static 00024 #endif 00025 #ifndef SQLITE_API 00026 # define SQLITE_API 00027 #endif 00028 /************** Begin file sqliteInt.h ***************************************/ 00029 /* 00030 ** 2001 September 15 00031 ** 00032 ** The author disclaims copyright to this source code. In place of 00033 ** a legal notice, here is a blessing: 00034 ** 00035 ** May you do good and not evil. 00036 ** May you find forgiveness for yourself and forgive others. 00037 ** May you share freely, never taking more than you give. 00038 ** 00039 ************************************************************************* 00040 ** Internal interface definitions for SQLite. 00041 ** 00042 */ 00043 #ifndef _SQLITEINT_H_ 00044 #define _SQLITEINT_H_ 00045 00046 /* 00047 ** These #defines should enable >2GB file support on POSIX if the 00048 ** underlying operating system supports it. If the OS lacks 00049 ** large file support, or if the OS is windows, these should be no-ops. 00050 ** 00051 ** Ticket #2739: The _LARGEFILE_SOURCE macro must appear before any 00052 ** system #includes. Hence, this block of code must be the very first 00053 ** code in all source files. 00054 ** 00055 ** Large file support can be disabled using the -DSQLITE_DISABLE_LFS switch 00056 ** on the compiler command line. This is necessary if you are compiling 00057 ** on a recent machine (ex: Red Hat 7.2) but you want your code to work 00058 ** on an older machine (ex: Red Hat 6.0). If you compile on Red Hat 7.2 00059 ** without this option, LFS is enable. But LFS does not exist in the kernel 00060 ** in Red Hat 6.0, so the code won't work. Hence, for maximum binary 00061 ** portability you should omit LFS. 00062 ** 00063 ** Similar is true for Mac OS X. LFS is only supported on Mac OS X 9 and later. 00064 */ 00065 #ifndef SQLITE_DISABLE_LFS 00066 # define _LARGE_FILE 1 00067 # ifndef _FILE_OFFSET_BITS 00068 # define _FILE_OFFSET_BITS 64 00069 # endif 00070 # define _LARGEFILE_SOURCE 1 00071 #endif 00072 00073 /* 00074 ** Include the configuration header output by 'configure' if we're using the 00075 ** autoconf-based build 00076 */ 00077 #ifdef _HAVE_SQLITE_CONFIG_H 00078 #include "config.h" 00079 #endif 00080 00081 /************** Include sqliteLimit.h in the middle of sqliteInt.h ***********/ 00082 /************** Begin file sqliteLimit.h *************************************/ 00083 /* 00084 ** 2007 May 7 00085 ** 00086 ** The author disclaims copyright to this source code. In place of 00087 ** a legal notice, here is a blessing: 00088 ** 00089 ** May you do good and not evil. 00090 ** May you find forgiveness for yourself and forgive others. 00091 ** May you share freely, never taking more than you give. 00092 ** 00093 ************************************************************************* 00094 ** 00095 ** This file defines various limits of what SQLite can process. 00096 */ 00097 00098 /* 00099 ** The maximum length of a TEXT or BLOB in bytes. This also 00100 ** limits the size of a row in a table or index. 00101 ** 00102 ** The hard limit is the ability of a 32-bit signed integer 00103 ** to count the size: 2^31-1 or 2147483647. 00104 */ 00105 #ifndef SQLITE_MAX_LENGTH 00106 # define SQLITE_MAX_LENGTH 1000000000 00107 #endif 00108 00109 /* 00110 ** This is the maximum number of 00111 ** 00112 ** * Columns in a table 00113 ** * Columns in an index 00114 ** * Columns in a view 00115 ** * Terms in the SET clause of an UPDATE statement 00116 ** * Terms in the result set of a SELECT statement 00117 ** * Terms in the GROUP BY or ORDER BY clauses of a SELECT statement. 00118 ** * Terms in the VALUES clause of an INSERT statement 00119 ** 00120 ** The hard upper limit here is 32676. Most database people will 00121 ** tell you that in a well-normalized database, you usually should 00122 ** not have more than a dozen or so columns in any table. And if 00123 ** that is the case, there is no point in having more than a few 00124 ** dozen values in any of the other situations described above. 00125 */ 00126 #ifndef SQLITE_MAX_COLUMN 00127 # define SQLITE_MAX_COLUMN 2000 00128 #endif 00129 00130 /* 00131 ** The maximum length of a single SQL statement in bytes. 00132 ** 00133 ** It used to be the case that setting this value to zero would 00134 ** turn the limit off. That is no longer true. It is not possible 00135 ** to turn this limit off. 00136 */ 00137 #ifndef SQLITE_MAX_SQL_LENGTH 00138 # define SQLITE_MAX_SQL_LENGTH 1000000000 00139 #endif 00140 00141 /* 00142 ** The maximum depth of an expression tree. This is limited to 00143 ** some extent by SQLITE_MAX_SQL_LENGTH. But sometime you might 00144 ** want to place more severe limits on the complexity of an 00145 ** expression. 00146 ** 00147 ** A value of 0 used to mean that the limit was not enforced. 00148 ** But that is no longer true. The limit is now strictly enforced 00149 ** at all times. 00150 */ 00151 #ifndef SQLITE_MAX_EXPR_DEPTH 00152 # define SQLITE_MAX_EXPR_DEPTH 1000 00153 #endif 00154 00155 /* 00156 ** The maximum number of terms in a compound SELECT statement. 00157 ** The code generator for compound SELECT statements does one 00158 ** level of recursion for each term. A stack overflow can result 00159 ** if the number of terms is too large. In practice, most SQL 00160 ** never has more than 3 or 4 terms. Use a value of 0 to disable 00161 ** any limit on the number of terms in a compount SELECT. 00162 */ 00163 #ifndef SQLITE_MAX_COMPOUND_SELECT 00164 # define SQLITE_MAX_COMPOUND_SELECT 500 00165 #endif 00166 00167 /* 00168 ** The maximum number of opcodes in a VDBE program. 00169 ** Not currently enforced. 00170 */ 00171 #ifndef SQLITE_MAX_VDBE_OP 00172 # define SQLITE_MAX_VDBE_OP 25000 00173 #endif 00174 00175 /* 00176 ** The maximum number of arguments to an SQL function. 00177 */ 00178 #ifndef SQLITE_MAX_FUNCTION_ARG 00179 # define SQLITE_MAX_FUNCTION_ARG 127 00180 #endif 00181 00182 /* 00183 ** The maximum number of in-memory pages to use for the main database 00184 ** table and for temporary tables. The SQLITE_DEFAULT_CACHE_SIZE 00185 */ 00186 #ifndef SQLITE_DEFAULT_CACHE_SIZE 00187 # define SQLITE_DEFAULT_CACHE_SIZE 2000 00188 #endif 00189 #ifndef SQLITE_DEFAULT_TEMP_CACHE_SIZE 00190 # define SQLITE_DEFAULT_TEMP_CACHE_SIZE 500 00191 #endif 00192 00193 /* 00194 ** The default number of frames to accumulate in the log file before 00195 ** checkpointing the database in WAL mode. 00196 */ 00197 #ifndef SQLITE_DEFAULT_WAL_AUTOCHECKPOINT 00198 # define SQLITE_DEFAULT_WAL_AUTOCHECKPOINT 1000 00199 #endif 00200 00201 /* 00202 ** The maximum number of attached databases. This must be between 0 00203 ** and 62. The upper bound on 62 is because a 64-bit integer bitmap 00204 ** is used internally to track attached databases. 00205 */ 00206 #ifndef SQLITE_MAX_ATTACHED 00207 # define SQLITE_MAX_ATTACHED 10 00208 #endif 00209 00210 00211 /* 00212 ** The maximum value of a ?nnn wildcard that the parser will accept. 00213 */ 00214 #ifndef SQLITE_MAX_VARIABLE_NUMBER 00215 # define SQLITE_MAX_VARIABLE_NUMBER 999 00216 #endif 00217 00218 /* Maximum page size. The upper bound on this value is 65536. This a limit 00219 ** imposed by the use of 16-bit offsets within each page. 00220 ** 00221 ** Earlier versions of SQLite allowed the user to change this value at 00222 ** compile time. This is no longer permitted, on the grounds that it creates 00223 ** a library that is technically incompatible with an SQLite library 00224 ** compiled with a different limit. If a process operating on a database 00225 ** with a page-size of 65536 bytes crashes, then an instance of SQLite 00226 ** compiled with the default page-size limit will not be able to rollback 00227 ** the aborted transaction. This could lead to database corruption. 00228 */ 00229 #ifdef SQLITE_MAX_PAGE_SIZE 00230 # undef SQLITE_MAX_PAGE_SIZE 00231 #endif 00232 #define SQLITE_MAX_PAGE_SIZE 65536 00233 00234 00235 /* 00236 ** The default size of a database page. 00237 */ 00238 #ifndef SQLITE_DEFAULT_PAGE_SIZE 00239 # define SQLITE_DEFAULT_PAGE_SIZE 1024 00240 #endif 00241 #if SQLITE_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE 00242 # undef SQLITE_DEFAULT_PAGE_SIZE 00243 # define SQLITE_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE 00244 #endif 00245 00246 /* 00247 ** Ordinarily, if no value is explicitly provided, SQLite creates databases 00248 ** with page size SQLITE_DEFAULT_PAGE_SIZE. However, based on certain 00249 ** device characteristics (sector-size and atomic write() support), 00250 ** SQLite may choose a larger value. This constant is the maximum value 00251 ** SQLite will choose on its own. 00252 */ 00253 #ifndef SQLITE_MAX_DEFAULT_PAGE_SIZE 00254 # define SQLITE_MAX_DEFAULT_PAGE_SIZE 8192 00255 #endif 00256 #if SQLITE_MAX_DEFAULT_PAGE_SIZE>SQLITE_MAX_PAGE_SIZE 00257 # undef SQLITE_MAX_DEFAULT_PAGE_SIZE 00258 # define SQLITE_MAX_DEFAULT_PAGE_SIZE SQLITE_MAX_PAGE_SIZE 00259 #endif 00260 00261 00262 /* 00263 ** Maximum number of pages in one database file. 00264 ** 00265 ** This is really just the default value for the max_page_count pragma. 00266 ** This value can be lowered (or raised) at run-time using that the 00267 ** max_page_count macro. 00268 */ 00269 #ifndef SQLITE_MAX_PAGE_COUNT 00270 # define SQLITE_MAX_PAGE_COUNT 1073741823 00271 #endif 00272 00273 /* 00274 ** Maximum length (in bytes) of the pattern in a LIKE or GLOB 00275 ** operator. 00276 */ 00277 #ifndef SQLITE_MAX_LIKE_PATTERN_LENGTH 00278 # define SQLITE_MAX_LIKE_PATTERN_LENGTH 50000 00279 #endif 00280 00281 /* 00282 ** Maximum depth of recursion for triggers. 00283 ** 00284 ** A value of 1 means that a trigger program will not be able to itself 00285 ** fire any triggers. A value of 0 means that no trigger programs at all 00286 ** may be executed. 00287 */ 00288 #ifndef SQLITE_MAX_TRIGGER_DEPTH 00289 # define SQLITE_MAX_TRIGGER_DEPTH 1000 00290 #endif 00291 00292 /************** End of sqliteLimit.h *****************************************/ 00293 /************** Continuing where we left off in sqliteInt.h ******************/ 00294 00295 /* Disable nuisance warnings on Borland compilers */ 00296 #if defined(__BORLANDC__) 00297 #pragma warn -rch /* unreachable code */ 00298 #pragma warn -ccc /* Condition is always true or false */ 00299 #pragma warn -aus /* Assigned value is never used */ 00300 #pragma warn -csu /* Comparing signed and unsigned */ 00301 #pragma warn -spa /* Suspicious pointer arithmetic */ 00302 #endif 00303 00304 /* Needed for various definitions... */ 00305 #ifndef _GNU_SOURCE 00306 # define _GNU_SOURCE 00307 #endif 00308 00309 /* 00310 ** Include standard header files as necessary 00311 */ 00312 #ifdef HAVE_STDINT_H 00313 #include <stdint.h> 00314 #endif 00315 #ifdef HAVE_INTTYPES_H 00316 #include <inttypes.h> 00317 #endif 00318 00319 /* 00320 ** The following macros are used to cast pointers to integers and 00321 ** integers to pointers. The way you do this varies from one compiler 00322 ** to the next, so we have developed the following set of #if statements 00323 ** to generate appropriate macros for a wide range of compilers. 00324 ** 00325 ** The correct "ANSI" way to do this is to use the intptr_t type. 00326 ** Unfortunately, that typedef is not available on all compilers, or 00327 ** if it is available, it requires an #include of specific headers 00328 ** that vary from one machine to the next. 00329 ** 00330 ** Ticket #3860: The llvm-gcc-4.2 compiler from Apple chokes on 00331 ** the ((void*)&((char*)0)[X]) construct. But MSVC chokes on ((void*)(X)). 00332 ** So we have to define the macros in different ways depending on the 00333 ** compiler. 00334 */ 00335 #if defined(__PTRDIFF_TYPE__) /* This case should work for GCC */ 00336 # define SQLITE_INT_TO_PTR(X) ((void*)(__PTRDIFF_TYPE__)(X)) 00337 # define SQLITE_PTR_TO_INT(X) ((int)(__PTRDIFF_TYPE__)(X)) 00338 #elif !defined(__GNUC__) /* Works for compilers other than LLVM */ 00339 # define SQLITE_INT_TO_PTR(X) ((void*)&((char*)0)[X]) 00340 # define SQLITE_PTR_TO_INT(X) ((int)(((char*)X)-(char*)0)) 00341 #elif defined(HAVE_STDINT_H) /* Use this case if we have ANSI headers */ 00342 # define SQLITE_INT_TO_PTR(X) ((void*)(intptr_t)(X)) 00343 # define SQLITE_PTR_TO_INT(X) ((int)(intptr_t)(X)) 00344 #else /* Generates a warning - but it always works */ 00345 # define SQLITE_INT_TO_PTR(X) ((void*)(X)) 00346 # define SQLITE_PTR_TO_INT(X) ((int)(X)) 00347 #endif 00348 00349 /* 00350 ** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2. 00351 ** 0 means mutexes are permanently disable and the library is never 00352 ** threadsafe. 1 means the library is serialized which is the highest 00353 ** level of threadsafety. 2 means the libary is multithreaded - multiple 00354 ** threads can use SQLite as long as no two threads try to use the same 00355 ** database connection at the same time. 00356 ** 00357 ** Older versions of SQLite used an optional THREADSAFE macro. 00358 ** We support that for legacy. 00359 */ 00360 #if !defined(SQLITE_THREADSAFE) 00361 #if defined(THREADSAFE) 00362 # define SQLITE_THREADSAFE THREADSAFE 00363 #else 00364 # define SQLITE_THREADSAFE 1 /* IMP: R-07272-22309 */ 00365 #endif 00366 #endif 00367 00368 /* 00369 ** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1. 00370 ** It determines whether or not the features related to 00371 ** SQLITE_CONFIG_MEMSTATUS are available by default or not. This value can 00372 ** be overridden at runtime using the sqlite3_config() API. 00373 */ 00374 #if !defined(SQLITE_DEFAULT_MEMSTATUS) 00375 # define SQLITE_DEFAULT_MEMSTATUS 1 00376 #endif 00377 00378 /* 00379 ** Exactly one of the following macros must be defined in order to 00380 ** specify which memory allocation subsystem to use. 00381 ** 00382 ** SQLITE_SYSTEM_MALLOC // Use normal system malloc() 00383 ** SQLITE_WIN32_MALLOC // Use Win32 native heap API 00384 ** SQLITE_MEMDEBUG // Debugging version of system malloc() 00385 ** 00386 ** On Windows, if the SQLITE_WIN32_MALLOC_VALIDATE macro is defined and the 00387 ** assert() macro is enabled, each call into the Win32 native heap subsystem 00388 ** will cause HeapValidate to be called. If heap validation should fail, an 00389 ** assertion will be triggered. 00390 ** 00391 ** (Historical note: There used to be several other options, but we've 00392 ** pared it down to just these three.) 00393 ** 00394 ** If none of the above are defined, then set SQLITE_SYSTEM_MALLOC as 00395 ** the default. 00396 */ 00397 #if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_WIN32_MALLOC)+defined(SQLITE_MEMDEBUG)>1 00398 # error "At most one of the following compile-time configuration options\ 00399 is allows: SQLITE_SYSTEM_MALLOC, SQLITE_WIN32_MALLOC, SQLITE_MEMDEBUG" 00400 #endif 00401 #if defined(SQLITE_SYSTEM_MALLOC)+defined(SQLITE_WIN32_MALLOC)+defined(SQLITE_MEMDEBUG)==0 00402 # define SQLITE_SYSTEM_MALLOC 1 00403 #endif 00404 00405 /* 00406 ** If SQLITE_MALLOC_SOFT_LIMIT is not zero, then try to keep the 00407 ** sizes of memory allocations below this value where possible. 00408 */ 00409 #if !defined(SQLITE_MALLOC_SOFT_LIMIT) 00410 # define SQLITE_MALLOC_SOFT_LIMIT 1024 00411 #endif 00412 00413 /* 00414 ** We need to define _XOPEN_SOURCE as follows in order to enable 00415 ** recursive mutexes on most Unix systems. But Mac OS X is different. 00416 ** The _XOPEN_SOURCE define causes problems for Mac OS X we are told, 00417 ** so it is omitted there. See ticket #2673. 00418 ** 00419 ** Later we learn that _XOPEN_SOURCE is poorly or incorrectly 00420 ** implemented on some systems. So we avoid defining it at all 00421 ** if it is already defined or if it is unneeded because we are 00422 ** not doing a threadsafe build. Ticket #2681. 00423 ** 00424 ** See also ticket #2741. 00425 */ 00426 #if !defined(_XOPEN_SOURCE) && !defined(__DARWIN__) && !defined(__APPLE__) && SQLITE_THREADSAFE 00427 # define _XOPEN_SOURCE 500 /* Needed to enable pthread recursive mutexes */ 00428 #endif 00429 00430 /* 00431 ** The TCL headers are only needed when compiling the TCL bindings. 00432 */ 00433 #if defined(SQLITE_TCL) || defined(TCLSH) 00434 # include <tcl.h> 00435 #endif 00436 00437 /* 00438 ** Many people are failing to set -DNDEBUG=1 when compiling SQLite. 00439 ** Setting NDEBUG makes the code smaller and run faster. So the following 00440 ** lines are added to automatically set NDEBUG unless the -DSQLITE_DEBUG=1 00441 ** option is set. Thus NDEBUG becomes an opt-in rather than an opt-out 00442 ** feature. 00443 */ 00444 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG) 00445 # define NDEBUG 1 00446 #endif 00447 00448 /* 00449 ** The testcase() macro is used to aid in coverage testing. When 00450 ** doing coverage testing, the condition inside the argument to 00451 ** testcase() must be evaluated both true and false in order to 00452 ** get full branch coverage. The testcase() macro is inserted 00453 ** to help ensure adequate test coverage in places where simple 00454 ** condition/decision coverage is inadequate. For example, testcase() 00455 ** can be used to make sure boundary values are tested. For 00456 ** bitmask tests, testcase() can be used to make sure each bit 00457 ** is significant and used at least once. On switch statements 00458 ** where multiple cases go to the same block of code, testcase() 00459 ** can insure that all cases are evaluated. 00460 ** 00461 */ 00462 #ifdef SQLITE_COVERAGE_TEST 00463 SQLITE_PRIVATE void sqlite3Coverage(int); 00464 # define testcase(X) if( X ){ sqlite3Coverage(__LINE__); } 00465 #else 00466 # define testcase(X) 00467 #endif 00468 00469 /* 00470 ** The TESTONLY macro is used to enclose variable declarations or 00471 ** other bits of code that are needed to support the arguments 00472 ** within testcase() and assert() macros. 00473 */ 00474 #if !defined(NDEBUG) || defined(SQLITE_COVERAGE_TEST) 00475 # define TESTONLY(X) X 00476 #else 00477 # define TESTONLY(X) 00478 #endif 00479 00480 /* 00481 ** Sometimes we need a small amount of code such as a variable initialization 00482 ** to setup for a later assert() statement. We do not want this code to 00483 ** appear when assert() is disabled. The following macro is therefore 00484 ** used to contain that setup code. The "VVA" acronym stands for 00485 ** "Verification, Validation, and Accreditation". In other words, the 00486 ** code within VVA_ONLY() will only run during verification processes. 00487 */ 00488 #ifndef NDEBUG 00489 # define VVA_ONLY(X) X 00490 #else 00491 # define VVA_ONLY(X) 00492 #endif 00493 00494 /* 00495 ** The ALWAYS and NEVER macros surround boolean expressions which 00496 ** are intended to always be true or false, respectively. Such 00497 ** expressions could be omitted from the code completely. But they 00498 ** are included in a few cases in order to enhance the resilience 00499 ** of SQLite to unexpected behavior - to make the code "self-healing" 00500 ** or "ductile" rather than being "brittle" and crashing at the first 00501 ** hint of unplanned behavior. 00502 ** 00503 ** In other words, ALWAYS and NEVER are added for defensive code. 00504 ** 00505 ** When doing coverage testing ALWAYS and NEVER are hard-coded to 00506 ** be true and false so that the unreachable code then specify will 00507 ** not be counted as untested code. 00508 */ 00509 #if defined(SQLITE_COVERAGE_TEST) 00510 # define ALWAYS(X) (1) 00511 # define NEVER(X) (0) 00512 #elif !defined(NDEBUG) 00513 # define ALWAYS(X) ((X)?1:(assert(0),0)) 00514 # define NEVER(X) ((X)?(assert(0),1):0) 00515 #else 00516 # define ALWAYS(X) (X) 00517 # define NEVER(X) (X) 00518 #endif 00519 00520 /* 00521 ** Return true (non-zero) if the input is a integer that is too large 00522 ** to fit in 32-bits. This macro is used inside of various testcase() 00523 ** macros to verify that we have tested SQLite for large-file support. 00524 */ 00525 #define IS_BIG_INT(X) (((X)&~(i64)0xffffffff)!=0) 00526 00527 /* 00528 ** The macro unlikely() is a hint that surrounds a boolean 00529 ** expression that is usually false. Macro likely() surrounds 00530 ** a boolean expression that is usually true. GCC is able to 00531 ** use these hints to generate better code, sometimes. 00532 */ 00533 #if defined(__GNUC__) && 0 00534 # define likely(X) __builtin_expect((X),1) 00535 # define unlikely(X) __builtin_expect((X),0) 00536 #else 00537 # define likely(X) !!(X) 00538 # define unlikely(X) !!(X) 00539 #endif 00540 00541 /************** Include sqlite3.h in the middle of sqliteInt.h ***************/ 00542 /************** Begin file sqlite3.h *****************************************/ 00543 /* 00544 ** 2001 September 15 00545 ** 00546 ** The author disclaims copyright to this source code. In place of 00547 ** a legal notice, here is a blessing: 00548 ** 00549 ** May you do good and not evil. 00550 ** May you find forgiveness for yourself and forgive others. 00551 ** May you share freely, never taking more than you give. 00552 ** 00553 ************************************************************************* 00554 ** This header file defines the interface that the SQLite library 00555 ** presents to client programs. If a C-function, structure, datatype, 00556 ** or constant definition does not appear in this file, then it is 00557 ** not a published API of SQLite, is subject to change without 00558 ** notice, and should not be referenced by programs that use SQLite. 00559 ** 00560 ** Some of the definitions that are in this file are marked as 00561 ** "experimental". Experimental interfaces are normally new 00562 ** features recently added to SQLite. We do not anticipate changes 00563 ** to experimental interfaces but reserve the right to make minor changes 00564 ** if experience from use "in the wild" suggest such changes are prudent. 00565 ** 00566 ** The official C-language API documentation for SQLite is derived 00567 ** from comments in this file. This file is the authoritative source 00568 ** on how SQLite interfaces are suppose to operate. 00569 ** 00570 ** The name of this file under configuration management is "sqlite.h.in". 00571 ** The makefile makes some minor changes to this file (such as inserting 00572 ** the version number) and changes its name to "sqlite3.h" as 00573 ** part of the build process. 00574 */ 00575 #ifndef _SQLITE3_H_ 00576 #define _SQLITE3_H_ 00577 #include <stdarg.h> /* Needed for the definition of va_list */ 00578 00579 /* 00580 ** Make sure we can call this stuff from C++. 00581 */ 00582 #if 0 00583 extern "C" { 00584 #endif 00585 00586 00587 /* 00588 ** Add the ability to override 'extern' 00589 */ 00590 #ifndef SQLITE_EXTERN 00591 # define SQLITE_EXTERN extern 00592 #endif 00593 00594 #ifndef SQLITE_API 00595 # define SQLITE_API 00596 #endif 00597 00598 00599 /* 00600 ** These no-op macros are used in front of interfaces to mark those 00601 ** interfaces as either deprecated or experimental. New applications 00602 ** should not use deprecated interfaces - they are support for backwards 00603 ** compatibility only. Application writers should be aware that 00604 ** experimental interfaces are subject to change in point releases. 00605 ** 00606 ** These macros used to resolve to various kinds of compiler magic that 00607 ** would generate warning messages when they were used. But that 00608 ** compiler magic ended up generating such a flurry of bug reports 00609 ** that we have taken it all out and gone back to using simple 00610 ** noop macros. 00611 */ 00612 #define SQLITE_DEPRECATED 00613 #define SQLITE_EXPERIMENTAL 00614 00615 /* 00616 ** Ensure these symbols were not defined by some previous header file. 00617 */ 00618 #ifdef SQLITE_VERSION 00619 # undef SQLITE_VERSION 00620 #endif 00621 #ifdef SQLITE_VERSION_NUMBER 00622 # undef SQLITE_VERSION_NUMBER 00623 #endif 00624 00625 /* 00626 ** CAPI3REF: Compile-Time Library Version Numbers 00627 ** 00628 ** ^(The [SQLITE_VERSION] C preprocessor macro in the sqlite3.h header 00629 ** evaluates to a string literal that is the SQLite version in the 00630 ** format "X.Y.Z" where X is the major version number (always 3 for 00631 ** SQLite3) and Y is the minor version number and Z is the release number.)^ 00632 ** ^(The [SQLITE_VERSION_NUMBER] C preprocessor macro resolves to an integer 00633 ** with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z are the same 00634 ** numbers used in [SQLITE_VERSION].)^ 00635 ** The SQLITE_VERSION_NUMBER for any given release of SQLite will also 00636 ** be larger than the release from which it is derived. Either Y will 00637 ** be held constant and Z will be incremented or else Y will be incremented 00638 ** and Z will be reset to zero. 00639 ** 00640 ** Since version 3.6.18, SQLite source code has been stored in the 00641 ** <a href="http://www.fossil-scm.org/">Fossil configuration management 00642 ** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to 00643 ** a string which identifies a particular check-in of SQLite 00644 ** within its configuration management system. ^The SQLITE_SOURCE_ID 00645 ** string contains the date and time of the check-in (UTC) and an SHA1 00646 ** hash of the entire source tree. 00647 ** 00648 ** See also: [sqlite3_libversion()], 00649 ** [sqlite3_libversion_number()], [sqlite3_sourceid()], 00650 ** [sqlite_version()] and [sqlite_source_id()]. 00651 */ 00652 #define SQLITE_VERSION "3.7.9" 00653 #define SQLITE_VERSION_NUMBER 3007009 00654 #define SQLITE_SOURCE_ID "2011-11-01 00:52:41 c7c6050ef060877ebe77b41d959e9df13f8c9b5e" 00655 00656 /* 00657 ** CAPI3REF: Run-Time Library Version Numbers 00658 ** KEYWORDS: sqlite3_version, sqlite3_sourceid 00659 ** 00660 ** These interfaces provide the same information as the [SQLITE_VERSION], 00661 ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros 00662 ** but are associated with the library instead of the header file. ^(Cautious 00663 ** programmers might include assert() statements in their application to 00664 ** verify that values returned by these interfaces match the macros in 00665 ** the header, and thus insure that the application is 00666 ** compiled with matching library and header files. 00667 ** 00668 ** <blockquote><pre> 00669 ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER ); 00670 ** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 ); 00671 ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 ); 00672 ** </pre></blockquote>)^ 00673 ** 00674 ** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION] 00675 ** macro. ^The sqlite3_libversion() function returns a pointer to the 00676 ** to the sqlite3_version[] string constant. The sqlite3_libversion() 00677 ** function is provided for use in DLLs since DLL users usually do not have 00678 ** direct access to string constants within the DLL. ^The 00679 ** sqlite3_libversion_number() function returns an integer equal to 00680 ** [SQLITE_VERSION_NUMBER]. ^The sqlite3_sourceid() function returns 00681 ** a pointer to a string constant whose value is the same as the 00682 ** [SQLITE_SOURCE_ID] C preprocessor macro. 00683 ** 00684 ** See also: [sqlite_version()] and [sqlite_source_id()]. 00685 */ 00686 SQLITE_API const char sqlite3_version[] = SQLITE_VERSION; 00687 SQLITE_API const char *sqlite3_libversion(void); 00688 SQLITE_API const char *sqlite3_sourceid(void); 00689 SQLITE_API int sqlite3_libversion_number(void); 00690 00691 /* 00692 ** CAPI3REF: Run-Time Library Compilation Options Diagnostics 00693 ** 00694 ** ^The sqlite3_compileoption_used() function returns 0 or 1 00695 ** indicating whether the specified option was defined at 00696 ** compile time. ^The SQLITE_ prefix may be omitted from the 00697 ** option name passed to sqlite3_compileoption_used(). 00698 ** 00699 ** ^The sqlite3_compileoption_get() function allows iterating 00700 ** over the list of options that were defined at compile time by 00701 ** returning the N-th compile time option string. ^If N is out of range, 00702 ** sqlite3_compileoption_get() returns a NULL pointer. ^The SQLITE_ 00703 ** prefix is omitted from any strings returned by 00704 ** sqlite3_compileoption_get(). 00705 ** 00706 ** ^Support for the diagnostic functions sqlite3_compileoption_used() 00707 ** and sqlite3_compileoption_get() may be omitted by specifying the 00708 ** [SQLITE_OMIT_COMPILEOPTION_DIAGS] option at compile time. 00709 ** 00710 ** See also: SQL functions [sqlite_compileoption_used()] and 00711 ** [sqlite_compileoption_get()] and the [compile_options pragma]. 00712 */ 00713 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS 00714 SQLITE_API int sqlite3_compileoption_used(const char *zOptName); 00715 SQLITE_API const char *sqlite3_compileoption_get(int N); 00716 #endif 00717 00718 /* 00719 ** CAPI3REF: Test To See If The Library Is Threadsafe 00720 ** 00721 ** ^The sqlite3_threadsafe() function returns zero if and only if 00722 ** SQLite was compiled mutexing code omitted due to the 00723 ** [SQLITE_THREADSAFE] compile-time option being set to 0. 00724 ** 00725 ** SQLite can be compiled with or without mutexes. When 00726 ** the [SQLITE_THREADSAFE] C preprocessor macro is 1 or 2, mutexes 00727 ** are enabled and SQLite is threadsafe. When the 00728 ** [SQLITE_THREADSAFE] macro is 0, 00729 ** the mutexes are omitted. Without the mutexes, it is not safe 00730 ** to use SQLite concurrently from more than one thread. 00731 ** 00732 ** Enabling mutexes incurs a measurable performance penalty. 00733 ** So if speed is of utmost importance, it makes sense to disable 00734 ** the mutexes. But for maximum safety, mutexes should be enabled. 00735 ** ^The default behavior is for mutexes to be enabled. 00736 ** 00737 ** This interface can be used by an application to make sure that the 00738 ** version of SQLite that it is linking against was compiled with 00739 ** the desired setting of the [SQLITE_THREADSAFE] macro. 00740 ** 00741 ** This interface only reports on the compile-time mutex setting 00742 ** of the [SQLITE_THREADSAFE] flag. If SQLite is compiled with 00743 ** SQLITE_THREADSAFE=1 or =2 then mutexes are enabled by default but 00744 ** can be fully or partially disabled using a call to [sqlite3_config()] 00745 ** with the verbs [SQLITE_CONFIG_SINGLETHREAD], [SQLITE_CONFIG_MULTITHREAD], 00746 ** or [SQLITE_CONFIG_MUTEX]. ^(The return value of the 00747 ** sqlite3_threadsafe() function shows only the compile-time setting of 00748 ** thread safety, not any run-time changes to that setting made by 00749 ** sqlite3_config(). In other words, the return value from sqlite3_threadsafe() 00750 ** is unchanged by calls to sqlite3_config().)^ 00751 ** 00752 ** See the [threading mode] documentation for additional information. 00753 */ 00754 SQLITE_API int sqlite3_threadsafe(void); 00755 00756 /* 00757 ** CAPI3REF: Database Connection Handle 00758 ** KEYWORDS: {database connection} {database connections} 00759 ** 00760 ** Each open SQLite database is represented by a pointer to an instance of 00761 ** the opaque structure named "sqlite3". It is useful to think of an sqlite3 00762 ** pointer as an object. The [sqlite3_open()], [sqlite3_open16()], and 00763 ** [sqlite3_open_v2()] interfaces are its constructors, and [sqlite3_close()] 00764 ** is its destructor. There are many other interfaces (such as 00765 ** [sqlite3_prepare_v2()], [sqlite3_create_function()], and 00766 ** [sqlite3_busy_timeout()] to name but three) that are methods on an 00767 ** sqlite3 object. 00768 */ 00769 typedef struct sqlite3 sqlite3; 00770 00771 /* 00772 ** CAPI3REF: 64-Bit Integer Types 00773 ** KEYWORDS: sqlite_int64 sqlite_uint64 00774 ** 00775 ** Because there is no cross-platform way to specify 64-bit integer types 00776 ** SQLite includes typedefs for 64-bit signed and unsigned integers. 00777 ** 00778 ** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions. 00779 ** The sqlite_int64 and sqlite_uint64 types are supported for backwards 00780 ** compatibility only. 00781 ** 00782 ** ^The sqlite3_int64 and sqlite_int64 types can store integer values 00783 ** between -9223372036854775808 and +9223372036854775807 inclusive. ^The 00784 ** sqlite3_uint64 and sqlite_uint64 types can store integer values 00785 ** between 0 and +18446744073709551615 inclusive. 00786 */ 00787 #ifdef SQLITE_INT64_TYPE 00788 typedef SQLITE_INT64_TYPE sqlite_int64; 00789 typedef unsigned SQLITE_INT64_TYPE sqlite_uint64; 00790 #elif defined(_MSC_VER) || defined(__BORLANDC__) 00791 typedef __int64 sqlite_int64; 00792 typedef unsigned __int64 sqlite_uint64; 00793 #else 00794 typedef long long int sqlite_int64; 00795 typedef unsigned long long int sqlite_uint64; 00796 #endif 00797 typedef sqlite_int64 sqlite3_int64; 00798 typedef sqlite_uint64 sqlite3_uint64; 00799 00800 /* 00801 ** If compiling for a processor that lacks floating point support, 00802 ** substitute integer for floating-point. 00803 */ 00804 #ifdef SQLITE_OMIT_FLOATING_POINT 00805 # define double sqlite3_int64 00806 #endif 00807 00808 /* 00809 ** CAPI3REF: Closing A Database Connection 00810 ** 00811 ** ^The sqlite3_close() routine is the destructor for the [sqlite3] object. 00812 ** ^Calls to sqlite3_close() return SQLITE_OK if the [sqlite3] object is 00813 ** successfully destroyed and all associated resources are deallocated. 00814 ** 00815 ** Applications must [sqlite3_finalize | finalize] all [prepared statements] 00816 ** and [sqlite3_blob_close | close] all [BLOB handles] associated with 00817 ** the [sqlite3] object prior to attempting to close the object. ^If 00818 ** sqlite3_close() is called on a [database connection] that still has 00819 ** outstanding [prepared statements] or [BLOB handles], then it returns 00820 ** SQLITE_BUSY. 00821 ** 00822 ** ^If [sqlite3_close()] is invoked while a transaction is open, 00823 ** the transaction is automatically rolled back. 00824 ** 00825 ** The C parameter to [sqlite3_close(C)] must be either a NULL 00826 ** pointer or an [sqlite3] object pointer obtained 00827 ** from [sqlite3_open()], [sqlite3_open16()], or 00828 ** [sqlite3_open_v2()], and not previously closed. 00829 ** ^Calling sqlite3_close() with a NULL pointer argument is a 00830 ** harmless no-op. 00831 */ 00832 SQLITE_API int sqlite3_close(sqlite3 *); 00833 00834 /* 00835 ** The type for a callback function. 00836 ** This is legacy and deprecated. It is included for historical 00837 ** compatibility and is not documented. 00838 */ 00839 typedef int (*sqlite3_callback)(void*,int,char**, char**); 00840 00841 /* 00842 ** CAPI3REF: One-Step Query Execution Interface 00843 ** 00844 ** The sqlite3_exec() interface is a convenience wrapper around 00845 ** [sqlite3_prepare_v2()], [sqlite3_step()], and [sqlite3_finalize()], 00846 ** that allows an application to run multiple statements of SQL 00847 ** without having to use a lot of C code. 00848 ** 00849 ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded, 00850 ** semicolon-separate SQL statements passed into its 2nd argument, 00851 ** in the context of the [database connection] passed in as its 1st 00852 ** argument. ^If the callback function of the 3rd argument to 00853 ** sqlite3_exec() is not NULL, then it is invoked for each result row 00854 ** coming out of the evaluated SQL statements. ^The 4th argument to 00855 ** sqlite3_exec() is relayed through to the 1st argument of each 00856 ** callback invocation. ^If the callback pointer to sqlite3_exec() 00857 ** is NULL, then no callback is ever invoked and result rows are 00858 ** ignored. 00859 ** 00860 ** ^If an error occurs while evaluating the SQL statements passed into 00861 ** sqlite3_exec(), then execution of the current statement stops and 00862 ** subsequent statements are skipped. ^If the 5th parameter to sqlite3_exec() 00863 ** is not NULL then any error message is written into memory obtained 00864 ** from [sqlite3_malloc()] and passed back through the 5th parameter. 00865 ** To avoid memory leaks, the application should invoke [sqlite3_free()] 00866 ** on error message strings returned through the 5th parameter of 00867 ** of sqlite3_exec() after the error message string is no longer needed. 00868 ** ^If the 5th parameter to sqlite3_exec() is not NULL and no errors 00869 ** occur, then sqlite3_exec() sets the pointer in its 5th parameter to 00870 ** NULL before returning. 00871 ** 00872 ** ^If an sqlite3_exec() callback returns non-zero, the sqlite3_exec() 00873 ** routine returns SQLITE_ABORT without invoking the callback again and 00874 ** without running any subsequent SQL statements. 00875 ** 00876 ** ^The 2nd argument to the sqlite3_exec() callback function is the 00877 ** number of columns in the result. ^The 3rd argument to the sqlite3_exec() 00878 ** callback is an array of pointers to strings obtained as if from 00879 ** [sqlite3_column_text()], one for each column. ^If an element of a 00880 ** result row is NULL then the corresponding string pointer for the 00881 ** sqlite3_exec() callback is a NULL pointer. ^The 4th argument to the 00882 ** sqlite3_exec() callback is an array of pointers to strings where each 00883 ** entry represents the name of corresponding result column as obtained 00884 ** from [sqlite3_column_name()]. 00885 ** 00886 ** ^If the 2nd parameter to sqlite3_exec() is a NULL pointer, a pointer 00887 ** to an empty string, or a pointer that contains only whitespace and/or 00888 ** SQL comments, then no SQL statements are evaluated and the database 00889 ** is not changed. 00890 ** 00891 ** Restrictions: 00892 ** 00893 ** <ul> 00894 ** <li> The application must insure that the 1st parameter to sqlite3_exec() 00895 ** is a valid and open [database connection]. 00896 ** <li> The application must not close [database connection] specified by 00897 ** the 1st parameter to sqlite3_exec() while sqlite3_exec() is running. 00898 ** <li> The application must not modify the SQL statement text passed into 00899 ** the 2nd parameter of sqlite3_exec() while sqlite3_exec() is running. 00900 ** </ul> 00901 */ 00902 SQLITE_API int sqlite3_exec( 00903 sqlite3*, /* An open database */ 00904 const char *sql, /* SQL to be evaluated */ 00905 int (*callback)(void*,int,char**,char**), /* Callback function */ 00906 void *, /* 1st argument to callback */ 00907 char **errmsg /* Error msg written here */ 00908 ); 00909 00910 /* 00911 ** CAPI3REF: Result Codes 00912 ** KEYWORDS: SQLITE_OK {error code} {error codes} 00913 ** KEYWORDS: {result code} {result codes} 00914 ** 00915 ** Many SQLite functions return an integer result code from the set shown 00916 ** here in order to indicates success or failure. 00917 ** 00918 ** New error codes may be added in future versions of SQLite. 00919 ** 00920 ** See also: [SQLITE_IOERR_READ | extended result codes], 00921 ** [sqlite3_vtab_on_conflict()] [SQLITE_ROLLBACK | result codes]. 00922 */ 00923 #define SQLITE_OK 0 /* Successful result */ 00924 /* beginning-of-error-codes */ 00925 #define SQLITE_ERROR 1 /* SQL error or missing database */ 00926 #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ 00927 #define SQLITE_PERM 3 /* Access permission denied */ 00928 #define SQLITE_ABORT 4 /* Callback routine requested an abort */ 00929 #define SQLITE_BUSY 5 /* The database file is locked */ 00930 #define SQLITE_LOCKED 6 /* A table in the database is locked */ 00931 #define SQLITE_NOMEM 7 /* A malloc() failed */ 00932 #define SQLITE_READONLY 8 /* Attempt to write a readonly database */ 00933 #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/ 00934 #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */ 00935 #define SQLITE_CORRUPT 11 /* The database disk image is malformed */ 00936 #define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */ 00937 #define SQLITE_FULL 13 /* Insertion failed because database is full */ 00938 #define SQLITE_CANTOPEN 14 /* Unable to open the database file */ 00939 #define SQLITE_PROTOCOL 15 /* Database lock protocol error */ 00940 #define SQLITE_EMPTY 16 /* Database is empty */ 00941 #define SQLITE_SCHEMA 17 /* The database schema changed */ 00942 #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */ 00943 #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */ 00944 #define SQLITE_MISMATCH 20 /* Data type mismatch */ 00945 #define SQLITE_MISUSE 21 /* Library used incorrectly */ 00946 #define SQLITE_NOLFS 22 /* Uses OS features not supported on host */ 00947 #define SQLITE_AUTH 23 /* Authorization denied */ 00948 #define SQLITE_FORMAT 24 /* Auxiliary database format error */ 00949 #define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */ 00950 #define SQLITE_NOTADB 26 /* File opened that is not a database file */ 00951 #define SQLITE_ROW 100 /* sqlite3_step() has another row ready */ 00952 #define SQLITE_DONE 101 /* sqlite3_step() has finished executing */ 00953 /* end-of-error-codes */ 00954 00955 /* 00956 ** CAPI3REF: Extended Result Codes 00957 ** KEYWORDS: {extended error code} {extended error codes} 00958 ** KEYWORDS: {extended result code} {extended result codes} 00959 ** 00960 ** In its default configuration, SQLite API routines return one of 26 integer 00961 ** [SQLITE_OK | result codes]. However, experience has shown that many of 00962 ** these result codes are too coarse-grained. They do not provide as 00963 ** much information about problems as programmers might like. In an effort to 00964 ** address this, newer versions of SQLite (version 3.3.8 and later) include 00965 ** support for additional result codes that provide more detailed information 00966 ** about errors. The extended result codes are enabled or disabled 00967 ** on a per database connection basis using the 00968 ** [sqlite3_extended_result_codes()] API. 00969 ** 00970 ** Some of the available extended result codes are listed here. 00971 ** One may expect the number of extended result codes will be expand 00972 ** over time. Software that uses extended result codes should expect 00973 ** to see new result codes in future releases of SQLite. 00974 ** 00975 ** The SQLITE_OK result code will never be extended. It will always 00976 ** be exactly zero. 00977 */ 00978 #define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8)) 00979 #define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8)) 00980 #define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8)) 00981 #define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8)) 00982 #define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8)) 00983 #define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8)) 00984 #define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8)) 00985 #define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8)) 00986 #define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8)) 00987 #define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8)) 00988 #define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8)) 00989 #define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8)) 00990 #define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8)) 00991 #define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8)) 00992 #define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8)) 00993 #define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8)) 00994 #define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8)) 00995 #define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8)) 00996 #define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8)) 00997 #define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8)) 00998 #define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8)) 00999 #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) 01000 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) 01001 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) 01002 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) 01003 #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) 01004 #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) 01005 #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) 01006 01007 /* 01008 ** CAPI3REF: Flags For File Open Operations 01009 ** 01010 ** These bit values are intended for use in the 01011 ** 3rd parameter to the [sqlite3_open_v2()] interface and 01012 ** in the 4th parameter to the [sqlite3_vfs.xOpen] method. 01013 */ 01014 #define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */ 01015 #define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */ 01016 #define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */ 01017 #define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */ 01018 #define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */ 01019 #define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */ 01020 #define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */ 01021 #define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */ 01022 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */ 01023 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */ 01024 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */ 01025 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */ 01026 #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */ 01027 #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */ 01028 #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */ 01029 #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */ 01030 #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ 01031 #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ 01032 #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */ 01033 01034 /* Reserved: 0x00F00000 */ 01035 01036 /* 01037 ** CAPI3REF: Device Characteristics 01038 ** 01039 ** The xDeviceCharacteristics method of the [sqlite3_io_methods] 01040 ** object returns an integer which is a vector of the these 01041 ** bit values expressing I/O characteristics of the mass storage 01042 ** device that holds the file that the [sqlite3_io_methods] 01043 ** refers to. 01044 ** 01045 ** The SQLITE_IOCAP_ATOMIC property means that all writes of 01046 ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values 01047 ** mean that writes of blocks that are nnn bytes in size and 01048 ** are aligned to an address which is an integer multiple of 01049 ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means 01050 ** that when data is appended to a file, the data is appended 01051 ** first then the size of the file is extended, never the other 01052 ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that 01053 ** information is written to disk in the same order as calls 01054 ** to xWrite(). 01055 */ 01056 #define SQLITE_IOCAP_ATOMIC 0x00000001 01057 #define SQLITE_IOCAP_ATOMIC512 0x00000002 01058 #define SQLITE_IOCAP_ATOMIC1K 0x00000004 01059 #define SQLITE_IOCAP_ATOMIC2K 0x00000008 01060 #define SQLITE_IOCAP_ATOMIC4K 0x00000010 01061 #define SQLITE_IOCAP_ATOMIC8K 0x00000020 01062 #define SQLITE_IOCAP_ATOMIC16K 0x00000040 01063 #define SQLITE_IOCAP_ATOMIC32K 0x00000080 01064 #define SQLITE_IOCAP_ATOMIC64K 0x00000100 01065 #define SQLITE_IOCAP_SAFE_APPEND 0x00000200 01066 #define SQLITE_IOCAP_SEQUENTIAL 0x00000400 01067 #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800 01068 01069 /* 01070 ** CAPI3REF: File Locking Levels 01071 ** 01072 ** SQLite uses one of these integer values as the second 01073 ** argument to calls it makes to the xLock() and xUnlock() methods 01074 ** of an [sqlite3_io_methods] object. 01075 */ 01076 #define SQLITE_LOCK_NONE 0 01077 #define SQLITE_LOCK_SHARED 1 01078 #define SQLITE_LOCK_RESERVED 2 01079 #define SQLITE_LOCK_PENDING 3 01080 #define SQLITE_LOCK_EXCLUSIVE 4 01081 01082 /* 01083 ** CAPI3REF: Synchronization Type Flags 01084 ** 01085 ** When SQLite invokes the xSync() method of an 01086 ** [sqlite3_io_methods] object it uses a combination of 01087 ** these integer values as the second argument. 01088 ** 01089 ** When the SQLITE_SYNC_DATAONLY flag is used, it means that the 01090 ** sync operation only needs to flush data to mass storage. Inode 01091 ** information need not be flushed. If the lower four bits of the flag 01092 ** equal SQLITE_SYNC_NORMAL, that means to use normal fsync() semantics. 01093 ** If the lower four bits equal SQLITE_SYNC_FULL, that means 01094 ** to use Mac OS X style fullsync instead of fsync(). 01095 ** 01096 ** Do not confuse the SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags 01097 ** with the [PRAGMA synchronous]=NORMAL and [PRAGMA synchronous]=FULL 01098 ** settings. The [synchronous pragma] determines when calls to the 01099 ** xSync VFS method occur and applies uniformly across all platforms. 01100 ** The SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL flags determine how 01101 ** energetic or rigorous or forceful the sync operations are and 01102 ** only make a difference on Mac OSX for the default SQLite code. 01103 ** (Third-party VFS implementations might also make the distinction 01104 ** between SQLITE_SYNC_NORMAL and SQLITE_SYNC_FULL, but among the 01105 ** operating systems natively supported by SQLite, only Mac OSX 01106 ** cares about the difference.) 01107 */ 01108 #define SQLITE_SYNC_NORMAL 0x00002 01109 #define SQLITE_SYNC_FULL 0x00003 01110 #define SQLITE_SYNC_DATAONLY 0x00010 01111 01112 /* 01113 ** CAPI3REF: OS Interface Open File Handle 01114 ** 01115 ** An [sqlite3_file] object represents an open file in the 01116 ** [sqlite3_vfs | OS interface layer]. Individual OS interface 01117 ** implementations will 01118 ** want to subclass this object by appending additional fields 01119 ** for their own use. The pMethods entry is a pointer to an 01120 ** [sqlite3_io_methods] object that defines methods for performing 01121 ** I/O operations on the open file. 01122 */ 01123 typedef struct sqlite3_file sqlite3_file; 01124 struct sqlite3_file { 01125 const struct sqlite3_io_methods *pMethods; /* Methods for an open file */ 01126 }; 01127 01128 /* 01129 ** CAPI3REF: OS Interface File Virtual Methods Object 01130 ** 01131 ** Every file opened by the [sqlite3_vfs.xOpen] method populates an 01132 ** [sqlite3_file] object (or, more commonly, a subclass of the 01133 ** [sqlite3_file] object) with a pointer to an instance of this object. 01134 ** This object defines the methods used to perform various operations 01135 ** against the open file represented by the [sqlite3_file] object. 01136 ** 01137 ** If the [sqlite3_vfs.xOpen] method sets the sqlite3_file.pMethods element 01138 ** to a non-NULL pointer, then the sqlite3_io_methods.xClose method 01139 ** may be invoked even if the [sqlite3_vfs.xOpen] reported that it failed. The 01140 ** only way to prevent a call to xClose following a failed [sqlite3_vfs.xOpen] 01141 ** is for the [sqlite3_vfs.xOpen] to set the sqlite3_file.pMethods element 01142 ** to NULL. 01143 ** 01144 ** The flags argument to xSync may be one of [SQLITE_SYNC_NORMAL] or 01145 ** [SQLITE_SYNC_FULL]. The first choice is the normal fsync(). 01146 ** The second choice is a Mac OS X style fullsync. The [SQLITE_SYNC_DATAONLY] 01147 ** flag may be ORed in to indicate that only the data of the file 01148 ** and not its inode needs to be synced. 01149 ** 01150 ** The integer values to xLock() and xUnlock() are one of 01151 ** <ul> 01152 ** <li> [SQLITE_LOCK_NONE], 01153 ** <li> [SQLITE_LOCK_SHARED], 01154 ** <li> [SQLITE_LOCK_RESERVED], 01155 ** <li> [SQLITE_LOCK_PENDING], or 01156 ** <li> [SQLITE_LOCK_EXCLUSIVE]. 01157 ** </ul> 01158 ** xLock() increases the lock. xUnlock() decreases the lock. 01159 ** The xCheckReservedLock() method checks whether any database connection, 01160 ** either in this process or in some other process, is holding a RESERVED, 01161 ** PENDING, or EXCLUSIVE lock on the file. It returns true 01162 ** if such a lock exists and false otherwise. 01163 ** 01164 ** The xFileControl() method is a generic interface that allows custom 01165 ** VFS implementations to directly control an open file using the 01166 ** [sqlite3_file_control()] interface. The second "op" argument is an 01167 ** integer opcode. The third argument is a generic pointer intended to 01168 ** point to a structure that may contain arguments or space in which to 01169 ** write return values. Potential uses for xFileControl() might be 01170 ** functions to enable blocking locks with timeouts, to change the 01171 ** locking strategy (for example to use dot-file locks), to inquire 01172 ** about the status of a lock, or to break stale locks. The SQLite 01173 ** core reserves all opcodes less than 100 for its own use. 01174 ** A [SQLITE_FCNTL_LOCKSTATE | list of opcodes] less than 100 is available. 01175 ** Applications that define a custom xFileControl method should use opcodes 01176 ** greater than 100 to avoid conflicts. VFS implementations should 01177 ** return [SQLITE_NOTFOUND] for file control opcodes that they do not 01178 ** recognize. 01179 ** 01180 ** The xSectorSize() method returns the sector size of the 01181 ** device that underlies the file. The sector size is the 01182 ** minimum write that can be performed without disturbing 01183 ** other bytes in the file. The xDeviceCharacteristics() 01184 ** method returns a bit vector describing behaviors of the 01185 ** underlying device: 01186 ** 01187 ** <ul> 01188 ** <li> [SQLITE_IOCAP_ATOMIC] 01189 ** <li> [SQLITE_IOCAP_ATOMIC512] 01190 ** <li> [SQLITE_IOCAP_ATOMIC1K] 01191 ** <li> [SQLITE_IOCAP_ATOMIC2K] 01192 ** <li> [SQLITE_IOCAP_ATOMIC4K] 01193 ** <li> [SQLITE_IOCAP_ATOMIC8K] 01194 ** <li> [SQLITE_IOCAP_ATOMIC16K] 01195 ** <li> [SQLITE_IOCAP_ATOMIC32K] 01196 ** <li> [SQLITE_IOCAP_ATOMIC64K] 01197 ** <li> [SQLITE_IOCAP_SAFE_APPEND] 01198 ** <li> [SQLITE_IOCAP_SEQUENTIAL] 01199 ** </ul> 01200 ** 01201 ** The SQLITE_IOCAP_ATOMIC property means that all writes of 01202 ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values 01203 ** mean that writes of blocks that are nnn bytes in size and 01204 ** are aligned to an address which is an integer multiple of 01205 ** nnn are atomic. The SQLITE_IOCAP_SAFE_APPEND value means 01206 ** that when data is appended to a file, the data is appended 01207 ** first then the size of the file is extended, never the other 01208 ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that 01209 ** information is written to disk in the same order as calls 01210 ** to xWrite(). 01211 ** 01212 ** If xRead() returns SQLITE_IOERR_SHORT_READ it must also fill 01213 ** in the unread portions of the buffer with zeros. A VFS that 01214 ** fails to zero-fill short reads might seem to work. However, 01215 ** failure to zero-fill short reads will eventually lead to 01216 ** database corruption. 01217 */ 01218 typedef struct sqlite3_io_methods sqlite3_io_methods; 01219 struct sqlite3_io_methods { 01220 int iVersion; 01221 int (*xClose)(sqlite3_file*); 01222 int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst); 01223 int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst); 01224 int (*xTruncate)(sqlite3_file*, sqlite3_int64 size); 01225 int (*xSync)(sqlite3_file*, int flags); 01226 int (*xFileSize)(sqlite3_file*, sqlite3_int64 *pSize); 01227 int (*xLock)(sqlite3_file*, int); 01228 int (*xUnlock)(sqlite3_file*, int); 01229 int (*xCheckReservedLock)(sqlite3_file*, int *pResOut); 01230 int (*xFileControl)(sqlite3_file*, int op, void *pArg); 01231 int (*xSectorSize)(sqlite3_file*); 01232 int (*xDeviceCharacteristics)(sqlite3_file*); 01233 /* Methods above are valid for version 1 */ 01234 int (*xShmMap)(sqlite3_file*, int iPg, int pgsz, int, void volatile**); 01235 int (*xShmLock)(sqlite3_file*, int offset, int n, int flags); 01236 void (*xShmBarrier)(sqlite3_file*); 01237 int (*xShmUnmap)(sqlite3_file*, int deleteFlag); 01238 /* Methods above are valid for version 2 */ 01239 /* Additional methods may be added in future releases */ 01240 }; 01241 01242 /* 01243 ** CAPI3REF: Standard File Control Opcodes 01244 ** 01245 ** These integer constants are opcodes for the xFileControl method 01246 ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()] 01247 ** interface. 01248 ** 01249 ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This 01250 ** opcode causes the xFileControl method to write the current state of 01251 ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED], 01252 ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE]) 01253 ** into an integer that the pArg argument points to. This capability 01254 ** is used during testing and only needs to be supported when SQLITE_TEST 01255 ** is defined. 01256 ** 01257 ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS 01258 ** layer a hint of how large the database file will grow to be during the 01259 ** current transaction. This hint is not guaranteed to be accurate but it 01260 ** is often close. The underlying VFS might choose to preallocate database 01261 ** file space based on this hint in order to help writes to the database 01262 ** file run faster. 01263 ** 01264 ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS 01265 ** extends and truncates the database file in chunks of a size specified 01266 ** by the user. The fourth argument to [sqlite3_file_control()] should 01267 ** point to an integer (type int) containing the new chunk-size to use 01268 ** for the nominated database. Allocating database file space in large 01269 ** chunks (say 1MB at a time), may reduce file-system fragmentation and 01270 ** improve performance on some systems. 01271 ** 01272 ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer 01273 ** to the [sqlite3_file] object associated with a particular database 01274 ** connection. See the [sqlite3_file_control()] documentation for 01275 ** additional information. 01276 ** 01277 ** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by 01278 ** SQLite and sent to all VFSes in place of a call to the xSync method 01279 ** when the database connection has [PRAGMA synchronous] set to OFF.)^ 01280 ** Some specialized VFSes need this signal in order to operate correctly 01281 ** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most 01282 ** VFSes do not need this signal and should silently ignore this opcode. 01283 ** Applications should not call [sqlite3_file_control()] with this 01284 ** opcode as doing so may disrupt the operation of the specialized VFSes 01285 ** that do require it. 01286 ** 01287 ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic 01288 ** retry counts and intervals for certain disk I/O operations for the 01289 ** windows [VFS] in order to work to provide robustness against 01290 ** anti-virus programs. By default, the windows VFS will retry file read, 01291 ** file write, and file delete operations up to 10 times, with a delay 01292 ** of 25 milliseconds before the first retry and with the delay increasing 01293 ** by an additional 25 milliseconds with each subsequent retry. This 01294 ** opcode allows those to values (10 retries and 25 milliseconds of delay) 01295 ** to be adjusted. The values are changed for all database connections 01296 ** within the same process. The argument is a pointer to an array of two 01297 ** integers where the first integer i the new retry count and the second 01298 ** integer is the delay. If either integer is negative, then the setting 01299 ** is not changed but instead the prior value of that setting is written 01300 ** into the array entry, allowing the current retry settings to be 01301 ** interrogated. The zDbName parameter is ignored. 01302 ** 01303 ** ^The [SQLITE_FCNTL_PERSIST_WAL] opcode is used to set or query the 01304 ** persistent [WAL | Write AHead Log] setting. By default, the auxiliary 01305 ** write ahead log and shared memory files used for transaction control 01306 ** are automatically deleted when the latest connection to the database 01307 ** closes. Setting persistent WAL mode causes those files to persist after 01308 ** close. Persisting the files is useful when other processes that do not 01309 ** have write permission on the directory containing the database file want 01310 ** to read the database file, as the WAL and shared memory files must exist 01311 ** in order for the database to be readable. The fourth parameter to 01312 ** [sqlite3_file_control()] for this opcode should be a pointer to an integer. 01313 ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent 01314 ** WAL mode. If the integer is -1, then it is overwritten with the current 01315 ** WAL persistence setting. 01316 ** 01317 ** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening 01318 ** a write transaction to indicate that, unless it is rolled back for some 01319 ** reason, the entire database file will be overwritten by the current 01320 ** transaction. This is used by VACUUM operations. 01321 */ 01322 #define SQLITE_FCNTL_LOCKSTATE 1 01323 #define SQLITE_GET_LOCKPROXYFILE 2 01324 #define SQLITE_SET_LOCKPROXYFILE 3 01325 #define SQLITE_LAST_ERRNO 4 01326 #define SQLITE_FCNTL_SIZE_HINT 5 01327 #define SQLITE_FCNTL_CHUNK_SIZE 6 01328 #define SQLITE_FCNTL_FILE_POINTER 7 01329 #define SQLITE_FCNTL_SYNC_OMITTED 8 01330 #define SQLITE_FCNTL_WIN32_AV_RETRY 9 01331 #define SQLITE_FCNTL_PERSIST_WAL 10 01332 #define SQLITE_FCNTL_OVERWRITE 11 01333 01334 /* 01335 ** CAPI3REF: Mutex Handle 01336 ** 01337 ** The mutex module within SQLite defines [sqlite3_mutex] to be an 01338 ** abstract type for a mutex object. The SQLite core never looks 01339 ** at the internal representation of an [sqlite3_mutex]. It only 01340 ** deals with pointers to the [sqlite3_mutex] object. 01341 ** 01342 ** Mutexes are created using [sqlite3_mutex_alloc()]. 01343 */ 01344 typedef struct sqlite3_mutex sqlite3_mutex; 01345 01346 /* 01347 ** CAPI3REF: OS Interface Object 01348 ** 01349 ** An instance of the sqlite3_vfs object defines the interface between 01350 ** the SQLite core and the underlying operating system. The "vfs" 01351 ** in the name of the object stands for "virtual file system". See 01352 ** the [VFS | VFS documentation] for further information. 01353 ** 01354 ** The value of the iVersion field is initially 1 but may be larger in 01355 ** future versions of SQLite. Additional fields may be appended to this 01356 ** object when the iVersion value is increased. Note that the structure 01357 ** of the sqlite3_vfs object changes in the transaction between 01358 ** SQLite version 3.5.9 and 3.6.0 and yet the iVersion field was not 01359 ** modified. 01360 ** 01361 ** The szOsFile field is the size of the subclassed [sqlite3_file] 01362 ** structure used by this VFS. mxPathname is the maximum length of 01363 ** a pathname in this VFS. 01364 ** 01365 ** Registered sqlite3_vfs objects are kept on a linked list formed by 01366 ** the pNext pointer. The [sqlite3_vfs_register()] 01367 ** and [sqlite3_vfs_unregister()] interfaces manage this list 01368 ** in a thread-safe way. The [sqlite3_vfs_find()] interface 01369 ** searches the list. Neither the application code nor the VFS 01370 ** implementation should use the pNext pointer. 01371 ** 01372 ** The pNext field is the only field in the sqlite3_vfs 01373 ** structure that SQLite will ever modify. SQLite will only access 01374 ** or modify this field while holding a particular static mutex. 01375 ** The application should never modify anything within the sqlite3_vfs 01376 ** object once the object has been registered. 01377 ** 01378 ** The zName field holds the name of the VFS module. The name must 01379 ** be unique across all VFS modules. 01380 ** 01381 ** [[sqlite3_vfs.xOpen]] 01382 ** ^SQLite guarantees that the zFilename parameter to xOpen 01383 ** is either a NULL pointer or string obtained 01384 ** from xFullPathname() with an optional suffix added. 01385 ** ^If a suffix is added to the zFilename parameter, it will 01386 ** consist of a single "-" character followed by no more than 01387 ** 10 alphanumeric and/or "-" characters. 01388 ** ^SQLite further guarantees that 01389 ** the string will be valid and unchanged until xClose() is 01390 ** called. Because of the previous sentence, 01391 ** the [sqlite3_file] can safely store a pointer to the 01392 ** filename if it needs to remember the filename for some reason. 01393 ** If the zFilename parameter to xOpen is a NULL pointer then xOpen 01394 ** must invent its own temporary name for the file. ^Whenever the 01395 ** xFilename parameter is NULL it will also be the case that the 01396 ** flags parameter will include [SQLITE_OPEN_DELETEONCLOSE]. 01397 ** 01398 ** The flags argument to xOpen() includes all bits set in 01399 ** the flags argument to [sqlite3_open_v2()]. Or if [sqlite3_open()] 01400 ** or [sqlite3_open16()] is used, then flags includes at least 01401 ** [SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]. 01402 ** If xOpen() opens a file read-only then it sets *pOutFlags to 01403 ** include [SQLITE_OPEN_READONLY]. Other bits in *pOutFlags may be set. 01404 ** 01405 ** ^(SQLite will also add one of the following flags to the xOpen() 01406 ** call, depending on the object being opened: 01407 ** 01408 ** <ul> 01409 ** <li> [SQLITE_OPEN_MAIN_DB] 01410 ** <li> [SQLITE_OPEN_MAIN_JOURNAL] 01411 ** <li> [SQLITE_OPEN_TEMP_DB] 01412 ** <li> [SQLITE_OPEN_TEMP_JOURNAL] 01413 ** <li> [SQLITE_OPEN_TRANSIENT_DB] 01414 ** <li> [SQLITE_OPEN_SUBJOURNAL] 01415 ** <li> [SQLITE_OPEN_MASTER_JOURNAL] 01416 ** <li> [SQLITE_OPEN_WAL] 01417 ** </ul>)^ 01418 ** 01419 ** The file I/O implementation can use the object type flags to 01420 ** change the way it deals with files. For example, an application 01421 ** that does not care about crash recovery or rollback might make 01422 ** the open of a journal file a no-op. Writes to this journal would 01423 ** also be no-ops, and any attempt to read the journal would return 01424 ** SQLITE_IOERR. Or the implementation might recognize that a database 01425 ** file will be doing page-aligned sector reads and writes in a random 01426 ** order and set up its I/O subsystem accordingly. 01427 ** 01428 ** SQLite might also add one of the following flags to the xOpen method: 01429 ** 01430 ** <ul> 01431 ** <li> [SQLITE_OPEN_DELETEONCLOSE] 01432 ** <li> [SQLITE_OPEN_EXCLUSIVE] 01433 ** </ul> 01434 ** 01435 ** The [SQLITE_OPEN_DELETEONCLOSE] flag means the file should be 01436 ** deleted when it is closed. ^The [SQLITE_OPEN_DELETEONCLOSE] 01437 ** will be set for TEMP databases and their journals, transient 01438 ** databases, and subjournals. 01439 ** 01440 ** ^The [SQLITE_OPEN_EXCLUSIVE] flag is always used in conjunction 01441 ** with the [SQLITE_OPEN_CREATE] flag, which are both directly 01442 ** analogous to the O_EXCL and O_CREAT flags of the POSIX open() 01443 ** API. The SQLITE_OPEN_EXCLUSIVE flag, when paired with the 01444 ** SQLITE_OPEN_CREATE, is used to indicate that file should always 01445 ** be created, and that it is an error if it already exists. 01446 ** It is <i>not</i> used to indicate the file should be opened 01447 ** for exclusive access. 01448 ** 01449 ** ^At least szOsFile bytes of memory are allocated by SQLite 01450 ** to hold the [sqlite3_file] structure passed as the third 01451 ** argument to xOpen. The xOpen method does not have to 01452 ** allocate the structure; it should just fill it in. Note that 01453 ** the xOpen method must set the sqlite3_file.pMethods to either 01454 ** a valid [sqlite3_io_methods] object or to NULL. xOpen must do 01455 ** this even if the open fails. SQLite expects that the sqlite3_file.pMethods 01456 ** element will be valid after xOpen returns regardless of the success 01457 ** or failure of the xOpen call. 01458 ** 01459 ** [[sqlite3_vfs.xAccess]] 01460 ** ^The flags argument to xAccess() may be [SQLITE_ACCESS_EXISTS] 01461 ** to test for the existence of a file, or [SQLITE_ACCESS_READWRITE] to 01462 ** test whether a file is readable and writable, or [SQLITE_ACCESS_READ] 01463 ** to test whether a file is at least readable. The file can be a 01464 ** directory. 01465 ** 01466 ** ^SQLite will always allocate at least mxPathname+1 bytes for the 01467 ** output buffer xFullPathname. The exact size of the output buffer 01468 ** is also passed as a parameter to both methods. If the output buffer 01469 ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is 01470 ** handled as a fatal error by SQLite, vfs implementations should endeavor 01471 ** to prevent this by setting mxPathname to a sufficiently large value. 01472 ** 01473 ** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64() 01474 ** interfaces are not strictly a part of the filesystem, but they are 01475 ** included in the VFS structure for completeness. 01476 ** The xRandomness() function attempts to return nBytes bytes 01477 ** of good-quality randomness into zOut. The return value is 01478 ** the actual number of bytes of randomness obtained. 01479 ** The xSleep() method causes the calling thread to sleep for at 01480 ** least the number of microseconds given. ^The xCurrentTime() 01481 ** method returns a Julian Day Number for the current date and time as 01482 ** a floating point value. 01483 ** ^The xCurrentTimeInt64() method returns, as an integer, the Julian 01484 ** Day Number multiplied by 86400000 (the number of milliseconds in 01485 ** a 24-hour day). 01486 ** ^SQLite will use the xCurrentTimeInt64() method to get the current 01487 ** date and time if that method is available (if iVersion is 2 or 01488 ** greater and the function pointer is not NULL) and will fall back 01489 ** to xCurrentTime() if xCurrentTimeInt64() is unavailable. 01490 ** 01491 ** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces 01492 ** are not used by the SQLite core. These optional interfaces are provided 01493 ** by some VFSes to facilitate testing of the VFS code. By overriding 01494 ** system calls with functions under its control, a test program can 01495 ** simulate faults and error conditions that would otherwise be difficult 01496 ** or impossible to induce. The set of system calls that can be overridden 01497 ** varies from one VFS to another, and from one version of the same VFS to the 01498 ** next. Applications that use these interfaces must be prepared for any 01499 ** or all of these interfaces to be NULL or for their behavior to change 01500 ** from one release to the next. Applications must not attempt to access 01501 ** any of these methods if the iVersion of the VFS is less than 3. 01502 */ 01503 typedef struct sqlite3_vfs sqlite3_vfs; 01504 typedef void (*sqlite3_syscall_ptr)(void); 01505 struct sqlite3_vfs { 01506 int iVersion; /* Structure version number (currently 3) */ 01507 int szOsFile; /* Size of subclassed sqlite3_file */ 01508 int mxPathname; /* Maximum file pathname length */ 01509 sqlite3_vfs *pNext; /* Next registered VFS */ 01510 const char *zName; /* Name of this virtual file system */ 01511 void *pAppData; /* Pointer to application-specific data */ 01512 int (*xOpen)(sqlite3_vfs*, const char *zName, sqlite3_file*, 01513 int flags, int *pOutFlags); 01514 int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir); 01515 int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut); 01516 int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut); 01517 void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename); 01518 void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg); 01519 void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void); 01520 void (*xDlClose)(sqlite3_vfs*, void*); 01521 int (*xRandomness)(sqlite3_vfs*, int nByte, char *zOut); 01522 int (*xSleep)(sqlite3_vfs*, int microseconds); 01523 int (*xCurrentTime)(sqlite3_vfs*, double*); 01524 int (*xGetLastError)(sqlite3_vfs*, int, char *); 01525 /* 01526 ** The methods above are in version 1 of the sqlite_vfs object 01527 ** definition. Those that follow are added in version 2 or later 01528 */ 01529 int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*); 01530 /* 01531 ** The methods above are in versions 1 and 2 of the sqlite_vfs object. 01532 ** Those below are for version 3 and greater. 01533 */ 01534 int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr); 01535 sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName); 01536 const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName); 01537 /* 01538 ** The methods above are in versions 1 through 3 of the sqlite_vfs object. 01539 ** New fields may be appended in figure versions. The iVersion 01540 ** value will increment whenever this happens. 01541 */ 01542 }; 01543 01544 /* 01545 ** CAPI3REF: Flags for the xAccess VFS method 01546 ** 01547 ** These integer constants can be used as the third parameter to 01548 ** the xAccess method of an [sqlite3_vfs] object. They determine 01549 ** what kind of permissions the xAccess method is looking for. 01550 ** With SQLITE_ACCESS_EXISTS, the xAccess method 01551 ** simply checks whether the file exists. 01552 ** With SQLITE_ACCESS_READWRITE, the xAccess method 01553 ** checks whether the named directory is both readable and writable 01554 ** (in other words, if files can be added, removed, and renamed within 01555 ** the directory). 01556 ** The SQLITE_ACCESS_READWRITE constant is currently used only by the 01557 ** [temp_store_directory pragma], though this could change in a future 01558 ** release of SQLite. 01559 ** With SQLITE_ACCESS_READ, the xAccess method 01560 ** checks whether the file is readable. The SQLITE_ACCESS_READ constant is 01561 ** currently unused, though it might be used in a future release of 01562 ** SQLite. 01563 */ 01564 #define SQLITE_ACCESS_EXISTS 0 01565 #define SQLITE_ACCESS_READWRITE 1 /* Used by PRAGMA temp_store_directory */ 01566 #define SQLITE_ACCESS_READ 2 /* Unused */ 01567 01568 /* 01569 ** CAPI3REF: Flags for the xShmLock VFS method 01570 ** 01571 ** These integer constants define the various locking operations 01572 ** allowed by the xShmLock method of [sqlite3_io_methods]. The 01573 ** following are the only legal combinations of flags to the 01574 ** xShmLock method: 01575 ** 01576 ** <ul> 01577 ** <li> SQLITE_SHM_LOCK | SQLITE_SHM_SHARED 01578 ** <li> SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE 01579 ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED 01580 ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE 01581 ** </ul> 01582 ** 01583 ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as 01584 ** was given no the corresponding lock. 01585 ** 01586 ** The xShmLock method can transition between unlocked and SHARED or 01587 ** between unlocked and EXCLUSIVE. It cannot transition between SHARED 01588 ** and EXCLUSIVE. 01589 */ 01590 #define SQLITE_SHM_UNLOCK 1 01591 #define SQLITE_SHM_LOCK 2 01592 #define SQLITE_SHM_SHARED 4 01593 #define SQLITE_SHM_EXCLUSIVE 8 01594 01595 /* 01596 ** CAPI3REF: Maximum xShmLock index 01597 ** 01598 ** The xShmLock method on [sqlite3_io_methods] may use values 01599 ** between 0 and this upper bound as its "offset" argument. 01600 ** The SQLite core will never attempt to acquire or release a 01601 ** lock outside of this range 01602 */ 01603 #define SQLITE_SHM_NLOCK 8 01604 01605 01606 /* 01607 ** CAPI3REF: Initialize The SQLite Library 01608 ** 01609 ** ^The sqlite3_initialize() routine initializes the 01610 ** SQLite library. ^The sqlite3_shutdown() routine 01611 ** deallocates any resources that were allocated by sqlite3_initialize(). 01612 ** These routines are designed to aid in process initialization and 01613 ** shutdown on embedded systems. Workstation applications using 01614 ** SQLite normally do not need to invoke either of these routines. 01615 ** 01616 ** A call to sqlite3_initialize() is an "effective" call if it is 01617 ** the first time sqlite3_initialize() is invoked during the lifetime of 01618 ** the process, or if it is the first time sqlite3_initialize() is invoked 01619 ** following a call to sqlite3_shutdown(). ^(Only an effective call 01620 ** of sqlite3_initialize() does any initialization. All other calls 01621 ** are harmless no-ops.)^ 01622 ** 01623 ** A call to sqlite3_shutdown() is an "effective" call if it is the first 01624 ** call to sqlite3_shutdown() since the last sqlite3_initialize(). ^(Only 01625 ** an effective call to sqlite3_shutdown() does any deinitialization. 01626 ** All other valid calls to sqlite3_shutdown() are harmless no-ops.)^ 01627 ** 01628 ** The sqlite3_initialize() interface is threadsafe, but sqlite3_shutdown() 01629 ** is not. The sqlite3_shutdown() interface must only be called from a 01630 ** single thread. All open [database connections] must be closed and all 01631 ** other SQLite resources must be deallocated prior to invoking 01632 ** sqlite3_shutdown(). 01633 ** 01634 ** Among other things, ^sqlite3_initialize() will invoke 01635 ** sqlite3_os_init(). Similarly, ^sqlite3_shutdown() 01636 ** will invoke sqlite3_os_end(). 01637 ** 01638 ** ^The sqlite3_initialize() routine returns [SQLITE_OK] on success. 01639 ** ^If for some reason, sqlite3_initialize() is unable to initialize 01640 ** the library (perhaps it is unable to allocate a needed resource such 01641 ** as a mutex) it returns an [error code] other than [SQLITE_OK]. 01642 ** 01643 ** ^The sqlite3_initialize() routine is called internally by many other 01644 ** SQLite interfaces so that an application usually does not need to 01645 ** invoke sqlite3_initialize() directly. For example, [sqlite3_open()] 01646 ** calls sqlite3_initialize() so the SQLite library will be automatically 01647 ** initialized when [sqlite3_open()] is called if it has not be initialized 01648 ** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT] 01649 ** compile-time option, then the automatic calls to sqlite3_initialize() 01650 ** are omitted and the application must call sqlite3_initialize() directly 01651 ** prior to using any other SQLite interface. For maximum portability, 01652 ** it is recommended that applications always invoke sqlite3_initialize() 01653 ** directly prior to using any other SQLite interface. Future releases 01654 ** of SQLite may require this. In other words, the behavior exhibited 01655 ** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the 01656 ** default behavior in some future release of SQLite. 01657 ** 01658 ** The sqlite3_os_init() routine does operating-system specific 01659 ** initialization of the SQLite library. The sqlite3_os_end() 01660 ** routine undoes the effect of sqlite3_os_init(). Typical tasks 01661 ** performed by these routines include allocation or deallocation 01662 ** of static resources, initialization of global variables, 01663 ** setting up a default [sqlite3_vfs] module, or setting up 01664 ** a default configuration using [sqlite3_config()]. 01665 ** 01666 ** The application should never invoke either sqlite3_os_init() 01667 ** or sqlite3_os_end() directly. The application should only invoke 01668 ** sqlite3_initialize() and sqlite3_shutdown(). The sqlite3_os_init() 01669 ** interface is called automatically by sqlite3_initialize() and 01670 ** sqlite3_os_end() is called by sqlite3_shutdown(). Appropriate 01671 ** implementations for sqlite3_os_init() and sqlite3_os_end() 01672 ** are built into SQLite when it is compiled for Unix, Windows, or OS/2. 01673 ** When [custom builds | built for other platforms] 01674 ** (using the [SQLITE_OS_OTHER=1] compile-time 01675 ** option) the application must supply a suitable implementation for 01676 ** sqlite3_os_init() and sqlite3_os_end(). An application-supplied 01677 ** implementation of sqlite3_os_init() or sqlite3_os_end() 01678 ** must return [SQLITE_OK] on success and some other [error code] upon 01679 ** failure. 01680 */ 01681 SQLITE_API int sqlite3_initialize(void); 01682 SQLITE_API int sqlite3_shutdown(void); 01683 SQLITE_API int sqlite3_os_init(void); 01684 SQLITE_API int sqlite3_os_end(void); 01685 01686 /* 01687 ** CAPI3REF: Configuring The SQLite Library 01688 ** 01689 ** The sqlite3_config() interface is used to make global configuration 01690 ** changes to SQLite in order to tune SQLite to the specific needs of 01691 ** the application. The default configuration is recommended for most 01692 ** applications and so this routine is usually not necessary. It is 01693 ** provided to support rare applications with unusual needs. 01694 ** 01695 ** The sqlite3_config() interface is not threadsafe. The application 01696 ** must insure that no other SQLite interfaces are invoked by other 01697 ** threads while sqlite3_config() is running. Furthermore, sqlite3_config() 01698 ** may only be invoked prior to library initialization using 01699 ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()]. 01700 ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before 01701 ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE. 01702 ** Note, however, that ^sqlite3_config() can be called as part of the 01703 ** implementation of an application-defined [sqlite3_os_init()]. 01704 ** 01705 ** The first argument to sqlite3_config() is an integer 01706 ** [configuration option] that determines 01707 ** what property of SQLite is to be configured. Subsequent arguments 01708 ** vary depending on the [configuration option] 01709 ** in the first argument. 01710 ** 01711 ** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK]. 01712 ** ^If the option is unknown or SQLite is unable to set the option 01713 ** then this routine returns a non-zero [error code]. 01714 */ 01715 SQLITE_API int sqlite3_config(int, ...); 01716 01717 /* 01718 ** CAPI3REF: Configure database connections 01719 ** 01720 ** The sqlite3_db_config() interface is used to make configuration 01721 ** changes to a [database connection]. The interface is similar to 01722 ** [sqlite3_config()] except that the changes apply to a single 01723 ** [database connection] (specified in the first argument). 01724 ** 01725 ** The second argument to sqlite3_db_config(D,V,...) is the 01726 ** [SQLITE_DBCONFIG_LOOKASIDE | configuration verb] - an integer code 01727 ** that indicates what aspect of the [database connection] is being configured. 01728 ** Subsequent arguments vary depending on the configuration verb. 01729 ** 01730 ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if 01731 ** the call is considered successful. 01732 */ 01733 SQLITE_API int sqlite3_db_config(sqlite3*, int op, ...); 01734 01735 /* 01736 ** CAPI3REF: Memory Allocation Routines 01737 ** 01738 ** An instance of this object defines the interface between SQLite 01739 ** and low-level memory allocation routines. 01740 ** 01741 ** This object is used in only one place in the SQLite interface. 01742 ** A pointer to an instance of this object is the argument to 01743 ** [sqlite3_config()] when the configuration option is 01744 ** [SQLITE_CONFIG_MALLOC] or [SQLITE_CONFIG_GETMALLOC]. 01745 ** By creating an instance of this object 01746 ** and passing it to [sqlite3_config]([SQLITE_CONFIG_MALLOC]) 01747 ** during configuration, an application can specify an alternative 01748 ** memory allocation subsystem for SQLite to use for all of its 01749 ** dynamic memory needs. 01750 ** 01751 ** Note that SQLite comes with several [built-in memory allocators] 01752 ** that are perfectly adequate for the overwhelming majority of applications 01753 ** and that this object is only useful to a tiny minority of applications 01754 ** with specialized memory allocation requirements. This object is 01755 ** also used during testing of SQLite in order to specify an alternative 01756 ** memory allocator that simulates memory out-of-memory conditions in 01757 ** order to verify that SQLite recovers gracefully from such 01758 ** conditions. 01759 ** 01760 ** The xMalloc, xRealloc, and xFree methods must work like the 01761 ** malloc(), realloc() and free() functions from the standard C library. 01762 ** ^SQLite guarantees that the second argument to 01763 ** xRealloc is always a value returned by a prior call to xRoundup. 01764 ** 01765 ** xSize should return the allocated size of a memory allocation 01766 ** previously obtained from xMalloc or xRealloc. The allocated size 01767 ** is always at least as big as the requested size but may be larger. 01768 ** 01769 ** The xRoundup method returns what would be the allocated size of 01770 ** a memory allocation given a particular requested size. Most memory 01771 ** allocators round up memory allocations at least to the next multiple 01772 ** of 8. Some allocators round up to a larger multiple or to a power of 2. 01773 ** Every memory allocation request coming in through [sqlite3_malloc()] 01774 ** or [sqlite3_realloc()] first calls xRoundup. If xRoundup returns 0, 01775 ** that causes the corresponding memory allocation to fail. 01776 ** 01777 ** The xInit method initializes the memory allocator. (For example, 01778 ** it might allocate any require mutexes or initialize internal data 01779 ** structures. The xShutdown method is invoked (indirectly) by 01780 ** [sqlite3_shutdown()] and should deallocate any resources acquired 01781 ** by xInit. The pAppData pointer is used as the only parameter to 01782 ** xInit and xShutdown. 01783 ** 01784 ** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes 01785 ** the xInit method, so the xInit method need not be threadsafe. The 01786 ** xShutdown method is only called from [sqlite3_shutdown()] so it does 01787 ** not need to be threadsafe either. For all other methods, SQLite 01788 ** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the 01789 ** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which 01790 ** it is by default) and so the methods are automatically serialized. 01791 ** However, if [SQLITE_CONFIG_MEMSTATUS] is disabled, then the other 01792 ** methods must be threadsafe or else make their own arrangements for 01793 ** serialization. 01794 ** 01795 ** SQLite will never invoke xInit() more than once without an intervening 01796 ** call to xShutdown(). 01797 */ 01798 typedef struct sqlite3_mem_methods sqlite3_mem_methods; 01799 struct sqlite3_mem_methods { 01800 void *(*xMalloc)(int); /* Memory allocation function */ 01801 void (*xFree)(void*); /* Free a prior allocation */ 01802 void *(*xRealloc)(void*,int); /* Resize an allocation */ 01803 int (*xSize)(void*); /* Return the size of an allocation */ 01804 int (*xRoundup)(int); /* Round up request size to allocation size */ 01805 int (*xInit)(void*); /* Initialize the memory allocator */ 01806 void (*xShutdown)(void*); /* Deinitialize the memory allocator */ 01807 void *pAppData; /* Argument to xInit() and xShutdown() */ 01808 }; 01809 01810 /* 01811 ** CAPI3REF: Configuration Options 01812 ** KEYWORDS: {configuration option} 01813 ** 01814 ** These constants are the available integer configuration options that 01815 ** can be passed as the first argument to the [sqlite3_config()] interface. 01816 ** 01817 ** New configuration options may be added in future releases of SQLite. 01818 ** Existing configuration options might be discontinued. Applications 01819 ** should check the return code from [sqlite3_config()] to make sure that 01820 ** the call worked. The [sqlite3_config()] interface will return a 01821 ** non-zero [error code] if a discontinued or unsupported configuration option 01822 ** is invoked. 01823 ** 01824 ** <dl> 01825 ** [[SQLITE_CONFIG_SINGLETHREAD]] <dt>SQLITE_CONFIG_SINGLETHREAD</dt> 01826 ** <dd>There are no arguments to this option. ^This option sets the 01827 ** [threading mode] to Single-thread. In other words, it disables 01828 ** all mutexing and puts SQLite into a mode where it can only be used 01829 ** by a single thread. ^If SQLite is compiled with 01830 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 01831 ** it is not possible to change the [threading mode] from its default 01832 ** value of Single-thread and so [sqlite3_config()] will return 01833 ** [SQLITE_ERROR] if called with the SQLITE_CONFIG_SINGLETHREAD 01834 ** configuration option.</dd> 01835 ** 01836 ** [[SQLITE_CONFIG_MULTITHREAD]] <dt>SQLITE_CONFIG_MULTITHREAD</dt> 01837 ** <dd>There are no arguments to this option. ^This option sets the 01838 ** [threading mode] to Multi-thread. In other words, it disables 01839 ** mutexing on [database connection] and [prepared statement] objects. 01840 ** The application is responsible for serializing access to 01841 ** [database connections] and [prepared statements]. But other mutexes 01842 ** are enabled so that SQLite will be safe to use in a multi-threaded 01843 ** environment as long as no two threads attempt to use the same 01844 ** [database connection] at the same time. ^If SQLite is compiled with 01845 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 01846 ** it is not possible to set the Multi-thread [threading mode] and 01847 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the 01848 ** SQLITE_CONFIG_MULTITHREAD configuration option.</dd> 01849 ** 01850 ** [[SQLITE_CONFIG_SERIALIZED]] <dt>SQLITE_CONFIG_SERIALIZED</dt> 01851 ** <dd>There are no arguments to this option. ^This option sets the 01852 ** [threading mode] to Serialized. In other words, this option enables 01853 ** all mutexes including the recursive 01854 ** mutexes on [database connection] and [prepared statement] objects. 01855 ** In this mode (which is the default when SQLite is compiled with 01856 ** [SQLITE_THREADSAFE=1]) the SQLite library will itself serialize access 01857 ** to [database connections] and [prepared statements] so that the 01858 ** application is free to use the same [database connection] or the 01859 ** same [prepared statement] in different threads at the same time. 01860 ** ^If SQLite is compiled with 01861 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 01862 ** it is not possible to set the Serialized [threading mode] and 01863 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the 01864 ** SQLITE_CONFIG_SERIALIZED configuration option.</dd> 01865 ** 01866 ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt> 01867 ** <dd> ^(This option takes a single argument which is a pointer to an 01868 ** instance of the [sqlite3_mem_methods] structure. The argument specifies 01869 ** alternative low-level memory allocation routines to be used in place of 01870 ** the memory allocation routines built into SQLite.)^ ^SQLite makes 01871 ** its own private copy of the content of the [sqlite3_mem_methods] structure 01872 ** before the [sqlite3_config()] call returns.</dd> 01873 ** 01874 ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt> 01875 ** <dd> ^(This option takes a single argument which is a pointer to an 01876 ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods] 01877 ** structure is filled with the currently defined memory allocation routines.)^ 01878 ** This option can be used to overload the default memory allocation 01879 ** routines with a wrapper that simulations memory allocation failure or 01880 ** tracks memory usage, for example. </dd> 01881 ** 01882 ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt> 01883 ** <dd> ^This option takes single argument of type int, interpreted as a 01884 ** boolean, which enables or disables the collection of memory allocation 01885 ** statistics. ^(When memory allocation statistics are disabled, the 01886 ** following SQLite interfaces become non-operational: 01887 ** <ul> 01888 ** <li> [sqlite3_memory_used()] 01889 ** <li> [sqlite3_memory_highwater()] 01890 ** <li> [sqlite3_soft_heap_limit64()] 01891 ** <li> [sqlite3_status()] 01892 ** </ul>)^ 01893 ** ^Memory allocation statistics are enabled by default unless SQLite is 01894 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory 01895 ** allocation statistics are disabled by default. 01896 ** </dd> 01897 ** 01898 ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt> 01899 ** <dd> ^This option specifies a static memory buffer that SQLite can use for 01900 ** scratch memory. There are three arguments: A pointer an 8-byte 01901 ** aligned memory buffer from which the scratch allocations will be 01902 ** drawn, the size of each scratch allocation (sz), 01903 ** and the maximum number of scratch allocations (N). The sz 01904 ** argument must be a multiple of 16. 01905 ** The first argument must be a pointer to an 8-byte aligned buffer 01906 ** of at least sz*N bytes of memory. 01907 ** ^SQLite will use no more than two scratch buffers per thread. So 01908 ** N should be set to twice the expected maximum number of threads. 01909 ** ^SQLite will never require a scratch buffer that is more than 6 01910 ** times the database page size. ^If SQLite needs needs additional 01911 ** scratch memory beyond what is provided by this configuration option, then 01912 ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd> 01913 ** 01914 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt> 01915 ** <dd> ^This option specifies a static memory buffer that SQLite can use for 01916 ** the database page cache with the default page cache implementation. 01917 ** This configuration should not be used if an application-define page 01918 ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option. 01919 ** There are three arguments to this option: A pointer to 8-byte aligned 01920 ** memory, the size of each page buffer (sz), and the number of pages (N). 01921 ** The sz argument should be the size of the largest database page 01922 ** (a power of two between 512 and 32768) plus a little extra for each 01923 ** page header. ^The page header size is 20 to 40 bytes depending on 01924 ** the host architecture. ^It is harmless, apart from the wasted memory, 01925 ** to make sz a little too large. The first 01926 ** argument should point to an allocation of at least sz*N bytes of memory. 01927 ** ^SQLite will use the memory provided by the first argument to satisfy its 01928 ** memory needs for the first N pages that it adds to cache. ^If additional 01929 ** page cache memory is needed beyond what is provided by this option, then 01930 ** SQLite goes to [sqlite3_malloc()] for the additional storage space. 01931 ** The pointer in the first argument must 01932 ** be aligned to an 8-byte boundary or subsequent behavior of SQLite 01933 ** will be undefined.</dd> 01934 ** 01935 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt> 01936 ** <dd> ^This option specifies a static memory buffer that SQLite will use 01937 ** for all of its dynamic memory allocation needs beyond those provided 01938 ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. 01939 ** There are three arguments: An 8-byte aligned pointer to the memory, 01940 ** the number of bytes in the memory buffer, and the minimum allocation size. 01941 ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts 01942 ** to using its default memory allocator (the system malloc() implementation), 01943 ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the 01944 ** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or 01945 ** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory 01946 ** allocator is engaged to handle all of SQLites memory allocation needs. 01947 ** The first pointer (the memory pointer) must be aligned to an 8-byte 01948 ** boundary or subsequent behavior of SQLite will be undefined. 01949 ** The minimum allocation size is capped at 2**12. Reasonable values 01950 ** for the minimum allocation size are 2**5 through 2**8.</dd> 01951 ** 01952 ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt> 01953 ** <dd> ^(This option takes a single argument which is a pointer to an 01954 ** instance of the [sqlite3_mutex_methods] structure. The argument specifies 01955 ** alternative low-level mutex routines to be used in place 01956 ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the 01957 ** content of the [sqlite3_mutex_methods] structure before the call to 01958 ** [sqlite3_config()] returns. ^If SQLite is compiled with 01959 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 01960 ** the entire mutexing subsystem is omitted from the build and hence calls to 01961 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will 01962 ** return [SQLITE_ERROR].</dd> 01963 ** 01964 ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt> 01965 ** <dd> ^(This option takes a single argument which is a pointer to an 01966 ** instance of the [sqlite3_mutex_methods] structure. The 01967 ** [sqlite3_mutex_methods] 01968 ** structure is filled with the currently defined mutex routines.)^ 01969 ** This option can be used to overload the default mutex allocation 01970 ** routines with a wrapper used to track mutex usage for performance 01971 ** profiling or testing, for example. ^If SQLite is compiled with 01972 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then 01973 ** the entire mutexing subsystem is omitted from the build and hence calls to 01974 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will 01975 ** return [SQLITE_ERROR].</dd> 01976 ** 01977 ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt> 01978 ** <dd> ^(This option takes two arguments that determine the default 01979 ** memory allocation for the lookaside memory allocator on each 01980 ** [database connection]. The first argument is the 01981 ** size of each lookaside buffer slot and the second is the number of 01982 ** slots allocated to each database connection.)^ ^(This option sets the 01983 ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE] 01984 ** verb to [sqlite3_db_config()] can be used to change the lookaside 01985 ** configuration on individual connections.)^ </dd> 01986 ** 01987 ** [[SQLITE_CONFIG_PCACHE]] <dt>SQLITE_CONFIG_PCACHE</dt> 01988 ** <dd> ^(This option takes a single argument which is a pointer to 01989 ** an [sqlite3_pcache_methods] object. This object specifies the interface 01990 ** to a custom page cache implementation.)^ ^SQLite makes a copy of the 01991 ** object and uses it for page cache memory allocations.</dd> 01992 ** 01993 ** [[SQLITE_CONFIG_GETPCACHE]] <dt>SQLITE_CONFIG_GETPCACHE</dt> 01994 ** <dd> ^(This option takes a single argument which is a pointer to an 01995 ** [sqlite3_pcache_methods] object. SQLite copies of the current 01996 ** page cache implementation into that object.)^ </dd> 01997 ** 01998 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt> 01999 ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a 02000 ** function with a call signature of void(*)(void*,int,const char*), 02001 ** and a pointer to void. ^If the function pointer is not NULL, it is 02002 ** invoked by [sqlite3_log()] to process each logging event. ^If the 02003 ** function pointer is NULL, the [sqlite3_log()] interface becomes a no-op. 02004 ** ^The void pointer that is the second argument to SQLITE_CONFIG_LOG is 02005 ** passed through as the first parameter to the application-defined logger 02006 ** function whenever that function is invoked. ^The second parameter to 02007 ** the logger function is a copy of the first parameter to the corresponding 02008 ** [sqlite3_log()] call and is intended to be a [result code] or an 02009 ** [extended result code]. ^The third parameter passed to the logger is 02010 ** log message after formatting via [sqlite3_snprintf()]. 02011 ** The SQLite logging interface is not reentrant; the logger function 02012 ** supplied by the application must not invoke any SQLite interface. 02013 ** In a multi-threaded application, the application-defined logger 02014 ** function must be threadsafe. </dd> 02015 ** 02016 ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI 02017 ** <dd> This option takes a single argument of type int. If non-zero, then 02018 ** URI handling is globally enabled. If the parameter is zero, then URI handling 02019 ** is globally disabled. If URI handling is globally enabled, all filenames 02020 ** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or 02021 ** specified as part of [ATTACH] commands are interpreted as URIs, regardless 02022 ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database 02023 ** connection is opened. If it is globally disabled, filenames are 02024 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the 02025 ** database connection is opened. By default, URI handling is globally 02026 ** disabled. The default value may be changed by compiling with the 02027 ** [SQLITE_USE_URI] symbol defined. 02028 ** </dl> 02029 */ 02030 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ 02031 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ 02032 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ 02033 #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ 02034 #define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */ 02035 #define SQLITE_CONFIG_SCRATCH 6 /* void*, int sz, int N */ 02036 #define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */ 02037 #define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */ 02038 #define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */ 02039 #define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */ 02040 #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */ 02041 /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ 02042 #define SQLITE_CONFIG_LOOKASIDE 13 /* int int */ 02043 #define SQLITE_CONFIG_PCACHE 14 /* sqlite3_pcache_methods* */ 02044 #define SQLITE_CONFIG_GETPCACHE 15 /* sqlite3_pcache_methods* */ 02045 #define SQLITE_CONFIG_LOG 16 /* xFunc, void* */ 02046 #define SQLITE_CONFIG_URI 17 /* int */ 02047 02048 /* 02049 ** CAPI3REF: Database Connection Configuration Options 02050 ** 02051 ** These constants are the available integer configuration options that 02052 ** can be passed as the second argument to the [sqlite3_db_config()] interface. 02053 ** 02054 ** New configuration options may be added in future releases of SQLite. 02055 ** Existing configuration options might be discontinued. Applications 02056 ** should check the return code from [sqlite3_db_config()] to make sure that 02057 ** the call worked. ^The [sqlite3_db_config()] interface will return a 02058 ** non-zero [error code] if a discontinued or unsupported configuration option 02059 ** is invoked. 02060 ** 02061 ** <dl> 02062 ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt> 02063 ** <dd> ^This option takes three additional arguments that determine the 02064 ** [lookaside memory allocator] configuration for the [database connection]. 02065 ** ^The first argument (the third parameter to [sqlite3_db_config()] is a 02066 ** pointer to a memory buffer to use for lookaside memory. 02067 ** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb 02068 ** may be NULL in which case SQLite will allocate the 02069 ** lookaside buffer itself using [sqlite3_malloc()]. ^The second argument is the 02070 ** size of each lookaside buffer slot. ^The third argument is the number of 02071 ** slots. The size of the buffer in the first argument must be greater than 02072 ** or equal to the product of the second and third arguments. The buffer 02073 ** must be aligned to an 8-byte boundary. ^If the second argument to 02074 ** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally 02075 ** rounded down to the next smaller multiple of 8. ^(The lookaside memory 02076 ** configuration for a database connection can only be changed when that 02077 ** connection is not currently using lookaside memory, or in other words 02078 ** when the "current value" returned by 02079 ** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero. 02080 ** Any attempt to change the lookaside memory configuration when lookaside 02081 ** memory is in use leaves the configuration unchanged and returns 02082 ** [SQLITE_BUSY].)^</dd> 02083 ** 02084 ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt> 02085 ** <dd> ^This option is used to enable or disable the enforcement of 02086 ** [foreign key constraints]. There should be two additional arguments. 02087 ** The first argument is an integer which is 0 to disable FK enforcement, 02088 ** positive to enable FK enforcement or negative to leave FK enforcement 02089 ** unchanged. The second parameter is a pointer to an integer into which 02090 ** is written 0 or 1 to indicate whether FK enforcement is off or on 02091 ** following this call. The second parameter may be a NULL pointer, in 02092 ** which case the FK enforcement setting is not reported back. </dd> 02093 ** 02094 ** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt> 02095 ** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers]. 02096 ** There should be two additional arguments. 02097 ** The first argument is an integer which is 0 to disable triggers, 02098 ** positive to enable triggers or negative to leave the setting unchanged. 02099 ** The second parameter is a pointer to an integer into which 02100 ** is written 0 or 1 to indicate whether triggers are disabled or enabled 02101 ** following this call. The second parameter may be a NULL pointer, in 02102 ** which case the trigger setting is not reported back. </dd> 02103 ** 02104 ** </dl> 02105 */ 02106 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */ 02107 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */ 02108 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */ 02109 02110 02111 /* 02112 ** CAPI3REF: Enable Or Disable Extended Result Codes 02113 ** 02114 ** ^The sqlite3_extended_result_codes() routine enables or disables the 02115 ** [extended result codes] feature of SQLite. ^The extended result 02116 ** codes are disabled by default for historical compatibility. 02117 */ 02118 SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff); 02119 02120 /* 02121 ** CAPI3REF: Last Insert Rowid 02122 ** 02123 ** ^Each entry in an SQLite table has a unique 64-bit signed 02124 ** integer key called the [ROWID | "rowid"]. ^The rowid is always available 02125 ** as an undeclared column named ROWID, OID, or _ROWID_ as long as those 02126 ** names are not also used by explicitly declared columns. ^If 02127 ** the table has a column of type [INTEGER PRIMARY KEY] then that column 02128 ** is another alias for the rowid. 02129 ** 02130 ** ^This routine returns the [rowid] of the most recent 02131 ** successful [INSERT] into the database from the [database connection] 02132 ** in the first argument. ^As of SQLite version 3.7.7, this routines 02133 ** records the last insert rowid of both ordinary tables and [virtual tables]. 02134 ** ^If no successful [INSERT]s 02135 ** have ever occurred on that database connection, zero is returned. 02136 ** 02137 ** ^(If an [INSERT] occurs within a trigger or within a [virtual table] 02138 ** method, then this routine will return the [rowid] of the inserted 02139 ** row as long as the trigger or virtual table method is running. 02140 ** But once the trigger or virtual table method ends, the value returned 02141 ** by this routine reverts to what it was before the trigger or virtual 02142 ** table method began.)^ 02143 ** 02144 ** ^An [INSERT] that fails due to a constraint violation is not a 02145 ** successful [INSERT] and does not change the value returned by this 02146 ** routine. ^Thus INSERT OR FAIL, INSERT OR IGNORE, INSERT OR ROLLBACK, 02147 ** and INSERT OR ABORT make no changes to the return value of this 02148 ** routine when their insertion fails. ^(When INSERT OR REPLACE 02149 ** encounters a constraint violation, it does not fail. The 02150 ** INSERT continues to completion after deleting rows that caused 02151 ** the constraint problem so INSERT OR REPLACE will always change 02152 ** the return value of this interface.)^ 02153 ** 02154 ** ^For the purposes of this routine, an [INSERT] is considered to 02155 ** be successful even if it is subsequently rolled back. 02156 ** 02157 ** This function is accessible to SQL statements via the 02158 ** [last_insert_rowid() SQL function]. 02159 ** 02160 ** If a separate thread performs a new [INSERT] on the same 02161 ** database connection while the [sqlite3_last_insert_rowid()] 02162 ** function is running and thus changes the last insert [rowid], 02163 ** then the value returned by [sqlite3_last_insert_rowid()] is 02164 ** unpredictable and might not equal either the old or the new 02165 ** last insert [rowid]. 02166 */ 02167 SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); 02168 02169 /* 02170 ** CAPI3REF: Count The Number Of Rows Modified 02171 ** 02172 ** ^This function returns the number of database rows that were changed 02173 ** or inserted or deleted by the most recently completed SQL statement 02174 ** on the [database connection] specified by the first parameter. 02175 ** ^(Only changes that are directly specified by the [INSERT], [UPDATE], 02176 ** or [DELETE] statement are counted. Auxiliary changes caused by 02177 ** triggers or [foreign key actions] are not counted.)^ Use the 02178 ** [sqlite3_total_changes()] function to find the total number of changes 02179 ** including changes caused by triggers and foreign key actions. 02180 ** 02181 ** ^Changes to a view that are simulated by an [INSTEAD OF trigger] 02182 ** are not counted. Only real table changes are counted. 02183 ** 02184 ** ^(A "row change" is a change to a single row of a single table 02185 ** caused by an INSERT, DELETE, or UPDATE statement. Rows that 02186 ** are changed as side effects of [REPLACE] constraint resolution, 02187 ** rollback, ABORT processing, [DROP TABLE], or by any other 02188 ** mechanisms do not count as direct row changes.)^ 02189 ** 02190 ** A "trigger context" is a scope of execution that begins and 02191 ** ends with the script of a [CREATE TRIGGER | trigger]. 02192 ** Most SQL statements are 02193 ** evaluated outside of any trigger. This is the "top level" 02194 ** trigger context. If a trigger fires from the top level, a 02195 ** new trigger context is entered for the duration of that one 02196 ** trigger. Subtriggers create subcontexts for their duration. 02197 ** 02198 ** ^Calling [sqlite3_exec()] or [sqlite3_step()] recursively does 02199 ** not create a new trigger context. 02200 ** 02201 ** ^This function returns the number of direct row changes in the 02202 ** most recent INSERT, UPDATE, or DELETE statement within the same 02203 ** trigger context. 02204 ** 02205 ** ^Thus, when called from the top level, this function returns the 02206 ** number of changes in the most recent INSERT, UPDATE, or DELETE 02207 ** that also occurred at the top level. ^(Within the body of a trigger, 02208 ** the sqlite3_changes() interface can be called to find the number of 02209 ** changes in the most recently completed INSERT, UPDATE, or DELETE 02210 ** statement within the body of the same trigger. 02211 ** However, the number returned does not include changes 02212 ** caused by subtriggers since those have their own context.)^ 02213 ** 02214 ** See also the [sqlite3_total_changes()] interface, the 02215 ** [count_changes pragma], and the [changes() SQL function]. 02216 ** 02217 ** If a separate thread makes changes on the same database connection 02218 ** while [sqlite3_changes()] is running then the value returned 02219 ** is unpredictable and not meaningful. 02220 */ 02221 SQLITE_API int sqlite3_changes(sqlite3*); 02222 02223 /* 02224 ** CAPI3REF: Total Number Of Rows Modified 02225 ** 02226 ** ^This function returns the number of row changes caused by [INSERT], 02227 ** [UPDATE] or [DELETE] statements since the [database connection] was opened. 02228 ** ^(The count returned by sqlite3_total_changes() includes all changes 02229 ** from all [CREATE TRIGGER | trigger] contexts and changes made by 02230 ** [foreign key actions]. However, 02231 ** the count does not include changes used to implement [REPLACE] constraints, 02232 ** do rollbacks or ABORT processing, or [DROP TABLE] processing. The 02233 ** count does not include rows of views that fire an [INSTEAD OF trigger], 02234 ** though if the INSTEAD OF trigger makes changes of its own, those changes 02235 ** are counted.)^ 02236 ** ^The sqlite3_total_changes() function counts the changes as soon as 02237 ** the statement that makes them is completed (when the statement handle 02238 ** is passed to [sqlite3_reset()] or [sqlite3_finalize()]). 02239 ** 02240 ** See also the [sqlite3_changes()] interface, the 02241 ** [count_changes pragma], and the [total_changes() SQL function]. 02242 ** 02243 ** If a separate thread makes changes on the same database connection 02244 ** while [sqlite3_total_changes()] is running then the value 02245 ** returned is unpredictable and not meaningful. 02246 */ 02247 SQLITE_API int sqlite3_total_changes(sqlite3*); 02248 02249 /* 02250 ** CAPI3REF: Interrupt A Long-Running Query 02251 ** 02252 ** ^This function causes any pending database operation to abort and 02253 ** return at its earliest opportunity. This routine is typically 02254 ** called in response to a user action such as pressing "Cancel" 02255 ** or Ctrl-C where the user wants a long query operation to halt 02256 ** immediately. 02257 ** 02258 ** ^It is safe to call this routine from a thread different from the 02259 ** thread that is currently running the database operation. But it 02260 ** is not safe to call this routine with a [database connection] that 02261 ** is closed or might close before sqlite3_interrupt() returns. 02262 ** 02263 ** ^If an SQL operation is very nearly finished at the time when 02264 ** sqlite3_interrupt() is called, then it might not have an opportunity 02265 ** to be interrupted and might continue to completion. 02266 ** 02267 ** ^An SQL operation that is interrupted will return [SQLITE_INTERRUPT]. 02268 ** ^If the interrupted SQL operation is an INSERT, UPDATE, or DELETE 02269 ** that is inside an explicit transaction, then the entire transaction 02270 ** will be rolled back automatically. 02271 ** 02272 ** ^The sqlite3_interrupt(D) call is in effect until all currently running 02273 ** SQL statements on [database connection] D complete. ^Any new SQL statements 02274 ** that are started after the sqlite3_interrupt() call and before the 02275 ** running statements reaches zero are interrupted as if they had been 02276 ** running prior to the sqlite3_interrupt() call. ^New SQL statements 02277 ** that are started after the running statement count reaches zero are 02278 ** not effected by the sqlite3_interrupt(). 02279 ** ^A call to sqlite3_interrupt(D) that occurs when there are no running 02280 ** SQL statements is a no-op and has no effect on SQL statements 02281 ** that are started after the sqlite3_interrupt() call returns. 02282 ** 02283 ** If the database connection closes while [sqlite3_interrupt()] 02284 ** is running then bad things will likely happen. 02285 */ 02286 SQLITE_API void sqlite3_interrupt(sqlite3*); 02287 02288 /* 02289 ** CAPI3REF: Determine If An SQL Statement Is Complete 02290 ** 02291 ** These routines are useful during command-line input to determine if the 02292 ** currently entered text seems to form a complete SQL statement or 02293 ** if additional input is needed before sending the text into 02294 ** SQLite for parsing. ^These routines return 1 if the input string 02295 ** appears to be a complete SQL statement. ^A statement is judged to be 02296 ** complete if it ends with a semicolon token and is not a prefix of a 02297 ** well-formed CREATE TRIGGER statement. ^Semicolons that are embedded within 02298 ** string literals or quoted identifier names or comments are not 02299 ** independent tokens (they are part of the token in which they are 02300 ** embedded) and thus do not count as a statement terminator. ^Whitespace 02301 ** and comments that follow the final semicolon are ignored. 02302 ** 02303 ** ^These routines return 0 if the statement is incomplete. ^If a 02304 ** memory allocation fails, then SQLITE_NOMEM is returned. 02305 ** 02306 ** ^These routines do not parse the SQL statements thus 02307 ** will not detect syntactically incorrect SQL. 02308 ** 02309 ** ^(If SQLite has not been initialized using [sqlite3_initialize()] prior 02310 ** to invoking sqlite3_complete16() then sqlite3_initialize() is invoked 02311 ** automatically by sqlite3_complete16(). If that initialization fails, 02312 ** then the return value from sqlite3_complete16() will be non-zero 02313 ** regardless of whether or not the input SQL is complete.)^ 02314 ** 02315 ** The input to [sqlite3_complete()] must be a zero-terminated 02316 ** UTF-8 string. 02317 ** 02318 ** The input to [sqlite3_complete16()] must be a zero-terminated 02319 ** UTF-16 string in native byte order. 02320 */ 02321 SQLITE_API int sqlite3_complete(const char *sql); 02322 SQLITE_API int sqlite3_complete16(const void *sql); 02323 02324 /* 02325 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors 02326 ** 02327 ** ^This routine sets a callback function that might be invoked whenever 02328 ** an attempt is made to open a database table that another thread 02329 ** or process has locked. 02330 ** 02331 ** ^If the busy callback is NULL, then [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] 02332 ** is returned immediately upon encountering the lock. ^If the busy callback 02333 ** is not NULL, then the callback might be invoked with two arguments. 02334 ** 02335 ** ^The first argument to the busy handler is a copy of the void* pointer which 02336 ** is the third argument to sqlite3_busy_handler(). ^The second argument to 02337 ** the busy handler callback is the number of times that the busy handler has 02338 ** been invoked for this locking event. ^If the 02339 ** busy callback returns 0, then no additional attempts are made to 02340 ** access the database and [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED] is returned. 02341 ** ^If the callback returns non-zero, then another attempt 02342 ** is made to open the database for reading and the cycle repeats. 02343 ** 02344 ** The presence of a busy handler does not guarantee that it will be invoked 02345 ** when there is lock contention. ^If SQLite determines that invoking the busy 02346 ** handler could result in a deadlock, it will go ahead and return [SQLITE_BUSY] 02347 ** or [SQLITE_IOERR_BLOCKED] instead of invoking the busy handler. 02348 ** Consider a scenario where one process is holding a read lock that 02349 ** it is trying to promote to a reserved lock and 02350 ** a second process is holding a reserved lock that it is trying 02351 ** to promote to an exclusive lock. The first process cannot proceed 02352 ** because it is blocked by the second and the second process cannot 02353 ** proceed because it is blocked by the first. If both processes 02354 ** invoke the busy handlers, neither will make any progress. Therefore, 02355 ** SQLite returns [SQLITE_BUSY] for the first process, hoping that this 02356 ** will induce the first process to release its read lock and allow 02357 ** the second process to proceed. 02358 ** 02359 ** ^The default busy callback is NULL. 02360 ** 02361 ** ^The [SQLITE_BUSY] error is converted to [SQLITE_IOERR_BLOCKED] 02362 ** when SQLite is in the middle of a large transaction where all the 02363 ** changes will not fit into the in-memory cache. SQLite will 02364 ** already hold a RESERVED lock on the database file, but it needs 02365 ** to promote this lock to EXCLUSIVE so that it can spill cache 02366 ** pages into the database file without harm to concurrent 02367 ** readers. ^If it is unable to promote the lock, then the in-memory 02368 ** cache will be left in an inconsistent state and so the error 02369 ** code is promoted from the relatively benign [SQLITE_BUSY] to 02370 ** the more severe [SQLITE_IOERR_BLOCKED]. ^This error code promotion 02371 ** forces an automatic rollback of the changes. See the 02372 ** <a href="/cvstrac/wiki?p=CorruptionFollowingBusyError"> 02373 ** CorruptionFollowingBusyError</a> wiki page for a discussion of why 02374 ** this is important. 02375 ** 02376 ** ^(There can only be a single busy handler defined for each 02377 ** [database connection]. Setting a new busy handler clears any 02378 ** previously set handler.)^ ^Note that calling [sqlite3_busy_timeout()] 02379 ** will also set or clear the busy handler. 02380 ** 02381 ** The busy callback should not take any actions which modify the 02382 ** database connection that invoked the busy handler. Any such actions 02383 ** result in undefined behavior. 02384 ** 02385 ** A busy handler must not close the database connection 02386 ** or [prepared statement] that invoked the busy handler. 02387 */ 02388 SQLITE_API int sqlite3_busy_handler(sqlite3*, int(*)(void*,int), void*); 02389 02390 /* 02391 ** CAPI3REF: Set A Busy Timeout 02392 ** 02393 ** ^This routine sets a [sqlite3_busy_handler | busy handler] that sleeps 02394 ** for a specified amount of time when a table is locked. ^The handler 02395 ** will sleep multiple times until at least "ms" milliseconds of sleeping 02396 ** have accumulated. ^After at least "ms" milliseconds of sleeping, 02397 ** the handler returns 0 which causes [sqlite3_step()] to return 02398 ** [SQLITE_BUSY] or [SQLITE_IOERR_BLOCKED]. 02399 ** 02400 ** ^Calling this routine with an argument less than or equal to zero 02401 ** turns off all busy handlers. 02402 ** 02403 ** ^(There can only be a single busy handler for a particular 02404 ** [database connection] any any given moment. If another busy handler 02405 ** was defined (using [sqlite3_busy_handler()]) prior to calling 02406 ** this routine, that other busy handler is cleared.)^ 02407 */ 02408 SQLITE_API int sqlite3_busy_timeout(sqlite3*, int ms); 02409 02410 /* 02411 ** CAPI3REF: Convenience Routines For Running Queries 02412 ** 02413 ** This is a legacy interface that is preserved for backwards compatibility. 02414 ** Use of this interface is not recommended. 02415 ** 02416 ** Definition: A <b>result table</b> is memory data structure created by the 02417 ** [sqlite3_get_table()] interface. A result table records the 02418 ** complete query results from one or more queries. 02419 ** 02420 ** The table conceptually has a number of rows and columns. But 02421 ** these numbers are not part of the result table itself. These 02422 ** numbers are obtained separately. Let N be the number of rows 02423 ** and M be the number of columns. 02424 ** 02425 ** A result table is an array of pointers to zero-terminated UTF-8 strings. 02426 ** There are (N+1)*M elements in the array. The first M pointers point 02427 ** to zero-terminated strings that contain the names of the columns. 02428 ** The remaining entries all point to query results. NULL values result 02429 ** in NULL pointers. All other values are in their UTF-8 zero-terminated 02430 ** string representation as returned by [sqlite3_column_text()]. 02431 ** 02432 ** A result table might consist of one or more memory allocations. 02433 ** It is not safe to pass a result table directly to [sqlite3_free()]. 02434 ** A result table should be deallocated using [sqlite3_free_table()]. 02435 ** 02436 ** ^(As an example of the result table format, suppose a query result 02437 ** is as follows: 02438 ** 02439 ** <blockquote><pre> 02440 ** Name | Age 02441 ** ----------------------- 02442 ** Alice | 43 02443 ** Bob | 28 02444 ** Cindy | 21 02445 ** </pre></blockquote> 02446 ** 02447 ** There are two column (M==2) and three rows (N==3). Thus the 02448 ** result table has 8 entries. Suppose the result table is stored 02449 ** in an array names azResult. Then azResult holds this content: 02450 ** 02451 ** <blockquote><pre> 02452 ** azResult[0] = "Name"; 02453 ** azResult[1] = "Age"; 02454 ** azResult[2] = "Alice"; 02455 ** azResult[3] = "43"; 02456 ** azResult[4] = "Bob"; 02457 ** azResult[5] = "28"; 02458 ** azResult[6] = "Cindy"; 02459 ** azResult[7] = "21"; 02460 ** </pre></blockquote>)^ 02461 ** 02462 ** ^The sqlite3_get_table() function evaluates one or more 02463 ** semicolon-separated SQL statements in the zero-terminated UTF-8 02464 ** string of its 2nd parameter and returns a result table to the 02465 ** pointer given in its 3rd parameter. 02466 ** 02467 ** After the application has finished with the result from sqlite3_get_table(), 02468 ** it must pass the result table pointer to sqlite3_free_table() in order to 02469 ** release the memory that was malloced. Because of the way the 02470 ** [sqlite3_malloc()] happens within sqlite3_get_table(), the calling 02471 ** function must not try to call [sqlite3_free()] directly. Only 02472 ** [sqlite3_free_table()] is able to release the memory properly and safely. 02473 ** 02474 ** The sqlite3_get_table() interface is implemented as a wrapper around 02475 ** [sqlite3_exec()]. The sqlite3_get_table() routine does not have access 02476 ** to any internal data structures of SQLite. It uses only the public 02477 ** interface defined here. As a consequence, errors that occur in the 02478 ** wrapper layer outside of the internal [sqlite3_exec()] call are not 02479 ** reflected in subsequent calls to [sqlite3_errcode()] or 02480 ** [sqlite3_errmsg()]. 02481 */ 02482 SQLITE_API int sqlite3_get_table( 02483 sqlite3 *db, /* An open database */ 02484 const char *zSql, /* SQL to be evaluated */ 02485 char ***pazResult, /* Results of the query */ 02486 int *pnRow, /* Number of result rows written here */ 02487 int *pnColumn, /* Number of result columns written here */ 02488 char **pzErrmsg /* Error msg written here */ 02489 ); 02490 SQLITE_API void sqlite3_free_table(char **result); 02491 02492 /* 02493 ** CAPI3REF: Formatted String Printing Functions 02494 ** 02495 ** These routines are work-alikes of the "printf()" family of functions 02496 ** from the standard C library. 02497 ** 02498 ** ^The sqlite3_mprintf() and sqlite3_vmprintf() routines write their 02499 ** results into memory obtained from [sqlite3_malloc()]. 02500 ** The strings returned by these two routines should be 02501 ** released by [sqlite3_free()]. ^Both routines return a 02502 ** NULL pointer if [sqlite3_malloc()] is unable to allocate enough 02503 ** memory to hold the resulting string. 02504 ** 02505 ** ^(The sqlite3_snprintf() routine is similar to "snprintf()" from 02506 ** the standard C library. The result is written into the 02507 ** buffer supplied as the second parameter whose size is given by 02508 ** the first parameter. Note that the order of the 02509 ** first two parameters is reversed from snprintf().)^ This is an 02510 ** historical accident that cannot be fixed without breaking 02511 ** backwards compatibility. ^(Note also that sqlite3_snprintf() 02512 ** returns a pointer to its buffer instead of the number of 02513 ** characters actually written into the buffer.)^ We admit that 02514 ** the number of characters written would be a more useful return 02515 ** value but we cannot change the implementation of sqlite3_snprintf() 02516 ** now without breaking compatibility. 02517 ** 02518 ** ^As long as the buffer size is greater than zero, sqlite3_snprintf() 02519 ** guarantees that the buffer is always zero-terminated. ^The first 02520 ** parameter "n" is the total size of the buffer, including space for 02521 ** the zero terminator. So the longest string that can be completely 02522 ** written will be n-1 characters. 02523 ** 02524 ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf(). 02525 ** 02526 ** These routines all implement some additional formatting 02527 ** options that are useful for constructing SQL statements. 02528 ** All of the usual printf() formatting options apply. In addition, there 02529 ** is are "%q", "%Q", and "%z" options. 02530 ** 02531 ** ^(The %q option works like %s in that it substitutes a null-terminated 02532 ** string from the argument list. But %q also doubles every '\'' character. 02533 ** %q is designed for use inside a string literal.)^ By doubling each '\'' 02534 ** character it escapes that character and allows it to be inserted into 02535 ** the string. 02536 ** 02537 ** For example, assume the string variable zText contains text as follows: 02538 ** 02539 ** <blockquote><pre> 02540 ** char *zText = "It's a happy day!"; 02541 ** </pre></blockquote> 02542 ** 02543 ** One can use this text in an SQL statement as follows: 02544 ** 02545 ** <blockquote><pre> 02546 ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText); 02547 ** sqlite3_exec(db, zSQL, 0, 0, 0); 02548 ** sqlite3_free(zSQL); 02549 ** </pre></blockquote> 02550 ** 02551 ** Because the %q format string is used, the '\'' character in zText 02552 ** is escaped and the SQL generated is as follows: 02553 ** 02554 ** <blockquote><pre> 02555 ** INSERT INTO table1 VALUES('It''s a happy day!') 02556 ** </pre></blockquote> 02557 ** 02558 ** This is correct. Had we used %s instead of %q, the generated SQL 02559 ** would have looked like this: 02560 ** 02561 ** <blockquote><pre> 02562 ** INSERT INTO table1 VALUES('It's a happy day!'); 02563 ** </pre></blockquote> 02564 ** 02565 ** This second example is an SQL syntax error. As a general rule you should 02566 ** always use %q instead of %s when inserting text into a string literal. 02567 ** 02568 ** ^(The %Q option works like %q except it also adds single quotes around 02569 ** the outside of the total string. Additionally, if the parameter in the 02570 ** argument list is a NULL pointer, %Q substitutes the text "NULL" (without 02571 ** single quotes).)^ So, for example, one could say: 02572 ** 02573 ** <blockquote><pre> 02574 ** char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES(%Q)", zText); 02575 ** sqlite3_exec(db, zSQL, 0, 0, 0); 02576 ** sqlite3_free(zSQL); 02577 ** </pre></blockquote> 02578 ** 02579 ** The code above will render a correct SQL statement in the zSQL 02580 ** variable even if the zText variable is a NULL pointer. 02581 ** 02582 ** ^(The "%z" formatting option works like "%s" but with the 02583 ** addition that after the string has been read and copied into 02584 ** the result, [sqlite3_free()] is called on the input string.)^ 02585 */ 02586 SQLITE_API char *sqlite3_mprintf(const char*,...); 02587 SQLITE_API char *sqlite3_vmprintf(const char*, va_list); 02588 SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...); 02589 SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list); 02590 02591 /* 02592 ** CAPI3REF: Memory Allocation Subsystem 02593 ** 02594 ** The SQLite core uses these three routines for all of its own 02595 ** internal memory allocation needs. "Core" in the previous sentence 02596 ** does not include operating-system specific VFS implementation. The 02597 ** Windows VFS uses native malloc() and free() for some operations. 02598 ** 02599 ** ^The sqlite3_malloc() routine returns a pointer to a block 02600 ** of memory at least N bytes in length, where N is the parameter. 02601 ** ^If sqlite3_malloc() is unable to obtain sufficient free 02602 ** memory, it returns a NULL pointer. ^If the parameter N to 02603 ** sqlite3_malloc() is zero or negative then sqlite3_malloc() returns 02604 ** a NULL pointer. 02605 ** 02606 ** ^Calling sqlite3_free() with a pointer previously returned 02607 ** by sqlite3_malloc() or sqlite3_realloc() releases that memory so 02608 ** that it might be reused. ^The sqlite3_free() routine is 02609 ** a no-op if is called with a NULL pointer. Passing a NULL pointer 02610 ** to sqlite3_free() is harmless. After being freed, memory 02611 ** should neither be read nor written. Even reading previously freed 02612 ** memory might result in a segmentation fault or other severe error. 02613 ** Memory corruption, a segmentation fault, or other severe error 02614 ** might result if sqlite3_free() is called with a non-NULL pointer that 02615 ** was not obtained from sqlite3_malloc() or sqlite3_realloc(). 02616 ** 02617 ** ^(The sqlite3_realloc() interface attempts to resize a 02618 ** prior memory allocation to be at least N bytes, where N is the 02619 ** second parameter. The memory allocation to be resized is the first 02620 ** parameter.)^ ^ If the first parameter to sqlite3_realloc() 02621 ** is a NULL pointer then its behavior is identical to calling 02622 ** sqlite3_malloc(N) where N is the second parameter to sqlite3_realloc(). 02623 ** ^If the second parameter to sqlite3_realloc() is zero or 02624 ** negative then the behavior is exactly the same as calling 02625 ** sqlite3_free(P) where P is the first parameter to sqlite3_realloc(). 02626 ** ^sqlite3_realloc() returns a pointer to a memory allocation 02627 ** of at least N bytes in size or NULL if sufficient memory is unavailable. 02628 ** ^If M is the size of the prior allocation, then min(N,M) bytes 02629 ** of the prior allocation are copied into the beginning of buffer returned 02630 ** by sqlite3_realloc() and the prior allocation is freed. 02631 ** ^If sqlite3_realloc() returns NULL, then the prior allocation 02632 ** is not freed. 02633 ** 02634 ** ^The memory returned by sqlite3_malloc() and sqlite3_realloc() 02635 ** is always aligned to at least an 8 byte boundary, or to a 02636 ** 4 byte boundary if the [SQLITE_4_BYTE_ALIGNED_MALLOC] compile-time 02637 ** option is used. 02638 ** 02639 ** In SQLite version 3.5.0 and 3.5.1, it was possible to define 02640 ** the SQLITE_OMIT_MEMORY_ALLOCATION which would cause the built-in 02641 ** implementation of these routines to be omitted. That capability 02642 ** is no longer provided. Only built-in memory allocators can be used. 02643 ** 02644 ** The Windows OS interface layer calls 02645 ** the system malloc() and free() directly when converting 02646 ** filenames between the UTF-8 encoding used by SQLite 02647 ** and whatever filename encoding is used by the particular Windows 02648 ** installation. Memory allocation errors are detected, but 02649 ** they are reported back as [SQLITE_CANTOPEN] or 02650 ** [SQLITE_IOERR] rather than [SQLITE_NOMEM]. 02651 ** 02652 ** The pointer arguments to [sqlite3_free()] and [sqlite3_realloc()] 02653 ** must be either NULL or else pointers obtained from a prior 02654 ** invocation of [sqlite3_malloc()] or [sqlite3_realloc()] that have 02655 ** not yet been released. 02656 ** 02657 ** The application must not read or write any part of 02658 ** a block of memory after it has been released using 02659 ** [sqlite3_free()] or [sqlite3_realloc()]. 02660 */ 02661 SQLITE_API void *sqlite3_malloc(int); 02662 SQLITE_API void *sqlite3_realloc(void*, int); 02663 SQLITE_API void sqlite3_free(void*); 02664 02665 /* 02666 ** CAPI3REF: Memory Allocator Statistics 02667 ** 02668 ** SQLite provides these two interfaces for reporting on the status 02669 ** of the [sqlite3_malloc()], [sqlite3_free()], and [sqlite3_realloc()] 02670 ** routines, which form the built-in memory allocation subsystem. 02671 ** 02672 ** ^The [sqlite3_memory_used()] routine returns the number of bytes 02673 ** of memory currently outstanding (malloced but not freed). 02674 ** ^The [sqlite3_memory_highwater()] routine returns the maximum 02675 ** value of [sqlite3_memory_used()] since the high-water mark 02676 ** was last reset. ^The values returned by [sqlite3_memory_used()] and 02677 ** [sqlite3_memory_highwater()] include any overhead 02678 ** added by SQLite in its implementation of [sqlite3_malloc()], 02679 ** but not overhead added by the any underlying system library 02680 ** routines that [sqlite3_malloc()] may call. 02681 ** 02682 ** ^The memory high-water mark is reset to the current value of 02683 ** [sqlite3_memory_used()] if and only if the parameter to 02684 ** [sqlite3_memory_highwater()] is true. ^The value returned 02685 ** by [sqlite3_memory_highwater(1)] is the high-water mark 02686 ** prior to the reset. 02687 */ 02688 SQLITE_API sqlite3_int64 sqlite3_memory_used(void); 02689 SQLITE_API sqlite3_int64 sqlite3_memory_highwater(int resetFlag); 02690 02691 /* 02692 ** CAPI3REF: Pseudo-Random Number Generator 02693 ** 02694 ** SQLite contains a high-quality pseudo-random number generator (PRNG) used to 02695 ** select random [ROWID | ROWIDs] when inserting new records into a table that 02696 ** already uses the largest possible [ROWID]. The PRNG is also used for 02697 ** the build-in random() and randomblob() SQL functions. This interface allows 02698 ** applications to access the same PRNG for other purposes. 02699 ** 02700 ** ^A call to this routine stores N bytes of randomness into buffer P. 02701 ** 02702 ** ^The first time this routine is invoked (either internally or by 02703 ** the application) the PRNG is seeded using randomness obtained 02704 ** from the xRandomness method of the default [sqlite3_vfs] object. 02705 ** ^On all subsequent invocations, the pseudo-randomness is generated 02706 ** internally and without recourse to the [sqlite3_vfs] xRandomness 02707 ** method. 02708 */ 02709 SQLITE_API void sqlite3_randomness(int N, void *P); 02710 02711 /* 02712 ** CAPI3REF: Compile-Time Authorization Callbacks 02713 ** 02714 ** ^This routine registers an authorizer callback with a particular 02715 ** [database connection], supplied in the first argument. 02716 ** ^The authorizer callback is invoked as SQL statements are being compiled 02717 ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()], 02718 ** [sqlite3_prepare16()] and [sqlite3_prepare16_v2()]. ^At various 02719 ** points during the compilation process, as logic is being created 02720 ** to perform various actions, the authorizer callback is invoked to 02721 ** see if those actions are allowed. ^The authorizer callback should 02722 ** return [SQLITE_OK] to allow the action, [SQLITE_IGNORE] to disallow the 02723 ** specific action but allow the SQL statement to continue to be 02724 ** compiled, or [SQLITE_DENY] to cause the entire SQL statement to be 02725 ** rejected with an error. ^If the authorizer callback returns 02726 ** any value other than [SQLITE_IGNORE], [SQLITE_OK], or [SQLITE_DENY] 02727 ** then the [sqlite3_prepare_v2()] or equivalent call that triggered 02728 ** the authorizer will fail with an error message. 02729 ** 02730 ** When the callback returns [SQLITE_OK], that means the operation 02731 ** requested is ok. ^When the callback returns [SQLITE_DENY], the 02732 ** [sqlite3_prepare_v2()] or equivalent call that triggered the 02733 ** authorizer will fail with an error message explaining that 02734 ** access is denied. 02735 ** 02736 ** ^The first parameter to the authorizer callback is a copy of the third 02737 ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter 02738 ** to the callback is an integer [SQLITE_COPY | action code] that specifies 02739 ** the particular action to be authorized. ^The third through sixth parameters 02740 ** to the callback are zero-terminated strings that contain additional 02741 ** details about the action to be authorized. 02742 ** 02743 ** ^If the action code is [SQLITE_READ] 02744 ** and the callback returns [SQLITE_IGNORE] then the 02745 ** [prepared statement] statement is constructed to substitute 02746 ** a NULL value in place of the table column that would have 02747 ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE] 02748 ** return can be used to deny an untrusted user access to individual 02749 ** columns of a table. 02750 ** ^If the action code is [SQLITE_DELETE] and the callback returns 02751 ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the 02752 ** [truncate optimization] is disabled and all rows are deleted individually. 02753 ** 02754 ** An authorizer is used when [sqlite3_prepare | preparing] 02755 ** SQL statements from an untrusted source, to ensure that the SQL statements 02756 ** do not try to access data they are not allowed to see, or that they do not 02757 ** try to execute malicious statements that damage the database. For 02758 ** example, an application may allow a user to enter arbitrary 02759 ** SQL queries for evaluation by a database. But the application does 02760 ** not want the user to be able to make arbitrary changes to the 02761 ** database. An authorizer could then be put in place while the 02762 ** user-entered SQL is being [sqlite3_prepare | prepared] that 02763 ** disallows everything except [SELECT] statements. 02764 ** 02765 ** Applications that need to process SQL from untrusted sources 02766 ** might also consider lowering resource limits using [sqlite3_limit()] 02767 ** and limiting database size using the [max_page_count] [PRAGMA] 02768 ** in addition to using an authorizer. 02769 ** 02770 ** ^(Only a single authorizer can be in place on a database connection 02771 ** at a time. Each call to sqlite3_set_authorizer overrides the 02772 ** previous call.)^ ^Disable the authorizer by installing a NULL callback. 02773 ** The authorizer is disabled by default. 02774 ** 02775 ** The authorizer callback must not do anything that will modify 02776 ** the database connection that invoked the authorizer callback. 02777 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 02778 ** database connections for the meaning of "modify" in this paragraph. 02779 ** 02780 ** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the 02781 ** statement might be re-prepared during [sqlite3_step()] due to a 02782 ** schema change. Hence, the application should ensure that the 02783 ** correct authorizer callback remains in place during the [sqlite3_step()]. 02784 ** 02785 ** ^Note that the authorizer callback is invoked only during 02786 ** [sqlite3_prepare()] or its variants. Authorization is not 02787 ** performed during statement evaluation in [sqlite3_step()], unless 02788 ** as stated in the previous paragraph, sqlite3_step() invokes 02789 ** sqlite3_prepare_v2() to reprepare a statement after a schema change. 02790 */ 02791 SQLITE_API int sqlite3_set_authorizer( 02792 sqlite3*, 02793 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*), 02794 void *pUserData 02795 ); 02796 02797 /* 02798 ** CAPI3REF: Authorizer Return Codes 02799 ** 02800 ** The [sqlite3_set_authorizer | authorizer callback function] must 02801 ** return either [SQLITE_OK] or one of these two constants in order 02802 ** to signal SQLite whether or not the action is permitted. See the 02803 ** [sqlite3_set_authorizer | authorizer documentation] for additional 02804 ** information. 02805 ** 02806 ** Note that SQLITE_IGNORE is also used as a [SQLITE_ROLLBACK | return code] 02807 ** from the [sqlite3_vtab_on_conflict()] interface. 02808 */ 02809 #define SQLITE_DENY 1 /* Abort the SQL statement with an error */ 02810 #define SQLITE_IGNORE 2 /* Don't allow access, but don't generate an error */ 02811 02812 /* 02813 ** CAPI3REF: Authorizer Action Codes 02814 ** 02815 ** The [sqlite3_set_authorizer()] interface registers a callback function 02816 ** that is invoked to authorize certain SQL statement actions. The 02817 ** second parameter to the callback is an integer code that specifies 02818 ** what action is being authorized. These are the integer action codes that 02819 ** the authorizer callback may be passed. 02820 ** 02821 ** These action code values signify what kind of operation is to be 02822 ** authorized. The 3rd and 4th parameters to the authorization 02823 ** callback function will be parameters or NULL depending on which of these 02824 ** codes is used as the second parameter. ^(The 5th parameter to the 02825 ** authorizer callback is the name of the database ("main", "temp", 02826 ** etc.) if applicable.)^ ^The 6th parameter to the authorizer callback 02827 ** is the name of the inner-most trigger or view that is responsible for 02828 ** the access attempt or NULL if this access attempt is directly from 02829 ** top-level SQL code. 02830 */ 02831 /******************************************* 3rd ************ 4th ***********/ 02832 #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */ 02833 #define SQLITE_CREATE_TABLE 2 /* Table Name NULL */ 02834 #define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */ 02835 #define SQLITE_CREATE_TEMP_TABLE 4 /* Table Name NULL */ 02836 #define SQLITE_CREATE_TEMP_TRIGGER 5 /* Trigger Name Table Name */ 02837 #define SQLITE_CREATE_TEMP_VIEW 6 /* View Name NULL */ 02838 #define SQLITE_CREATE_TRIGGER 7 /* Trigger Name Table Name */ 02839 #define SQLITE_CREATE_VIEW 8 /* View Name NULL */ 02840 #define SQLITE_DELETE 9 /* Table Name NULL */ 02841 #define SQLITE_DROP_INDEX 10 /* Index Name Table Name */ 02842 #define SQLITE_DROP_TABLE 11 /* Table Name NULL */ 02843 #define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */ 02844 #define SQLITE_DROP_TEMP_TABLE 13 /* Table Name NULL */ 02845 #define SQLITE_DROP_TEMP_TRIGGER 14 /* Trigger Name Table Name */ 02846 #define SQLITE_DROP_TEMP_VIEW 15 /* View Name NULL */ 02847 #define SQLITE_DROP_TRIGGER 16 /* Trigger Name Table Name */ 02848 #define SQLITE_DROP_VIEW 17 /* View Name NULL */ 02849 #define SQLITE_INSERT 18 /* Table Name NULL */ 02850 #define SQLITE_PRAGMA 19 /* Pragma Name 1st arg or NULL */ 02851 #define SQLITE_READ 20 /* Table Name Column Name */ 02852 #define SQLITE_SELECT 21 /* NULL NULL */ 02853 #define SQLITE_TRANSACTION 22 /* Operation NULL */ 02854 #define SQLITE_UPDATE 23 /* Table Name Column Name */ 02855 #define SQLITE_ATTACH 24 /* Filename NULL */ 02856 #define SQLITE_DETACH 25 /* Database Name NULL */ 02857 #define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */ 02858 #define SQLITE_REINDEX 27 /* Index Name NULL */ 02859 #define SQLITE_ANALYZE 28 /* Table Name NULL */ 02860 #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */ 02861 #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */ 02862 #define SQLITE_FUNCTION 31 /* NULL Function Name */ 02863 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */ 02864 #define SQLITE_COPY 0 /* No longer used */ 02865 02866 /* 02867 ** CAPI3REF: Tracing And Profiling Functions 02868 ** 02869 ** These routines register callback functions that can be used for 02870 ** tracing and profiling the execution of SQL statements. 02871 ** 02872 ** ^The callback function registered by sqlite3_trace() is invoked at 02873 ** various times when an SQL statement is being run by [sqlite3_step()]. 02874 ** ^The sqlite3_trace() callback is invoked with a UTF-8 rendering of the 02875 ** SQL statement text as the statement first begins executing. 02876 ** ^(Additional sqlite3_trace() callbacks might occur 02877 ** as each triggered subprogram is entered. The callbacks for triggers 02878 ** contain a UTF-8 SQL comment that identifies the trigger.)^ 02879 ** 02880 ** ^The callback function registered by sqlite3_profile() is invoked 02881 ** as each SQL statement finishes. ^The profile callback contains 02882 ** the original statement text and an estimate of wall-clock time 02883 ** of how long that statement took to run. ^The profile callback 02884 ** time is in units of nanoseconds, however the current implementation 02885 ** is only capable of millisecond resolution so the six least significant 02886 ** digits in the time are meaningless. Future versions of SQLite 02887 ** might provide greater resolution on the profiler callback. The 02888 ** sqlite3_profile() function is considered experimental and is 02889 ** subject to change in future versions of SQLite. 02890 */ 02891 SQLITE_API void *sqlite3_trace(sqlite3*, void(*xTrace)(void*,const char*), void*); 02892 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_profile(sqlite3*, 02893 void(*xProfile)(void*,const char*,sqlite3_uint64), void*); 02894 02895 /* 02896 ** CAPI3REF: Query Progress Callbacks 02897 ** 02898 ** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback 02899 ** function X to be invoked periodically during long running calls to 02900 ** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for 02901 ** database connection D. An example use for this 02902 ** interface is to keep a GUI updated during a large query. 02903 ** 02904 ** ^The parameter P is passed through as the only parameter to the 02905 ** callback function X. ^The parameter N is the number of 02906 ** [virtual machine instructions] that are evaluated between successive 02907 ** invocations of the callback X. 02908 ** 02909 ** ^Only a single progress handler may be defined at one time per 02910 ** [database connection]; setting a new progress handler cancels the 02911 ** old one. ^Setting parameter X to NULL disables the progress handler. 02912 ** ^The progress handler is also disabled by setting N to a value less 02913 ** than 1. 02914 ** 02915 ** ^If the progress callback returns non-zero, the operation is 02916 ** interrupted. This feature can be used to implement a 02917 ** "Cancel" button on a GUI progress dialog box. 02918 ** 02919 ** The progress handler callback must not do anything that will modify 02920 ** the database connection that invoked the progress handler. 02921 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 02922 ** database connections for the meaning of "modify" in this paragraph. 02923 ** 02924 */ 02925 SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*); 02926 02927 /* 02928 ** CAPI3REF: Opening A New Database Connection 02929 ** 02930 ** ^These routines open an SQLite database file as specified by the 02931 ** filename argument. ^The filename argument is interpreted as UTF-8 for 02932 ** sqlite3_open() and sqlite3_open_v2() and as UTF-16 in the native byte 02933 ** order for sqlite3_open16(). ^(A [database connection] handle is usually 02934 ** returned in *ppDb, even if an error occurs. The only exception is that 02935 ** if SQLite is unable to allocate memory to hold the [sqlite3] object, 02936 ** a NULL will be written into *ppDb instead of a pointer to the [sqlite3] 02937 ** object.)^ ^(If the database is opened (and/or created) successfully, then 02938 ** [SQLITE_OK] is returned. Otherwise an [error code] is returned.)^ ^The 02939 ** [sqlite3_errmsg()] or [sqlite3_errmsg16()] routines can be used to obtain 02940 ** an English language description of the error following a failure of any 02941 ** of the sqlite3_open() routines. 02942 ** 02943 ** ^The default encoding for the database will be UTF-8 if 02944 ** sqlite3_open() or sqlite3_open_v2() is called and 02945 ** UTF-16 in the native byte order if sqlite3_open16() is used. 02946 ** 02947 ** Whether or not an error occurs when it is opened, resources 02948 ** associated with the [database connection] handle should be released by 02949 ** passing it to [sqlite3_close()] when it is no longer required. 02950 ** 02951 ** The sqlite3_open_v2() interface works like sqlite3_open() 02952 ** except that it accepts two additional parameters for additional control 02953 ** over the new database connection. ^(The flags parameter to 02954 ** sqlite3_open_v2() can take one of 02955 ** the following three values, optionally combined with the 02956 ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE], 02957 ** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^ 02958 ** 02959 ** <dl> 02960 ** ^(<dt>[SQLITE_OPEN_READONLY]</dt> 02961 ** <dd>The database is opened in read-only mode. If the database does not 02962 ** already exist, an error is returned.</dd>)^ 02963 ** 02964 ** ^(<dt>[SQLITE_OPEN_READWRITE]</dt> 02965 ** <dd>The database is opened for reading and writing if possible, or reading 02966 ** only if the file is write protected by the operating system. In either 02967 ** case the database must already exist, otherwise an error is returned.</dd>)^ 02968 ** 02969 ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt> 02970 ** <dd>The database is opened for reading and writing, and is created if 02971 ** it does not already exist. This is the behavior that is always used for 02972 ** sqlite3_open() and sqlite3_open16().</dd>)^ 02973 ** </dl> 02974 ** 02975 ** If the 3rd parameter to sqlite3_open_v2() is not one of the 02976 ** combinations shown above optionally combined with other 02977 ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits] 02978 ** then the behavior is undefined. 02979 ** 02980 ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection 02981 ** opens in the multi-thread [threading mode] as long as the single-thread 02982 ** mode has not been set at compile-time or start-time. ^If the 02983 ** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens 02984 ** in the serialized [threading mode] unless single-thread was 02985 ** previously selected at compile-time or start-time. 02986 ** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be 02987 ** eligible to use [shared cache mode], regardless of whether or not shared 02988 ** cache is enabled using [sqlite3_enable_shared_cache()]. ^The 02989 ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not 02990 ** participate in [shared cache mode] even if it is enabled. 02991 ** 02992 ** ^The fourth parameter to sqlite3_open_v2() is the name of the 02993 ** [sqlite3_vfs] object that defines the operating system interface that 02994 ** the new database connection should use. ^If the fourth parameter is 02995 ** a NULL pointer then the default [sqlite3_vfs] object is used. 02996 ** 02997 ** ^If the filename is ":memory:", then a private, temporary in-memory database 02998 ** is created for the connection. ^This in-memory database will vanish when 02999 ** the database connection is closed. Future versions of SQLite might 03000 ** make use of additional special filenames that begin with the ":" character. 03001 ** It is recommended that when a database filename actually does begin with 03002 ** a ":" character you should prefix the filename with a pathname such as 03003 ** "./" to avoid ambiguity. 03004 ** 03005 ** ^If the filename is an empty string, then a private, temporary 03006 ** on-disk database will be created. ^This private database will be 03007 ** automatically deleted as soon as the database connection is closed. 03008 ** 03009 ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3> 03010 ** 03011 ** ^If [URI filename] interpretation is enabled, and the filename argument 03012 ** begins with "file:", then the filename is interpreted as a URI. ^URI 03013 ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is 03014 ** set in the fourth argument to sqlite3_open_v2(), or if it has 03015 ** been enabled globally using the [SQLITE_CONFIG_URI] option with the 03016 ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option. 03017 ** As of SQLite version 3.7.7, URI filename interpretation is turned off 03018 ** by default, but future releases of SQLite might enable URI filename 03019 ** interpretation by default. See "[URI filenames]" for additional 03020 ** information. 03021 ** 03022 ** URI filenames are parsed according to RFC 3986. ^If the URI contains an 03023 ** authority, then it must be either an empty string or the string 03024 ** "localhost". ^If the authority is not an empty string or "localhost", an 03025 ** error is returned to the caller. ^The fragment component of a URI, if 03026 ** present, is ignored. 03027 ** 03028 ** ^SQLite uses the path component of the URI as the name of the disk file 03029 ** which contains the database. ^If the path begins with a '/' character, 03030 ** then it is interpreted as an absolute path. ^If the path does not begin 03031 ** with a '/' (meaning that the authority section is omitted from the URI) 03032 ** then the path is interpreted as a relative path. 03033 ** ^On windows, the first component of an absolute path 03034 ** is a drive specification (e.g. "C:"). 03035 ** 03036 ** [[core URI query parameters]] 03037 ** The query component of a URI may contain parameters that are interpreted 03038 ** either by SQLite itself, or by a [VFS | custom VFS implementation]. 03039 ** SQLite interprets the following three query parameters: 03040 ** 03041 ** <ul> 03042 ** <li> <b>vfs</b>: ^The "vfs" parameter may be used to specify the name of 03043 ** a VFS object that provides the operating system interface that should 03044 ** be used to access the database file on disk. ^If this option is set to 03045 ** an empty string the default VFS object is used. ^Specifying an unknown 03046 ** VFS is an error. ^If sqlite3_open_v2() is used and the vfs option is 03047 ** present, then the VFS specified by the option takes precedence over 03048 ** the value passed as the fourth parameter to sqlite3_open_v2(). 03049 ** 03050 ** <li> <b>mode</b>: ^(The mode parameter may be set to either "ro", "rw" or 03051 ** "rwc". Attempting to set it to any other value is an error)^. 03052 ** ^If "ro" is specified, then the database is opened for read-only 03053 ** access, just as if the [SQLITE_OPEN_READONLY] flag had been set in the 03054 ** third argument to sqlite3_prepare_v2(). ^If the mode option is set to 03055 ** "rw", then the database is opened for read-write (but not create) 03056 ** access, as if SQLITE_OPEN_READWRITE (but not SQLITE_OPEN_CREATE) had 03057 ** been set. ^Value "rwc" is equivalent to setting both 03058 ** SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. ^If sqlite3_open_v2() is 03059 ** used, it is an error to specify a value for the mode parameter that is 03060 ** less restrictive than that specified by the flags passed as the third 03061 ** parameter. 03062 ** 03063 ** <li> <b>cache</b>: ^The cache parameter may be set to either "shared" or 03064 ** "private". ^Setting it to "shared" is equivalent to setting the 03065 ** SQLITE_OPEN_SHAREDCACHE bit in the flags argument passed to 03066 ** sqlite3_open_v2(). ^Setting the cache parameter to "private" is 03067 ** equivalent to setting the SQLITE_OPEN_PRIVATECACHE bit. 03068 ** ^If sqlite3_open_v2() is used and the "cache" parameter is present in 03069 ** a URI filename, its value overrides any behaviour requested by setting 03070 ** SQLITE_OPEN_PRIVATECACHE or SQLITE_OPEN_SHAREDCACHE flag. 03071 ** </ul> 03072 ** 03073 ** ^Specifying an unknown parameter in the query component of a URI is not an 03074 ** error. Future versions of SQLite might understand additional query 03075 ** parameters. See "[query parameters with special meaning to SQLite]" for 03076 ** additional information. 03077 ** 03078 ** [[URI filename examples]] <h3>URI filename examples</h3> 03079 ** 03080 ** <table border="1" align=center cellpadding=5> 03081 ** <tr><th> URI filenames <th> Results 03082 ** <tr><td> file:data.db <td> 03083 ** Open the file "data.db" in the current directory. 03084 ** <tr><td> file:/home/fred/data.db<br> 03085 ** file:///home/fred/data.db <br> 03086 ** file://localhost/home/fred/data.db <br> <td> 03087 ** Open the database file "/home/fred/data.db". 03088 ** <tr><td> file://darkstar/home/fred/data.db <td> 03089 ** An error. "darkstar" is not a recognized authority. 03090 ** <tr><td style="white-space:nowrap"> 03091 ** file:///C:/Documents%20and%20Settings/fred/Desktop/data.db 03092 ** <td> Windows only: Open the file "data.db" on fred's desktop on drive 03093 ** C:. Note that the %20 escaping in this example is not strictly 03094 ** necessary - space characters can be used literally 03095 ** in URI filenames. 03096 ** <tr><td> file:data.db?mode=ro&cache=private <td> 03097 ** Open file "data.db" in the current directory for read-only access. 03098 ** Regardless of whether or not shared-cache mode is enabled by 03099 ** default, use a private cache. 03100 ** <tr><td> file:/home/fred/data.db?vfs=unix-nolock <td> 03101 ** Open file "/home/fred/data.db". Use the special VFS "unix-nolock". 03102 ** <tr><td> file:data.db?mode=readonly <td> 03103 ** An error. "readonly" is not a valid option for the "mode" parameter. 03104 ** </table> 03105 ** 03106 ** ^URI hexadecimal escape sequences (%HH) are supported within the path and 03107 ** query components of a URI. A hexadecimal escape sequence consists of a 03108 ** percent sign - "%" - followed by exactly two hexadecimal digits 03109 ** specifying an octet value. ^Before the path or query components of a 03110 ** URI filename are interpreted, they are encoded using UTF-8 and all 03111 ** hexadecimal escape sequences replaced by a single byte containing the 03112 ** corresponding octet. If this process generates an invalid UTF-8 encoding, 03113 ** the results are undefined. 03114 ** 03115 ** <b>Note to Windows users:</b> The encoding used for the filename argument 03116 ** of sqlite3_open() and sqlite3_open_v2() must be UTF-8, not whatever 03117 ** codepage is currently defined. Filenames containing international 03118 ** characters must be converted to UTF-8 prior to passing them into 03119 ** sqlite3_open() or sqlite3_open_v2(). 03120 */ 03121 SQLITE_API int sqlite3_open( 03122 const char *filename, /* Database filename (UTF-8) */ 03123 sqlite3 **ppDb /* OUT: SQLite db handle */ 03124 ); 03125 SQLITE_API int sqlite3_open16( 03126 const void *filename, /* Database filename (UTF-16) */ 03127 sqlite3 **ppDb /* OUT: SQLite db handle */ 03128 ); 03129 SQLITE_API int sqlite3_open_v2( 03130 const char *filename, /* Database filename (UTF-8) */ 03131 sqlite3 **ppDb, /* OUT: SQLite db handle */ 03132 int flags, /* Flags */ 03133 const char *zVfs /* Name of VFS module to use */ 03134 ); 03135 03136 /* 03137 ** CAPI3REF: Obtain Values For URI Parameters 03138 ** 03139 ** This is a utility routine, useful to VFS implementations, that checks 03140 ** to see if a database file was a URI that contained a specific query 03141 ** parameter, and if so obtains the value of the query parameter. 03142 ** 03143 ** The zFilename argument is the filename pointer passed into the xOpen() 03144 ** method of a VFS implementation. The zParam argument is the name of the 03145 ** query parameter we seek. This routine returns the value of the zParam 03146 ** parameter if it exists. If the parameter does not exist, this routine 03147 ** returns a NULL pointer. 03148 ** 03149 ** If the zFilename argument to this function is not a pointer that SQLite 03150 ** passed into the xOpen VFS method, then the behavior of this routine 03151 ** is undefined and probably undesirable. 03152 */ 03153 SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam); 03154 03155 03156 /* 03157 ** CAPI3REF: Error Codes And Messages 03158 ** 03159 ** ^The sqlite3_errcode() interface returns the numeric [result code] or 03160 ** [extended result code] for the most recent failed sqlite3_* API call 03161 ** associated with a [database connection]. If a prior API call failed 03162 ** but the most recent API call succeeded, the return value from 03163 ** sqlite3_errcode() is undefined. ^The sqlite3_extended_errcode() 03164 ** interface is the same except that it always returns the 03165 ** [extended result code] even when extended result codes are 03166 ** disabled. 03167 ** 03168 ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language 03169 ** text that describes the error, as either UTF-8 or UTF-16 respectively. 03170 ** ^(Memory to hold the error message string is managed internally. 03171 ** The application does not need to worry about freeing the result. 03172 ** However, the error string might be overwritten or deallocated by 03173 ** subsequent calls to other SQLite interface functions.)^ 03174 ** 03175 ** When the serialized [threading mode] is in use, it might be the 03176 ** case that a second error occurs on a separate thread in between 03177 ** the time of the first error and the call to these interfaces. 03178 ** When that happens, the second error will be reported since these 03179 ** interfaces always report the most recent result. To avoid 03180 ** this, each thread can obtain exclusive use of the [database connection] D 03181 ** by invoking [sqlite3_mutex_enter]([sqlite3_db_mutex](D)) before beginning 03182 ** to use D and invoking [sqlite3_mutex_leave]([sqlite3_db_mutex](D)) after 03183 ** all calls to the interfaces listed here are completed. 03184 ** 03185 ** If an interface fails with SQLITE_MISUSE, that means the interface 03186 ** was invoked incorrectly by the application. In that case, the 03187 ** error code and message may or may not be set. 03188 */ 03189 SQLITE_API int sqlite3_errcode(sqlite3 *db); 03190 SQLITE_API int sqlite3_extended_errcode(sqlite3 *db); 03191 SQLITE_API const char *sqlite3_errmsg(sqlite3*); 03192 SQLITE_API const void *sqlite3_errmsg16(sqlite3*); 03193 03194 /* 03195 ** CAPI3REF: SQL Statement Object 03196 ** KEYWORDS: {prepared statement} {prepared statements} 03197 ** 03198 ** An instance of this object represents a single SQL statement. 03199 ** This object is variously known as a "prepared statement" or a 03200 ** "compiled SQL statement" or simply as a "statement". 03201 ** 03202 ** The life of a statement object goes something like this: 03203 ** 03204 ** <ol> 03205 ** <li> Create the object using [sqlite3_prepare_v2()] or a related 03206 ** function. 03207 ** <li> Bind values to [host parameters] using the sqlite3_bind_*() 03208 ** interfaces. 03209 ** <li> Run the SQL by calling [sqlite3_step()] one or more times. 03210 ** <li> Reset the statement using [sqlite3_reset()] then go back 03211 ** to step 2. Do this zero or more times. 03212 ** <li> Destroy the object using [sqlite3_finalize()]. 03213 ** </ol> 03214 ** 03215 ** Refer to documentation on individual methods above for additional 03216 ** information. 03217 */ 03218 typedef struct sqlite3_stmt sqlite3_stmt; 03219 03220 /* 03221 ** CAPI3REF: Run-time Limits 03222 ** 03223 ** ^(This interface allows the size of various constructs to be limited 03224 ** on a connection by connection basis. The first parameter is the 03225 ** [database connection] whose limit is to be set or queried. The 03226 ** second parameter is one of the [limit categories] that define a 03227 ** class of constructs to be size limited. The third parameter is the 03228 ** new limit for that construct.)^ 03229 ** 03230 ** ^If the new limit is a negative number, the limit is unchanged. 03231 ** ^(For each limit category SQLITE_LIMIT_<i>NAME</i> there is a 03232 ** [limits | hard upper bound] 03233 ** set at compile-time by a C preprocessor macro called 03234 ** [limits | SQLITE_MAX_<i>NAME</i>]. 03235 ** (The "_LIMIT_" in the name is changed to "_MAX_".))^ 03236 ** ^Attempts to increase a limit above its hard upper bound are 03237 ** silently truncated to the hard upper bound. 03238 ** 03239 ** ^Regardless of whether or not the limit was changed, the 03240 ** [sqlite3_limit()] interface returns the prior value of the limit. 03241 ** ^Hence, to find the current value of a limit without changing it, 03242 ** simply invoke this interface with the third parameter set to -1. 03243 ** 03244 ** Run-time limits are intended for use in applications that manage 03245 ** both their own internal database and also databases that are controlled 03246 ** by untrusted external sources. An example application might be a 03247 ** web browser that has its own databases for storing history and 03248 ** separate databases controlled by JavaScript applications downloaded 03249 ** off the Internet. The internal databases can be given the 03250 ** large, default limits. Databases managed by external sources can 03251 ** be given much smaller limits designed to prevent a denial of service 03252 ** attack. Developers might also want to use the [sqlite3_set_authorizer()] 03253 ** interface to further control untrusted SQL. The size of the database 03254 ** created by an untrusted script can be contained using the 03255 ** [max_page_count] [PRAGMA]. 03256 ** 03257 ** New run-time limit categories may be added in future releases. 03258 */ 03259 SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal); 03260 03261 /* 03262 ** CAPI3REF: Run-Time Limit Categories 03263 ** KEYWORDS: {limit category} {*limit categories} 03264 ** 03265 ** These constants define various performance limits 03266 ** that can be lowered at run-time using [sqlite3_limit()]. 03267 ** The synopsis of the meanings of the various limits is shown below. 03268 ** Additional information is available at [limits | Limits in SQLite]. 03269 ** 03270 ** <dl> 03271 ** [[SQLITE_LIMIT_LENGTH]] ^(<dt>SQLITE_LIMIT_LENGTH</dt> 03272 ** <dd>The maximum size of any string or BLOB or table row, in bytes.<dd>)^ 03273 ** 03274 ** [[SQLITE_LIMIT_SQL_LENGTH]] ^(<dt>SQLITE_LIMIT_SQL_LENGTH</dt> 03275 ** <dd>The maximum length of an SQL statement, in bytes.</dd>)^ 03276 ** 03277 ** [[SQLITE_LIMIT_COLUMN]] ^(<dt>SQLITE_LIMIT_COLUMN</dt> 03278 ** <dd>The maximum number of columns in a table definition or in the 03279 ** result set of a [SELECT] or the maximum number of columns in an index 03280 ** or in an ORDER BY or GROUP BY clause.</dd>)^ 03281 ** 03282 ** [[SQLITE_LIMIT_EXPR_DEPTH]] ^(<dt>SQLITE_LIMIT_EXPR_DEPTH</dt> 03283 ** <dd>The maximum depth of the parse tree on any expression.</dd>)^ 03284 ** 03285 ** [[SQLITE_LIMIT_COMPOUND_SELECT]] ^(<dt>SQLITE_LIMIT_COMPOUND_SELECT</dt> 03286 ** <dd>The maximum number of terms in a compound SELECT statement.</dd>)^ 03287 ** 03288 ** [[SQLITE_LIMIT_VDBE_OP]] ^(<dt>SQLITE_LIMIT_VDBE_OP</dt> 03289 ** <dd>The maximum number of instructions in a virtual machine program 03290 ** used to implement an SQL statement. This limit is not currently 03291 ** enforced, though that might be added in some future release of 03292 ** SQLite.</dd>)^ 03293 ** 03294 ** [[SQLITE_LIMIT_FUNCTION_ARG]] ^(<dt>SQLITE_LIMIT_FUNCTION_ARG</dt> 03295 ** <dd>The maximum number of arguments on a function.</dd>)^ 03296 ** 03297 ** [[SQLITE_LIMIT_ATTACHED]] ^(<dt>SQLITE_LIMIT_ATTACHED</dt> 03298 ** <dd>The maximum number of [ATTACH | attached databases].)^</dd> 03299 ** 03300 ** [[SQLITE_LIMIT_LIKE_PATTERN_LENGTH]] 03301 ** ^(<dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt> 03302 ** <dd>The maximum length of the pattern argument to the [LIKE] or 03303 ** [GLOB] operators.</dd>)^ 03304 ** 03305 ** [[SQLITE_LIMIT_VARIABLE_NUMBER]] 03306 ** ^(<dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt> 03307 ** <dd>The maximum index number of any [parameter] in an SQL statement.)^ 03308 ** 03309 ** [[SQLITE_LIMIT_TRIGGER_DEPTH]] ^(<dt>SQLITE_LIMIT_TRIGGER_DEPTH</dt> 03310 ** <dd>The maximum depth of recursion for triggers.</dd>)^ 03311 ** </dl> 03312 */ 03313 #define SQLITE_LIMIT_LENGTH 0 03314 #define SQLITE_LIMIT_SQL_LENGTH 1 03315 #define SQLITE_LIMIT_COLUMN 2 03316 #define SQLITE_LIMIT_EXPR_DEPTH 3 03317 #define SQLITE_LIMIT_COMPOUND_SELECT 4 03318 #define SQLITE_LIMIT_VDBE_OP 5 03319 #define SQLITE_LIMIT_FUNCTION_ARG 6 03320 #define SQLITE_LIMIT_ATTACHED 7 03321 #define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8 03322 #define SQLITE_LIMIT_VARIABLE_NUMBER 9 03323 #define SQLITE_LIMIT_TRIGGER_DEPTH 10 03324 03325 /* 03326 ** CAPI3REF: Compiling An SQL Statement 03327 ** KEYWORDS: {SQL statement compiler} 03328 ** 03329 ** To execute an SQL query, it must first be compiled into a byte-code 03330 ** program using one of these routines. 03331 ** 03332 ** The first argument, "db", is a [database connection] obtained from a 03333 ** prior successful call to [sqlite3_open()], [sqlite3_open_v2()] or 03334 ** [sqlite3_open16()]. The database connection must not have been closed. 03335 ** 03336 ** The second argument, "zSql", is the statement to be compiled, encoded 03337 ** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2() 03338 ** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2() 03339 ** use UTF-16. 03340 ** 03341 ** ^If the nByte argument is less than zero, then zSql is read up to the 03342 ** first zero terminator. ^If nByte is non-negative, then it is the maximum 03343 ** number of bytes read from zSql. ^When nByte is non-negative, the 03344 ** zSql string ends at either the first '\000' or '\u0000' character or 03345 ** the nByte-th byte, whichever comes first. If the caller knows 03346 ** that the supplied string is nul-terminated, then there is a small 03347 ** performance advantage to be gained by passing an nByte parameter that 03348 ** is equal to the number of bytes in the input string <i>including</i> 03349 ** the nul-terminator bytes as this saves SQLite from having to 03350 ** make a copy of the input string. 03351 ** 03352 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte 03353 ** past the end of the first SQL statement in zSql. These routines only 03354 ** compile the first statement in zSql, so *pzTail is left pointing to 03355 ** what remains uncompiled. 03356 ** 03357 ** ^*ppStmt is left pointing to a compiled [prepared statement] that can be 03358 ** executed using [sqlite3_step()]. ^If there is an error, *ppStmt is set 03359 ** to NULL. ^If the input text contains no SQL (if the input is an empty 03360 ** string or a comment) then *ppStmt is set to NULL. 03361 ** The calling procedure is responsible for deleting the compiled 03362 ** SQL statement using [sqlite3_finalize()] after it has finished with it. 03363 ** ppStmt may not be NULL. 03364 ** 03365 ** ^On success, the sqlite3_prepare() family of routines return [SQLITE_OK]; 03366 ** otherwise an [error code] is returned. 03367 ** 03368 ** The sqlite3_prepare_v2() and sqlite3_prepare16_v2() interfaces are 03369 ** recommended for all new programs. The two older interfaces are retained 03370 ** for backwards compatibility, but their use is discouraged. 03371 ** ^In the "v2" interfaces, the prepared statement 03372 ** that is returned (the [sqlite3_stmt] object) contains a copy of the 03373 ** original SQL text. This causes the [sqlite3_step()] interface to 03374 ** behave differently in three ways: 03375 ** 03376 ** <ol> 03377 ** <li> 03378 ** ^If the database schema changes, instead of returning [SQLITE_SCHEMA] as it 03379 ** always used to do, [sqlite3_step()] will automatically recompile the SQL 03380 ** statement and try to run it again. 03381 ** </li> 03382 ** 03383 ** <li> 03384 ** ^When an error occurs, [sqlite3_step()] will return one of the detailed 03385 ** [error codes] or [extended error codes]. ^The legacy behavior was that 03386 ** [sqlite3_step()] would only return a generic [SQLITE_ERROR] result code 03387 ** and the application would have to make a second call to [sqlite3_reset()] 03388 ** in order to find the underlying cause of the problem. With the "v2" prepare 03389 ** interfaces, the underlying reason for the error is returned immediately. 03390 ** </li> 03391 ** 03392 ** <li> 03393 ** ^If the specific value bound to [parameter | host parameter] in the 03394 ** WHERE clause might influence the choice of query plan for a statement, 03395 ** then the statement will be automatically recompiled, as if there had been 03396 ** a schema change, on the first [sqlite3_step()] call following any change 03397 ** to the [sqlite3_bind_text | bindings] of that [parameter]. 03398 ** ^The specific value of WHERE-clause [parameter] might influence the 03399 ** choice of query plan if the parameter is the left-hand side of a [LIKE] 03400 ** or [GLOB] operator or if the parameter is compared to an indexed column 03401 ** and the [SQLITE_ENABLE_STAT3] compile-time option is enabled. 03402 ** the 03403 ** </li> 03404 ** </ol> 03405 */ 03406 SQLITE_API int sqlite3_prepare( 03407 sqlite3 *db, /* Database handle */ 03408 const char *zSql, /* SQL statement, UTF-8 encoded */ 03409 int nByte, /* Maximum length of zSql in bytes. */ 03410 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 03411 const char **pzTail /* OUT: Pointer to unused portion of zSql */ 03412 ); 03413 SQLITE_API int sqlite3_prepare_v2( 03414 sqlite3 *db, /* Database handle */ 03415 const char *zSql, /* SQL statement, UTF-8 encoded */ 03416 int nByte, /* Maximum length of zSql in bytes. */ 03417 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 03418 const char **pzTail /* OUT: Pointer to unused portion of zSql */ 03419 ); 03420 SQLITE_API int sqlite3_prepare16( 03421 sqlite3 *db, /* Database handle */ 03422 const void *zSql, /* SQL statement, UTF-16 encoded */ 03423 int nByte, /* Maximum length of zSql in bytes. */ 03424 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 03425 const void **pzTail /* OUT: Pointer to unused portion of zSql */ 03426 ); 03427 SQLITE_API int sqlite3_prepare16_v2( 03428 sqlite3 *db, /* Database handle */ 03429 const void *zSql, /* SQL statement, UTF-16 encoded */ 03430 int nByte, /* Maximum length of zSql in bytes. */ 03431 sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 03432 const void **pzTail /* OUT: Pointer to unused portion of zSql */ 03433 ); 03434 03435 /* 03436 ** CAPI3REF: Retrieving Statement SQL 03437 ** 03438 ** ^This interface can be used to retrieve a saved copy of the original 03439 ** SQL text used to create a [prepared statement] if that statement was 03440 ** compiled using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()]. 03441 */ 03442 SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt); 03443 03444 /* 03445 ** CAPI3REF: Determine If An SQL Statement Writes The Database 03446 ** 03447 ** ^The sqlite3_stmt_readonly(X) interface returns true (non-zero) if 03448 ** and only if the [prepared statement] X makes no direct changes to 03449 ** the content of the database file. 03450 ** 03451 ** Note that [application-defined SQL functions] or 03452 ** [virtual tables] might change the database indirectly as a side effect. 03453 ** ^(For example, if an application defines a function "eval()" that 03454 ** calls [sqlite3_exec()], then the following SQL statement would 03455 ** change the database file through side-effects: 03456 ** 03457 ** <blockquote><pre> 03458 ** SELECT eval('DELETE FROM t1') FROM t2; 03459 ** </pre></blockquote> 03460 ** 03461 ** But because the [SELECT] statement does not change the database file 03462 ** directly, sqlite3_stmt_readonly() would still return true.)^ 03463 ** 03464 ** ^Transaction control statements such as [BEGIN], [COMMIT], [ROLLBACK], 03465 ** [SAVEPOINT], and [RELEASE] cause sqlite3_stmt_readonly() to return true, 03466 ** since the statements themselves do not actually modify the database but 03467 ** rather they control the timing of when other statements modify the 03468 ** database. ^The [ATTACH] and [DETACH] statements also cause 03469 ** sqlite3_stmt_readonly() to return true since, while those statements 03470 ** change the configuration of a database connection, they do not make 03471 ** changes to the content of the database files on disk. 03472 */ 03473 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt); 03474 03475 /* 03476 ** CAPI3REF: Dynamically Typed Value Object 03477 ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value} 03478 ** 03479 ** SQLite uses the sqlite3_value object to represent all values 03480 ** that can be stored in a database table. SQLite uses dynamic typing 03481 ** for the values it stores. ^Values stored in sqlite3_value objects 03482 ** can be integers, floating point values, strings, BLOBs, or NULL. 03483 ** 03484 ** An sqlite3_value object may be either "protected" or "unprotected". 03485 ** Some interfaces require a protected sqlite3_value. Other interfaces 03486 ** will accept either a protected or an unprotected sqlite3_value. 03487 ** Every interface that accepts sqlite3_value arguments specifies 03488 ** whether or not it requires a protected sqlite3_value. 03489 ** 03490 ** The terms "protected" and "unprotected" refer to whether or not 03491 ** a mutex is held. An internal mutex is held for a protected 03492 ** sqlite3_value object but no mutex is held for an unprotected 03493 ** sqlite3_value object. If SQLite is compiled to be single-threaded 03494 ** (with [SQLITE_THREADSAFE=0] and with [sqlite3_threadsafe()] returning 0) 03495 ** or if SQLite is run in one of reduced mutex modes 03496 ** [SQLITE_CONFIG_SINGLETHREAD] or [SQLITE_CONFIG_MULTITHREAD] 03497 ** then there is no distinction between protected and unprotected 03498 ** sqlite3_value objects and they can be used interchangeably. However, 03499 ** for maximum code portability it is recommended that applications 03500 ** still make the distinction between protected and unprotected 03501 ** sqlite3_value objects even when not strictly required. 03502 ** 03503 ** ^The sqlite3_value objects that are passed as parameters into the 03504 ** implementation of [application-defined SQL functions] are protected. 03505 ** ^The sqlite3_value object returned by 03506 ** [sqlite3_column_value()] is unprotected. 03507 ** Unprotected sqlite3_value objects may only be used with 03508 ** [sqlite3_result_value()] and [sqlite3_bind_value()]. 03509 ** The [sqlite3_value_blob | sqlite3_value_type()] family of 03510 ** interfaces require protected sqlite3_value objects. 03511 */ 03512 typedef struct Mem sqlite3_value; 03513 03514 /* 03515 ** CAPI3REF: SQL Function Context Object 03516 ** 03517 ** The context in which an SQL function executes is stored in an 03518 ** sqlite3_context object. ^A pointer to an sqlite3_context object 03519 ** is always first parameter to [application-defined SQL functions]. 03520 ** The application-defined SQL function implementation will pass this 03521 ** pointer through into calls to [sqlite3_result_int | sqlite3_result()], 03522 ** [sqlite3_aggregate_context()], [sqlite3_user_data()], 03523 ** [sqlite3_context_db_handle()], [sqlite3_get_auxdata()], 03524 ** and/or [sqlite3_set_auxdata()]. 03525 */ 03526 typedef struct sqlite3_context sqlite3_context; 03527 03528 /* 03529 ** CAPI3REF: Binding Values To Prepared Statements 03530 ** KEYWORDS: {host parameter} {host parameters} {host parameter name} 03531 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding} 03532 ** 03533 ** ^(In the SQL statement text input to [sqlite3_prepare_v2()] and its variants, 03534 ** literals may be replaced by a [parameter] that matches one of following 03535 ** templates: 03536 ** 03537 ** <ul> 03538 ** <li> ? 03539 ** <li> ?NNN 03540 ** <li> :VVV 03541 ** <li> @VVV 03542 ** <li> $VVV 03543 ** </ul> 03544 ** 03545 ** In the templates above, NNN represents an integer literal, 03546 ** and VVV represents an alphanumeric identifier.)^ ^The values of these 03547 ** parameters (also called "host parameter names" or "SQL parameters") 03548 ** can be set using the sqlite3_bind_*() routines defined here. 03549 ** 03550 ** ^The first argument to the sqlite3_bind_*() routines is always 03551 ** a pointer to the [sqlite3_stmt] object returned from 03552 ** [sqlite3_prepare_v2()] or its variants. 03553 ** 03554 ** ^The second argument is the index of the SQL parameter to be set. 03555 ** ^The leftmost SQL parameter has an index of 1. ^When the same named 03556 ** SQL parameter is used more than once, second and subsequent 03557 ** occurrences have the same index as the first occurrence. 03558 ** ^The index for named parameters can be looked up using the 03559 ** [sqlite3_bind_parameter_index()] API if desired. ^The index 03560 ** for "?NNN" parameters is the value of NNN. 03561 ** ^The NNN value must be between 1 and the [sqlite3_limit()] 03562 ** parameter [SQLITE_LIMIT_VARIABLE_NUMBER] (default value: 999). 03563 ** 03564 ** ^The third argument is the value to bind to the parameter. 03565 ** 03566 ** ^(In those routines that have a fourth argument, its value is the 03567 ** number of bytes in the parameter. To be clear: the value is the 03568 ** number of <u>bytes</u> in the value, not the number of characters.)^ 03569 ** ^If the fourth parameter is negative, the length of the string is 03570 ** the number of bytes up to the first zero terminator. 03571 ** If a non-negative fourth parameter is provided to sqlite3_bind_text() 03572 ** or sqlite3_bind_text16() then that parameter must be the byte offset 03573 ** where the NUL terminator would occur assuming the string were NUL 03574 ** terminated. If any NUL characters occur at byte offsets less than 03575 ** the value of the fourth parameter then the resulting string value will 03576 ** contain embedded NULs. The result of expressions involving strings 03577 ** with embedded NULs is undefined. 03578 ** 03579 ** ^The fifth argument to sqlite3_bind_blob(), sqlite3_bind_text(), and 03580 ** sqlite3_bind_text16() is a destructor used to dispose of the BLOB or 03581 ** string after SQLite has finished with it. ^The destructor is called 03582 ** to dispose of the BLOB or string even if the call to sqlite3_bind_blob(), 03583 ** sqlite3_bind_text(), or sqlite3_bind_text16() fails. 03584 ** ^If the fifth argument is 03585 ** the special value [SQLITE_STATIC], then SQLite assumes that the 03586 ** information is in static, unmanaged space and does not need to be freed. 03587 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then 03588 ** SQLite makes its own private copy of the data immediately, before 03589 ** the sqlite3_bind_*() routine returns. 03590 ** 03591 ** ^The sqlite3_bind_zeroblob() routine binds a BLOB of length N that 03592 ** is filled with zeroes. ^A zeroblob uses a fixed amount of memory 03593 ** (just an integer to hold its size) while it is being processed. 03594 ** Zeroblobs are intended to serve as placeholders for BLOBs whose 03595 ** content is later written using 03596 ** [sqlite3_blob_open | incremental BLOB I/O] routines. 03597 ** ^A negative value for the zeroblob results in a zero-length BLOB. 03598 ** 03599 ** ^If any of the sqlite3_bind_*() routines are called with a NULL pointer 03600 ** for the [prepared statement] or with a prepared statement for which 03601 ** [sqlite3_step()] has been called more recently than [sqlite3_reset()], 03602 ** then the call will return [SQLITE_MISUSE]. If any sqlite3_bind_() 03603 ** routine is passed a [prepared statement] that has been finalized, the 03604 ** result is undefined and probably harmful. 03605 ** 03606 ** ^Bindings are not cleared by the [sqlite3_reset()] routine. 03607 ** ^Unbound parameters are interpreted as NULL. 03608 ** 03609 ** ^The sqlite3_bind_* routines return [SQLITE_OK] on success or an 03610 ** [error code] if anything goes wrong. 03611 ** ^[SQLITE_RANGE] is returned if the parameter 03612 ** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails. 03613 ** 03614 ** See also: [sqlite3_bind_parameter_count()], 03615 ** [sqlite3_bind_parameter_name()], and [sqlite3_bind_parameter_index()]. 03616 */ 03617 SQLITE_API int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*)); 03618 SQLITE_API int sqlite3_bind_double(sqlite3_stmt*, int, double); 03619 SQLITE_API int sqlite3_bind_int(sqlite3_stmt*, int, int); 03620 SQLITE_API int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64); 03621 SQLITE_API int sqlite3_bind_null(sqlite3_stmt*, int); 03622 SQLITE_API int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void(*)(void*)); 03623 SQLITE_API int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void(*)(void*)); 03624 SQLITE_API int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); 03625 SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); 03626 03627 /* 03628 ** CAPI3REF: Number Of SQL Parameters 03629 ** 03630 ** ^This routine can be used to find the number of [SQL parameters] 03631 ** in a [prepared statement]. SQL parameters are tokens of the 03632 ** form "?", "?NNN", ":AAA", "$AAA", or "@AAA" that serve as 03633 ** placeholders for values that are [sqlite3_bind_blob | bound] 03634 ** to the parameters at a later time. 03635 ** 03636 ** ^(This routine actually returns the index of the largest (rightmost) 03637 ** parameter. For all forms except ?NNN, this will correspond to the 03638 ** number of unique parameters. If parameters of the ?NNN form are used, 03639 ** there may be gaps in the list.)^ 03640 ** 03641 ** See also: [sqlite3_bind_blob|sqlite3_bind()], 03642 ** [sqlite3_bind_parameter_name()], and 03643 ** [sqlite3_bind_parameter_index()]. 03644 */ 03645 SQLITE_API int sqlite3_bind_parameter_count(sqlite3_stmt*); 03646 03647 /* 03648 ** CAPI3REF: Name Of A Host Parameter 03649 ** 03650 ** ^The sqlite3_bind_parameter_name(P,N) interface returns 03651 ** the name of the N-th [SQL parameter] in the [prepared statement] P. 03652 ** ^(SQL parameters of the form "?NNN" or ":AAA" or "@AAA" or "$AAA" 03653 ** have a name which is the string "?NNN" or ":AAA" or "@AAA" or "$AAA" 03654 ** respectively. 03655 ** In other words, the initial ":" or "$" or "@" or "?" 03656 ** is included as part of the name.)^ 03657 ** ^Parameters of the form "?" without a following integer have no name 03658 ** and are referred to as "nameless" or "anonymous parameters". 03659 ** 03660 ** ^The first host parameter has an index of 1, not 0. 03661 ** 03662 ** ^If the value N is out of range or if the N-th parameter is 03663 ** nameless, then NULL is returned. ^The returned string is 03664 ** always in UTF-8 encoding even if the named parameter was 03665 ** originally specified as UTF-16 in [sqlite3_prepare16()] or 03666 ** [sqlite3_prepare16_v2()]. 03667 ** 03668 ** See also: [sqlite3_bind_blob|sqlite3_bind()], 03669 ** [sqlite3_bind_parameter_count()], and 03670 ** [sqlite3_bind_parameter_index()]. 03671 */ 03672 SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int); 03673 03674 /* 03675 ** CAPI3REF: Index Of A Parameter With A Given Name 03676 ** 03677 ** ^Return the index of an SQL parameter given its name. ^The 03678 ** index value returned is suitable for use as the second 03679 ** parameter to [sqlite3_bind_blob|sqlite3_bind()]. ^A zero 03680 ** is returned if no matching parameter is found. ^The parameter 03681 ** name must be given in UTF-8 even if the original statement 03682 ** was prepared from UTF-16 text using [sqlite3_prepare16_v2()]. 03683 ** 03684 ** See also: [sqlite3_bind_blob|sqlite3_bind()], 03685 ** [sqlite3_bind_parameter_count()], and 03686 ** [sqlite3_bind_parameter_index()]. 03687 */ 03688 SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); 03689 03690 /* 03691 ** CAPI3REF: Reset All Bindings On A Prepared Statement 03692 ** 03693 ** ^Contrary to the intuition of many, [sqlite3_reset()] does not reset 03694 ** the [sqlite3_bind_blob | bindings] on a [prepared statement]. 03695 ** ^Use this routine to reset all host parameters to NULL. 03696 */ 03697 SQLITE_API int sqlite3_clear_bindings(sqlite3_stmt*); 03698 03699 /* 03700 ** CAPI3REF: Number Of Columns In A Result Set 03701 ** 03702 ** ^Return the number of columns in the result set returned by the 03703 ** [prepared statement]. ^This routine returns 0 if pStmt is an SQL 03704 ** statement that does not return data (for example an [UPDATE]). 03705 ** 03706 ** See also: [sqlite3_data_count()] 03707 */ 03708 SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt); 03709 03710 /* 03711 ** CAPI3REF: Column Names In A Result Set 03712 ** 03713 ** ^These routines return the name assigned to a particular column 03714 ** in the result set of a [SELECT] statement. ^The sqlite3_column_name() 03715 ** interface returns a pointer to a zero-terminated UTF-8 string 03716 ** and sqlite3_column_name16() returns a pointer to a zero-terminated 03717 ** UTF-16 string. ^The first parameter is the [prepared statement] 03718 ** that implements the [SELECT] statement. ^The second parameter is the 03719 ** column number. ^The leftmost column is number 0. 03720 ** 03721 ** ^The returned string pointer is valid until either the [prepared statement] 03722 ** is destroyed by [sqlite3_finalize()] or until the statement is automatically 03723 ** reprepared by the first call to [sqlite3_step()] for a particular run 03724 ** or until the next call to 03725 ** sqlite3_column_name() or sqlite3_column_name16() on the same column. 03726 ** 03727 ** ^If sqlite3_malloc() fails during the processing of either routine 03728 ** (for example during a conversion from UTF-8 to UTF-16) then a 03729 ** NULL pointer is returned. 03730 ** 03731 ** ^The name of a result column is the value of the "AS" clause for 03732 ** that column, if there is an AS clause. If there is no AS clause 03733 ** then the name of the column is unspecified and may change from 03734 ** one release of SQLite to the next. 03735 */ 03736 SQLITE_API const char *sqlite3_column_name(sqlite3_stmt*, int N); 03737 SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt*, int N); 03738 03739 /* 03740 ** CAPI3REF: Source Of Data In A Query Result 03741 ** 03742 ** ^These routines provide a means to determine the database, table, and 03743 ** table column that is the origin of a particular result column in 03744 ** [SELECT] statement. 03745 ** ^The name of the database or table or column can be returned as 03746 ** either a UTF-8 or UTF-16 string. ^The _database_ routines return 03747 ** the database name, the _table_ routines return the table name, and 03748 ** the origin_ routines return the column name. 03749 ** ^The returned string is valid until the [prepared statement] is destroyed 03750 ** using [sqlite3_finalize()] or until the statement is automatically 03751 ** reprepared by the first call to [sqlite3_step()] for a particular run 03752 ** or until the same information is requested 03753 ** again in a different encoding. 03754 ** 03755 ** ^The names returned are the original un-aliased names of the 03756 ** database, table, and column. 03757 ** 03758 ** ^The first argument to these interfaces is a [prepared statement]. 03759 ** ^These functions return information about the Nth result column returned by 03760 ** the statement, where N is the second function argument. 03761 ** ^The left-most column is column 0 for these routines. 03762 ** 03763 ** ^If the Nth column returned by the statement is an expression or 03764 ** subquery and is not a column value, then all of these functions return 03765 ** NULL. ^These routine might also return NULL if a memory allocation error 03766 ** occurs. ^Otherwise, they return the name of the attached database, table, 03767 ** or column that query result column was extracted from. 03768 ** 03769 ** ^As with all other SQLite APIs, those whose names end with "16" return 03770 ** UTF-16 encoded strings and the other functions return UTF-8. 03771 ** 03772 ** ^These APIs are only available if the library was compiled with the 03773 ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol. 03774 ** 03775 ** If two or more threads call one or more of these routines against the same 03776 ** prepared statement and column at the same time then the results are 03777 ** undefined. 03778 ** 03779 ** If two or more threads call one or more 03780 ** [sqlite3_column_database_name | column metadata interfaces] 03781 ** for the same [prepared statement] and result column 03782 ** at the same time then the results are undefined. 03783 */ 03784 SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt*,int); 03785 SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt*,int); 03786 SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt*,int); 03787 SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt*,int); 03788 SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt*,int); 03789 SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt*,int); 03790 03791 /* 03792 ** CAPI3REF: Declared Datatype Of A Query Result 03793 ** 03794 ** ^(The first parameter is a [prepared statement]. 03795 ** If this statement is a [SELECT] statement and the Nth column of the 03796 ** returned result set of that [SELECT] is a table column (not an 03797 ** expression or subquery) then the declared type of the table 03798 ** column is returned.)^ ^If the Nth column of the result set is an 03799 ** expression or subquery, then a NULL pointer is returned. 03800 ** ^The returned string is always UTF-8 encoded. 03801 ** 03802 ** ^(For example, given the database schema: 03803 ** 03804 ** CREATE TABLE t1(c1 VARIANT); 03805 ** 03806 ** and the following statement to be compiled: 03807 ** 03808 ** SELECT c1 + 1, c1 FROM t1; 03809 ** 03810 ** this routine would return the string "VARIANT" for the second result 03811 ** column (i==1), and a NULL pointer for the first result column (i==0).)^ 03812 ** 03813 ** ^SQLite uses dynamic run-time typing. ^So just because a column 03814 ** is declared to contain a particular type does not mean that the 03815 ** data stored in that column is of the declared type. SQLite is 03816 ** strongly typed, but the typing is dynamic not static. ^Type 03817 ** is associated with individual values, not with the containers 03818 ** used to hold those values. 03819 */ 03820 SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt*,int); 03821 SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt*,int); 03822 03823 /* 03824 ** CAPI3REF: Evaluate An SQL Statement 03825 ** 03826 ** After a [prepared statement] has been prepared using either 03827 ** [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] or one of the legacy 03828 ** interfaces [sqlite3_prepare()] or [sqlite3_prepare16()], this function 03829 ** must be called one or more times to evaluate the statement. 03830 ** 03831 ** The details of the behavior of the sqlite3_step() interface depend 03832 ** on whether the statement was prepared using the newer "v2" interface 03833 ** [sqlite3_prepare_v2()] and [sqlite3_prepare16_v2()] or the older legacy 03834 ** interface [sqlite3_prepare()] and [sqlite3_prepare16()]. The use of the 03835 ** new "v2" interface is recommended for new applications but the legacy 03836 ** interface will continue to be supported. 03837 ** 03838 ** ^In the legacy interface, the return value will be either [SQLITE_BUSY], 03839 ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE]. 03840 ** ^With the "v2" interface, any of the other [result codes] or 03841 ** [extended result codes] might be returned as well. 03842 ** 03843 ** ^[SQLITE_BUSY] means that the database engine was unable to acquire the 03844 ** database locks it needs to do its job. ^If the statement is a [COMMIT] 03845 ** or occurs outside of an explicit transaction, then you can retry the 03846 ** statement. If the statement is not a [COMMIT] and occurs within an 03847 ** explicit transaction then you should rollback the transaction before 03848 ** continuing. 03849 ** 03850 ** ^[SQLITE_DONE] means that the statement has finished executing 03851 ** successfully. sqlite3_step() should not be called again on this virtual 03852 ** machine without first calling [sqlite3_reset()] to reset the virtual 03853 ** machine back to its initial state. 03854 ** 03855 ** ^If the SQL statement being executed returns any data, then [SQLITE_ROW] 03856 ** is returned each time a new row of data is ready for processing by the 03857 ** caller. The values may be accessed using the [column access functions]. 03858 ** sqlite3_step() is called again to retrieve the next row of data. 03859 ** 03860 ** ^[SQLITE_ERROR] means that a run-time error (such as a constraint 03861 ** violation) has occurred. sqlite3_step() should not be called again on 03862 ** the VM. More information may be found by calling [sqlite3_errmsg()]. 03863 ** ^With the legacy interface, a more specific error code (for example, 03864 ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth) 03865 ** can be obtained by calling [sqlite3_reset()] on the 03866 ** [prepared statement]. ^In the "v2" interface, 03867 ** the more specific error code is returned directly by sqlite3_step(). 03868 ** 03869 ** [SQLITE_MISUSE] means that the this routine was called inappropriately. 03870 ** Perhaps it was called on a [prepared statement] that has 03871 ** already been [sqlite3_finalize | finalized] or on one that had 03872 ** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could 03873 ** be the case that the same database connection is being used by two or 03874 ** more threads at the same moment in time. 03875 ** 03876 ** For all versions of SQLite up to and including 3.6.23.1, a call to 03877 ** [sqlite3_reset()] was required after sqlite3_step() returned anything 03878 ** other than [SQLITE_ROW] before any subsequent invocation of 03879 ** sqlite3_step(). Failure to reset the prepared statement using 03880 ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from 03881 ** sqlite3_step(). But after version 3.6.23.1, sqlite3_step() began 03882 ** calling [sqlite3_reset()] automatically in this circumstance rather 03883 ** than returning [SQLITE_MISUSE]. This is not considered a compatibility 03884 ** break because any application that ever receives an SQLITE_MISUSE error 03885 ** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option 03886 ** can be used to restore the legacy behavior. 03887 ** 03888 ** <b>Goofy Interface Alert:</b> In the legacy interface, the sqlite3_step() 03889 ** API always returns a generic error code, [SQLITE_ERROR], following any 03890 ** error other than [SQLITE_BUSY] and [SQLITE_MISUSE]. You must call 03891 ** [sqlite3_reset()] or [sqlite3_finalize()] in order to find one of the 03892 ** specific [error codes] that better describes the error. 03893 ** We admit that this is a goofy design. The problem has been fixed 03894 ** with the "v2" interface. If you prepare all of your SQL statements 03895 ** using either [sqlite3_prepare_v2()] or [sqlite3_prepare16_v2()] instead 03896 ** of the legacy [sqlite3_prepare()] and [sqlite3_prepare16()] interfaces, 03897 ** then the more specific [error codes] are returned directly 03898 ** by sqlite3_step(). The use of the "v2" interface is recommended. 03899 */ 03900 SQLITE_API int sqlite3_step(sqlite3_stmt*); 03901 03902 /* 03903 ** CAPI3REF: Number of columns in a result set 03904 ** 03905 ** ^The sqlite3_data_count(P) interface returns the number of columns in the 03906 ** current row of the result set of [prepared statement] P. 03907 ** ^If prepared statement P does not have results ready to return 03908 ** (via calls to the [sqlite3_column_int | sqlite3_column_*()] of 03909 ** interfaces) then sqlite3_data_count(P) returns 0. 03910 ** ^The sqlite3_data_count(P) routine also returns 0 if P is a NULL pointer. 03911 ** ^The sqlite3_data_count(P) routine returns 0 if the previous call to 03912 ** [sqlite3_step](P) returned [SQLITE_DONE]. ^The sqlite3_data_count(P) 03913 ** will return non-zero if previous call to [sqlite3_step](P) returned 03914 ** [SQLITE_ROW], except in the case of the [PRAGMA incremental_vacuum] 03915 ** where it always returns zero since each step of that multi-step 03916 ** pragma returns 0 columns of data. 03917 ** 03918 ** See also: [sqlite3_column_count()] 03919 */ 03920 SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt); 03921 03922 /* 03923 ** CAPI3REF: Fundamental Datatypes 03924 ** KEYWORDS: SQLITE_TEXT 03925 ** 03926 ** ^(Every value in SQLite has one of five fundamental datatypes: 03927 ** 03928 ** <ul> 03929 ** <li> 64-bit signed integer 03930 ** <li> 64-bit IEEE floating point number 03931 ** <li> string 03932 ** <li> BLOB 03933 ** <li> NULL 03934 ** </ul>)^ 03935 ** 03936 ** These constants are codes for each of those types. 03937 ** 03938 ** Note that the SQLITE_TEXT constant was also used in SQLite version 2 03939 ** for a completely different meaning. Software that links against both 03940 ** SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT, not 03941 ** SQLITE_TEXT. 03942 */ 03943 #define SQLITE_INTEGER 1 03944 #define SQLITE_FLOAT 2 03945 #define SQLITE_BLOB 4 03946 #define SQLITE_NULL 5 03947 #ifdef SQLITE_TEXT 03948 # undef SQLITE_TEXT 03949 #else 03950 # define SQLITE_TEXT 3 03951 #endif 03952 #define SQLITE3_TEXT 3 03953 03954 /* 03955 ** CAPI3REF: Result Values From A Query 03956 ** KEYWORDS: {column access functions} 03957 ** 03958 ** These routines form the "result set" interface. 03959 ** 03960 ** ^These routines return information about a single column of the current 03961 ** result row of a query. ^In every case the first argument is a pointer 03962 ** to the [prepared statement] that is being evaluated (the [sqlite3_stmt*] 03963 ** that was returned from [sqlite3_prepare_v2()] or one of its variants) 03964 ** and the second argument is the index of the column for which information 03965 ** should be returned. ^The leftmost column of the result set has the index 0. 03966 ** ^The number of columns in the result can be determined using 03967 ** [sqlite3_column_count()]. 03968 ** 03969 ** If the SQL statement does not currently point to a valid row, or if the 03970 ** column index is out of range, the result is undefined. 03971 ** These routines may only be called when the most recent call to 03972 ** [sqlite3_step()] has returned [SQLITE_ROW] and neither 03973 ** [sqlite3_reset()] nor [sqlite3_finalize()] have been called subsequently. 03974 ** If any of these routines are called after [sqlite3_reset()] or 03975 ** [sqlite3_finalize()] or after [sqlite3_step()] has returned 03976 ** something other than [SQLITE_ROW], the results are undefined. 03977 ** If [sqlite3_step()] or [sqlite3_reset()] or [sqlite3_finalize()] 03978 ** are called from a different thread while any of these routines 03979 ** are pending, then the results are undefined. 03980 ** 03981 ** ^The sqlite3_column_type() routine returns the 03982 ** [SQLITE_INTEGER | datatype code] for the initial data type 03983 ** of the result column. ^The returned value is one of [SQLITE_INTEGER], 03984 ** [SQLITE_FLOAT], [SQLITE_TEXT], [SQLITE_BLOB], or [SQLITE_NULL]. The value 03985 ** returned by sqlite3_column_type() is only meaningful if no type 03986 ** conversions have occurred as described below. After a type conversion, 03987 ** the value returned by sqlite3_column_type() is undefined. Future 03988 ** versions of SQLite may change the behavior of sqlite3_column_type() 03989 ** following a type conversion. 03990 ** 03991 ** ^If the result is a BLOB or UTF-8 string then the sqlite3_column_bytes() 03992 ** routine returns the number of bytes in that BLOB or string. 03993 ** ^If the result is a UTF-16 string, then sqlite3_column_bytes() converts 03994 ** the string to UTF-8 and then returns the number of bytes. 03995 ** ^If the result is a numeric value then sqlite3_column_bytes() uses 03996 ** [sqlite3_snprintf()] to convert that value to a UTF-8 string and returns 03997 ** the number of bytes in that string. 03998 ** ^If the result is NULL, then sqlite3_column_bytes() returns zero. 03999 ** 04000 ** ^If the result is a BLOB or UTF-16 string then the sqlite3_column_bytes16() 04001 ** routine returns the number of bytes in that BLOB or string. 04002 ** ^If the result is a UTF-8 string, then sqlite3_column_bytes16() converts 04003 ** the string to UTF-16 and then returns the number of bytes. 04004 ** ^If the result is a numeric value then sqlite3_column_bytes16() uses 04005 ** [sqlite3_snprintf()] to convert that value to a UTF-16 string and returns 04006 ** the number of bytes in that string. 04007 ** ^If the result is NULL, then sqlite3_column_bytes16() returns zero. 04008 ** 04009 ** ^The values returned by [sqlite3_column_bytes()] and 04010 ** [sqlite3_column_bytes16()] do not include the zero terminators at the end 04011 ** of the string. ^For clarity: the values returned by 04012 ** [sqlite3_column_bytes()] and [sqlite3_column_bytes16()] are the number of 04013 ** bytes in the string, not the number of characters. 04014 ** 04015 ** ^Strings returned by sqlite3_column_text() and sqlite3_column_text16(), 04016 ** even empty strings, are always zero terminated. ^The return 04017 ** value from sqlite3_column_blob() for a zero-length BLOB is a NULL pointer. 04018 ** 04019 ** ^The object returned by [sqlite3_column_value()] is an 04020 ** [unprotected sqlite3_value] object. An unprotected sqlite3_value object 04021 ** may only be used with [sqlite3_bind_value()] and [sqlite3_result_value()]. 04022 ** If the [unprotected sqlite3_value] object returned by 04023 ** [sqlite3_column_value()] is used in any other way, including calls 04024 ** to routines like [sqlite3_value_int()], [sqlite3_value_text()], 04025 ** or [sqlite3_value_bytes()], then the behavior is undefined. 04026 ** 04027 ** These routines attempt to convert the value where appropriate. ^For 04028 ** example, if the internal representation is FLOAT and a text result 04029 ** is requested, [sqlite3_snprintf()] is used internally to perform the 04030 ** conversion automatically. ^(The following table details the conversions 04031 ** that are applied: 04032 ** 04033 ** <blockquote> 04034 ** <table border="1"> 04035 ** <tr><th> Internal<br>Type <th> Requested<br>Type <th> Conversion 04036 ** 04037 ** <tr><td> NULL <td> INTEGER <td> Result is 0 04038 ** <tr><td> NULL <td> FLOAT <td> Result is 0.0 04039 ** <tr><td> NULL <td> TEXT <td> Result is NULL pointer 04040 ** <tr><td> NULL <td> BLOB <td> Result is NULL pointer 04041 ** <tr><td> INTEGER <td> FLOAT <td> Convert from integer to float 04042 ** <tr><td> INTEGER <td> TEXT <td> ASCII rendering of the integer 04043 ** <tr><td> INTEGER <td> BLOB <td> Same as INTEGER->TEXT 04044 ** <tr><td> FLOAT <td> INTEGER <td> Convert from float to integer 04045 ** <tr><td> FLOAT <td> TEXT <td> ASCII rendering of the float 04046 ** <tr><td> FLOAT <td> BLOB <td> Same as FLOAT->TEXT 04047 ** <tr><td> TEXT <td> INTEGER <td> Use atoi() 04048 ** <tr><td> TEXT <td> FLOAT <td> Use atof() 04049 ** <tr><td> TEXT <td> BLOB <td> No change 04050 ** <tr><td> BLOB <td> INTEGER <td> Convert to TEXT then use atoi() 04051 ** <tr><td> BLOB <td> FLOAT <td> Convert to TEXT then use atof() 04052 ** <tr><td> BLOB <td> TEXT <td> Add a zero terminator if needed 04053 ** </table> 04054 ** </blockquote>)^ 04055 ** 04056 ** The table above makes reference to standard C library functions atoi() 04057 ** and atof(). SQLite does not really use these functions. It has its 04058 ** own equivalent internal routines. The atoi() and atof() names are 04059 ** used in the table for brevity and because they are familiar to most 04060 ** C programmers. 04061 ** 04062 ** Note that when type conversions occur, pointers returned by prior 04063 ** calls to sqlite3_column_blob(), sqlite3_column_text(), and/or 04064 ** sqlite3_column_text16() may be invalidated. 04065 ** Type conversions and pointer invalidations might occur 04066 ** in the following cases: 04067 ** 04068 ** <ul> 04069 ** <li> The initial content is a BLOB and sqlite3_column_text() or 04070 ** sqlite3_column_text16() is called. A zero-terminator might 04071 ** need to be added to the string.</li> 04072 ** <li> The initial content is UTF-8 text and sqlite3_column_bytes16() or 04073 ** sqlite3_column_text16() is called. The content must be converted 04074 ** to UTF-16.</li> 04075 ** <li> The initial content is UTF-16 text and sqlite3_column_bytes() or 04076 ** sqlite3_column_text() is called. The content must be converted 04077 ** to UTF-8.</li> 04078 ** </ul> 04079 ** 04080 ** ^Conversions between UTF-16be and UTF-16le are always done in place and do 04081 ** not invalidate a prior pointer, though of course the content of the buffer 04082 ** that the prior pointer references will have been modified. Other kinds 04083 ** of conversion are done in place when it is possible, but sometimes they 04084 ** are not possible and in those cases prior pointers are invalidated. 04085 ** 04086 ** The safest and easiest to remember policy is to invoke these routines 04087 ** in one of the following ways: 04088 ** 04089 ** <ul> 04090 ** <li>sqlite3_column_text() followed by sqlite3_column_bytes()</li> 04091 ** <li>sqlite3_column_blob() followed by sqlite3_column_bytes()</li> 04092 ** <li>sqlite3_column_text16() followed by sqlite3_column_bytes16()</li> 04093 ** </ul> 04094 ** 04095 ** In other words, you should call sqlite3_column_text(), 04096 ** sqlite3_column_blob(), or sqlite3_column_text16() first to force the result 04097 ** into the desired format, then invoke sqlite3_column_bytes() or 04098 ** sqlite3_column_bytes16() to find the size of the result. Do not mix calls 04099 ** to sqlite3_column_text() or sqlite3_column_blob() with calls to 04100 ** sqlite3_column_bytes16(), and do not mix calls to sqlite3_column_text16() 04101 ** with calls to sqlite3_column_bytes(). 04102 ** 04103 ** ^The pointers returned are valid until a type conversion occurs as 04104 ** described above, or until [sqlite3_step()] or [sqlite3_reset()] or 04105 ** [sqlite3_finalize()] is called. ^The memory space used to hold strings 04106 ** and BLOBs is freed automatically. Do <b>not</b> pass the pointers returned 04107 ** [sqlite3_column_blob()], [sqlite3_column_text()], etc. into 04108 ** [sqlite3_free()]. 04109 ** 04110 ** ^(If a memory allocation error occurs during the evaluation of any 04111 ** of these routines, a default value is returned. The default value 04112 ** is either the integer 0, the floating point number 0.0, or a NULL 04113 ** pointer. Subsequent calls to [sqlite3_errcode()] will return 04114 ** [SQLITE_NOMEM].)^ 04115 */ 04116 SQLITE_API const void *sqlite3_column_blob(sqlite3_stmt*, int iCol); 04117 SQLITE_API int sqlite3_column_bytes(sqlite3_stmt*, int iCol); 04118 SQLITE_API int sqlite3_column_bytes16(sqlite3_stmt*, int iCol); 04119 SQLITE_API double sqlite3_column_double(sqlite3_stmt*, int iCol); 04120 SQLITE_API int sqlite3_column_int(sqlite3_stmt*, int iCol); 04121 SQLITE_API sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol); 04122 SQLITE_API const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol); 04123 SQLITE_API const void *sqlite3_column_text16(sqlite3_stmt*, int iCol); 04124 SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol); 04125 SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol); 04126 04127 /* 04128 ** CAPI3REF: Destroy A Prepared Statement Object 04129 ** 04130 ** ^The sqlite3_finalize() function is called to delete a [prepared statement]. 04131 ** ^If the most recent evaluation of the statement encountered no errors 04132 ** or if the statement is never been evaluated, then sqlite3_finalize() returns 04133 ** SQLITE_OK. ^If the most recent evaluation of statement S failed, then 04134 ** sqlite3_finalize(S) returns the appropriate [error code] or 04135 ** [extended error code]. 04136 ** 04137 ** ^The sqlite3_finalize(S) routine can be called at any point during 04138 ** the life cycle of [prepared statement] S: 04139 ** before statement S is ever evaluated, after 04140 ** one or more calls to [sqlite3_reset()], or after any call 04141 ** to [sqlite3_step()] regardless of whether or not the statement has 04142 ** completed execution. 04143 ** 04144 ** ^Invoking sqlite3_finalize() on a NULL pointer is a harmless no-op. 04145 ** 04146 ** The application must finalize every [prepared statement] in order to avoid 04147 ** resource leaks. It is a grievous error for the application to try to use 04148 ** a prepared statement after it has been finalized. Any use of a prepared 04149 ** statement after it has been finalized can result in undefined and 04150 ** undesirable behavior such as segfaults and heap corruption. 04151 */ 04152 SQLITE_API int sqlite3_finalize(sqlite3_stmt *pStmt); 04153 04154 /* 04155 ** CAPI3REF: Reset A Prepared Statement Object 04156 ** 04157 ** The sqlite3_reset() function is called to reset a [prepared statement] 04158 ** object back to its initial state, ready to be re-executed. 04159 ** ^Any SQL statement variables that had values bound to them using 04160 ** the [sqlite3_bind_blob | sqlite3_bind_*() API] retain their values. 04161 ** Use [sqlite3_clear_bindings()] to reset the bindings. 04162 ** 04163 ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S 04164 ** back to the beginning of its program. 04165 ** 04166 ** ^If the most recent call to [sqlite3_step(S)] for the 04167 ** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE], 04168 ** or if [sqlite3_step(S)] has never before been called on S, 04169 ** then [sqlite3_reset(S)] returns [SQLITE_OK]. 04170 ** 04171 ** ^If the most recent call to [sqlite3_step(S)] for the 04172 ** [prepared statement] S indicated an error, then 04173 ** [sqlite3_reset(S)] returns an appropriate [error code]. 04174 ** 04175 ** ^The [sqlite3_reset(S)] interface does not change the values 04176 ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S. 04177 */ 04178 SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt); 04179 04180 /* 04181 ** CAPI3REF: Create Or Redefine SQL Functions 04182 ** KEYWORDS: {function creation routines} 04183 ** KEYWORDS: {application-defined SQL function} 04184 ** KEYWORDS: {application-defined SQL functions} 04185 ** 04186 ** ^These functions (collectively known as "function creation routines") 04187 ** are used to add SQL functions or aggregates or to redefine the behavior 04188 ** of existing SQL functions or aggregates. The only differences between 04189 ** these routines are the text encoding expected for 04190 ** the second parameter (the name of the function being created) 04191 ** and the presence or absence of a destructor callback for 04192 ** the application data pointer. 04193 ** 04194 ** ^The first parameter is the [database connection] to which the SQL 04195 ** function is to be added. ^If an application uses more than one database 04196 ** connection then application-defined SQL functions must be added 04197 ** to each database connection separately. 04198 ** 04199 ** ^The second parameter is the name of the SQL function to be created or 04200 ** redefined. ^The length of the name is limited to 255 bytes in a UTF-8 04201 ** representation, exclusive of the zero-terminator. ^Note that the name 04202 ** length limit is in UTF-8 bytes, not characters nor UTF-16 bytes. 04203 ** ^Any attempt to create a function with a longer name 04204 ** will result in [SQLITE_MISUSE] being returned. 04205 ** 04206 ** ^The third parameter (nArg) 04207 ** is the number of arguments that the SQL function or 04208 ** aggregate takes. ^If this parameter is -1, then the SQL function or 04209 ** aggregate may take any number of arguments between 0 and the limit 04210 ** set by [sqlite3_limit]([SQLITE_LIMIT_FUNCTION_ARG]). If the third 04211 ** parameter is less than -1 or greater than 127 then the behavior is 04212 ** undefined. 04213 ** 04214 ** ^The fourth parameter, eTextRep, specifies what 04215 ** [SQLITE_UTF8 | text encoding] this SQL function prefers for 04216 ** its parameters. Every SQL function implementation must be able to work 04217 ** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be 04218 ** more efficient with one encoding than another. ^An application may 04219 ** invoke sqlite3_create_function() or sqlite3_create_function16() multiple 04220 ** times with the same function but with different values of eTextRep. 04221 ** ^When multiple implementations of the same function are available, SQLite 04222 ** will pick the one that involves the least amount of data conversion. 04223 ** If there is only a single implementation which does not care what text 04224 ** encoding is used, then the fourth argument should be [SQLITE_ANY]. 04225 ** 04226 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the 04227 ** function can gain access to this pointer using [sqlite3_user_data()].)^ 04228 ** 04229 ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are 04230 ** pointers to C-language functions that implement the SQL function or 04231 ** aggregate. ^A scalar SQL function requires an implementation of the xFunc 04232 ** callback only; NULL pointers must be passed as the xStep and xFinal 04233 ** parameters. ^An aggregate SQL function requires an implementation of xStep 04234 ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing 04235 ** SQL function or aggregate, pass NULL pointers for all three function 04236 ** callbacks. 04237 ** 04238 ** ^(If the ninth parameter to sqlite3_create_function_v2() is not NULL, 04239 ** then it is destructor for the application data pointer. 04240 ** The destructor is invoked when the function is deleted, either by being 04241 ** overloaded or when the database connection closes.)^ 04242 ** ^The destructor is also invoked if the call to 04243 ** sqlite3_create_function_v2() fails. 04244 ** ^When the destructor callback of the tenth parameter is invoked, it 04245 ** is passed a single argument which is a copy of the application data 04246 ** pointer which was the fifth parameter to sqlite3_create_function_v2(). 04247 ** 04248 ** ^It is permitted to register multiple implementations of the same 04249 ** functions with the same name but with either differing numbers of 04250 ** arguments or differing preferred text encodings. ^SQLite will use 04251 ** the implementation that most closely matches the way in which the 04252 ** SQL function is used. ^A function implementation with a non-negative 04253 ** nArg parameter is a better match than a function implementation with 04254 ** a negative nArg. ^A function where the preferred text encoding 04255 ** matches the database encoding is a better 04256 ** match than a function where the encoding is different. 04257 ** ^A function where the encoding difference is between UTF16le and UTF16be 04258 ** is a closer match than a function where the encoding difference is 04259 ** between UTF8 and UTF16. 04260 ** 04261 ** ^Built-in functions may be overloaded by new application-defined functions. 04262 ** 04263 ** ^An application-defined function is permitted to call other 04264 ** SQLite interfaces. However, such calls must not 04265 ** close the database connection nor finalize or reset the prepared 04266 ** statement in which the function is running. 04267 */ 04268 SQLITE_API int sqlite3_create_function( 04269 sqlite3 *db, 04270 const char *zFunctionName, 04271 int nArg, 04272 int eTextRep, 04273 void *pApp, 04274 void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 04275 void (*xStep)(sqlite3_context*,int,sqlite3_value**), 04276 void (*xFinal)(sqlite3_context*) 04277 ); 04278 SQLITE_API int sqlite3_create_function16( 04279 sqlite3 *db, 04280 const void *zFunctionName, 04281 int nArg, 04282 int eTextRep, 04283 void *pApp, 04284 void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 04285 void (*xStep)(sqlite3_context*,int,sqlite3_value**), 04286 void (*xFinal)(sqlite3_context*) 04287 ); 04288 SQLITE_API int sqlite3_create_function_v2( 04289 sqlite3 *db, 04290 const char *zFunctionName, 04291 int nArg, 04292 int eTextRep, 04293 void *pApp, 04294 void (*xFunc)(sqlite3_context*,int,sqlite3_value**), 04295 void (*xStep)(sqlite3_context*,int,sqlite3_value**), 04296 void (*xFinal)(sqlite3_context*), 04297 void(*xDestroy)(void*) 04298 ); 04299 04300 /* 04301 ** CAPI3REF: Text Encodings 04302 ** 04303 ** These constant define integer codes that represent the various 04304 ** text encodings supported by SQLite. 04305 */ 04306 #define SQLITE_UTF8 1 04307 #define SQLITE_UTF16LE 2 04308 #define SQLITE_UTF16BE 3 04309 #define SQLITE_UTF16 4 /* Use native byte order */ 04310 #define SQLITE_ANY 5 /* sqlite3_create_function only */ 04311 #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */ 04312 04313 /* 04314 ** CAPI3REF: Deprecated Functions 04315 ** DEPRECATED 04316 ** 04317 ** These functions are [deprecated]. In order to maintain 04318 ** backwards compatibility with older code, these functions continue 04319 ** to be supported. However, new applications should avoid 04320 ** the use of these functions. To help encourage people to avoid 04321 ** using these functions, we are not going to tell you what they do. 04322 */ 04323 #ifndef SQLITE_OMIT_DEPRECATED 04324 SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*); 04325 SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*); 04326 SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*); 04327 SQLITE_API SQLITE_DEPRECATED int sqlite3_global_recover(void); 04328 SQLITE_API SQLITE_DEPRECATED void sqlite3_thread_cleanup(void); 04329 SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int),void*,sqlite3_int64); 04330 #endif 04331 04332 /* 04333 ** CAPI3REF: Obtaining SQL Function Parameter Values 04334 ** 04335 ** The C-language implementation of SQL functions and aggregates uses 04336 ** this set of interface routines to access the parameter values on 04337 ** the function or aggregate. 04338 ** 04339 ** The xFunc (for scalar functions) or xStep (for aggregates) parameters 04340 ** to [sqlite3_create_function()] and [sqlite3_create_function16()] 04341 ** define callbacks that implement the SQL functions and aggregates. 04342 ** The 3rd parameter to these callbacks is an array of pointers to 04343 ** [protected sqlite3_value] objects. There is one [sqlite3_value] object for 04344 ** each parameter to the SQL function. These routines are used to 04345 ** extract values from the [sqlite3_value] objects. 04346 ** 04347 ** These routines work only with [protected sqlite3_value] objects. 04348 ** Any attempt to use these routines on an [unprotected sqlite3_value] 04349 ** object results in undefined behavior. 04350 ** 04351 ** ^These routines work just like the corresponding [column access functions] 04352 ** except that these routines take a single [protected sqlite3_value] object 04353 ** pointer instead of a [sqlite3_stmt*] pointer and an integer column number. 04354 ** 04355 ** ^The sqlite3_value_text16() interface extracts a UTF-16 string 04356 ** in the native byte-order of the host machine. ^The 04357 ** sqlite3_value_text16be() and sqlite3_value_text16le() interfaces 04358 ** extract UTF-16 strings as big-endian and little-endian respectively. 04359 ** 04360 ** ^(The sqlite3_value_numeric_type() interface attempts to apply 04361 ** numeric affinity to the value. This means that an attempt is 04362 ** made to convert the value to an integer or floating point. If 04363 ** such a conversion is possible without loss of information (in other 04364 ** words, if the value is a string that looks like a number) 04365 ** then the conversion is performed. Otherwise no conversion occurs. 04366 ** The [SQLITE_INTEGER | datatype] after conversion is returned.)^ 04367 ** 04368 ** Please pay particular attention to the fact that the pointer returned 04369 ** from [sqlite3_value_blob()], [sqlite3_value_text()], or 04370 ** [sqlite3_value_text16()] can be invalidated by a subsequent call to 04371 ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()], 04372 ** or [sqlite3_value_text16()]. 04373 ** 04374 ** These routines must be called from the same thread as 04375 ** the SQL function that supplied the [sqlite3_value*] parameters. 04376 */ 04377 SQLITE_API const void *sqlite3_value_blob(sqlite3_value*); 04378 SQLITE_API int sqlite3_value_bytes(sqlite3_value*); 04379 SQLITE_API int sqlite3_value_bytes16(sqlite3_value*); 04380 SQLITE_API double sqlite3_value_double(sqlite3_value*); 04381 SQLITE_API int sqlite3_value_int(sqlite3_value*); 04382 SQLITE_API sqlite3_int64 sqlite3_value_int64(sqlite3_value*); 04383 SQLITE_API const unsigned char *sqlite3_value_text(sqlite3_value*); 04384 SQLITE_API const void *sqlite3_value_text16(sqlite3_value*); 04385 SQLITE_API const void *sqlite3_value_text16le(sqlite3_value*); 04386 SQLITE_API const void *sqlite3_value_text16be(sqlite3_value*); 04387 SQLITE_API int sqlite3_value_type(sqlite3_value*); 04388 SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*); 04389 04390 /* 04391 ** CAPI3REF: Obtain Aggregate Function Context 04392 ** 04393 ** Implementations of aggregate SQL functions use this 04394 ** routine to allocate memory for storing their state. 04395 ** 04396 ** ^The first time the sqlite3_aggregate_context(C,N) routine is called 04397 ** for a particular aggregate function, SQLite 04398 ** allocates N of memory, zeroes out that memory, and returns a pointer 04399 ** to the new memory. ^On second and subsequent calls to 04400 ** sqlite3_aggregate_context() for the same aggregate function instance, 04401 ** the same buffer is returned. Sqlite3_aggregate_context() is normally 04402 ** called once for each invocation of the xStep callback and then one 04403 ** last time when the xFinal callback is invoked. ^(When no rows match 04404 ** an aggregate query, the xStep() callback of the aggregate function 04405 ** implementation is never called and xFinal() is called exactly once. 04406 ** In those cases, sqlite3_aggregate_context() might be called for the 04407 ** first time from within xFinal().)^ 04408 ** 04409 ** ^The sqlite3_aggregate_context(C,N) routine returns a NULL pointer if N is 04410 ** less than or equal to zero or if a memory allocate error occurs. 04411 ** 04412 ** ^(The amount of space allocated by sqlite3_aggregate_context(C,N) is 04413 ** determined by the N parameter on first successful call. Changing the 04414 ** value of N in subsequent call to sqlite3_aggregate_context() within 04415 ** the same aggregate function instance will not resize the memory 04416 ** allocation.)^ 04417 ** 04418 ** ^SQLite automatically frees the memory allocated by 04419 ** sqlite3_aggregate_context() when the aggregate query concludes. 04420 ** 04421 ** The first parameter must be a copy of the 04422 ** [sqlite3_context | SQL function context] that is the first parameter 04423 ** to the xStep or xFinal callback routine that implements the aggregate 04424 ** function. 04425 ** 04426 ** This routine must be called from the same thread in which 04427 ** the aggregate SQL function is running. 04428 */ 04429 SQLITE_API void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); 04430 04431 /* 04432 ** CAPI3REF: User Data For Functions 04433 ** 04434 ** ^The sqlite3_user_data() interface returns a copy of 04435 ** the pointer that was the pUserData parameter (the 5th parameter) 04436 ** of the [sqlite3_create_function()] 04437 ** and [sqlite3_create_function16()] routines that originally 04438 ** registered the application defined function. 04439 ** 04440 ** This routine must be called from the same thread in which 04441 ** the application-defined function is running. 04442 */ 04443 SQLITE_API void *sqlite3_user_data(sqlite3_context*); 04444 04445 /* 04446 ** CAPI3REF: Database Connection For Functions 04447 ** 04448 ** ^The sqlite3_context_db_handle() interface returns a copy of 04449 ** the pointer to the [database connection] (the 1st parameter) 04450 ** of the [sqlite3_create_function()] 04451 ** and [sqlite3_create_function16()] routines that originally 04452 ** registered the application defined function. 04453 */ 04454 SQLITE_API sqlite3 *sqlite3_context_db_handle(sqlite3_context*); 04455 04456 /* 04457 ** CAPI3REF: Function Auxiliary Data 04458 ** 04459 ** The following two functions may be used by scalar SQL functions to 04460 ** associate metadata with argument values. If the same value is passed to 04461 ** multiple invocations of the same SQL function during query execution, under 04462 ** some circumstances the associated metadata may be preserved. This may 04463 ** be used, for example, to add a regular-expression matching scalar 04464 ** function. The compiled version of the regular expression is stored as 04465 ** metadata associated with the SQL value passed as the regular expression 04466 ** pattern. The compiled regular expression can be reused on multiple 04467 ** invocations of the same function so that the original pattern string 04468 ** does not need to be recompiled on each invocation. 04469 ** 04470 ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata 04471 ** associated by the sqlite3_set_auxdata() function with the Nth argument 04472 ** value to the application-defined function. ^If no metadata has been ever 04473 ** been set for the Nth argument of the function, or if the corresponding 04474 ** function parameter has changed since the meta-data was set, 04475 ** then sqlite3_get_auxdata() returns a NULL pointer. 04476 ** 04477 ** ^The sqlite3_set_auxdata() interface saves the metadata 04478 ** pointed to by its 3rd parameter as the metadata for the N-th 04479 ** argument of the application-defined function. Subsequent 04480 ** calls to sqlite3_get_auxdata() might return this data, if it has 04481 ** not been destroyed. 04482 ** ^If it is not NULL, SQLite will invoke the destructor 04483 ** function given by the 4th parameter to sqlite3_set_auxdata() on 04484 ** the metadata when the corresponding function parameter changes 04485 ** or when the SQL statement completes, whichever comes first. 04486 ** 04487 ** SQLite is free to call the destructor and drop metadata on any 04488 ** parameter of any function at any time. ^The only guarantee is that 04489 ** the destructor will be called before the metadata is dropped. 04490 ** 04491 ** ^(In practice, metadata is preserved between function calls for 04492 ** expressions that are constant at compile time. This includes literal 04493 ** values and [parameters].)^ 04494 ** 04495 ** These routines must be called from the same thread in which 04496 ** the SQL function is running. 04497 */ 04498 SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N); 04499 SQLITE_API void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void (*)(void*)); 04500 04501 04502 /* 04503 ** CAPI3REF: Constants Defining Special Destructor Behavior 04504 ** 04505 ** These are special values for the destructor that is passed in as the 04506 ** final argument to routines like [sqlite3_result_blob()]. ^If the destructor 04507 ** argument is SQLITE_STATIC, it means that the content pointer is constant 04508 ** and will never change. It does not need to be destroyed. ^The 04509 ** SQLITE_TRANSIENT value means that the content will likely change in 04510 ** the near future and that SQLite should make its own private copy of 04511 ** the content before returning. 04512 ** 04513 ** The typedef is necessary to work around problems in certain 04514 ** C++ compilers. See ticket #2191. 04515 */ 04516 typedef void (*sqlite3_destructor_type)(void*); 04517 #define SQLITE_STATIC ((sqlite3_destructor_type)0) 04518 #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) 04519 04520 /* 04521 ** CAPI3REF: Setting The Result Of An SQL Function 04522 ** 04523 ** These routines are used by the xFunc or xFinal callbacks that 04524 ** implement SQL functions and aggregates. See 04525 ** [sqlite3_create_function()] and [sqlite3_create_function16()] 04526 ** for additional information. 04527 ** 04528 ** These functions work very much like the [parameter binding] family of 04529 ** functions used to bind values to host parameters in prepared statements. 04530 ** Refer to the [SQL parameter] documentation for additional information. 04531 ** 04532 ** ^The sqlite3_result_blob() interface sets the result from 04533 ** an application-defined function to be the BLOB whose content is pointed 04534 ** to by the second parameter and which is N bytes long where N is the 04535 ** third parameter. 04536 ** 04537 ** ^The sqlite3_result_zeroblob() interfaces set the result of 04538 ** the application-defined function to be a BLOB containing all zero 04539 ** bytes and N bytes in size, where N is the value of the 2nd parameter. 04540 ** 04541 ** ^The sqlite3_result_double() interface sets the result from 04542 ** an application-defined function to be a floating point value specified 04543 ** by its 2nd argument. 04544 ** 04545 ** ^The sqlite3_result_error() and sqlite3_result_error16() functions 04546 ** cause the implemented SQL function to throw an exception. 04547 ** ^SQLite uses the string pointed to by the 04548 ** 2nd parameter of sqlite3_result_error() or sqlite3_result_error16() 04549 ** as the text of an error message. ^SQLite interprets the error 04550 ** message string from sqlite3_result_error() as UTF-8. ^SQLite 04551 ** interprets the string from sqlite3_result_error16() as UTF-16 in native 04552 ** byte order. ^If the third parameter to sqlite3_result_error() 04553 ** or sqlite3_result_error16() is negative then SQLite takes as the error 04554 ** message all text up through the first zero character. 04555 ** ^If the third parameter to sqlite3_result_error() or 04556 ** sqlite3_result_error16() is non-negative then SQLite takes that many 04557 ** bytes (not characters) from the 2nd parameter as the error message. 04558 ** ^The sqlite3_result_error() and sqlite3_result_error16() 04559 ** routines make a private copy of the error message text before 04560 ** they return. Hence, the calling function can deallocate or 04561 ** modify the text after they return without harm. 04562 ** ^The sqlite3_result_error_code() function changes the error code 04563 ** returned by SQLite as a result of an error in a function. ^By default, 04564 ** the error code is SQLITE_ERROR. ^A subsequent call to sqlite3_result_error() 04565 ** or sqlite3_result_error16() resets the error code to SQLITE_ERROR. 04566 ** 04567 ** ^The sqlite3_result_toobig() interface causes SQLite to throw an error 04568 ** indicating that a string or BLOB is too long to represent. 04569 ** 04570 ** ^The sqlite3_result_nomem() interface causes SQLite to throw an error 04571 ** indicating that a memory allocation failed. 04572 ** 04573 ** ^The sqlite3_result_int() interface sets the return value 04574 ** of the application-defined function to be the 32-bit signed integer 04575 ** value given in the 2nd argument. 04576 ** ^The sqlite3_result_int64() interface sets the return value 04577 ** of the application-defined function to be the 64-bit signed integer 04578 ** value given in the 2nd argument. 04579 ** 04580 ** ^The sqlite3_result_null() interface sets the return value 04581 ** of the application-defined function to be NULL. 04582 ** 04583 ** ^The sqlite3_result_text(), sqlite3_result_text16(), 04584 ** sqlite3_result_text16le(), and sqlite3_result_text16be() interfaces 04585 ** set the return value of the application-defined function to be 04586 ** a text string which is represented as UTF-8, UTF-16 native byte order, 04587 ** UTF-16 little endian, or UTF-16 big endian, respectively. 04588 ** ^SQLite takes the text result from the application from 04589 ** the 2nd parameter of the sqlite3_result_text* interfaces. 04590 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces 04591 ** is negative, then SQLite takes result text from the 2nd parameter 04592 ** through the first zero character. 04593 ** ^If the 3rd parameter to the sqlite3_result_text* interfaces 04594 ** is non-negative, then as many bytes (not characters) of the text 04595 ** pointed to by the 2nd parameter are taken as the application-defined 04596 ** function result. If the 3rd parameter is non-negative, then it 04597 ** must be the byte offset into the string where the NUL terminator would 04598 ** appear if the string where NUL terminated. If any NUL characters occur 04599 ** in the string at a byte offset that is less than the value of the 3rd 04600 ** parameter, then the resulting string will contain embedded NULs and the 04601 ** result of expressions operating on strings with embedded NULs is undefined. 04602 ** ^If the 4th parameter to the sqlite3_result_text* interfaces 04603 ** or sqlite3_result_blob is a non-NULL pointer, then SQLite calls that 04604 ** function as the destructor on the text or BLOB result when it has 04605 ** finished using that result. 04606 ** ^If the 4th parameter to the sqlite3_result_text* interfaces or to 04607 ** sqlite3_result_blob is the special constant SQLITE_STATIC, then SQLite 04608 ** assumes that the text or BLOB result is in constant space and does not 04609 ** copy the content of the parameter nor call a destructor on the content 04610 ** when it has finished using that result. 04611 ** ^If the 4th parameter to the sqlite3_result_text* interfaces 04612 ** or sqlite3_result_blob is the special constant SQLITE_TRANSIENT 04613 ** then SQLite makes a copy of the result into space obtained from 04614 ** from [sqlite3_malloc()] before it returns. 04615 ** 04616 ** ^The sqlite3_result_value() interface sets the result of 04617 ** the application-defined function to be a copy the 04618 ** [unprotected sqlite3_value] object specified by the 2nd parameter. ^The 04619 ** sqlite3_result_value() interface makes a copy of the [sqlite3_value] 04620 ** so that the [sqlite3_value] specified in the parameter may change or 04621 ** be deallocated after sqlite3_result_value() returns without harm. 04622 ** ^A [protected sqlite3_value] object may always be used where an 04623 ** [unprotected sqlite3_value] object is required, so either 04624 ** kind of [sqlite3_value] object can be used with this interface. 04625 ** 04626 ** If these routines are called from within the different thread 04627 ** than the one containing the application-defined function that received 04628 ** the [sqlite3_context] pointer, the results are undefined. 04629 */ 04630 SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*)); 04631 SQLITE_API void sqlite3_result_double(sqlite3_context*, double); 04632 SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int); 04633 SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int); 04634 SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*); 04635 SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*); 04636 SQLITE_API void sqlite3_result_error_code(sqlite3_context*, int); 04637 SQLITE_API void sqlite3_result_int(sqlite3_context*, int); 04638 SQLITE_API void sqlite3_result_int64(sqlite3_context*, sqlite3_int64); 04639 SQLITE_API void sqlite3_result_null(sqlite3_context*); 04640 SQLITE_API void sqlite3_result_text(sqlite3_context*, const char*, int, void(*)(void*)); 04641 SQLITE_API void sqlite3_result_text16(sqlite3_context*, const void*, int, void(*)(void*)); 04642 SQLITE_API void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*)); 04643 SQLITE_API void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*)); 04644 SQLITE_API void sqlite3_result_value(sqlite3_context*, sqlite3_value*); 04645 SQLITE_API void sqlite3_result_zeroblob(sqlite3_context*, int n); 04646 04647 /* 04648 ** CAPI3REF: Define New Collating Sequences 04649 ** 04650 ** ^These functions add, remove, or modify a [collation] associated 04651 ** with the [database connection] specified as the first argument. 04652 ** 04653 ** ^The name of the collation is a UTF-8 string 04654 ** for sqlite3_create_collation() and sqlite3_create_collation_v2() 04655 ** and a UTF-16 string in native byte order for sqlite3_create_collation16(). 04656 ** ^Collation names that compare equal according to [sqlite3_strnicmp()] are 04657 ** considered to be the same name. 04658 ** 04659 ** ^(The third argument (eTextRep) must be one of the constants: 04660 ** <ul> 04661 ** <li> [SQLITE_UTF8], 04662 ** <li> [SQLITE_UTF16LE], 04663 ** <li> [SQLITE_UTF16BE], 04664 ** <li> [SQLITE_UTF16], or 04665 ** <li> [SQLITE_UTF16_ALIGNED]. 04666 ** </ul>)^ 04667 ** ^The eTextRep argument determines the encoding of strings passed 04668 ** to the collating function callback, xCallback. 04669 ** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep 04670 ** force strings to be UTF16 with native byte order. 04671 ** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin 04672 ** on an even byte address. 04673 ** 04674 ** ^The fourth argument, pArg, is an application data pointer that is passed 04675 ** through as the first argument to the collating function callback. 04676 ** 04677 ** ^The fifth argument, xCallback, is a pointer to the collating function. 04678 ** ^Multiple collating functions can be registered using the same name but 04679 ** with different eTextRep parameters and SQLite will use whichever 04680 ** function requires the least amount of data transformation. 04681 ** ^If the xCallback argument is NULL then the collating function is 04682 ** deleted. ^When all collating functions having the same name are deleted, 04683 ** that collation is no longer usable. 04684 ** 04685 ** ^The collating function callback is invoked with a copy of the pArg 04686 ** application data pointer and with two strings in the encoding specified 04687 ** by the eTextRep argument. The collating function must return an 04688 ** integer that is negative, zero, or positive 04689 ** if the first string is less than, equal to, or greater than the second, 04690 ** respectively. A collating function must always return the same answer 04691 ** given the same inputs. If two or more collating functions are registered 04692 ** to the same collation name (using different eTextRep values) then all 04693 ** must give an equivalent answer when invoked with equivalent strings. 04694 ** The collating function must obey the following properties for all 04695 ** strings A, B, and C: 04696 ** 04697 ** <ol> 04698 ** <li> If A==B then B==A. 04699 ** <li> If A==B and B==C then A==C. 04700 ** <li> If A<B THEN B>A. 04701 ** <li> If A<B and B<C then A<C. 04702 ** </ol> 04703 ** 04704 ** If a collating function fails any of the above constraints and that 04705 ** collating function is registered and used, then the behavior of SQLite 04706 ** is undefined. 04707 ** 04708 ** ^The sqlite3_create_collation_v2() works like sqlite3_create_collation() 04709 ** with the addition that the xDestroy callback is invoked on pArg when 04710 ** the collating function is deleted. 04711 ** ^Collating functions are deleted when they are overridden by later 04712 ** calls to the collation creation functions or when the 04713 ** [database connection] is closed using [sqlite3_close()]. 04714 ** 04715 ** ^The xDestroy callback is <u>not</u> called if the 04716 ** sqlite3_create_collation_v2() function fails. Applications that invoke 04717 ** sqlite3_create_collation_v2() with a non-NULL xDestroy argument should 04718 ** check the return code and dispose of the application data pointer 04719 ** themselves rather than expecting SQLite to deal with it for them. 04720 ** This is different from every other SQLite interface. The inconsistency 04721 ** is unfortunate but cannot be changed without breaking backwards 04722 ** compatibility. 04723 ** 04724 ** See also: [sqlite3_collation_needed()] and [sqlite3_collation_needed16()]. 04725 */ 04726 SQLITE_API int sqlite3_create_collation( 04727 sqlite3*, 04728 const char *zName, 04729 int eTextRep, 04730 void *pArg, 04731 int(*xCompare)(void*,int,const void*,int,const void*) 04732 ); 04733 SQLITE_API int sqlite3_create_collation_v2( 04734 sqlite3*, 04735 const char *zName, 04736 int eTextRep, 04737 void *pArg, 04738 int(*xCompare)(void*,int,const void*,int,const void*), 04739 void(*xDestroy)(void*) 04740 ); 04741 SQLITE_API int sqlite3_create_collation16( 04742 sqlite3*, 04743 const void *zName, 04744 int eTextRep, 04745 void *pArg, 04746 int(*xCompare)(void*,int,const void*,int,const void*) 04747 ); 04748 04749 /* 04750 ** CAPI3REF: Collation Needed Callbacks 04751 ** 04752 ** ^To avoid having to register all collation sequences before a database 04753 ** can be used, a single callback function may be registered with the 04754 ** [database connection] to be invoked whenever an undefined collation 04755 ** sequence is required. 04756 ** 04757 ** ^If the function is registered using the sqlite3_collation_needed() API, 04758 ** then it is passed the names of undefined collation sequences as strings 04759 ** encoded in UTF-8. ^If sqlite3_collation_needed16() is used, 04760 ** the names are passed as UTF-16 in machine native byte order. 04761 ** ^A call to either function replaces the existing collation-needed callback. 04762 ** 04763 ** ^(When the callback is invoked, the first argument passed is a copy 04764 ** of the second argument to sqlite3_collation_needed() or 04765 ** sqlite3_collation_needed16(). The second argument is the database 04766 ** connection. The third argument is one of [SQLITE_UTF8], [SQLITE_UTF16BE], 04767 ** or [SQLITE_UTF16LE], indicating the most desirable form of the collation 04768 ** sequence function required. The fourth parameter is the name of the 04769 ** required collation sequence.)^ 04770 ** 04771 ** The callback function should register the desired collation using 04772 ** [sqlite3_create_collation()], [sqlite3_create_collation16()], or 04773 ** [sqlite3_create_collation_v2()]. 04774 */ 04775 SQLITE_API int sqlite3_collation_needed( 04776 sqlite3*, 04777 void*, 04778 void(*)(void*,sqlite3*,int eTextRep,const char*) 04779 ); 04780 SQLITE_API int sqlite3_collation_needed16( 04781 sqlite3*, 04782 void*, 04783 void(*)(void*,sqlite3*,int eTextRep,const void*) 04784 ); 04785 04786 #ifdef SQLITE_HAS_CODEC 04787 /* 04788 ** Specify the key for an encrypted database. This routine should be 04789 ** called right after sqlite3_open(). 04790 ** 04791 ** The code to implement this API is not available in the public release 04792 ** of SQLite. 04793 */ 04794 SQLITE_API int sqlite3_key( 04795 sqlite3 *db, /* Database to be rekeyed */ 04796 const void *pKey, int nKey /* The key */ 04797 ); 04798 04799 /* 04800 ** Change the key on an open database. If the current database is not 04801 ** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the 04802 ** database is decrypted. 04803 ** 04804 ** The code to implement this API is not available in the public release 04805 ** of SQLite. 04806 */ 04807 SQLITE_API int sqlite3_rekey( 04808 sqlite3 *db, /* Database to be rekeyed */ 04809 const void *pKey, int nKey /* The new key */ 04810 ); 04811 04812 /* 04813 ** Specify the activation key for a SEE database. Unless 04814 ** activated, none of the SEE routines will work. 04815 */ 04816 SQLITE_API void sqlite3_activate_see( 04817 const char *zPassPhrase /* Activation phrase */ 04818 ); 04819 #endif 04820 04821 #ifdef SQLITE_ENABLE_CEROD 04822 /* 04823 ** Specify the activation key for a CEROD database. Unless 04824 ** activated, none of the CEROD routines will work. 04825 */ 04826 SQLITE_API void sqlite3_activate_cerod( 04827 const char *zPassPhrase /* Activation phrase */ 04828 ); 04829 #endif 04830 04831 /* 04832 ** CAPI3REF: Suspend Execution For A Short Time 04833 ** 04834 ** The sqlite3_sleep() function causes the current thread to suspend execution 04835 ** for at least a number of milliseconds specified in its parameter. 04836 ** 04837 ** If the operating system does not support sleep requests with 04838 ** millisecond time resolution, then the time will be rounded up to 04839 ** the nearest second. The number of milliseconds of sleep actually 04840 ** requested from the operating system is returned. 04841 ** 04842 ** ^SQLite implements this interface by calling the xSleep() 04843 ** method of the default [sqlite3_vfs] object. If the xSleep() method 04844 ** of the default VFS is not implemented correctly, or not implemented at 04845 ** all, then the behavior of sqlite3_sleep() may deviate from the description 04846 ** in the previous paragraphs. 04847 */ 04848 SQLITE_API int sqlite3_sleep(int); 04849 04850 /* 04851 ** CAPI3REF: Name Of The Folder Holding Temporary Files 04852 ** 04853 ** ^(If this global variable is made to point to a string which is 04854 ** the name of a folder (a.k.a. directory), then all temporary files 04855 ** created by SQLite when using a built-in [sqlite3_vfs | VFS] 04856 ** will be placed in that directory.)^ ^If this variable 04857 ** is a NULL pointer, then SQLite performs a search for an appropriate 04858 ** temporary file directory. 04859 ** 04860 ** It is not safe to read or modify this variable in more than one 04861 ** thread at a time. It is not safe to read or modify this variable 04862 ** if a [database connection] is being used at the same time in a separate 04863 ** thread. 04864 ** It is intended that this variable be set once 04865 ** as part of process initialization and before any SQLite interface 04866 ** routines have been called and that this variable remain unchanged 04867 ** thereafter. 04868 ** 04869 ** ^The [temp_store_directory pragma] may modify this variable and cause 04870 ** it to point to memory obtained from [sqlite3_malloc]. ^Furthermore, 04871 ** the [temp_store_directory pragma] always assumes that any string 04872 ** that this variable points to is held in memory obtained from 04873 ** [sqlite3_malloc] and the pragma may attempt to free that memory 04874 ** using [sqlite3_free]. 04875 ** Hence, if this variable is modified directly, either it should be 04876 ** made NULL or made to point to memory obtained from [sqlite3_malloc] 04877 ** or else the use of the [temp_store_directory pragma] should be avoided. 04878 */ 04879 SQLITE_API char *sqlite3_temp_directory; 04880 04881 /* 04882 ** CAPI3REF: Test For Auto-Commit Mode 04883 ** KEYWORDS: {autocommit mode} 04884 ** 04885 ** ^The sqlite3_get_autocommit() interface returns non-zero or 04886 ** zero if the given database connection is or is not in autocommit mode, 04887 ** respectively. ^Autocommit mode is on by default. 04888 ** ^Autocommit mode is disabled by a [BEGIN] statement. 04889 ** ^Autocommit mode is re-enabled by a [COMMIT] or [ROLLBACK]. 04890 ** 04891 ** If certain kinds of errors occur on a statement within a multi-statement 04892 ** transaction (errors including [SQLITE_FULL], [SQLITE_IOERR], 04893 ** [SQLITE_NOMEM], [SQLITE_BUSY], and [SQLITE_INTERRUPT]) then the 04894 ** transaction might be rolled back automatically. The only way to 04895 ** find out whether SQLite automatically rolled back the transaction after 04896 ** an error is to use this function. 04897 ** 04898 ** If another thread changes the autocommit status of the database 04899 ** connection while this routine is running, then the return value 04900 ** is undefined. 04901 */ 04902 SQLITE_API int sqlite3_get_autocommit(sqlite3*); 04903 04904 /* 04905 ** CAPI3REF: Find The Database Handle Of A Prepared Statement 04906 ** 04907 ** ^The sqlite3_db_handle interface returns the [database connection] handle 04908 ** to which a [prepared statement] belongs. ^The [database connection] 04909 ** returned by sqlite3_db_handle is the same [database connection] 04910 ** that was the first argument 04911 ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to 04912 ** create the statement in the first place. 04913 */ 04914 SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*); 04915 04916 /* 04917 ** CAPI3REF: Find the next prepared statement 04918 ** 04919 ** ^This interface returns a pointer to the next [prepared statement] after 04920 ** pStmt associated with the [database connection] pDb. ^If pStmt is NULL 04921 ** then this interface returns a pointer to the first prepared statement 04922 ** associated with the database connection pDb. ^If no prepared statement 04923 ** satisfies the conditions of this routine, it returns NULL. 04924 ** 04925 ** The [database connection] pointer D in a call to 04926 ** [sqlite3_next_stmt(D,S)] must refer to an open database 04927 ** connection and in particular must not be a NULL pointer. 04928 */ 04929 SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); 04930 04931 /* 04932 ** CAPI3REF: Commit And Rollback Notification Callbacks 04933 ** 04934 ** ^The sqlite3_commit_hook() interface registers a callback 04935 ** function to be invoked whenever a transaction is [COMMIT | committed]. 04936 ** ^Any callback set by a previous call to sqlite3_commit_hook() 04937 ** for the same database connection is overridden. 04938 ** ^The sqlite3_rollback_hook() interface registers a callback 04939 ** function to be invoked whenever a transaction is [ROLLBACK | rolled back]. 04940 ** ^Any callback set by a previous call to sqlite3_rollback_hook() 04941 ** for the same database connection is overridden. 04942 ** ^The pArg argument is passed through to the callback. 04943 ** ^If the callback on a commit hook function returns non-zero, 04944 ** then the commit is converted into a rollback. 04945 ** 04946 ** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions 04947 ** return the P argument from the previous call of the same function 04948 ** on the same [database connection] D, or NULL for 04949 ** the first call for each function on D. 04950 ** 04951 ** The callback implementation must not do anything that will modify 04952 ** the database connection that invoked the callback. Any actions 04953 ** to modify the database connection must be deferred until after the 04954 ** completion of the [sqlite3_step()] call that triggered the commit 04955 ** or rollback hook in the first place. 04956 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 04957 ** database connections for the meaning of "modify" in this paragraph. 04958 ** 04959 ** ^Registering a NULL function disables the callback. 04960 ** 04961 ** ^When the commit hook callback routine returns zero, the [COMMIT] 04962 ** operation is allowed to continue normally. ^If the commit hook 04963 ** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK]. 04964 ** ^The rollback hook is invoked on a rollback that results from a commit 04965 ** hook returning non-zero, just as it would be with any other rollback. 04966 ** 04967 ** ^For the purposes of this API, a transaction is said to have been 04968 ** rolled back if an explicit "ROLLBACK" statement is executed, or 04969 ** an error or constraint causes an implicit rollback to occur. 04970 ** ^The rollback callback is not invoked if a transaction is 04971 ** automatically rolled back because the database connection is closed. 04972 ** 04973 ** See also the [sqlite3_update_hook()] interface. 04974 */ 04975 SQLITE_API void *sqlite3_commit_hook(sqlite3*, int(*)(void*), void*); 04976 SQLITE_API void *sqlite3_rollback_hook(sqlite3*, void(*)(void *), void*); 04977 04978 /* 04979 ** CAPI3REF: Data Change Notification Callbacks 04980 ** 04981 ** ^The sqlite3_update_hook() interface registers a callback function 04982 ** with the [database connection] identified by the first argument 04983 ** to be invoked whenever a row is updated, inserted or deleted. 04984 ** ^Any callback set by a previous call to this function 04985 ** for the same database connection is overridden. 04986 ** 04987 ** ^The second argument is a pointer to the function to invoke when a 04988 ** row is updated, inserted or deleted. 04989 ** ^The first argument to the callback is a copy of the third argument 04990 ** to sqlite3_update_hook(). 04991 ** ^The second callback argument is one of [SQLITE_INSERT], [SQLITE_DELETE], 04992 ** or [SQLITE_UPDATE], depending on the operation that caused the callback 04993 ** to be invoked. 04994 ** ^The third and fourth arguments to the callback contain pointers to the 04995 ** database and table name containing the affected row. 04996 ** ^The final callback parameter is the [rowid] of the row. 04997 ** ^In the case of an update, this is the [rowid] after the update takes place. 04998 ** 04999 ** ^(The update hook is not invoked when internal system tables are 05000 ** modified (i.e. sqlite_master and sqlite_sequence).)^ 05001 ** 05002 ** ^In the current implementation, the update hook 05003 ** is not invoked when duplication rows are deleted because of an 05004 ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook 05005 ** invoked when rows are deleted using the [truncate optimization]. 05006 ** The exceptions defined in this paragraph might change in a future 05007 ** release of SQLite. 05008 ** 05009 ** The update hook implementation must not do anything that will modify 05010 ** the database connection that invoked the update hook. Any actions 05011 ** to modify the database connection must be deferred until after the 05012 ** completion of the [sqlite3_step()] call that triggered the update hook. 05013 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their 05014 ** database connections for the meaning of "modify" in this paragraph. 05015 ** 05016 ** ^The sqlite3_update_hook(D,C,P) function 05017 ** returns the P argument from the previous call 05018 ** on the same [database connection] D, or NULL for 05019 ** the first call on D. 05020 ** 05021 ** See also the [sqlite3_commit_hook()] and [sqlite3_rollback_hook()] 05022 ** interfaces. 05023 */ 05024 SQLITE_API void *sqlite3_update_hook( 05025 sqlite3*, 05026 void(*)(void *,int ,char const *,char const *,sqlite3_int64), 05027 void* 05028 ); 05029 05030 /* 05031 ** CAPI3REF: Enable Or Disable Shared Pager Cache 05032 ** KEYWORDS: {shared cache} 05033 ** 05034 ** ^(This routine enables or disables the sharing of the database cache 05035 ** and schema data structures between [database connection | connections] 05036 ** to the same database. Sharing is enabled if the argument is true 05037 ** and disabled if the argument is false.)^ 05038 ** 05039 ** ^Cache sharing is enabled and disabled for an entire process. 05040 ** This is a change as of SQLite version 3.5.0. In prior versions of SQLite, 05041 ** sharing was enabled or disabled for each thread separately. 05042 ** 05043 ** ^(The cache sharing mode set by this interface effects all subsequent 05044 ** calls to [sqlite3_open()], [sqlite3_open_v2()], and [sqlite3_open16()]. 05045 ** Existing database connections continue use the sharing mode 05046 ** that was in effect at the time they were opened.)^ 05047 ** 05048 ** ^(This routine returns [SQLITE_OK] if shared cache was enabled or disabled 05049 ** successfully. An [error code] is returned otherwise.)^ 05050 ** 05051 ** ^Shared cache is disabled by default. But this might change in 05052 ** future releases of SQLite. Applications that care about shared 05053 ** cache setting should set it explicitly. 05054 ** 05055 ** See Also: [SQLite Shared-Cache Mode] 05056 */ 05057 SQLITE_API int sqlite3_enable_shared_cache(int); 05058 05059 /* 05060 ** CAPI3REF: Attempt To Free Heap Memory 05061 ** 05062 ** ^The sqlite3_release_memory() interface attempts to free N bytes 05063 ** of heap memory by deallocating non-essential memory allocations 05064 ** held by the database library. Memory used to cache database 05065 ** pages to improve performance is an example of non-essential memory. 05066 ** ^sqlite3_release_memory() returns the number of bytes actually freed, 05067 ** which might be more or less than the amount requested. 05068 ** ^The sqlite3_release_memory() routine is a no-op returning zero 05069 ** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT]. 05070 */ 05071 SQLITE_API int sqlite3_release_memory(int); 05072 05073 /* 05074 ** CAPI3REF: Impose A Limit On Heap Size 05075 ** 05076 ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the 05077 ** soft limit on the amount of heap memory that may be allocated by SQLite. 05078 ** ^SQLite strives to keep heap memory utilization below the soft heap 05079 ** limit by reducing the number of pages held in the page cache 05080 ** as heap memory usages approaches the limit. 05081 ** ^The soft heap limit is "soft" because even though SQLite strives to stay 05082 ** below the limit, it will exceed the limit rather than generate 05083 ** an [SQLITE_NOMEM] error. In other words, the soft heap limit 05084 ** is advisory only. 05085 ** 05086 ** ^The return value from sqlite3_soft_heap_limit64() is the size of 05087 ** the soft heap limit prior to the call. ^If the argument N is negative 05088 ** then no change is made to the soft heap limit. Hence, the current 05089 ** size of the soft heap limit can be determined by invoking 05090 ** sqlite3_soft_heap_limit64() with a negative argument. 05091 ** 05092 ** ^If the argument N is zero then the soft heap limit is disabled. 05093 ** 05094 ** ^(The soft heap limit is not enforced in the current implementation 05095 ** if one or more of following conditions are true: 05096 ** 05097 ** <ul> 05098 ** <li> The soft heap limit is set to zero. 05099 ** <li> Memory accounting is disabled using a combination of the 05100 ** [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and 05101 ** the [SQLITE_DEFAULT_MEMSTATUS] compile-time option. 05102 ** <li> An alternative page cache implementation is specified using 05103 ** [sqlite3_config]([SQLITE_CONFIG_PCACHE],...). 05104 ** <li> The page cache allocates from its own memory pool supplied 05105 ** by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than 05106 ** from the heap. 05107 ** </ul>)^ 05108 ** 05109 ** Beginning with SQLite version 3.7.3, the soft heap limit is enforced 05110 ** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT] 05111 ** compile-time option is invoked. With [SQLITE_ENABLE_MEMORY_MANAGEMENT], 05112 ** the soft heap limit is enforced on every memory allocation. Without 05113 ** [SQLITE_ENABLE_MEMORY_MANAGEMENT], the soft heap limit is only enforced 05114 ** when memory is allocated by the page cache. Testing suggests that because 05115 ** the page cache is the predominate memory user in SQLite, most 05116 ** applications will achieve adequate soft heap limit enforcement without 05117 ** the use of [SQLITE_ENABLE_MEMORY_MANAGEMENT]. 05118 ** 05119 ** The circumstances under which SQLite will enforce the soft heap limit may 05120 ** changes in future releases of SQLite. 05121 */ 05122 SQLITE_API sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N); 05123 05124 /* 05125 ** CAPI3REF: Deprecated Soft Heap Limit Interface 05126 ** DEPRECATED 05127 ** 05128 ** This is a deprecated version of the [sqlite3_soft_heap_limit64()] 05129 ** interface. This routine is provided for historical compatibility 05130 ** only. All new applications should use the 05131 ** [sqlite3_soft_heap_limit64()] interface rather than this one. 05132 */ 05133 SQLITE_API SQLITE_DEPRECATED void sqlite3_soft_heap_limit(int N); 05134 05135 05136 /* 05137 ** CAPI3REF: Extract Metadata About A Column Of A Table 05138 ** 05139 ** ^This routine returns metadata about a specific column of a specific 05140 ** database table accessible using the [database connection] handle 05141 ** passed as the first function argument. 05142 ** 05143 ** ^The column is identified by the second, third and fourth parameters to 05144 ** this function. ^The second parameter is either the name of the database 05145 ** (i.e. "main", "temp", or an attached database) containing the specified 05146 ** table or NULL. ^If it is NULL, then all attached databases are searched 05147 ** for the table using the same algorithm used by the database engine to 05148 ** resolve unqualified table references. 05149 ** 05150 ** ^The third and fourth parameters to this function are the table and column 05151 ** name of the desired column, respectively. Neither of these parameters 05152 ** may be NULL. 05153 ** 05154 ** ^Metadata is returned by writing to the memory locations passed as the 5th 05155 ** and subsequent parameters to this function. ^Any of these arguments may be 05156 ** NULL, in which case the corresponding element of metadata is omitted. 05157 ** 05158 ** ^(<blockquote> 05159 ** <table border="1"> 05160 ** <tr><th> Parameter <th> Output<br>Type <th> Description 05161 ** 05162 ** <tr><td> 5th <td> const char* <td> Data type 05163 ** <tr><td> 6th <td> const char* <td> Name of default collation sequence 05164 ** <tr><td> 7th <td> int <td> True if column has a NOT NULL constraint 05165 ** <tr><td> 8th <td> int <td> True if column is part of the PRIMARY KEY 05166 ** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT] 05167 ** </table> 05168 ** </blockquote>)^ 05169 ** 05170 ** ^The memory pointed to by the character pointers returned for the 05171 ** declaration type and collation sequence is valid only until the next 05172 ** call to any SQLite API function. 05173 ** 05174 ** ^If the specified table is actually a view, an [error code] is returned. 05175 ** 05176 ** ^If the specified column is "rowid", "oid" or "_rowid_" and an 05177 ** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output 05178 ** parameters are set for the explicitly declared column. ^(If there is no 05179 ** explicitly declared [INTEGER PRIMARY KEY] column, then the output 05180 ** parameters are set as follows: 05181 ** 05182 ** <pre> 05183 ** data type: "INTEGER" 05184 ** collation sequence: "BINARY" 05185 ** not null: 0 05186 ** primary key: 1 05187 ** auto increment: 0 05188 ** </pre>)^ 05189 ** 05190 ** ^(This function may load one or more schemas from database files. If an 05191 ** error occurs during this process, or if the requested table or column 05192 ** cannot be found, an [error code] is returned and an error message left 05193 ** in the [database connection] (to be retrieved using sqlite3_errmsg()).)^ 05194 ** 05195 ** ^This API is only available if the library was compiled with the 05196 ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined. 05197 */ 05198 SQLITE_API int sqlite3_table_column_metadata( 05199 sqlite3 *db, /* Connection handle */ 05200 const char *zDbName, /* Database name or NULL */ 05201 const char *zTableName, /* Table name */ 05202 const char *zColumnName, /* Column name */ 05203 char const **pzDataType, /* OUTPUT: Declared data type */ 05204 char const **pzCollSeq, /* OUTPUT: Collation sequence name */ 05205 int *pNotNull, /* OUTPUT: True if NOT NULL constraint exists */ 05206 int *pPrimaryKey, /* OUTPUT: True if column part of PK */ 05207 int *pAutoinc /* OUTPUT: True if column is auto-increment */ 05208 ); 05209 05210 /* 05211 ** CAPI3REF: Load An Extension 05212 ** 05213 ** ^This interface loads an SQLite extension library from the named file. 05214 ** 05215 ** ^The sqlite3_load_extension() interface attempts to load an 05216 ** SQLite extension library contained in the file zFile. 05217 ** 05218 ** ^The entry point is zProc. 05219 ** ^zProc may be 0, in which case the name of the entry point 05220 ** defaults to "sqlite3_extension_init". 05221 ** ^The sqlite3_load_extension() interface returns 05222 ** [SQLITE_OK] on success and [SQLITE_ERROR] if something goes wrong. 05223 ** ^If an error occurs and pzErrMsg is not 0, then the 05224 ** [sqlite3_load_extension()] interface shall attempt to 05225 ** fill *pzErrMsg with error message text stored in memory 05226 ** obtained from [sqlite3_malloc()]. The calling function 05227 ** should free this memory by calling [sqlite3_free()]. 05228 ** 05229 ** ^Extension loading must be enabled using 05230 ** [sqlite3_enable_load_extension()] prior to calling this API, 05231 ** otherwise an error will be returned. 05232 ** 05233 ** See also the [load_extension() SQL function]. 05234 */ 05235 SQLITE_API int sqlite3_load_extension( 05236 sqlite3 *db, /* Load the extension into this database connection */ 05237 const char *zFile, /* Name of the shared library containing extension */ 05238 const char *zProc, /* Entry point. Derived from zFile if 0 */ 05239 char **pzErrMsg /* Put error message here if not 0 */ 05240 ); 05241 05242 /* 05243 ** CAPI3REF: Enable Or Disable Extension Loading 05244 ** 05245 ** ^So as not to open security holes in older applications that are 05246 ** unprepared to deal with extension loading, and as a means of disabling 05247 ** extension loading while evaluating user-entered SQL, the following API 05248 ** is provided to turn the [sqlite3_load_extension()] mechanism on and off. 05249 ** 05250 ** ^Extension loading is off by default. See ticket #1863. 05251 ** ^Call the sqlite3_enable_load_extension() routine with onoff==1 05252 ** to turn extension loading on and call it with onoff==0 to turn 05253 ** it back off again. 05254 */ 05255 SQLITE_API int sqlite3_enable_load_extension(sqlite3 *db, int onoff); 05256 05257 /* 05258 ** CAPI3REF: Automatically Load Statically Linked Extensions 05259 ** 05260 ** ^This interface causes the xEntryPoint() function to be invoked for 05261 ** each new [database connection] that is created. The idea here is that 05262 ** xEntryPoint() is the entry point for a statically linked SQLite extension 05263 ** that is to be automatically loaded into all new database connections. 05264 ** 05265 ** ^(Even though the function prototype shows that xEntryPoint() takes 05266 ** no arguments and returns void, SQLite invokes xEntryPoint() with three 05267 ** arguments and expects and integer result as if the signature of the 05268 ** entry point where as follows: 05269 ** 05270 ** <blockquote><pre> 05271 ** int xEntryPoint( 05272 ** sqlite3 *db, 05273 ** const char **pzErrMsg, 05274 ** const struct sqlite3_api_routines *pThunk 05275 ** ); 05276 ** </pre></blockquote>)^ 05277 ** 05278 ** If the xEntryPoint routine encounters an error, it should make *pzErrMsg 05279 ** point to an appropriate error message (obtained from [sqlite3_mprintf()]) 05280 ** and return an appropriate [error code]. ^SQLite ensures that *pzErrMsg 05281 ** is NULL before calling the xEntryPoint(). ^SQLite will invoke 05282 ** [sqlite3_free()] on *pzErrMsg after xEntryPoint() returns. ^If any 05283 ** xEntryPoint() returns an error, the [sqlite3_open()], [sqlite3_open16()], 05284 ** or [sqlite3_open_v2()] call that provoked the xEntryPoint() will fail. 05285 ** 05286 ** ^Calling sqlite3_auto_extension(X) with an entry point X that is already 05287 ** on the list of automatic extensions is a harmless no-op. ^No entry point 05288 ** will be called more than once for each database connection that is opened. 05289 ** 05290 ** See also: [sqlite3_reset_auto_extension()]. 05291 */ 05292 SQLITE_API int sqlite3_auto_extension(void (*xEntryPoint)(void)); 05293 05294 /* 05295 ** CAPI3REF: Reset Automatic Extension Loading 05296 ** 05297 ** ^This interface disables all automatic extensions previously 05298 ** registered using [sqlite3_auto_extension()]. 05299 */ 05300 SQLITE_API void sqlite3_reset_auto_extension(void); 05301 05302 /* 05303 ** The interface to the virtual-table mechanism is currently considered 05304 ** to be experimental. The interface might change in incompatible ways. 05305 ** If this is a problem for you, do not use the interface at this time. 05306 ** 05307 ** When the virtual-table mechanism stabilizes, we will declare the 05308 ** interface fixed, support it indefinitely, and remove this comment. 05309 */ 05310 05311 /* 05312 ** Structures used by the virtual table interface 05313 */ 05314 typedef struct sqlite3_vtab sqlite3_vtab; 05315 typedef struct sqlite3_index_info sqlite3_index_info; 05316 typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor; 05317 typedef struct sqlite3_module sqlite3_module; 05318 05319 /* 05320 ** CAPI3REF: Virtual Table Object 05321 ** KEYWORDS: sqlite3_module {virtual table module} 05322 ** 05323 ** This structure, sometimes called a "virtual table module", 05324 ** defines the implementation of a [virtual tables]. 05325 ** This structure consists mostly of methods for the module. 05326 ** 05327 ** ^A virtual table module is created by filling in a persistent 05328 ** instance of this structure and passing a pointer to that instance 05329 ** to [sqlite3_create_module()] or [sqlite3_create_module_v2()]. 05330 ** ^The registration remains valid until it is replaced by a different 05331 ** module or until the [database connection] closes. The content 05332 ** of this structure must not change while it is registered with 05333 ** any database connection. 05334 */ 05335 struct sqlite3_module { 05336 int iVersion; 05337 int (*xCreate)(sqlite3*, void *pAux, 05338 int argc, const char *const*argv, 05339 sqlite3_vtab **ppVTab, char**); 05340 int (*xConnect)(sqlite3*, void *pAux, 05341 int argc, const char *const*argv, 05342 sqlite3_vtab **ppVTab, char**); 05343 int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*); 05344 int (*xDisconnect)(sqlite3_vtab *pVTab); 05345 int (*xDestroy)(sqlite3_vtab *pVTab); 05346 int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor); 05347 int (*xClose)(sqlite3_vtab_cursor*); 05348 int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr, 05349 int argc, sqlite3_value **argv); 05350 int (*xNext)(sqlite3_vtab_cursor*); 05351 int (*xEof)(sqlite3_vtab_cursor*); 05352 int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int); 05353 int (*xRowid)(sqlite3_vtab_cursor*, sqlite3_int64 *pRowid); 05354 int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *); 05355 int (*xBegin)(sqlite3_vtab *pVTab); 05356 int (*xSync)(sqlite3_vtab *pVTab); 05357 int (*xCommit)(sqlite3_vtab *pVTab); 05358 int (*xRollback)(sqlite3_vtab *pVTab); 05359 int (*xFindFunction)(sqlite3_vtab *pVtab, int nArg, const char *zName, 05360 void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), 05361 void **ppArg); 05362 int (*xRename)(sqlite3_vtab *pVtab, const char *zNew); 05363 /* The methods above are in version 1 of the sqlite_module object. Those 05364 ** below are for version 2 and greater. */ 05365 int (*xSavepoint)(sqlite3_vtab *pVTab, int); 05366 int (*xRelease)(sqlite3_vtab *pVTab, int); 05367 int (*xRollbackTo)(sqlite3_vtab *pVTab, int); 05368 }; 05369 05370 /* 05371 ** CAPI3REF: Virtual Table Indexing Information 05372 ** KEYWORDS: sqlite3_index_info 05373 ** 05374 ** The sqlite3_index_info structure and its substructures is used as part 05375 ** of the [virtual table] interface to 05376 ** pass information into and receive the reply from the [xBestIndex] 05377 ** method of a [virtual table module]. The fields under **Inputs** are the 05378 ** inputs to xBestIndex and are read-only. xBestIndex inserts its 05379 ** results into the **Outputs** fields. 05380 ** 05381 ** ^(The aConstraint[] array records WHERE clause constraints of the form: 05382 ** 05383 ** <blockquote>column OP expr</blockquote> 05384 ** 05385 ** where OP is =, <, <=, >, or >=.)^ ^(The particular operator is 05386 ** stored in aConstraint[].op using one of the 05387 ** [SQLITE_INDEX_CONSTRAINT_EQ | SQLITE_INDEX_CONSTRAINT_ values].)^ 05388 ** ^(The index of the column is stored in 05389 ** aConstraint[].iColumn.)^ ^(aConstraint[].usable is TRUE if the 05390 ** expr on the right-hand side can be evaluated (and thus the constraint 05391 ** is usable) and false if it cannot.)^ 05392 ** 05393 ** ^The optimizer automatically inverts terms of the form "expr OP column" 05394 ** and makes other simplifications to the WHERE clause in an attempt to 05395 ** get as many WHERE clause terms into the form shown above as possible. 05396 ** ^The aConstraint[] array only reports WHERE clause terms that are 05397 ** relevant to the particular virtual table being queried. 05398 ** 05399 ** ^Information about the ORDER BY clause is stored in aOrderBy[]. 05400 ** ^Each term of aOrderBy records a column of the ORDER BY clause. 05401 ** 05402 ** The [xBestIndex] method must fill aConstraintUsage[] with information 05403 ** about what parameters to pass to xFilter. ^If argvIndex>0 then 05404 ** the right-hand side of the corresponding aConstraint[] is evaluated 05405 ** and becomes the argvIndex-th entry in argv. ^(If aConstraintUsage[].omit 05406 ** is true, then the constraint is assumed to be fully handled by the 05407 ** virtual table and is not checked again by SQLite.)^ 05408 ** 05409 ** ^The idxNum and idxPtr values are recorded and passed into the 05410 ** [xFilter] method. 05411 ** ^[sqlite3_free()] is used to free idxPtr if and only if 05412 ** needToFreeIdxPtr is true. 05413 ** 05414 ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in 05415 ** the correct order to satisfy the ORDER BY clause so that no separate 05416 ** sorting step is required. 05417 ** 05418 ** ^The estimatedCost value is an estimate of the cost of doing the 05419 ** particular lookup. A full scan of a table with N entries should have 05420 ** a cost of N. A binary search of a table of N entries should have a 05421 ** cost of approximately log(N). 05422 */ 05423 struct sqlite3_index_info { 05424 /* Inputs */ 05425 int nConstraint; /* Number of entries in aConstraint */ 05426 struct sqlite3_index_constraint { 05427 int iColumn; /* Column on left-hand side of constraint */ 05428 unsigned char op; /* Constraint operator */ 05429 unsigned char usable; /* True if this constraint is usable */ 05430 int iTermOffset; /* Used internally - xBestIndex should ignore */ 05431 } *aConstraint; /* Table of WHERE clause constraints */ 05432 int nOrderBy; /* Number of terms in the ORDER BY clause */ 05433 struct sqlite3_index_orderby { 05434 int iColumn; /* Column number */ 05435 unsigned char desc; /* True for DESC. False for ASC. */ 05436 } *aOrderBy; /* The ORDER BY clause */ 05437 /* Outputs */ 05438 struct sqlite3_index_constraint_usage { 05439 int argvIndex; /* if >0, constraint is part of argv to xFilter */ 05440 unsigned char omit; /* Do not code a test for this constraint */ 05441 } *aConstraintUsage; 05442 int idxNum; /* Number used to identify the index */ 05443 char *idxStr; /* String, possibly obtained from sqlite3_malloc */ 05444 int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */ 05445 int orderByConsumed; /* True if output is already ordered */ 05446 double estimatedCost; /* Estimated cost of using this index */ 05447 }; 05448 05449 /* 05450 ** CAPI3REF: Virtual Table Constraint Operator Codes 05451 ** 05452 ** These macros defined the allowed values for the 05453 ** [sqlite3_index_info].aConstraint[].op field. Each value represents 05454 ** an operator that is part of a constraint term in the wHERE clause of 05455 ** a query that uses a [virtual table]. 05456 */ 05457 #define SQLITE_INDEX_CONSTRAINT_EQ 2 05458 #define SQLITE_INDEX_CONSTRAINT_GT 4 05459 #define SQLITE_INDEX_CONSTRAINT_LE 8 05460 #define SQLITE_INDEX_CONSTRAINT_LT 16 05461 #define SQLITE_INDEX_CONSTRAINT_GE 32 05462 #define SQLITE_INDEX_CONSTRAINT_MATCH 64 05463 05464 /* 05465 ** CAPI3REF: Register A Virtual Table Implementation 05466 ** 05467 ** ^These routines are used to register a new [virtual table module] name. 05468 ** ^Module names must be registered before 05469 ** creating a new [virtual table] using the module and before using a 05470 ** preexisting [virtual table] for the module. 05471 ** 05472 ** ^The module name is registered on the [database connection] specified 05473 ** by the first parameter. ^The name of the module is given by the 05474 ** second parameter. ^The third parameter is a pointer to 05475 ** the implementation of the [virtual table module]. ^The fourth 05476 ** parameter is an arbitrary client data pointer that is passed through 05477 ** into the [xCreate] and [xConnect] methods of the virtual table module 05478 ** when a new virtual table is be being created or reinitialized. 05479 ** 05480 ** ^The sqlite3_create_module_v2() interface has a fifth parameter which 05481 ** is a pointer to a destructor for the pClientData. ^SQLite will 05482 ** invoke the destructor function (if it is not NULL) when SQLite 05483 ** no longer needs the pClientData pointer. ^The destructor will also 05484 ** be invoked if the call to sqlite3_create_module_v2() fails. 05485 ** ^The sqlite3_create_module() 05486 ** interface is equivalent to sqlite3_create_module_v2() with a NULL 05487 ** destructor. 05488 */ 05489 SQLITE_API int sqlite3_create_module( 05490 sqlite3 *db, /* SQLite connection to register module with */ 05491 const char *zName, /* Name of the module */ 05492 const sqlite3_module *p, /* Methods for the module */ 05493 void *pClientData /* Client data for xCreate/xConnect */ 05494 ); 05495 SQLITE_API int sqlite3_create_module_v2( 05496 sqlite3 *db, /* SQLite connection to register module with */ 05497 const char *zName, /* Name of the module */ 05498 const sqlite3_module *p, /* Methods for the module */ 05499 void *pClientData, /* Client data for xCreate/xConnect */ 05500 void(*xDestroy)(void*) /* Module destructor function */ 05501 ); 05502 05503 /* 05504 ** CAPI3REF: Virtual Table Instance Object 05505 ** KEYWORDS: sqlite3_vtab 05506 ** 05507 ** Every [virtual table module] implementation uses a subclass 05508 ** of this object to describe a particular instance 05509 ** of the [virtual table]. Each subclass will 05510 ** be tailored to the specific needs of the module implementation. 05511 ** The purpose of this superclass is to define certain fields that are 05512 ** common to all module implementations. 05513 ** 05514 ** ^Virtual tables methods can set an error message by assigning a 05515 ** string obtained from [sqlite3_mprintf()] to zErrMsg. The method should 05516 ** take care that any prior string is freed by a call to [sqlite3_free()] 05517 ** prior to assigning a new string to zErrMsg. ^After the error message 05518 ** is delivered up to the client application, the string will be automatically 05519 ** freed by sqlite3_free() and the zErrMsg field will be zeroed. 05520 */ 05521 struct sqlite3_vtab { 05522 const sqlite3_module *pModule; /* The module for this virtual table */ 05523 int nRef; /* NO LONGER USED */ 05524 char *zErrMsg; /* Error message from sqlite3_mprintf() */ 05525 /* Virtual table implementations will typically add additional fields */ 05526 }; 05527 05528 /* 05529 ** CAPI3REF: Virtual Table Cursor Object 05530 ** KEYWORDS: sqlite3_vtab_cursor {virtual table cursor} 05531 ** 05532 ** Every [virtual table module] implementation uses a subclass of the 05533 ** following structure to describe cursors that point into the 05534 ** [virtual table] and are used 05535 ** to loop through the virtual table. Cursors are created using the 05536 ** [sqlite3_module.xOpen | xOpen] method of the module and are destroyed 05537 ** by the [sqlite3_module.xClose | xClose] method. Cursors are used 05538 ** by the [xFilter], [xNext], [xEof], [xColumn], and [xRowid] methods 05539 ** of the module. Each module implementation will define 05540 ** the content of a cursor structure to suit its own needs. 05541 ** 05542 ** This superclass exists in order to define fields of the cursor that 05543 ** are common to all implementations. 05544 */ 05545 struct sqlite3_vtab_cursor { 05546 sqlite3_vtab *pVtab; /* Virtual table of this cursor */ 05547 /* Virtual table implementations will typically add additional fields */ 05548 }; 05549 05550 /* 05551 ** CAPI3REF: Declare The Schema Of A Virtual Table 05552 ** 05553 ** ^The [xCreate] and [xConnect] methods of a 05554 ** [virtual table module] call this interface 05555 ** to declare the format (the names and datatypes of the columns) of 05556 ** the virtual tables they implement. 05557 */ 05558 SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL); 05559 05560 /* 05561 ** CAPI3REF: Overload A Function For A Virtual Table 05562 ** 05563 ** ^(Virtual tables can provide alternative implementations of functions 05564 ** using the [xFindFunction] method of the [virtual table module]. 05565 ** But global versions of those functions 05566 ** must exist in order to be overloaded.)^ 05567 ** 05568 ** ^(This API makes sure a global version of a function with a particular 05569 ** name and number of parameters exists. If no such function exists 05570 ** before this API is called, a new function is created.)^ ^The implementation 05571 ** of the new function always causes an exception to be thrown. So 05572 ** the new function is not good for anything by itself. Its only 05573 ** purpose is to be a placeholder function that can be overloaded 05574 ** by a [virtual table]. 05575 */ 05576 SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg); 05577 05578 /* 05579 ** The interface to the virtual-table mechanism defined above (back up 05580 ** to a comment remarkably similar to this one) is currently considered 05581 ** to be experimental. The interface might change in incompatible ways. 05582 ** If this is a problem for you, do not use the interface at this time. 05583 ** 05584 ** When the virtual-table mechanism stabilizes, we will declare the 05585 ** interface fixed, support it indefinitely, and remove this comment. 05586 */ 05587 05588 /* 05589 ** CAPI3REF: A Handle To An Open BLOB 05590 ** KEYWORDS: {BLOB handle} {BLOB handles} 05591 ** 05592 ** An instance of this object represents an open BLOB on which 05593 ** [sqlite3_blob_open | incremental BLOB I/O] can be performed. 05594 ** ^Objects of this type are created by [sqlite3_blob_open()] 05595 ** and destroyed by [sqlite3_blob_close()]. 05596 ** ^The [sqlite3_blob_read()] and [sqlite3_blob_write()] interfaces 05597 ** can be used to read or write small subsections of the BLOB. 05598 ** ^The [sqlite3_blob_bytes()] interface returns the size of the BLOB in bytes. 05599 */ 05600 typedef struct sqlite3_blob sqlite3_blob; 05601 05602 /* 05603 ** CAPI3REF: Open A BLOB For Incremental I/O 05604 ** 05605 ** ^(This interfaces opens a [BLOB handle | handle] to the BLOB located 05606 ** in row iRow, column zColumn, table zTable in database zDb; 05607 ** in other words, the same BLOB that would be selected by: 05608 ** 05609 ** <pre> 05610 ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow; 05611 ** </pre>)^ 05612 ** 05613 ** ^If the flags parameter is non-zero, then the BLOB is opened for read 05614 ** and write access. ^If it is zero, the BLOB is opened for read access. 05615 ** ^It is not possible to open a column that is part of an index or primary 05616 ** key for writing. ^If [foreign key constraints] are enabled, it is 05617 ** not possible to open a column that is part of a [child key] for writing. 05618 ** 05619 ** ^Note that the database name is not the filename that contains 05620 ** the database but rather the symbolic name of the database that 05621 ** appears after the AS keyword when the database is connected using [ATTACH]. 05622 ** ^For the main database file, the database name is "main". 05623 ** ^For TEMP tables, the database name is "temp". 05624 ** 05625 ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is written 05626 ** to *ppBlob. Otherwise an [error code] is returned and *ppBlob is set 05627 ** to be a null pointer.)^ 05628 ** ^This function sets the [database connection] error code and message 05629 ** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()] and related 05630 ** functions. ^Note that the *ppBlob variable is always initialized in a 05631 ** way that makes it safe to invoke [sqlite3_blob_close()] on *ppBlob 05632 ** regardless of the success or failure of this routine. 05633 ** 05634 ** ^(If the row that a BLOB handle points to is modified by an 05635 ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects 05636 ** then the BLOB handle is marked as "expired". 05637 ** This is true if any column of the row is changed, even a column 05638 ** other than the one the BLOB handle is open on.)^ 05639 ** ^Calls to [sqlite3_blob_read()] and [sqlite3_blob_write()] for 05640 ** an expired BLOB handle fail with a return code of [SQLITE_ABORT]. 05641 ** ^(Changes written into a BLOB prior to the BLOB expiring are not 05642 ** rolled back by the expiration of the BLOB. Such changes will eventually 05643 ** commit if the transaction continues to completion.)^ 05644 ** 05645 ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of 05646 ** the opened blob. ^The size of a blob may not be changed by this 05647 ** interface. Use the [UPDATE] SQL command to change the size of a 05648 ** blob. 05649 ** 05650 ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces 05651 ** and the built-in [zeroblob] SQL function can be used, if desired, 05652 ** to create an empty, zero-filled blob in which to read or write using 05653 ** this interface. 05654 ** 05655 ** To avoid a resource leak, every open [BLOB handle] should eventually 05656 ** be released by a call to [sqlite3_blob_close()]. 05657 */ 05658 SQLITE_API int sqlite3_blob_open( 05659 sqlite3*, 05660 const char *zDb, 05661 const char *zTable, 05662 const char *zColumn, 05663 sqlite3_int64 iRow, 05664 int flags, 05665 sqlite3_blob **ppBlob 05666 ); 05667 05668 /* 05669 ** CAPI3REF: Move a BLOB Handle to a New Row 05670 ** 05671 ** ^This function is used to move an existing blob handle so that it points 05672 ** to a different row of the same database table. ^The new row is identified 05673 ** by the rowid value passed as the second argument. Only the row can be 05674 ** changed. ^The database, table and column on which the blob handle is open 05675 ** remain the same. Moving an existing blob handle to a new row can be 05676 ** faster than closing the existing handle and opening a new one. 05677 ** 05678 ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] - 05679 ** it must exist and there must be either a blob or text value stored in 05680 ** the nominated column.)^ ^If the new row is not present in the table, or if 05681 ** it does not contain a blob or text value, or if another error occurs, an 05682 ** SQLite error code is returned and the blob handle is considered aborted. 05683 ** ^All subsequent calls to [sqlite3_blob_read()], [sqlite3_blob_write()] or 05684 ** [sqlite3_blob_reopen()] on an aborted blob handle immediately return 05685 ** SQLITE_ABORT. ^Calling [sqlite3_blob_bytes()] on an aborted blob handle 05686 ** always returns zero. 05687 ** 05688 ** ^This function sets the database handle error code and message. 05689 */ 05690 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); 05691 05692 /* 05693 ** CAPI3REF: Close A BLOB Handle 05694 ** 05695 ** ^Closes an open [BLOB handle]. 05696 ** 05697 ** ^Closing a BLOB shall cause the current transaction to commit 05698 ** if there are no other BLOBs, no pending prepared statements, and the 05699 ** database connection is in [autocommit mode]. 05700 ** ^If any writes were made to the BLOB, they might be held in cache 05701 ** until the close operation if they will fit. 05702 ** 05703 ** ^(Closing the BLOB often forces the changes 05704 ** out to disk and so if any I/O errors occur, they will likely occur 05705 ** at the time when the BLOB is closed. Any errors that occur during 05706 ** closing are reported as a non-zero return value.)^ 05707 ** 05708 ** ^(The BLOB is closed unconditionally. Even if this routine returns 05709 ** an error code, the BLOB is still closed.)^ 05710 ** 05711 ** ^Calling this routine with a null pointer (such as would be returned 05712 ** by a failed call to [sqlite3_blob_open()]) is a harmless no-op. 05713 */ 05714 SQLITE_API int sqlite3_blob_close(sqlite3_blob *); 05715 05716 /* 05717 ** CAPI3REF: Return The Size Of An Open BLOB 05718 ** 05719 ** ^Returns the size in bytes of the BLOB accessible via the 05720 ** successfully opened [BLOB handle] in its only argument. ^The 05721 ** incremental blob I/O routines can only read or overwriting existing 05722 ** blob content; they cannot change the size of a blob. 05723 ** 05724 ** This routine only works on a [BLOB handle] which has been created 05725 ** by a prior successful call to [sqlite3_blob_open()] and which has not 05726 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in 05727 ** to this routine results in undefined and probably undesirable behavior. 05728 */ 05729 SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *); 05730 05731 /* 05732 ** CAPI3REF: Read Data From A BLOB Incrementally 05733 ** 05734 ** ^(This function is used to read data from an open [BLOB handle] into a 05735 ** caller-supplied buffer. N bytes of data are copied into buffer Z 05736 ** from the open BLOB, starting at offset iOffset.)^ 05737 ** 05738 ** ^If offset iOffset is less than N bytes from the end of the BLOB, 05739 ** [SQLITE_ERROR] is returned and no data is read. ^If N or iOffset is 05740 ** less than zero, [SQLITE_ERROR] is returned and no data is read. 05741 ** ^The size of the blob (and hence the maximum value of N+iOffset) 05742 ** can be determined using the [sqlite3_blob_bytes()] interface. 05743 ** 05744 ** ^An attempt to read from an expired [BLOB handle] fails with an 05745 ** error code of [SQLITE_ABORT]. 05746 ** 05747 ** ^(On success, sqlite3_blob_read() returns SQLITE_OK. 05748 ** Otherwise, an [error code] or an [extended error code] is returned.)^ 05749 ** 05750 ** This routine only works on a [BLOB handle] which has been created 05751 ** by a prior successful call to [sqlite3_blob_open()] and which has not 05752 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in 05753 ** to this routine results in undefined and probably undesirable behavior. 05754 ** 05755 ** See also: [sqlite3_blob_write()]. 05756 */ 05757 SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); 05758 05759 /* 05760 ** CAPI3REF: Write Data Into A BLOB Incrementally 05761 ** 05762 ** ^This function is used to write data into an open [BLOB handle] from a 05763 ** caller-supplied buffer. ^N bytes of data are copied from the buffer Z 05764 ** into the open BLOB, starting at offset iOffset. 05765 ** 05766 ** ^If the [BLOB handle] passed as the first argument was not opened for 05767 ** writing (the flags parameter to [sqlite3_blob_open()] was zero), 05768 ** this function returns [SQLITE_READONLY]. 05769 ** 05770 ** ^This function may only modify the contents of the BLOB; it is 05771 ** not possible to increase the size of a BLOB using this API. 05772 ** ^If offset iOffset is less than N bytes from the end of the BLOB, 05773 ** [SQLITE_ERROR] is returned and no data is written. ^If N is 05774 ** less than zero [SQLITE_ERROR] is returned and no data is written. 05775 ** The size of the BLOB (and hence the maximum value of N+iOffset) 05776 ** can be determined using the [sqlite3_blob_bytes()] interface. 05777 ** 05778 ** ^An attempt to write to an expired [BLOB handle] fails with an 05779 ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred 05780 ** before the [BLOB handle] expired are not rolled back by the 05781 ** expiration of the handle, though of course those changes might 05782 ** have been overwritten by the statement that expired the BLOB handle 05783 ** or by other independent statements. 05784 ** 05785 ** ^(On success, sqlite3_blob_write() returns SQLITE_OK. 05786 ** Otherwise, an [error code] or an [extended error code] is returned.)^ 05787 ** 05788 ** This routine only works on a [BLOB handle] which has been created 05789 ** by a prior successful call to [sqlite3_blob_open()] and which has not 05790 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in 05791 ** to this routine results in undefined and probably undesirable behavior. 05792 ** 05793 ** See also: [sqlite3_blob_read()]. 05794 */ 05795 SQLITE_API int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset); 05796 05797 /* 05798 ** CAPI3REF: Virtual File System Objects 05799 ** 05800 ** A virtual filesystem (VFS) is an [sqlite3_vfs] object 05801 ** that SQLite uses to interact 05802 ** with the underlying operating system. Most SQLite builds come with a 05803 ** single default VFS that is appropriate for the host computer. 05804 ** New VFSes can be registered and existing VFSes can be unregistered. 05805 ** The following interfaces are provided. 05806 ** 05807 ** ^The sqlite3_vfs_find() interface returns a pointer to a VFS given its name. 05808 ** ^Names are case sensitive. 05809 ** ^Names are zero-terminated UTF-8 strings. 05810 ** ^If there is no match, a NULL pointer is returned. 05811 ** ^If zVfsName is NULL then the default VFS is returned. 05812 ** 05813 ** ^New VFSes are registered with sqlite3_vfs_register(). 05814 ** ^Each new VFS becomes the default VFS if the makeDflt flag is set. 05815 ** ^The same VFS can be registered multiple times without injury. 05816 ** ^To make an existing VFS into the default VFS, register it again 05817 ** with the makeDflt flag set. If two different VFSes with the 05818 ** same name are registered, the behavior is undefined. If a 05819 ** VFS is registered with a name that is NULL or an empty string, 05820 ** then the behavior is undefined. 05821 ** 05822 ** ^Unregister a VFS with the sqlite3_vfs_unregister() interface. 05823 ** ^(If the default VFS is unregistered, another VFS is chosen as 05824 ** the default. The choice for the new VFS is arbitrary.)^ 05825 */ 05826 SQLITE_API sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName); 05827 SQLITE_API int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt); 05828 SQLITE_API int sqlite3_vfs_unregister(sqlite3_vfs*); 05829 05830 /* 05831 ** CAPI3REF: Mutexes 05832 ** 05833 ** The SQLite core uses these routines for thread 05834 ** synchronization. Though they are intended for internal 05835 ** use by SQLite, code that links against SQLite is 05836 ** permitted to use any of these routines. 05837 ** 05838 ** The SQLite source code contains multiple implementations 05839 ** of these mutex routines. An appropriate implementation 05840 ** is selected automatically at compile-time. ^(The following 05841 ** implementations are available in the SQLite core: 05842 ** 05843 ** <ul> 05844 ** <li> SQLITE_MUTEX_OS2 05845 ** <li> SQLITE_MUTEX_PTHREAD 05846 ** <li> SQLITE_MUTEX_W32 05847 ** <li> SQLITE_MUTEX_NOOP 05848 ** </ul>)^ 05849 ** 05850 ** ^The SQLITE_MUTEX_NOOP implementation is a set of routines 05851 ** that does no real locking and is appropriate for use in 05852 ** a single-threaded application. ^The SQLITE_MUTEX_OS2, 05853 ** SQLITE_MUTEX_PTHREAD, and SQLITE_MUTEX_W32 implementations 05854 ** are appropriate for use on OS/2, Unix, and Windows. 05855 ** 05856 ** ^(If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor 05857 ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex 05858 ** implementation is included with the library. In this case the 05859 ** application must supply a custom mutex implementation using the 05860 ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function 05861 ** before calling sqlite3_initialize() or any other public sqlite3_ 05862 ** function that calls sqlite3_initialize().)^ 05863 ** 05864 ** ^The sqlite3_mutex_alloc() routine allocates a new 05865 ** mutex and returns a pointer to it. ^If it returns NULL 05866 ** that means that a mutex could not be allocated. ^SQLite 05867 ** will unwind its stack and return an error. ^(The argument 05868 ** to sqlite3_mutex_alloc() is one of these integer constants: 05869 ** 05870 ** <ul> 05871 ** <li> SQLITE_MUTEX_FAST 05872 ** <li> SQLITE_MUTEX_RECURSIVE 05873 ** <li> SQLITE_MUTEX_STATIC_MASTER 05874 ** <li> SQLITE_MUTEX_STATIC_MEM 05875 ** <li> SQLITE_MUTEX_STATIC_MEM2 05876 ** <li> SQLITE_MUTEX_STATIC_PRNG 05877 ** <li> SQLITE_MUTEX_STATIC_LRU 05878 ** <li> SQLITE_MUTEX_STATIC_LRU2 05879 ** </ul>)^ 05880 ** 05881 ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) 05882 ** cause sqlite3_mutex_alloc() to create 05883 ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE 05884 ** is used but not necessarily so when SQLITE_MUTEX_FAST is used. 05885 ** The mutex implementation does not need to make a distinction 05886 ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does 05887 ** not want to. ^SQLite will only request a recursive mutex in 05888 ** cases where it really needs one. ^If a faster non-recursive mutex 05889 ** implementation is available on the host platform, the mutex subsystem 05890 ** might return such a mutex in response to SQLITE_MUTEX_FAST. 05891 ** 05892 ** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other 05893 ** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return 05894 ** a pointer to a static preexisting mutex. ^Six static mutexes are 05895 ** used by the current version of SQLite. Future versions of SQLite 05896 ** may add additional static mutexes. Static mutexes are for internal 05897 ** use by SQLite only. Applications that use SQLite mutexes should 05898 ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or 05899 ** SQLITE_MUTEX_RECURSIVE. 05900 ** 05901 ** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST 05902 ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc() 05903 ** returns a different mutex on every call. ^But for the static 05904 ** mutex types, the same mutex is returned on every call that has 05905 ** the same type number. 05906 ** 05907 ** ^The sqlite3_mutex_free() routine deallocates a previously 05908 ** allocated dynamic mutex. ^SQLite is careful to deallocate every 05909 ** dynamic mutex that it allocates. The dynamic mutexes must not be in 05910 ** use when they are deallocated. Attempting to deallocate a static 05911 ** mutex results in undefined behavior. ^SQLite never deallocates 05912 ** a static mutex. 05913 ** 05914 ** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt 05915 ** to enter a mutex. ^If another thread is already within the mutex, 05916 ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return 05917 ** SQLITE_BUSY. ^The sqlite3_mutex_try() interface returns [SQLITE_OK] 05918 ** upon successful entry. ^(Mutexes created using 05919 ** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread. 05920 ** In such cases the, 05921 ** mutex must be exited an equal number of times before another thread 05922 ** can enter.)^ ^(If the same thread tries to enter any other 05923 ** kind of mutex more than once, the behavior is undefined. 05924 ** SQLite will never exhibit 05925 ** such behavior in its own use of mutexes.)^ 05926 ** 05927 ** ^(Some systems (for example, Windows 95) do not support the operation 05928 ** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try() 05929 ** will always return SQLITE_BUSY. The SQLite core only ever uses 05930 ** sqlite3_mutex_try() as an optimization so this is acceptable behavior.)^ 05931 ** 05932 ** ^The sqlite3_mutex_leave() routine exits a mutex that was 05933 ** previously entered by the same thread. ^(The behavior 05934 ** is undefined if the mutex is not currently entered by the 05935 ** calling thread or is not currently allocated. SQLite will 05936 ** never do either.)^ 05937 ** 05938 ** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or 05939 ** sqlite3_mutex_leave() is a NULL pointer, then all three routines 05940 ** behave as no-ops. 05941 ** 05942 ** See also: [sqlite3_mutex_held()] and [sqlite3_mutex_notheld()]. 05943 */ 05944 SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int); 05945 SQLITE_API void sqlite3_mutex_free(sqlite3_mutex*); 05946 SQLITE_API void sqlite3_mutex_enter(sqlite3_mutex*); 05947 SQLITE_API int sqlite3_mutex_try(sqlite3_mutex*); 05948 SQLITE_API void sqlite3_mutex_leave(sqlite3_mutex*); 05949 05950 /* 05951 ** CAPI3REF: Mutex Methods Object 05952 ** 05953 ** An instance of this structure defines the low-level routines 05954 ** used to allocate and use mutexes. 05955 ** 05956 ** Usually, the default mutex implementations provided by SQLite are 05957 ** sufficient, however the user has the option of substituting a custom 05958 ** implementation for specialized deployments or systems for which SQLite 05959 ** does not provide a suitable implementation. In this case, the user 05960 ** creates and populates an instance of this structure to pass 05961 ** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option. 05962 ** Additionally, an instance of this structure can be used as an 05963 ** output variable when querying the system for the current mutex 05964 ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option. 05965 ** 05966 ** ^The xMutexInit method defined by this structure is invoked as 05967 ** part of system initialization by the sqlite3_initialize() function. 05968 ** ^The xMutexInit routine is called by SQLite exactly once for each 05969 ** effective call to [sqlite3_initialize()]. 05970 ** 05971 ** ^The xMutexEnd method defined by this structure is invoked as 05972 ** part of system shutdown by the sqlite3_shutdown() function. The 05973 ** implementation of this method is expected to release all outstanding 05974 ** resources obtained by the mutex methods implementation, especially 05975 ** those obtained by the xMutexInit method. ^The xMutexEnd() 05976 ** interface is invoked exactly once for each call to [sqlite3_shutdown()]. 05977 ** 05978 ** ^(The remaining seven methods defined by this structure (xMutexAlloc, 05979 ** xMutexFree, xMutexEnter, xMutexTry, xMutexLeave, xMutexHeld and 05980 ** xMutexNotheld) implement the following interfaces (respectively): 05981 ** 05982 ** <ul> 05983 ** <li> [sqlite3_mutex_alloc()] </li> 05984 ** <li> [sqlite3_mutex_free()] </li> 05985 ** <li> [sqlite3_mutex_enter()] </li> 05986 ** <li> [sqlite3_mutex_try()] </li> 05987 ** <li> [sqlite3_mutex_leave()] </li> 05988 ** <li> [sqlite3_mutex_held()] </li> 05989 ** <li> [sqlite3_mutex_notheld()] </li> 05990 ** </ul>)^ 05991 ** 05992 ** The only difference is that the public sqlite3_XXX functions enumerated 05993 ** above silently ignore any invocations that pass a NULL pointer instead 05994 ** of a valid mutex handle. The implementations of the methods defined 05995 ** by this structure are not required to handle this case, the results 05996 ** of passing a NULL pointer instead of a valid mutex handle are undefined 05997 ** (i.e. it is acceptable to provide an implementation that segfaults if 05998 ** it is passed a NULL pointer). 05999 ** 06000 ** The xMutexInit() method must be threadsafe. ^It must be harmless to 06001 ** invoke xMutexInit() multiple times within the same process and without 06002 ** intervening calls to xMutexEnd(). Second and subsequent calls to 06003 ** xMutexInit() must be no-ops. 06004 ** 06005 ** ^xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()] 06006 ** and its associates). ^Similarly, xMutexAlloc() must not use SQLite memory 06007 ** allocation for a static mutex. ^However xMutexAlloc() may use SQLite 06008 ** memory allocation for a fast or recursive mutex. 06009 ** 06010 ** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is 06011 ** called, but only if the prior call to xMutexInit returned SQLITE_OK. 06012 ** If xMutexInit fails in any way, it is expected to clean up after itself 06013 ** prior to returning. 06014 */ 06015 typedef struct sqlite3_mutex_methods sqlite3_mutex_methods; 06016 struct sqlite3_mutex_methods { 06017 int (*xMutexInit)(void); 06018 int (*xMutexEnd)(void); 06019 sqlite3_mutex *(*xMutexAlloc)(int); 06020 void (*xMutexFree)(sqlite3_mutex *); 06021 void (*xMutexEnter)(sqlite3_mutex *); 06022 int (*xMutexTry)(sqlite3_mutex *); 06023 void (*xMutexLeave)(sqlite3_mutex *); 06024 int (*xMutexHeld)(sqlite3_mutex *); 06025 int (*xMutexNotheld)(sqlite3_mutex *); 06026 }; 06027 06028 /* 06029 ** CAPI3REF: Mutex Verification Routines 06030 ** 06031 ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines 06032 ** are intended for use inside assert() statements. ^The SQLite core 06033 ** never uses these routines except inside an assert() and applications 06034 ** are advised to follow the lead of the core. ^The SQLite core only 06035 ** provides implementations for these routines when it is compiled 06036 ** with the SQLITE_DEBUG flag. ^External mutex implementations 06037 ** are only required to provide these routines if SQLITE_DEBUG is 06038 ** defined and if NDEBUG is not defined. 06039 ** 06040 ** ^These routines should return true if the mutex in their argument 06041 ** is held or not held, respectively, by the calling thread. 06042 ** 06043 ** ^The implementation is not required to provided versions of these 06044 ** routines that actually work. If the implementation does not provide working 06045 ** versions of these routines, it should at least provide stubs that always 06046 ** return true so that one does not get spurious assertion failures. 06047 ** 06048 ** ^If the argument to sqlite3_mutex_held() is a NULL pointer then 06049 ** the routine should return 1. This seems counter-intuitive since 06050 ** clearly the mutex cannot be held if it does not exist. But 06051 ** the reason the mutex does not exist is because the build is not 06052 ** using mutexes. And we do not want the assert() containing the 06053 ** call to sqlite3_mutex_held() to fail, so a non-zero return is 06054 ** the appropriate thing to do. ^The sqlite3_mutex_notheld() 06055 ** interface should also return 1 when given a NULL pointer. 06056 */ 06057 #ifndef NDEBUG 06058 SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*); 06059 SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*); 06060 #endif 06061 06062 /* 06063 ** CAPI3REF: Mutex Types 06064 ** 06065 ** The [sqlite3_mutex_alloc()] interface takes a single argument 06066 ** which is one of these integer constants. 06067 ** 06068 ** The set of static mutexes may change from one SQLite release to the 06069 ** next. Applications that override the built-in mutex logic must be 06070 ** prepared to accommodate additional static mutexes. 06071 */ 06072 #define SQLITE_MUTEX_FAST 0 06073 #define SQLITE_MUTEX_RECURSIVE 1 06074 #define SQLITE_MUTEX_STATIC_MASTER 2 06075 #define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */ 06076 #define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */ 06077 #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */ 06078 #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_random() */ 06079 #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */ 06080 #define SQLITE_MUTEX_STATIC_LRU2 7 /* NOT USED */ 06081 #define SQLITE_MUTEX_STATIC_PMEM 7 /* sqlite3PageMalloc() */ 06082 06083 /* 06084 ** CAPI3REF: Retrieve the mutex for a database connection 06085 ** 06086 ** ^This interface returns a pointer the [sqlite3_mutex] object that 06087 ** serializes access to the [database connection] given in the argument 06088 ** when the [threading mode] is Serialized. 06089 ** ^If the [threading mode] is Single-thread or Multi-thread then this 06090 ** routine returns a NULL pointer. 06091 */ 06092 SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3*); 06093 06094 /* 06095 ** CAPI3REF: Low-Level Control Of Database Files 06096 ** 06097 ** ^The [sqlite3_file_control()] interface makes a direct call to the 06098 ** xFileControl method for the [sqlite3_io_methods] object associated 06099 ** with a particular database identified by the second argument. ^The 06100 ** name of the database is "main" for the main database or "temp" for the 06101 ** TEMP database, or the name that appears after the AS keyword for 06102 ** databases that are added using the [ATTACH] SQL command. 06103 ** ^A NULL pointer can be used in place of "main" to refer to the 06104 ** main database file. 06105 ** ^The third and fourth parameters to this routine 06106 ** are passed directly through to the second and third parameters of 06107 ** the xFileControl method. ^The return value of the xFileControl 06108 ** method becomes the return value of this routine. 06109 ** 06110 ** ^The SQLITE_FCNTL_FILE_POINTER value for the op parameter causes 06111 ** a pointer to the underlying [sqlite3_file] object to be written into 06112 ** the space pointed to by the 4th parameter. ^The SQLITE_FCNTL_FILE_POINTER 06113 ** case is a short-circuit path which does not actually invoke the 06114 ** underlying sqlite3_io_methods.xFileControl method. 06115 ** 06116 ** ^If the second parameter (zDbName) does not match the name of any 06117 ** open database file, then SQLITE_ERROR is returned. ^This error 06118 ** code is not remembered and will not be recalled by [sqlite3_errcode()] 06119 ** or [sqlite3_errmsg()]. The underlying xFileControl method might 06120 ** also return SQLITE_ERROR. There is no way to distinguish between 06121 ** an incorrect zDbName and an SQLITE_ERROR return from the underlying 06122 ** xFileControl method. 06123 ** 06124 ** See also: [SQLITE_FCNTL_LOCKSTATE] 06125 */ 06126 SQLITE_API int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*); 06127 06128 /* 06129 ** CAPI3REF: Testing Interface 06130 ** 06131 ** ^The sqlite3_test_control() interface is used to read out internal 06132 ** state of SQLite and to inject faults into SQLite for testing 06133 ** purposes. ^The first parameter is an operation code that determines 06134 ** the number, meaning, and operation of all subsequent parameters. 06135 ** 06136 ** This interface is not for use by applications. It exists solely 06137 ** for verifying the correct operation of the SQLite library. Depending 06138 ** on how the SQLite library is compiled, this interface might not exist. 06139 ** 06140 ** The details of the operation codes, their meanings, the parameters 06141 ** they take, and what they do are all subject to change without notice. 06142 ** Unlike most of the SQLite API, this function is not guaranteed to 06143 ** operate consistently from one release to the next. 06144 */ 06145 SQLITE_API int sqlite3_test_control(int op, ...); 06146 06147 /* 06148 ** CAPI3REF: Testing Interface Operation Codes 06149 ** 06150 ** These constants are the valid operation code parameters used 06151 ** as the first argument to [sqlite3_test_control()]. 06152 ** 06153 ** These parameters and their meanings are subject to change 06154 ** without notice. These values are for testing purposes only. 06155 ** Applications should not use any of these parameters or the 06156 ** [sqlite3_test_control()] interface. 06157 */ 06158 #define SQLITE_TESTCTRL_FIRST 5 06159 #define SQLITE_TESTCTRL_PRNG_SAVE 5 06160 #define SQLITE_TESTCTRL_PRNG_RESTORE 6 06161 #define SQLITE_TESTCTRL_PRNG_RESET 7 06162 #define SQLITE_TESTCTRL_BITVEC_TEST 8 06163 #define SQLITE_TESTCTRL_FAULT_INSTALL 9 06164 #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS 10 06165 #define SQLITE_TESTCTRL_PENDING_BYTE 11 06166 #define SQLITE_TESTCTRL_ASSERT 12 06167 #define SQLITE_TESTCTRL_ALWAYS 13 06168 #define SQLITE_TESTCTRL_RESERVE 14 06169 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15 06170 #define SQLITE_TESTCTRL_ISKEYWORD 16 06171 #define SQLITE_TESTCTRL_PGHDRSZ 17 06172 #define SQLITE_TESTCTRL_SCRATCHMALLOC 18 06173 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 19 06174 #define SQLITE_TESTCTRL_LAST 19 06175 06176 /* 06177 ** CAPI3REF: SQLite Runtime Status 06178 ** 06179 ** ^This interface is used to retrieve runtime status information 06180 ** about the performance of SQLite, and optionally to reset various 06181 ** highwater marks. ^The first argument is an integer code for 06182 ** the specific parameter to measure. ^(Recognized integer codes 06183 ** are of the form [status parameters | SQLITE_STATUS_...].)^ 06184 ** ^The current value of the parameter is returned into *pCurrent. 06185 ** ^The highest recorded value is returned in *pHighwater. ^If the 06186 ** resetFlag is true, then the highest record value is reset after 06187 ** *pHighwater is written. ^(Some parameters do not record the highest 06188 ** value. For those parameters 06189 ** nothing is written into *pHighwater and the resetFlag is ignored.)^ 06190 ** ^(Other parameters record only the highwater mark and not the current 06191 ** value. For these latter parameters nothing is written into *pCurrent.)^ 06192 ** 06193 ** ^The sqlite3_status() routine returns SQLITE_OK on success and a 06194 ** non-zero [error code] on failure. 06195 ** 06196 ** This routine is threadsafe but is not atomic. This routine can be 06197 ** called while other threads are running the same or different SQLite 06198 ** interfaces. However the values returned in *pCurrent and 06199 ** *pHighwater reflect the status of SQLite at different points in time 06200 ** and it is possible that another thread might change the parameter 06201 ** in between the times when *pCurrent and *pHighwater are written. 06202 ** 06203 ** See also: [sqlite3_db_status()] 06204 */ 06205 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag); 06206 06207 06208 /* 06209 ** CAPI3REF: Status Parameters 06210 ** KEYWORDS: {status parameters} 06211 ** 06212 ** These integer constants designate various run-time status parameters 06213 ** that can be returned by [sqlite3_status()]. 06214 ** 06215 ** <dl> 06216 ** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt> 06217 ** <dd>This parameter is the current amount of memory checked out 06218 ** using [sqlite3_malloc()], either directly or indirectly. The 06219 ** figure includes calls made to [sqlite3_malloc()] by the application 06220 ** and internal memory usage by the SQLite library. Scratch memory 06221 ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache 06222 ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in 06223 ** this parameter. The amount returned is the sum of the allocation 06224 ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^ 06225 ** 06226 ** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt> 06227 ** <dd>This parameter records the largest memory allocation request 06228 ** handed to [sqlite3_malloc()] or [sqlite3_realloc()] (or their 06229 ** internal equivalents). Only the value returned in the 06230 ** *pHighwater parameter to [sqlite3_status()] is of interest. 06231 ** The value written into the *pCurrent parameter is undefined.</dd>)^ 06232 ** 06233 ** [[SQLITE_STATUS_MALLOC_COUNT]] ^(<dt>SQLITE_STATUS_MALLOC_COUNT</dt> 06234 ** <dd>This parameter records the number of separate memory allocations 06235 ** currently checked out.</dd>)^ 06236 ** 06237 ** [[SQLITE_STATUS_PAGECACHE_USED]] ^(<dt>SQLITE_STATUS_PAGECACHE_USED</dt> 06238 ** <dd>This parameter returns the number of pages used out of the 06239 ** [pagecache memory allocator] that was configured using 06240 ** [SQLITE_CONFIG_PAGECACHE]. The 06241 ** value returned is in pages, not in bytes.</dd>)^ 06242 ** 06243 ** [[SQLITE_STATUS_PAGECACHE_OVERFLOW]] 06244 ** ^(<dt>SQLITE_STATUS_PAGECACHE_OVERFLOW</dt> 06245 ** <dd>This parameter returns the number of bytes of page cache 06246 ** allocation which could not be satisfied by the [SQLITE_CONFIG_PAGECACHE] 06247 ** buffer and where forced to overflow to [sqlite3_malloc()]. The 06248 ** returned value includes allocations that overflowed because they 06249 ** where too large (they were larger than the "sz" parameter to 06250 ** [SQLITE_CONFIG_PAGECACHE]) and allocations that overflowed because 06251 ** no space was left in the page cache.</dd>)^ 06252 ** 06253 ** [[SQLITE_STATUS_PAGECACHE_SIZE]] ^(<dt>SQLITE_STATUS_PAGECACHE_SIZE</dt> 06254 ** <dd>This parameter records the largest memory allocation request 06255 ** handed to [pagecache memory allocator]. Only the value returned in the 06256 ** *pHighwater parameter to [sqlite3_status()] is of interest. 06257 ** The value written into the *pCurrent parameter is undefined.</dd>)^ 06258 ** 06259 ** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt> 06260 ** <dd>This parameter returns the number of allocations used out of the 06261 ** [scratch memory allocator] configured using 06262 ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not 06263 ** in bytes. Since a single thread may only have one scratch allocation 06264 ** outstanding at time, this parameter also reports the number of threads 06265 ** using scratch memory at the same time.</dd>)^ 06266 ** 06267 ** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt> 06268 ** <dd>This parameter returns the number of bytes of scratch memory 06269 ** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH] 06270 ** buffer and where forced to overflow to [sqlite3_malloc()]. The values 06271 ** returned include overflows because the requested allocation was too 06272 ** larger (that is, because the requested allocation was larger than the 06273 ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer 06274 ** slots were available. 06275 ** </dd>)^ 06276 ** 06277 ** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt> 06278 ** <dd>This parameter records the largest memory allocation request 06279 ** handed to [scratch memory allocator]. Only the value returned in the 06280 ** *pHighwater parameter to [sqlite3_status()] is of interest. 06281 ** The value written into the *pCurrent parameter is undefined.</dd>)^ 06282 ** 06283 ** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt> 06284 ** <dd>This parameter records the deepest parser stack. It is only 06285 ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^ 06286 ** </dl> 06287 ** 06288 ** New status parameters may be added from time to time. 06289 */ 06290 #define SQLITE_STATUS_MEMORY_USED 0 06291 #define SQLITE_STATUS_PAGECACHE_USED 1 06292 #define SQLITE_STATUS_PAGECACHE_OVERFLOW 2 06293 #define SQLITE_STATUS_SCRATCH_USED 3 06294 #define SQLITE_STATUS_SCRATCH_OVERFLOW 4 06295 #define SQLITE_STATUS_MALLOC_SIZE 5 06296 #define SQLITE_STATUS_PARSER_STACK 6 06297 #define SQLITE_STATUS_PAGECACHE_SIZE 7 06298 #define SQLITE_STATUS_SCRATCH_SIZE 8 06299 #define SQLITE_STATUS_MALLOC_COUNT 9 06300 06301 /* 06302 ** CAPI3REF: Database Connection Status 06303 ** 06304 ** ^This interface is used to retrieve runtime status information 06305 ** about a single [database connection]. ^The first argument is the 06306 ** database connection object to be interrogated. ^The second argument 06307 ** is an integer constant, taken from the set of 06308 ** [SQLITE_DBSTATUS options], that 06309 ** determines the parameter to interrogate. The set of 06310 ** [SQLITE_DBSTATUS options] is likely 06311 ** to grow in future releases of SQLite. 06312 ** 06313 ** ^The current value of the requested parameter is written into *pCur 06314 ** and the highest instantaneous value is written into *pHiwtr. ^If 06315 ** the resetFlg is true, then the highest instantaneous value is 06316 ** reset back down to the current value. 06317 ** 06318 ** ^The sqlite3_db_status() routine returns SQLITE_OK on success and a 06319 ** non-zero [error code] on failure. 06320 ** 06321 ** See also: [sqlite3_status()] and [sqlite3_stmt_status()]. 06322 */ 06323 SQLITE_API int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); 06324 06325 /* 06326 ** CAPI3REF: Status Parameters for database connections 06327 ** KEYWORDS: {SQLITE_DBSTATUS options} 06328 ** 06329 ** These constants are the available integer "verbs" that can be passed as 06330 ** the second argument to the [sqlite3_db_status()] interface. 06331 ** 06332 ** New verbs may be added in future releases of SQLite. Existing verbs 06333 ** might be discontinued. Applications should check the return code from 06334 ** [sqlite3_db_status()] to make sure that the call worked. 06335 ** The [sqlite3_db_status()] interface will return a non-zero error code 06336 ** if a discontinued or unsupported verb is invoked. 06337 ** 06338 ** <dl> 06339 ** [[SQLITE_DBSTATUS_LOOKASIDE_USED]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_USED</dt> 06340 ** <dd>This parameter returns the number of lookaside memory slots currently 06341 ** checked out.</dd>)^ 06342 ** 06343 ** [[SQLITE_DBSTATUS_LOOKASIDE_HIT]] ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_HIT</dt> 06344 ** <dd>This parameter returns the number malloc attempts that were 06345 ** satisfied using lookaside memory. Only the high-water value is meaningful; 06346 ** the current value is always zero.)^ 06347 ** 06348 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE]] 06349 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE</dt> 06350 ** <dd>This parameter returns the number malloc attempts that might have 06351 ** been satisfied using lookaside memory but failed due to the amount of 06352 ** memory requested being larger than the lookaside slot size. 06353 ** Only the high-water value is meaningful; 06354 ** the current value is always zero.)^ 06355 ** 06356 ** [[SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL]] 06357 ** ^(<dt>SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL</dt> 06358 ** <dd>This parameter returns the number malloc attempts that might have 06359 ** been satisfied using lookaside memory but failed due to all lookaside 06360 ** memory already being in use. 06361 ** Only the high-water value is meaningful; 06362 ** the current value is always zero.)^ 06363 ** 06364 ** [[SQLITE_DBSTATUS_CACHE_USED]] ^(<dt>SQLITE_DBSTATUS_CACHE_USED</dt> 06365 ** <dd>This parameter returns the approximate number of of bytes of heap 06366 ** memory used by all pager caches associated with the database connection.)^ 06367 ** ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_USED is always 0. 06368 ** 06369 ** [[SQLITE_DBSTATUS_SCHEMA_USED]] ^(<dt>SQLITE_DBSTATUS_SCHEMA_USED</dt> 06370 ** <dd>This parameter returns the approximate number of of bytes of heap 06371 ** memory used to store the schema for all databases associated 06372 ** with the connection - main, temp, and any [ATTACH]-ed databases.)^ 06373 ** ^The full amount of memory used by the schemas is reported, even if the 06374 ** schema memory is shared with other database connections due to 06375 ** [shared cache mode] being enabled. 06376 ** ^The highwater mark associated with SQLITE_DBSTATUS_SCHEMA_USED is always 0. 06377 ** 06378 ** [[SQLITE_DBSTATUS_STMT_USED]] ^(<dt>SQLITE_DBSTATUS_STMT_USED</dt> 06379 ** <dd>This parameter returns the approximate number of of bytes of heap 06380 ** and lookaside memory used by all prepared statements associated with 06381 ** the database connection.)^ 06382 ** ^The highwater mark associated with SQLITE_DBSTATUS_STMT_USED is always 0. 06383 ** </dd> 06384 ** 06385 ** [[SQLITE_DBSTATUS_CACHE_HIT]] ^(<dt>SQLITE_DBSTATUS_CACHE_HIT</dt> 06386 ** <dd>This parameter returns the number of pager cache hits that have 06387 ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_HIT 06388 ** is always 0. 06389 ** </dd> 06390 ** 06391 ** [[SQLITE_DBSTATUS_CACHE_MISS]] ^(<dt>SQLITE_DBSTATUS_CACHE_MISS</dt> 06392 ** <dd>This parameter returns the number of pager cache misses that have 06393 ** occurred.)^ ^The highwater mark associated with SQLITE_DBSTATUS_CACHE_MISS 06394 ** is always 0. 06395 ** </dd> 06396 ** </dl> 06397 */ 06398 #define SQLITE_DBSTATUS_LOOKASIDE_USED 0 06399 #define SQLITE_DBSTATUS_CACHE_USED 1 06400 #define SQLITE_DBSTATUS_SCHEMA_USED 2 06401 #define SQLITE_DBSTATUS_STMT_USED 3 06402 #define SQLITE_DBSTATUS_LOOKASIDE_HIT 4 06403 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE 5 06404 #define SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL 6 06405 #define SQLITE_DBSTATUS_CACHE_HIT 7 06406 #define SQLITE_DBSTATUS_CACHE_MISS 8 06407 #define SQLITE_DBSTATUS_MAX 8 /* Largest defined DBSTATUS */ 06408 06409 06410 /* 06411 ** CAPI3REF: Prepared Statement Status 06412 ** 06413 ** ^(Each prepared statement maintains various 06414 ** [SQLITE_STMTSTATUS counters] that measure the number 06415 ** of times it has performed specific operations.)^ These counters can 06416 ** be used to monitor the performance characteristics of the prepared 06417 ** statements. For example, if the number of table steps greatly exceeds 06418 ** the number of table searches or result rows, that would tend to indicate 06419 ** that the prepared statement is using a full table scan rather than 06420 ** an index. 06421 ** 06422 ** ^(This interface is used to retrieve and reset counter values from 06423 ** a [prepared statement]. The first argument is the prepared statement 06424 ** object to be interrogated. The second argument 06425 ** is an integer code for a specific [SQLITE_STMTSTATUS counter] 06426 ** to be interrogated.)^ 06427 ** ^The current value of the requested counter is returned. 06428 ** ^If the resetFlg is true, then the counter is reset to zero after this 06429 ** interface call returns. 06430 ** 06431 ** See also: [sqlite3_status()] and [sqlite3_db_status()]. 06432 */ 06433 SQLITE_API int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); 06434 06435 /* 06436 ** CAPI3REF: Status Parameters for prepared statements 06437 ** KEYWORDS: {SQLITE_STMTSTATUS counter} {SQLITE_STMTSTATUS counters} 06438 ** 06439 ** These preprocessor macros define integer codes that name counter 06440 ** values associated with the [sqlite3_stmt_status()] interface. 06441 ** The meanings of the various counters are as follows: 06442 ** 06443 ** <dl> 06444 ** [[SQLITE_STMTSTATUS_FULLSCAN_STEP]] <dt>SQLITE_STMTSTATUS_FULLSCAN_STEP</dt> 06445 ** <dd>^This is the number of times that SQLite has stepped forward in 06446 ** a table as part of a full table scan. Large numbers for this counter 06447 ** may indicate opportunities for performance improvement through 06448 ** careful use of indices.</dd> 06449 ** 06450 ** [[SQLITE_STMTSTATUS_SORT]] <dt>SQLITE_STMTSTATUS_SORT</dt> 06451 ** <dd>^This is the number of sort operations that have occurred. 06452 ** A non-zero value in this counter may indicate an opportunity to 06453 ** improvement performance through careful use of indices.</dd> 06454 ** 06455 ** [[SQLITE_STMTSTATUS_AUTOINDEX]] <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt> 06456 ** <dd>^This is the number of rows inserted into transient indices that 06457 ** were created automatically in order to help joins run faster. 06458 ** A non-zero value in this counter may indicate an opportunity to 06459 ** improvement performance by adding permanent indices that do not 06460 ** need to be reinitialized each time the statement is run.</dd> 06461 ** </dl> 06462 */ 06463 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1 06464 #define SQLITE_STMTSTATUS_SORT 2 06465 #define SQLITE_STMTSTATUS_AUTOINDEX 3 06466 06467 /* 06468 ** CAPI3REF: Custom Page Cache Object 06469 ** 06470 ** The sqlite3_pcache type is opaque. It is implemented by 06471 ** the pluggable module. The SQLite core has no knowledge of 06472 ** its size or internal structure and never deals with the 06473 ** sqlite3_pcache object except by holding and passing pointers 06474 ** to the object. 06475 ** 06476 ** See [sqlite3_pcache_methods] for additional information. 06477 */ 06478 typedef struct sqlite3_pcache sqlite3_pcache; 06479 06480 /* 06481 ** CAPI3REF: Application Defined Page Cache. 06482 ** KEYWORDS: {page cache} 06483 ** 06484 ** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can 06485 ** register an alternative page cache implementation by passing in an 06486 ** instance of the sqlite3_pcache_methods structure.)^ 06487 ** In many applications, most of the heap memory allocated by 06488 ** SQLite is used for the page cache. 06489 ** By implementing a 06490 ** custom page cache using this API, an application can better control 06491 ** the amount of memory consumed by SQLite, the way in which 06492 ** that memory is allocated and released, and the policies used to 06493 ** determine exactly which parts of a database file are cached and for 06494 ** how long. 06495 ** 06496 ** The alternative page cache mechanism is an 06497 ** extreme measure that is only needed by the most demanding applications. 06498 ** The built-in page cache is recommended for most uses. 06499 ** 06500 ** ^(The contents of the sqlite3_pcache_methods structure are copied to an 06501 ** internal buffer by SQLite within the call to [sqlite3_config]. Hence 06502 ** the application may discard the parameter after the call to 06503 ** [sqlite3_config()] returns.)^ 06504 ** 06505 ** [[the xInit() page cache method]] 06506 ** ^(The xInit() method is called once for each effective 06507 ** call to [sqlite3_initialize()])^ 06508 ** (usually only once during the lifetime of the process). ^(The xInit() 06509 ** method is passed a copy of the sqlite3_pcache_methods.pArg value.)^ 06510 ** The intent of the xInit() method is to set up global data structures 06511 ** required by the custom page cache implementation. 06512 ** ^(If the xInit() method is NULL, then the 06513 ** built-in default page cache is used instead of the application defined 06514 ** page cache.)^ 06515 ** 06516 ** [[the xShutdown() page cache method]] 06517 ** ^The xShutdown() method is called by [sqlite3_shutdown()]. 06518 ** It can be used to clean up 06519 ** any outstanding resources before process shutdown, if required. 06520 ** ^The xShutdown() method may be NULL. 06521 ** 06522 ** ^SQLite automatically serializes calls to the xInit method, 06523 ** so the xInit method need not be threadsafe. ^The 06524 ** xShutdown method is only called from [sqlite3_shutdown()] so it does 06525 ** not need to be threadsafe either. All other methods must be threadsafe 06526 ** in multithreaded applications. 06527 ** 06528 ** ^SQLite will never invoke xInit() more than once without an intervening 06529 ** call to xShutdown(). 06530 ** 06531 ** [[the xCreate() page cache methods]] 06532 ** ^SQLite invokes the xCreate() method to construct a new cache instance. 06533 ** SQLite will typically create one cache instance for each open database file, 06534 ** though this is not guaranteed. ^The 06535 ** first parameter, szPage, is the size in bytes of the pages that must 06536 ** be allocated by the cache. ^szPage will not be a power of two. ^szPage 06537 ** will the page size of the database file that is to be cached plus an 06538 ** increment (here called "R") of less than 250. SQLite will use the 06539 ** extra R bytes on each page to store metadata about the underlying 06540 ** database page on disk. The value of R depends 06541 ** on the SQLite version, the target platform, and how SQLite was compiled. 06542 ** ^(R is constant for a particular build of SQLite. Except, there are two 06543 ** distinct values of R when SQLite is compiled with the proprietary 06544 ** ZIPVFS extension.)^ ^The second argument to 06545 ** xCreate(), bPurgeable, is true if the cache being created will 06546 ** be used to cache database pages of a file stored on disk, or 06547 ** false if it is used for an in-memory database. The cache implementation 06548 ** does not have to do anything special based with the value of bPurgeable; 06549 ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will 06550 ** never invoke xUnpin() except to deliberately delete a page. 06551 ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to 06552 ** false will always have the "discard" flag set to true. 06553 ** ^Hence, a cache created with bPurgeable false will 06554 ** never contain any unpinned pages. 06555 ** 06556 ** [[the xCachesize() page cache method]] 06557 ** ^(The xCachesize() method may be called at any time by SQLite to set the 06558 ** suggested maximum cache-size (number of pages stored by) the cache 06559 ** instance passed as the first argument. This is the value configured using 06560 ** the SQLite "[PRAGMA cache_size]" command.)^ As with the bPurgeable 06561 ** parameter, the implementation is not required to do anything with this 06562 ** value; it is advisory only. 06563 ** 06564 ** [[the xPagecount() page cache methods]] 06565 ** The xPagecount() method must return the number of pages currently 06566 ** stored in the cache, both pinned and unpinned. 06567 ** 06568 ** [[the xFetch() page cache methods]] 06569 ** The xFetch() method locates a page in the cache and returns a pointer to 06570 ** the page, or a NULL pointer. 06571 ** A "page", in this context, means a buffer of szPage bytes aligned at an 06572 ** 8-byte boundary. The page to be fetched is determined by the key. ^The 06573 ** minimum key value is 1. After it has been retrieved using xFetch, the page 06574 ** is considered to be "pinned". 06575 ** 06576 ** If the requested page is already in the page cache, then the page cache 06577 ** implementation must return a pointer to the page buffer with its content 06578 ** intact. If the requested page is not already in the cache, then the 06579 ** cache implementation should use the value of the createFlag 06580 ** parameter to help it determined what action to take: 06581 ** 06582 ** <table border=1 width=85% align=center> 06583 ** <tr><th> createFlag <th> Behaviour when page is not already in cache 06584 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL. 06585 ** <tr><td> 1 <td> Allocate a new page if it easy and convenient to do so. 06586 ** Otherwise return NULL. 06587 ** <tr><td> 2 <td> Make every effort to allocate a new page. Only return 06588 ** NULL if allocating a new page is effectively impossible. 06589 ** </table> 06590 ** 06591 ** ^(SQLite will normally invoke xFetch() with a createFlag of 0 or 1. SQLite 06592 ** will only use a createFlag of 2 after a prior call with a createFlag of 1 06593 ** failed.)^ In between the to xFetch() calls, SQLite may 06594 ** attempt to unpin one or more cache pages by spilling the content of 06595 ** pinned pages to disk and synching the operating system disk cache. 06596 ** 06597 ** [[the xUnpin() page cache method]] 06598 ** ^xUnpin() is called by SQLite with a pointer to a currently pinned page 06599 ** as its second argument. If the third parameter, discard, is non-zero, 06600 ** then the page must be evicted from the cache. 06601 ** ^If the discard parameter is 06602 ** zero, then the page may be discarded or retained at the discretion of 06603 ** page cache implementation. ^The page cache implementation 06604 ** may choose to evict unpinned pages at any time. 06605 ** 06606 ** The cache must not perform any reference counting. A single 06607 ** call to xUnpin() unpins the page regardless of the number of prior calls 06608 ** to xFetch(). 06609 ** 06610 ** [[the xRekey() page cache methods]] 06611 ** The xRekey() method is used to change the key value associated with the 06612 ** page passed as the second argument. If the cache 06613 ** previously contains an entry associated with newKey, it must be 06614 ** discarded. ^Any prior cache entry associated with newKey is guaranteed not 06615 ** to be pinned. 06616 ** 06617 ** When SQLite calls the xTruncate() method, the cache must discard all 06618 ** existing cache entries with page numbers (keys) greater than or equal 06619 ** to the value of the iLimit parameter passed to xTruncate(). If any 06620 ** of these pages are pinned, they are implicitly unpinned, meaning that 06621 ** they can be safely discarded. 06622 ** 06623 ** [[the xDestroy() page cache method]] 06624 ** ^The xDestroy() method is used to delete a cache allocated by xCreate(). 06625 ** All resources associated with the specified cache should be freed. ^After 06626 ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*] 06627 ** handle invalid, and will not use it with any other sqlite3_pcache_methods 06628 ** functions. 06629 */ 06630 typedef struct sqlite3_pcache_methods sqlite3_pcache_methods; 06631 struct sqlite3_pcache_methods { 06632 void *pArg; 06633 int (*xInit)(void*); 06634 void (*xShutdown)(void*); 06635 sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable); 06636 void (*xCachesize)(sqlite3_pcache*, int nCachesize); 06637 int (*xPagecount)(sqlite3_pcache*); 06638 void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag); 06639 void (*xUnpin)(sqlite3_pcache*, void*, int discard); 06640 void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey); 06641 void (*xTruncate)(sqlite3_pcache*, unsigned iLimit); 06642 void (*xDestroy)(sqlite3_pcache*); 06643 }; 06644 06645 /* 06646 ** CAPI3REF: Online Backup Object 06647 ** 06648 ** The sqlite3_backup object records state information about an ongoing 06649 ** online backup operation. ^The sqlite3_backup object is created by 06650 ** a call to [sqlite3_backup_init()] and is destroyed by a call to 06651 ** [sqlite3_backup_finish()]. 06652 ** 06653 ** See Also: [Using the SQLite Online Backup API] 06654 */ 06655 typedef struct sqlite3_backup sqlite3_backup; 06656 06657 /* 06658 ** CAPI3REF: Online Backup API. 06659 ** 06660 ** The backup API copies the content of one database into another. 06661 ** It is useful either for creating backups of databases or 06662 ** for copying in-memory databases to or from persistent files. 06663 ** 06664 ** See Also: [Using the SQLite Online Backup API] 06665 ** 06666 ** ^SQLite holds a write transaction open on the destination database file 06667 ** for the duration of the backup operation. 06668 ** ^The source database is read-locked only while it is being read; 06669 ** it is not locked continuously for the entire backup operation. 06670 ** ^Thus, the backup may be performed on a live source database without 06671 ** preventing other database connections from 06672 ** reading or writing to the source database while the backup is underway. 06673 ** 06674 ** ^(To perform a backup operation: 06675 ** <ol> 06676 ** <li><b>sqlite3_backup_init()</b> is called once to initialize the 06677 ** backup, 06678 ** <li><b>sqlite3_backup_step()</b> is called one or more times to transfer 06679 ** the data between the two databases, and finally 06680 ** <li><b>sqlite3_backup_finish()</b> is called to release all resources 06681 ** associated with the backup operation. 06682 ** </ol>)^ 06683 ** There should be exactly one call to sqlite3_backup_finish() for each 06684 ** successful call to sqlite3_backup_init(). 06685 ** 06686 ** [[sqlite3_backup_init()]] <b>sqlite3_backup_init()</b> 06687 ** 06688 ** ^The D and N arguments to sqlite3_backup_init(D,N,S,M) are the 06689 ** [database connection] associated with the destination database 06690 ** and the database name, respectively. 06691 ** ^The database name is "main" for the main database, "temp" for the 06692 ** temporary database, or the name specified after the AS keyword in 06693 ** an [ATTACH] statement for an attached database. 06694 ** ^The S and M arguments passed to 06695 ** sqlite3_backup_init(D,N,S,M) identify the [database connection] 06696 ** and database name of the source database, respectively. 06697 ** ^The source and destination [database connections] (parameters S and D) 06698 ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with 06699 ** an error. 06700 ** 06701 ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is 06702 ** returned and an error code and error message are stored in the 06703 ** destination [database connection] D. 06704 ** ^The error code and message for the failed call to sqlite3_backup_init() 06705 ** can be retrieved using the [sqlite3_errcode()], [sqlite3_errmsg()], and/or 06706 ** [sqlite3_errmsg16()] functions. 06707 ** ^A successful call to sqlite3_backup_init() returns a pointer to an 06708 ** [sqlite3_backup] object. 06709 ** ^The [sqlite3_backup] object may be used with the sqlite3_backup_step() and 06710 ** sqlite3_backup_finish() functions to perform the specified backup 06711 ** operation. 06712 ** 06713 ** [[sqlite3_backup_step()]] <b>sqlite3_backup_step()</b> 06714 ** 06715 ** ^Function sqlite3_backup_step(B,N) will copy up to N pages between 06716 ** the source and destination databases specified by [sqlite3_backup] object B. 06717 ** ^If N is negative, all remaining source pages are copied. 06718 ** ^If sqlite3_backup_step(B,N) successfully copies N pages and there 06719 ** are still more pages to be copied, then the function returns [SQLITE_OK]. 06720 ** ^If sqlite3_backup_step(B,N) successfully finishes copying all pages 06721 ** from source to destination, then it returns [SQLITE_DONE]. 06722 ** ^If an error occurs while running sqlite3_backup_step(B,N), 06723 ** then an [error code] is returned. ^As well as [SQLITE_OK] and 06724 ** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY], 06725 ** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an 06726 ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code. 06727 ** 06728 ** ^(The sqlite3_backup_step() might return [SQLITE_READONLY] if 06729 ** <ol> 06730 ** <li> the destination database was opened read-only, or 06731 ** <li> the destination database is using write-ahead-log journaling 06732 ** and the destination and source page sizes differ, or 06733 ** <li> the destination database is an in-memory database and the 06734 ** destination and source page sizes differ. 06735 ** </ol>)^ 06736 ** 06737 ** ^If sqlite3_backup_step() cannot obtain a required file-system lock, then 06738 ** the [sqlite3_busy_handler | busy-handler function] 06739 ** is invoked (if one is specified). ^If the 06740 ** busy-handler returns non-zero before the lock is available, then 06741 ** [SQLITE_BUSY] is returned to the caller. ^In this case the call to 06742 ** sqlite3_backup_step() can be retried later. ^If the source 06743 ** [database connection] 06744 ** is being used to write to the source database when sqlite3_backup_step() 06745 ** is called, then [SQLITE_LOCKED] is returned immediately. ^Again, in this 06746 ** case the call to sqlite3_backup_step() can be retried later on. ^(If 06747 ** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or 06748 ** [SQLITE_READONLY] is returned, then 06749 ** there is no point in retrying the call to sqlite3_backup_step(). These 06750 ** errors are considered fatal.)^ The application must accept 06751 ** that the backup operation has failed and pass the backup operation handle 06752 ** to the sqlite3_backup_finish() to release associated resources. 06753 ** 06754 ** ^The first call to sqlite3_backup_step() obtains an exclusive lock 06755 ** on the destination file. ^The exclusive lock is not released until either 06756 ** sqlite3_backup_finish() is called or the backup operation is complete 06757 ** and sqlite3_backup_step() returns [SQLITE_DONE]. ^Every call to 06758 ** sqlite3_backup_step() obtains a [shared lock] on the source database that 06759 ** lasts for the duration of the sqlite3_backup_step() call. 06760 ** ^Because the source database is not locked between calls to 06761 ** sqlite3_backup_step(), the source database may be modified mid-way 06762 ** through the backup process. ^If the source database is modified by an 06763 ** external process or via a database connection other than the one being 06764 ** used by the backup operation, then the backup will be automatically 06765 ** restarted by the next call to sqlite3_backup_step(). ^If the source 06766 ** database is modified by the using the same database connection as is used 06767 ** by the backup operation, then the backup database is automatically 06768 ** updated at the same time. 06769 ** 06770 ** [[sqlite3_backup_finish()]] <b>sqlite3_backup_finish()</b> 06771 ** 06772 ** When sqlite3_backup_step() has returned [SQLITE_DONE], or when the 06773 ** application wishes to abandon the backup operation, the application 06774 ** should destroy the [sqlite3_backup] by passing it to sqlite3_backup_finish(). 06775 ** ^The sqlite3_backup_finish() interfaces releases all 06776 ** resources associated with the [sqlite3_backup] object. 06777 ** ^If sqlite3_backup_step() has not yet returned [SQLITE_DONE], then any 06778 ** active write-transaction on the destination database is rolled back. 06779 ** The [sqlite3_backup] object is invalid 06780 ** and may not be used following a call to sqlite3_backup_finish(). 06781 ** 06782 ** ^The value returned by sqlite3_backup_finish is [SQLITE_OK] if no 06783 ** sqlite3_backup_step() errors occurred, regardless or whether or not 06784 ** sqlite3_backup_step() completed. 06785 ** ^If an out-of-memory condition or IO error occurred during any prior 06786 ** sqlite3_backup_step() call on the same [sqlite3_backup] object, then 06787 ** sqlite3_backup_finish() returns the corresponding [error code]. 06788 ** 06789 ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step() 06790 ** is not a permanent error and does not affect the return value of 06791 ** sqlite3_backup_finish(). 06792 ** 06793 ** [[sqlite3_backup__remaining()]] [[sqlite3_backup_pagecount()]] 06794 ** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b> 06795 ** 06796 ** ^Each call to sqlite3_backup_step() sets two values inside 06797 ** the [sqlite3_backup] object: the number of pages still to be backed 06798 ** up and the total number of pages in the source database file. 06799 ** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces 06800 ** retrieve these two values, respectively. 06801 ** 06802 ** ^The values returned by these functions are only updated by 06803 ** sqlite3_backup_step(). ^If the source database is modified during a backup 06804 ** operation, then the values are not updated to account for any extra 06805 ** pages that need to be updated or the size of the source database file 06806 ** changing. 06807 ** 06808 ** <b>Concurrent Usage of Database Handles</b> 06809 ** 06810 ** ^The source [database connection] may be used by the application for other 06811 ** purposes while a backup operation is underway or being initialized. 06812 ** ^If SQLite is compiled and configured to support threadsafe database 06813 ** connections, then the source database connection may be used concurrently 06814 ** from within other threads. 06815 ** 06816 ** However, the application must guarantee that the destination 06817 ** [database connection] is not passed to any other API (by any thread) after 06818 ** sqlite3_backup_init() is called and before the corresponding call to 06819 ** sqlite3_backup_finish(). SQLite does not currently check to see 06820 ** if the application incorrectly accesses the destination [database connection] 06821 ** and so no error code is reported, but the operations may malfunction 06822 ** nevertheless. Use of the destination database connection while a 06823 ** backup is in progress might also also cause a mutex deadlock. 06824 ** 06825 ** If running in [shared cache mode], the application must 06826 ** guarantee that the shared cache used by the destination database 06827 ** is not accessed while the backup is running. In practice this means 06828 ** that the application must guarantee that the disk file being 06829 ** backed up to is not accessed by any connection within the process, 06830 ** not just the specific connection that was passed to sqlite3_backup_init(). 06831 ** 06832 ** The [sqlite3_backup] object itself is partially threadsafe. Multiple 06833 ** threads may safely make multiple concurrent calls to sqlite3_backup_step(). 06834 ** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount() 06835 ** APIs are not strictly speaking threadsafe. If they are invoked at the 06836 ** same time as another thread is invoking sqlite3_backup_step() it is 06837 ** possible that they return invalid values. 06838 */ 06839 SQLITE_API sqlite3_backup *sqlite3_backup_init( 06840 sqlite3 *pDest, /* Destination database handle */ 06841 const char *zDestName, /* Destination database name */ 06842 sqlite3 *pSource, /* Source database handle */ 06843 const char *zSourceName /* Source database name */ 06844 ); 06845 SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage); 06846 SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p); 06847 SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p); 06848 SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p); 06849 06850 /* 06851 ** CAPI3REF: Unlock Notification 06852 ** 06853 ** ^When running in shared-cache mode, a database operation may fail with 06854 ** an [SQLITE_LOCKED] error if the required locks on the shared-cache or 06855 ** individual tables within the shared-cache cannot be obtained. See 06856 ** [SQLite Shared-Cache Mode] for a description of shared-cache locking. 06857 ** ^This API may be used to register a callback that SQLite will invoke 06858 ** when the connection currently holding the required lock relinquishes it. 06859 ** ^This API is only available if the library was compiled with the 06860 ** [SQLITE_ENABLE_UNLOCK_NOTIFY] C-preprocessor symbol defined. 06861 ** 06862 ** See Also: [Using the SQLite Unlock Notification Feature]. 06863 ** 06864 ** ^Shared-cache locks are released when a database connection concludes 06865 ** its current transaction, either by committing it or rolling it back. 06866 ** 06867 ** ^When a connection (known as the blocked connection) fails to obtain a 06868 ** shared-cache lock and SQLITE_LOCKED is returned to the caller, the 06869 ** identity of the database connection (the blocking connection) that 06870 ** has locked the required resource is stored internally. ^After an 06871 ** application receives an SQLITE_LOCKED error, it may call the 06872 ** sqlite3_unlock_notify() method with the blocked connection handle as 06873 ** the first argument to register for a callback that will be invoked 06874 ** when the blocking connections current transaction is concluded. ^The 06875 ** callback is invoked from within the [sqlite3_step] or [sqlite3_close] 06876 ** call that concludes the blocking connections transaction. 06877 ** 06878 ** ^(If sqlite3_unlock_notify() is called in a multi-threaded application, 06879 ** there is a chance that the blocking connection will have already 06880 ** concluded its transaction by the time sqlite3_unlock_notify() is invoked. 06881 ** If this happens, then the specified callback is invoked immediately, 06882 ** from within the call to sqlite3_unlock_notify().)^ 06883 ** 06884 ** ^If the blocked connection is attempting to obtain a write-lock on a 06885 ** shared-cache table, and more than one other connection currently holds 06886 ** a read-lock on the same table, then SQLite arbitrarily selects one of 06887 ** the other connections to use as the blocking connection. 06888 ** 06889 ** ^(There may be at most one unlock-notify callback registered by a 06890 ** blocked connection. If sqlite3_unlock_notify() is called when the 06891 ** blocked connection already has a registered unlock-notify callback, 06892 ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is 06893 ** called with a NULL pointer as its second argument, then any existing 06894 ** unlock-notify callback is canceled. ^The blocked connections 06895 ** unlock-notify callback may also be canceled by closing the blocked 06896 ** connection using [sqlite3_close()]. 06897 ** 06898 ** The unlock-notify callback is not reentrant. If an application invokes 06899 ** any sqlite3_xxx API functions from within an unlock-notify callback, a 06900 ** crash or deadlock may be the result. 06901 ** 06902 ** ^Unless deadlock is detected (see below), sqlite3_unlock_notify() always 06903 ** returns SQLITE_OK. 06904 ** 06905 ** <b>Callback Invocation Details</b> 06906 ** 06907 ** When an unlock-notify callback is registered, the application provides a 06908 ** single void* pointer that is passed to the callback when it is invoked. 06909 ** However, the signature of the callback function allows SQLite to pass 06910 ** it an array of void* context pointers. The first argument passed to 06911 ** an unlock-notify callback is a pointer to an array of void* pointers, 06912 ** and the second is the number of entries in the array. 06913 ** 06914 ** When a blocking connections transaction is concluded, there may be 06915 ** more than one blocked connection that has registered for an unlock-notify 06916 ** callback. ^If two or more such blocked connections have specified the 06917 ** same callback function, then instead of invoking the callback function 06918 ** multiple times, it is invoked once with the set of void* context pointers 06919 ** specified by the blocked connections bundled together into an array. 06920 ** This gives the application an opportunity to prioritize any actions 06921 ** related to the set of unblocked database connections. 06922 ** 06923 ** <b>Deadlock Detection</b> 06924 ** 06925 ** Assuming that after registering for an unlock-notify callback a 06926 ** database waits for the callback to be issued before taking any further 06927 ** action (a reasonable assumption), then using this API may cause the 06928 ** application to deadlock. For example, if connection X is waiting for 06929 ** connection Y's transaction to be concluded, and similarly connection 06930 ** Y is waiting on connection X's transaction, then neither connection 06931 ** will proceed and the system may remain deadlocked indefinitely. 06932 ** 06933 ** To avoid this scenario, the sqlite3_unlock_notify() performs deadlock 06934 ** detection. ^If a given call to sqlite3_unlock_notify() would put the 06935 ** system in a deadlocked state, then SQLITE_LOCKED is returned and no 06936 ** unlock-notify callback is registered. The system is said to be in 06937 ** a deadlocked state if connection A has registered for an unlock-notify 06938 ** callback on the conclusion of connection B's transaction, and connection 06939 ** B has itself registered for an unlock-notify callback when connection 06940 ** A's transaction is concluded. ^Indirect deadlock is also detected, so 06941 ** the system is also considered to be deadlocked if connection B has 06942 ** registered for an unlock-notify callback on the conclusion of connection 06943 ** C's transaction, where connection C is waiting on connection A. ^Any 06944 ** number of levels of indirection are allowed. 06945 ** 06946 ** <b>The "DROP TABLE" Exception</b> 06947 ** 06948 ** When a call to [sqlite3_step()] returns SQLITE_LOCKED, it is almost 06949 ** always appropriate to call sqlite3_unlock_notify(). There is however, 06950 ** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement, 06951 ** SQLite checks if there are any currently executing SELECT statements 06952 ** that belong to the same connection. If there are, SQLITE_LOCKED is 06953 ** returned. In this case there is no "blocking connection", so invoking 06954 ** sqlite3_unlock_notify() results in the unlock-notify callback being 06955 ** invoked immediately. If the application then re-attempts the "DROP TABLE" 06956 ** or "DROP INDEX" query, an infinite loop might be the result. 06957 ** 06958 ** One way around this problem is to check the extended error code returned 06959 ** by an sqlite3_step() call. ^(If there is a blocking connection, then the 06960 ** extended error code is set to SQLITE_LOCKED_SHAREDCACHE. Otherwise, in 06961 ** the special "DROP TABLE/INDEX" case, the extended error code is just 06962 ** SQLITE_LOCKED.)^ 06963 */ 06964 SQLITE_API int sqlite3_unlock_notify( 06965 sqlite3 *pBlocked, /* Waiting connection */ 06966 void (*xNotify)(void **apArg, int nArg), /* Callback function to invoke */ 06967 void *pNotifyArg /* Argument to pass to xNotify */ 06968 ); 06969 06970 06971 /* 06972 ** CAPI3REF: String Comparison 06973 ** 06974 ** ^The [sqlite3_strnicmp()] API allows applications and extensions to 06975 ** compare the contents of two buffers containing UTF-8 strings in a 06976 ** case-independent fashion, using the same definition of case independence 06977 ** that SQLite uses internally when comparing identifiers. 06978 */ 06979 SQLITE_API int sqlite3_strnicmp(const char *, const char *, int); 06980 06981 /* 06982 ** CAPI3REF: Error Logging Interface 06983 ** 06984 ** ^The [sqlite3_log()] interface writes a message into the error log 06985 ** established by the [SQLITE_CONFIG_LOG] option to [sqlite3_config()]. 06986 ** ^If logging is enabled, the zFormat string and subsequent arguments are 06987 ** used with [sqlite3_snprintf()] to generate the final output string. 06988 ** 06989 ** The sqlite3_log() interface is intended for use by extensions such as 06990 ** virtual tables, collating functions, and SQL functions. While there is 06991 ** nothing to prevent an application from calling sqlite3_log(), doing so 06992 ** is considered bad form. 06993 ** 06994 ** The zFormat string must not be NULL. 06995 ** 06996 ** To avoid deadlocks and other threading problems, the sqlite3_log() routine 06997 ** will not use dynamically allocated memory. The log message is stored in 06998 ** a fixed-length buffer on the stack. If the log message is longer than 06999 ** a few hundred characters, it will be truncated to the length of the 07000 ** buffer. 07001 */ 07002 SQLITE_API void sqlite3_log(int iErrCode, const char *zFormat, ...); 07003 07004 /* 07005 ** CAPI3REF: Write-Ahead Log Commit Hook 07006 ** 07007 ** ^The [sqlite3_wal_hook()] function is used to register a callback that 07008 ** will be invoked each time a database connection commits data to a 07009 ** [write-ahead log] (i.e. whenever a transaction is committed in 07010 ** [journal_mode | journal_mode=WAL mode]). 07011 ** 07012 ** ^The callback is invoked by SQLite after the commit has taken place and 07013 ** the associated write-lock on the database released, so the implementation 07014 ** may read, write or [checkpoint] the database as required. 07015 ** 07016 ** ^The first parameter passed to the callback function when it is invoked 07017 ** is a copy of the third parameter passed to sqlite3_wal_hook() when 07018 ** registering the callback. ^The second is a copy of the database handle. 07019 ** ^The third parameter is the name of the database that was written to - 07020 ** either "main" or the name of an [ATTACH]-ed database. ^The fourth parameter 07021 ** is the number of pages currently in the write-ahead log file, 07022 ** including those that were just committed. 07023 ** 07024 ** The callback function should normally return [SQLITE_OK]. ^If an error 07025 ** code is returned, that error will propagate back up through the 07026 ** SQLite code base to cause the statement that provoked the callback 07027 ** to report an error, though the commit will have still occurred. If the 07028 ** callback returns [SQLITE_ROW] or [SQLITE_DONE], or if it returns a value 07029 ** that does not correspond to any valid SQLite error code, the results 07030 ** are undefined. 07031 ** 07032 ** A single database handle may have at most a single write-ahead log callback 07033 ** registered at one time. ^Calling [sqlite3_wal_hook()] replaces any 07034 ** previously registered write-ahead log callback. ^Note that the 07035 ** [sqlite3_wal_autocheckpoint()] interface and the 07036 ** [wal_autocheckpoint pragma] both invoke [sqlite3_wal_hook()] and will 07037 ** those overwrite any prior [sqlite3_wal_hook()] settings. 07038 */ 07039 SQLITE_API void *sqlite3_wal_hook( 07040 sqlite3*, 07041 int(*)(void *,sqlite3*,const char*,int), 07042 void* 07043 ); 07044 07045 /* 07046 ** CAPI3REF: Configure an auto-checkpoint 07047 ** 07048 ** ^The [sqlite3_wal_autocheckpoint(D,N)] is a wrapper around 07049 ** [sqlite3_wal_hook()] that causes any database on [database connection] D 07050 ** to automatically [checkpoint] 07051 ** after committing a transaction if there are N or 07052 ** more frames in the [write-ahead log] file. ^Passing zero or 07053 ** a negative value as the nFrame parameter disables automatic 07054 ** checkpoints entirely. 07055 ** 07056 ** ^The callback registered by this function replaces any existing callback 07057 ** registered using [sqlite3_wal_hook()]. ^Likewise, registering a callback 07058 ** using [sqlite3_wal_hook()] disables the automatic checkpoint mechanism 07059 ** configured by this function. 07060 ** 07061 ** ^The [wal_autocheckpoint pragma] can be used to invoke this interface 07062 ** from SQL. 07063 ** 07064 ** ^Every new [database connection] defaults to having the auto-checkpoint 07065 ** enabled with a threshold of 1000 or [SQLITE_DEFAULT_WAL_AUTOCHECKPOINT] 07066 ** pages. The use of this interface 07067 ** is only necessary if the default setting is found to be suboptimal 07068 ** for a particular application. 07069 */ 07070 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N); 07071 07072 /* 07073 ** CAPI3REF: Checkpoint a database 07074 ** 07075 ** ^The [sqlite3_wal_checkpoint(D,X)] interface causes database named X 07076 ** on [database connection] D to be [checkpointed]. ^If X is NULL or an 07077 ** empty string, then a checkpoint is run on all databases of 07078 ** connection D. ^If the database connection D is not in 07079 ** [WAL | write-ahead log mode] then this interface is a harmless no-op. 07080 ** 07081 ** ^The [wal_checkpoint pragma] can be used to invoke this interface 07082 ** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the 07083 ** [wal_autocheckpoint pragma] can be used to cause this interface to be 07084 ** run whenever the WAL reaches a certain size threshold. 07085 ** 07086 ** See also: [sqlite3_wal_checkpoint_v2()] 07087 */ 07088 SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); 07089 07090 /* 07091 ** CAPI3REF: Checkpoint a database 07092 ** 07093 ** Run a checkpoint operation on WAL database zDb attached to database 07094 ** handle db. The specific operation is determined by the value of the 07095 ** eMode parameter: 07096 ** 07097 ** <dl> 07098 ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd> 07099 ** Checkpoint as many frames as possible without waiting for any database 07100 ** readers or writers to finish. Sync the db file if all frames in the log 07101 ** are checkpointed. This mode is the same as calling 07102 ** sqlite3_wal_checkpoint(). The busy-handler callback is never invoked. 07103 ** 07104 ** <dt>SQLITE_CHECKPOINT_FULL<dd> 07105 ** This mode blocks (calls the busy-handler callback) until there is no 07106 ** database writer and all readers are reading from the most recent database 07107 ** snapshot. It then checkpoints all frames in the log file and syncs the 07108 ** database file. This call blocks database writers while it is running, 07109 ** but not database readers. 07110 ** 07111 ** <dt>SQLITE_CHECKPOINT_RESTART<dd> 07112 ** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after 07113 ** checkpointing the log file it blocks (calls the busy-handler callback) 07114 ** until all readers are reading from the database file only. This ensures 07115 ** that the next client to write to the database file restarts the log file 07116 ** from the beginning. This call blocks database writers while it is running, 07117 ** but not database readers. 07118 ** </dl> 07119 ** 07120 ** If pnLog is not NULL, then *pnLog is set to the total number of frames in 07121 ** the log file before returning. If pnCkpt is not NULL, then *pnCkpt is set to 07122 ** the total number of checkpointed frames (including any that were already 07123 ** checkpointed when this function is called). *pnLog and *pnCkpt may be 07124 ** populated even if sqlite3_wal_checkpoint_v2() returns other than SQLITE_OK. 07125 ** If no values are available because of an error, they are both set to -1 07126 ** before returning to communicate this to the caller. 07127 ** 07128 ** All calls obtain an exclusive "checkpoint" lock on the database file. If 07129 ** any other process is running a checkpoint operation at the same time, the 07130 ** lock cannot be obtained and SQLITE_BUSY is returned. Even if there is a 07131 ** busy-handler configured, it will not be invoked in this case. 07132 ** 07133 ** The SQLITE_CHECKPOINT_FULL and RESTART modes also obtain the exclusive 07134 ** "writer" lock on the database file. If the writer lock cannot be obtained 07135 ** immediately, and a busy-handler is configured, it is invoked and the writer 07136 ** lock retried until either the busy-handler returns 0 or the lock is 07137 ** successfully obtained. The busy-handler is also invoked while waiting for 07138 ** database readers as described above. If the busy-handler returns 0 before 07139 ** the writer lock is obtained or while waiting for database readers, the 07140 ** checkpoint operation proceeds from that point in the same way as 07141 ** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible 07142 ** without blocking any further. SQLITE_BUSY is returned in this case. 07143 ** 07144 ** If parameter zDb is NULL or points to a zero length string, then the 07145 ** specified operation is attempted on all WAL databases. In this case the 07146 ** values written to output parameters *pnLog and *pnCkpt are undefined. If 07147 ** an SQLITE_BUSY error is encountered when processing one or more of the 07148 ** attached WAL databases, the operation is still attempted on any remaining 07149 ** attached databases and SQLITE_BUSY is returned to the caller. If any other 07150 ** error occurs while processing an attached database, processing is abandoned 07151 ** and the error code returned to the caller immediately. If no error 07152 ** (SQLITE_BUSY or otherwise) is encountered while processing the attached 07153 ** databases, SQLITE_OK is returned. 07154 ** 07155 ** If database zDb is the name of an attached database that is not in WAL 07156 ** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. If 07157 ** zDb is not NULL (or a zero length string) and is not the name of any 07158 ** attached database, SQLITE_ERROR is returned to the caller. 07159 */ 07160 SQLITE_API int sqlite3_wal_checkpoint_v2( 07161 sqlite3 *db, /* Database handle */ 07162 const char *zDb, /* Name of attached database (or NULL) */ 07163 int eMode, /* SQLITE_CHECKPOINT_* value */ 07164 int *pnLog, /* OUT: Size of WAL log in frames */ 07165 int *pnCkpt /* OUT: Total number of frames checkpointed */ 07166 ); 07167 07168 /* 07169 ** CAPI3REF: Checkpoint operation parameters 07170 ** 07171 ** These constants can be used as the 3rd parameter to 07172 ** [sqlite3_wal_checkpoint_v2()]. See the [sqlite3_wal_checkpoint_v2()] 07173 ** documentation for additional information about the meaning and use of 07174 ** each of these values. 07175 */ 07176 #define SQLITE_CHECKPOINT_PASSIVE 0 07177 #define SQLITE_CHECKPOINT_FULL 1 07178 #define SQLITE_CHECKPOINT_RESTART 2 07179 07180 /* 07181 ** CAPI3REF: Virtual Table Interface Configuration 07182 ** 07183 ** This function may be called by either the [xConnect] or [xCreate] method 07184 ** of a [virtual table] implementation to configure 07185 ** various facets of the virtual table interface. 07186 ** 07187 ** If this interface is invoked outside the context of an xConnect or 07188 ** xCreate virtual table method then the behavior is undefined. 07189 ** 07190 ** At present, there is only one option that may be configured using 07191 ** this function. (See [SQLITE_VTAB_CONSTRAINT_SUPPORT].) Further options 07192 ** may be added in the future. 07193 */ 07194 SQLITE_API int sqlite3_vtab_config(sqlite3*, int op, ...); 07195 07196 /* 07197 ** CAPI3REF: Virtual Table Configuration Options 07198 ** 07199 ** These macros define the various options to the 07200 ** [sqlite3_vtab_config()] interface that [virtual table] implementations 07201 ** can use to customize and optimize their behavior. 07202 ** 07203 ** <dl> 07204 ** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT 07205 ** <dd>Calls of the form 07206 ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported, 07207 ** where X is an integer. If X is zero, then the [virtual table] whose 07208 ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not 07209 ** support constraints. In this configuration (which is the default) if 07210 ** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire 07211 ** statement is rolled back as if [ON CONFLICT | OR ABORT] had been 07212 ** specified as part of the users SQL statement, regardless of the actual 07213 ** ON CONFLICT mode specified. 07214 ** 07215 ** If X is non-zero, then the virtual table implementation guarantees 07216 ** that if [xUpdate] returns [SQLITE_CONSTRAINT], it will do so before 07217 ** any modifications to internal or persistent data structures have been made. 07218 ** If the [ON CONFLICT] mode is ABORT, FAIL, IGNORE or ROLLBACK, SQLite 07219 ** is able to roll back a statement or database transaction, and abandon 07220 ** or continue processing the current SQL statement as appropriate. 07221 ** If the ON CONFLICT mode is REPLACE and the [xUpdate] method returns 07222 ** [SQLITE_CONSTRAINT], SQLite handles this as if the ON CONFLICT mode 07223 ** had been ABORT. 07224 ** 07225 ** Virtual table implementations that are required to handle OR REPLACE 07226 ** must do so within the [xUpdate] method. If a call to the 07227 ** [sqlite3_vtab_on_conflict()] function indicates that the current ON 07228 ** CONFLICT policy is REPLACE, the virtual table implementation should 07229 ** silently replace the appropriate rows within the xUpdate callback and 07230 ** return SQLITE_OK. Or, if this is not possible, it may return 07231 ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT 07232 ** constraint handling. 07233 ** </dl> 07234 */ 07235 #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1 07236 07237 /* 07238 ** CAPI3REF: Determine The Virtual Table Conflict Policy 07239 ** 07240 ** This function may only be called from within a call to the [xUpdate] method 07241 ** of a [virtual table] implementation for an INSERT or UPDATE operation. ^The 07242 ** value returned is one of [SQLITE_ROLLBACK], [SQLITE_IGNORE], [SQLITE_FAIL], 07243 ** [SQLITE_ABORT], or [SQLITE_REPLACE], according to the [ON CONFLICT] mode 07244 ** of the SQL statement that triggered the call to the [xUpdate] method of the 07245 ** [virtual table]. 07246 */ 07247 SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *); 07248 07249 /* 07250 ** CAPI3REF: Conflict resolution modes 07251 ** 07252 ** These constants are returned by [sqlite3_vtab_on_conflict()] to 07253 ** inform a [virtual table] implementation what the [ON CONFLICT] mode 07254 ** is for the SQL statement being evaluated. 07255 ** 07256 ** Note that the [SQLITE_IGNORE] constant is also used as a potential 07257 ** return value from the [sqlite3_set_authorizer()] callback and that 07258 ** [SQLITE_ABORT] is also a [result code]. 07259 */ 07260 #define SQLITE_ROLLBACK 1 07261 /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */ 07262 #define SQLITE_FAIL 3 07263 /* #define SQLITE_ABORT 4 // Also an error code */ 07264 #define SQLITE_REPLACE 5 07265 07266 07267 07268 /* 07269 ** Undo the hack that converts floating point types to integer for 07270 ** builds on processors without floating point support. 07271 */ 07272 #ifdef SQLITE_OMIT_FLOATING_POINT 07273 # undef double 07274 #endif 07275 07276 #if 0 07277 } /* End of the 'extern "C"' block */ 07278 #endif 07279 #endif 07280 07281 /* 07282 ** 2010 August 30 07283 ** 07284 ** The author disclaims copyright to this source code. In place of 07285 ** a legal notice, here is a blessing: 07286 ** 07287 ** May you do good and not evil. 07288 ** May you find forgiveness for yourself and forgive others. 07289 ** May you share freely, never taking more than you give. 07290 ** 07291 ************************************************************************* 07292 */ 07293 07294 #ifndef _SQLITE3RTREE_H_ 07295 #define _SQLITE3RTREE_H_ 07296 07297 07298 #if 0 07299 extern "C" { 07300 #endif 07301 07302 typedef struct sqlite3_rtree_geometry sqlite3_rtree_geometry; 07303 07304 /* 07305 ** Register a geometry callback named zGeom that can be used as part of an 07306 ** R-Tree geometry query as follows: 07307 ** 07308 ** SELECT ... FROM <rtree> WHERE <rtree col> MATCH $zGeom(... params ...) 07309 */ 07310 SQLITE_API int sqlite3_rtree_geometry_callback( 07311 sqlite3 *db, 07312 const char *zGeom, 07313 int (*xGeom)(sqlite3_rtree_geometry *, int nCoord, double *aCoord, int *pRes), 07314 void *pContext 07315 ); 07316 07317 07318 /* 07319 ** A pointer to a structure of the following type is passed as the first 07320 ** argument to callbacks registered using rtree_geometry_callback(). 07321 */ 07322 struct sqlite3_rtree_geometry { 07323 void *pContext; /* Copy of pContext passed to s_r_g_c() */ 07324 int nParam; /* Size of array aParam[] */ 07325 double *aParam; /* Parameters passed to SQL geom function */ 07326 void *pUser; /* Callback implementation user data */ 07327 void (*xDelUser)(void *); /* Called by SQLite to clean up pUser */ 07328 }; 07329 07330 07331 #if 0 07332 } /* end of the 'extern "C"' block */ 07333 #endif 07334 07335 #endif /* ifndef _SQLITE3RTREE_H_ */ 07336 07337 07338 /************** End of sqlite3.h *********************************************/ 07339 /************** Continuing where we left off in sqliteInt.h ******************/ 07340 /************** Include hash.h in the middle of sqliteInt.h ******************/ 07341 /************** Begin file hash.h ********************************************/ 07342 /* 07343 ** 2001 September 22 07344 ** 07345 ** The author disclaims copyright to this source code. In place of 07346 ** a legal notice, here is a blessing: 07347 ** 07348 ** May you do good and not evil. 07349 ** May you find forgiveness for yourself and forgive others. 07350 ** May you share freely, never taking more than you give. 07351 ** 07352 ************************************************************************* 07353 ** This is the header file for the generic hash-table implemenation 07354 ** used in SQLite. 07355 */ 07356 #ifndef _SQLITE_HASH_H_ 07357 #define _SQLITE_HASH_H_ 07358 07359 /* Forward declarations of structures. */ 07360 typedef struct Hash Hash; 07361 typedef struct HashElem HashElem; 07362 07363 /* A complete hash table is an instance of the following structure. 07364 ** The internals of this structure are intended to be opaque -- client 07365 ** code should not attempt to access or modify the fields of this structure 07366 ** directly. Change this structure only by using the routines below. 07367 ** However, some of the "procedures" and "functions" for modifying and 07368 ** accessing this structure are really macros, so we can't really make 07369 ** this structure opaque. 07370 ** 07371 ** All elements of the hash table are on a single doubly-linked list. 07372 ** Hash.first points to the head of this list. 07373 ** 07374 ** There are Hash.htsize buckets. Each bucket points to a spot in 07375 ** the global doubly-linked list. The contents of the bucket are the 07376 ** element pointed to plus the next _ht.count-1 elements in the list. 07377 ** 07378 ** Hash.htsize and Hash.ht may be zero. In that case lookup is done 07379 ** by a linear search of the global list. For small tables, the 07380 ** Hash.ht table is never allocated because if there are few elements 07381 ** in the table, it is faster to do a linear search than to manage 07382 ** the hash table. 07383 */ 07384 struct Hash { 07385 unsigned int htsize; /* Number of buckets in the hash table */ 07386 unsigned int count; /* Number of entries in this table */ 07387 HashElem *first; /* The first element of the array */ 07388 struct _ht { /* the hash table */ 07389 int count; /* Number of entries with this hash */ 07390 HashElem *chain; /* Pointer to first entry with this hash */ 07391 } *ht; 07392 }; 07393 07394 /* Each element in the hash table is an instance of the following 07395 ** structure. All elements are stored on a single doubly-linked list. 07396 ** 07397 ** Again, this structure is intended to be opaque, but it can't really 07398 ** be opaque because it is used by macros. 07399 */ 07400 struct HashElem { 07401 HashElem *next, *prev; /* Next and previous elements in the table */ 07402 void *data; /* Data associated with this element */ 07403 const char *pKey; int nKey; /* Key associated with this element */ 07404 }; 07405 07406 /* 07407 ** Access routines. To delete, insert a NULL pointer. 07408 */ 07409 SQLITE_PRIVATE void sqlite3HashInit(Hash*); 07410 SQLITE_PRIVATE void *sqlite3HashInsert(Hash*, const char *pKey, int nKey, void *pData); 07411 SQLITE_PRIVATE void *sqlite3HashFind(const Hash*, const char *pKey, int nKey); 07412 SQLITE_PRIVATE void sqlite3HashClear(Hash*); 07413 07414 /* 07415 ** Macros for looping over all elements of a hash table. The idiom is 07416 ** like this: 07417 ** 07418 ** Hash h; 07419 ** HashElem *p; 07420 ** ... 07421 ** for(p=sqliteHashFirst(&h); p; p=sqliteHashNext(p)){ 07422 ** SomeStructure *pData = sqliteHashData(p); 07423 ** // do something with pData 07424 ** } 07425 */ 07426 #define sqliteHashFirst(H) ((H)->first) 07427 #define sqliteHashNext(E) ((E)->next) 07428 #define sqliteHashData(E) ((E)->data) 07429 /* #define sqliteHashKey(E) ((E)->pKey) // NOT USED */ 07430 /* #define sqliteHashKeysize(E) ((E)->nKey) // NOT USED */ 07431 07432 /* 07433 ** Number of entries in a hash table 07434 */ 07435 /* #define sqliteHashCount(H) ((H)->count) // NOT USED */ 07436 07437 #endif /* _SQLITE_HASH_H_ */ 07438 07439 /************** End of hash.h ************************************************/ 07440 /************** Continuing where we left off in sqliteInt.h ******************/ 07441 /************** Include parse.h in the middle of sqliteInt.h *****************/ 07442 /************** Begin file parse.h *******************************************/ 07443 #define TK_SEMI 1 07444 #define TK_EXPLAIN 2 07445 #define TK_QUERY 3 07446 #define TK_PLAN 4 07447 #define TK_BEGIN 5 07448 #define TK_TRANSACTION 6 07449 #define TK_DEFERRED 7 07450 #define TK_IMMEDIATE 8 07451 #define TK_EXCLUSIVE 9 07452 #define TK_COMMIT 10 07453 #define TK_END 11 07454 #define TK_ROLLBACK 12 07455 #define TK_SAVEPOINT 13 07456 #define TK_RELEASE 14 07457 #define TK_TO 15 07458 #define TK_TABLE 16 07459 #define TK_CREATE 17 07460 #define TK_IF 18 07461 #define TK_NOT 19 07462 #define TK_EXISTS 20 07463 #define TK_TEMP 21 07464 #define TK_LP 22 07465 #define TK_RP 23 07466 #define TK_AS 24 07467 #define TK_COMMA 25 07468 #define TK_ID 26 07469 #define TK_INDEXED 27 07470 #define TK_ABORT 28 07471 #define TK_ACTION 29 07472 #define TK_AFTER 30 07473 #define TK_ANALYZE 31 07474 #define TK_ASC 32 07475 #define TK_ATTACH 33 07476 #define TK_BEFORE 34 07477 #define TK_BY 35 07478 #define TK_CASCADE 36 07479 #define TK_CAST 37 07480 #define TK_COLUMNKW 38 07481 #define TK_CONFLICT 39 07482 #define TK_DATABASE 40 07483 #define TK_DESC 41 07484 #define TK_DETACH 42 07485 #define TK_EACH 43 07486 #define TK_FAIL 44 07487 #define TK_FOR 45 07488 #define TK_IGNORE 46 07489 #define TK_INITIALLY 47 07490 #define TK_INSTEAD 48 07491 #define TK_LIKE_KW 49 07492 #define TK_MATCH 50 07493 #define TK_NO 51 07494 #define TK_KEY 52 07495 #define TK_OF 53 07496 #define TK_OFFSET 54 07497 #define TK_PRAGMA 55 07498 #define TK_RAISE 56 07499 #define TK_REPLACE 57 07500 #define TK_RESTRICT 58 07501 #define TK_ROW 59 07502 #define TK_TRIGGER 60 07503 #define TK_VACUUM 61 07504 #define TK_VIEW 62 07505 #define TK_VIRTUAL 63 07506 #define TK_REINDEX 64 07507 #define TK_RENAME 65 07508 #define TK_CTIME_KW 66 07509 #define TK_ANY 67 07510 #define TK_OR 68 07511 #define TK_AND 69 07512 #define TK_IS 70 07513 #define TK_BETWEEN 71 07514 #define TK_IN 72 07515 #define TK_ISNULL 73 07516 #define TK_NOTNULL 74 07517 #define TK_NE 75 07518 #define TK_EQ 76 07519 #define TK_GT 77 07520 #define TK_LE 78 07521 #define TK_LT 79 07522 #define TK_GE 80 07523 #define TK_ESCAPE 81 07524 #define TK_BITAND 82 07525 #define TK_BITOR 83 07526 #define TK_LSHIFT 84 07527 #define TK_RSHIFT 85 07528 #define TK_PLUS 86 07529 #define TK_MINUS 87 07530 #define TK_STAR 88 07531 #define TK_SLASH 89 07532 #define TK_REM 90 07533 #define TK_CONCAT 91 07534 #define TK_COLLATE 92 07535 #define TK_BITNOT 93 07536 #define TK_STRING 94 07537 #define TK_JOIN_KW 95 07538 #define TK_CONSTRAINT 96 07539 #define TK_DEFAULT 97 07540 #define TK_NULL 98 07541 #define TK_PRIMARY 99 07542 #define TK_UNIQUE 100 07543 #define TK_CHECK 101 07544 #define TK_REFERENCES 102 07545 #define TK_AUTOINCR 103 07546 #define TK_ON 104 07547 #define TK_INSERT 105 07548 #define TK_DELETE 106 07549 #define TK_UPDATE 107 07550 #define TK_SET 108 07551 #define TK_DEFERRABLE 109 07552 #define TK_FOREIGN 110 07553 #define TK_DROP 111 07554 #define TK_UNION 112 07555 #define TK_ALL 113 07556 #define TK_EXCEPT 114 07557 #define TK_INTERSECT 115 07558 #define TK_SELECT 116 07559 #define TK_DISTINCT 117 07560 #define TK_DOT 118 07561 #define TK_FROM 119 07562 #define TK_JOIN 120 07563 #define TK_USING 121 07564 #define TK_ORDER 122 07565 #define TK_GROUP 123 07566 #define TK_HAVING 124 07567 #define TK_LIMIT 125 07568 #define TK_WHERE 126 07569 #define TK_INTO 127 07570 #define TK_VALUES 128 07571 #define TK_INTEGER 129 07572 #define TK_FLOAT 130 07573 #define TK_BLOB 131 07574 #define TK_REGISTER 132 07575 #define TK_VARIABLE 133 07576 #define TK_CASE 134 07577 #define TK_WHEN 135 07578 #define TK_THEN 136 07579 #define TK_ELSE 137 07580 #define TK_INDEX 138 07581 #define TK_ALTER 139 07582 #define TK_ADD 140 07583 #define TK_TO_TEXT 141 07584 #define TK_TO_BLOB 142 07585 #define TK_TO_NUMERIC 143 07586 #define TK_TO_INT 144 07587 #define TK_TO_REAL 145 07588 #define TK_ISNOT 146 07589 #define TK_END_OF_FILE 147 07590 #define TK_ILLEGAL 148 07591 #define TK_SPACE 149 07592 #define TK_UNCLOSED_STRING 150 07593 #define TK_FUNCTION 151 07594 #define TK_COLUMN 152 07595 #define TK_AGG_FUNCTION 153 07596 #define TK_AGG_COLUMN 154 07597 #define TK_CONST_FUNC 155 07598 #define TK_UMINUS 156 07599 #define TK_UPLUS 157 07600 07601 /************** End of parse.h ***********************************************/ 07602 /************** Continuing where we left off in sqliteInt.h ******************/ 07603 #include <stdio.h> 07604 #include <stdlib.h> 07605 #include <string.h> 07606 #include <assert.h> 07607 #include <stddef.h> 07608 07609 /* 07610 ** If compiling for a processor that lacks floating point support, 07611 ** substitute integer for floating-point 07612 */ 07613 #ifdef SQLITE_OMIT_FLOATING_POINT 07614 # define double sqlite_int64 07615 # define float sqlite_int64 07616 # define LONGDOUBLE_TYPE sqlite_int64 07617 # ifndef SQLITE_BIG_DBL 07618 # define SQLITE_BIG_DBL (((sqlite3_int64)1)<<50) 07619 # endif 07620 # define SQLITE_OMIT_DATETIME_FUNCS 1 07621 # define SQLITE_OMIT_TRACE 1 07622 # undef SQLITE_MIXED_ENDIAN_64BIT_FLOAT 07623 # undef SQLITE_HAVE_ISNAN 07624 #endif 07625 #ifndef SQLITE_BIG_DBL 07626 # define SQLITE_BIG_DBL (1e99) 07627 #endif 07628 07629 /* 07630 ** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0 07631 ** afterward. Having this macro allows us to cause the C compiler 07632 ** to omit code used by TEMP tables without messy #ifndef statements. 07633 */ 07634 #ifdef SQLITE_OMIT_TEMPDB 07635 #define OMIT_TEMPDB 1 07636 #else 07637 #define OMIT_TEMPDB 0 07638 #endif 07639 07640 /* 07641 ** The "file format" number is an integer that is incremented whenever 07642 ** the VDBE-level file format changes. The following macros define the 07643 ** the default file format for new databases and the maximum file format 07644 ** that the library can read. 07645 */ 07646 #define SQLITE_MAX_FILE_FORMAT 4 07647 #ifndef SQLITE_DEFAULT_FILE_FORMAT 07648 # define SQLITE_DEFAULT_FILE_FORMAT 1 07649 #endif 07650 07651 /* 07652 ** Determine whether triggers are recursive by default. This can be 07653 ** changed at run-time using a pragma. 07654 */ 07655 #ifndef SQLITE_DEFAULT_RECURSIVE_TRIGGERS 07656 # define SQLITE_DEFAULT_RECURSIVE_TRIGGERS 0 07657 #endif 07658 07659 /* 07660 ** Provide a default value for SQLITE_TEMP_STORE in case it is not specified 07661 ** on the command-line 07662 */ 07663 #ifndef SQLITE_TEMP_STORE 07664 # define SQLITE_TEMP_STORE 1 07665 #endif 07666 07667 /* 07668 ** GCC does not define the offsetof() macro so we'll have to do it 07669 ** ourselves. 07670 */ 07671 #ifndef offsetof 07672 #define offsetof(STRUCTURE,FIELD) ((int)((char*)&((STRUCTURE*)0)->FIELD)) 07673 #endif 07674 07675 /* 07676 ** Check to see if this machine uses EBCDIC. (Yes, believe it or 07677 ** not, there are still machines out there that use EBCDIC.) 07678 */ 07679 #if 'A' == '\301' 07680 # define SQLITE_EBCDIC 1 07681 #else 07682 # define SQLITE_ASCII 1 07683 #endif 07684 07685 /* 07686 ** Integers of known sizes. These typedefs might change for architectures 07687 ** where the sizes very. Preprocessor macros are available so that the 07688 ** types can be conveniently redefined at compile-type. Like this: 07689 ** 07690 ** cc '-DUINTPTR_TYPE=long long int' ... 07691 */ 07692 #ifndef UINT32_TYPE 07693 # ifdef HAVE_UINT32_T 07694 # define UINT32_TYPE uint32_t 07695 # else 07696 # define UINT32_TYPE unsigned int 07697 # endif 07698 #endif 07699 #ifndef UINT16_TYPE 07700 # ifdef HAVE_UINT16_T 07701 # define UINT16_TYPE uint16_t 07702 # else 07703 # define UINT16_TYPE unsigned short int 07704 # endif 07705 #endif 07706 #ifndef INT16_TYPE 07707 # ifdef HAVE_INT16_T 07708 # define INT16_TYPE int16_t 07709 # else 07710 # define INT16_TYPE short int 07711 # endif 07712 #endif 07713 #ifndef UINT8_TYPE 07714 # ifdef HAVE_UINT8_T 07715 # define UINT8_TYPE uint8_t 07716 # else 07717 # define UINT8_TYPE unsigned char 07718 # endif 07719 #endif 07720 #ifndef INT8_TYPE 07721 # ifdef HAVE_INT8_T 07722 # define INT8_TYPE int8_t 07723 # else 07724 # define INT8_TYPE signed char 07725 # endif 07726 #endif 07727 #ifndef LONGDOUBLE_TYPE 07728 # define LONGDOUBLE_TYPE long double 07729 #endif 07730 typedef sqlite_int64 i64; /* 8-byte signed integer */ 07731 typedef sqlite_uint64 u64; /* 8-byte unsigned integer */ 07732 typedef UINT32_TYPE u32; /* 4-byte unsigned integer */ 07733 typedef UINT16_TYPE u16; /* 2-byte unsigned integer */ 07734 typedef INT16_TYPE i16; /* 2-byte signed integer */ 07735 typedef UINT8_TYPE u8; /* 1-byte unsigned integer */ 07736 typedef INT8_TYPE i8; /* 1-byte signed integer */ 07737 07738 /* 07739 ** SQLITE_MAX_U32 is a u64 constant that is the maximum u64 value 07740 ** that can be stored in a u32 without loss of data. The value 07741 ** is 0x00000000ffffffff. But because of quirks of some compilers, we 07742 ** have to specify the value in the less intuitive manner shown: 07743 */ 07744 #define SQLITE_MAX_U32 ((((u64)1)<<32)-1) 07745 07746 /* 07747 ** The datatype used to store estimates of the number of rows in a 07748 ** table or index. This is an unsigned integer type. For 99.9% of 07749 ** the world, a 32-bit integer is sufficient. But a 64-bit integer 07750 ** can be used at compile-time if desired. 07751 */ 07752 #ifdef SQLITE_64BIT_STATS 07753 typedef u64 tRowcnt; /* 64-bit only if requested at compile-time */ 07754 #else 07755 typedef u32 tRowcnt; /* 32-bit is the default */ 07756 #endif 07757 07758 /* 07759 ** Macros to determine whether the machine is big or little endian, 07760 ** evaluated at runtime. 07761 */ 07762 #ifdef SQLITE_AMALGAMATION 07763 SQLITE_PRIVATE const int sqlite3one = 1; 07764 #else 07765 SQLITE_PRIVATE const int sqlite3one; 07766 #endif 07767 #if defined(i386) || defined(__i386__) || defined(_M_IX86)\ 07768 || defined(__x86_64) || defined(__x86_64__) 07769 # define SQLITE_BIGENDIAN 0 07770 # define SQLITE_LITTLEENDIAN 1 07771 # define SQLITE_UTF16NATIVE SQLITE_UTF16LE 07772 #else 07773 # define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0) 07774 # define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1) 07775 # define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE) 07776 #endif 07777 07778 /* 07779 ** Constants for the largest and smallest possible 64-bit signed integers. 07780 ** These macros are designed to work correctly on both 32-bit and 64-bit 07781 ** compilers. 07782 */ 07783 #define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32)) 07784 #define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64) 07785 07786 /* 07787 ** Round up a number to the next larger multiple of 8. This is used 07788 ** to force 8-byte alignment on 64-bit architectures. 07789 */ 07790 #define ROUND8(x) (((x)+7)&~7) 07791 07792 /* 07793 ** Round down to the nearest multiple of 8 07794 */ 07795 #define ROUNDDOWN8(x) ((x)&~7) 07796 07797 /* 07798 ** Assert that the pointer X is aligned to an 8-byte boundary. This 07799 ** macro is used only within assert() to verify that the code gets 07800 ** all alignment restrictions correct. 07801 ** 07802 ** Except, if SQLITE_4_BYTE_ALIGNED_MALLOC is defined, then the 07803 ** underlying malloc() implemention might return us 4-byte aligned 07804 ** pointers. In that case, only verify 4-byte alignment. 07805 */ 07806 #ifdef SQLITE_4_BYTE_ALIGNED_MALLOC 07807 # define EIGHT_BYTE_ALIGNMENT(X) ((((char*)(X) - (char*)0)&3)==0) 07808 #else 07809 # define EIGHT_BYTE_ALIGNMENT(X) ((((char*)(X) - (char*)0)&7)==0) 07810 #endif 07811 07812 07813 /* 07814 ** An instance of the following structure is used to store the busy-handler 07815 ** callback for a given sqlite handle. 07816 ** 07817 ** The sqlite.busyHandler member of the sqlite struct contains the busy 07818 ** callback for the database handle. Each pager opened via the sqlite 07819 ** handle is passed a pointer to sqlite.busyHandler. The busy-handler 07820 ** callback is currently invoked only from within pager.c. 07821 */ 07822 typedef struct BusyHandler BusyHandler; 07823 struct BusyHandler { 07824 int (*xFunc)(void *,int); /* The busy callback */ 07825 void *pArg; /* First arg to busy callback */ 07826 int nBusy; /* Incremented with each busy call */ 07827 }; 07828 07829 /* 07830 ** Name of the master database table. The master database table 07831 ** is a special table that holds the names and attributes of all 07832 ** user tables and indices. 07833 */ 07834 #define MASTER_NAME "sqlite_master" 07835 #define TEMP_MASTER_NAME "sqlite_temp_master" 07836 07837 /* 07838 ** The root-page of the master database table. 07839 */ 07840 #define MASTER_ROOT 1 07841 07842 /* 07843 ** The name of the schema table. 07844 */ 07845 #define SCHEMA_TABLE(x) ((!OMIT_TEMPDB)&&(x==1)?TEMP_MASTER_NAME:MASTER_NAME) 07846 07847 /* 07848 ** A convenience macro that returns the number of elements in 07849 ** an array. 07850 */ 07851 #define ArraySize(X) ((int)(sizeof(X)/sizeof(X[0]))) 07852 07853 /* 07854 ** The following value as a destructor means to use sqlite3DbFree(). 07855 ** This is an internal extension to SQLITE_STATIC and SQLITE_TRANSIENT. 07856 */ 07857 #define SQLITE_DYNAMIC ((sqlite3_destructor_type)sqlite3DbFree) 07858 07859 /* 07860 ** When SQLITE_OMIT_WSD is defined, it means that the target platform does 07861 ** not support Writable Static Data (WSD) such as global and static variables. 07862 ** All variables must either be on the stack or dynamically allocated from 07863 ** the heap. When WSD is unsupported, the variable declarations scattered 07864 ** throughout the SQLite code must become constants instead. The SQLITE_WSD 07865 ** macro is used for this purpose. And instead of referencing the variable 07866 ** directly, we use its constant as a key to lookup the run-time allocated 07867 ** buffer that holds real variable. The constant is also the initializer 07868 ** for the run-time allocated buffer. 07869 ** 07870 ** In the usual case where WSD is supported, the SQLITE_WSD and GLOBAL 07871 ** macros become no-ops and have zero performance impact. 07872 */ 07873 #ifdef SQLITE_OMIT_WSD 07874 #define SQLITE_WSD const 07875 #define GLOBAL(t,v) (*(t*)sqlite3_wsd_find((void*)&(v), sizeof(v))) 07876 #define sqlite3GlobalConfig GLOBAL(struct Sqlite3Config, sqlite3Config) 07877 SQLITE_API int sqlite3_wsd_init(int N, int J); 07878 SQLITE_API void *sqlite3_wsd_find(void *K, int L); 07879 #else 07880 #define SQLITE_WSD 07881 #define GLOBAL(t,v) v 07882 #define sqlite3GlobalConfig sqlite3Config 07883 #endif 07884 07885 /* 07886 ** The following macros are used to suppress compiler warnings and to 07887 ** make it clear to human readers when a function parameter is deliberately 07888 ** left unused within the body of a function. This usually happens when 07889 ** a function is called via a function pointer. For example the 07890 ** implementation of an SQL aggregate step callback may not use the 07891 ** parameter indicating the number of arguments passed to the aggregate, 07892 ** if it knows that this is enforced elsewhere. 07893 ** 07894 ** When a function parameter is not used at all within the body of a function, 07895 ** it is generally named "NotUsed" or "NotUsed2" to make things even clearer. 07896 ** However, these macros may also be used to suppress warnings related to 07897 ** parameters that may or may not be used depending on compilation options. 07898 ** For example those parameters only used in assert() statements. In these 07899 ** cases the parameters are named as per the usual conventions. 07900 */ 07901 #define UNUSED_PARAMETER(x) (void)(x) 07902 #define UNUSED_PARAMETER2(x,y) UNUSED_PARAMETER(x),UNUSED_PARAMETER(y) 07903 07904 /* 07905 ** Forward references to structures 07906 */ 07907 typedef struct AggInfo AggInfo; 07908 typedef struct AuthContext AuthContext; 07909 typedef struct AutoincInfo AutoincInfo; 07910 typedef struct Bitvec Bitvec; 07911 typedef struct CollSeq CollSeq; 07912 typedef struct Column Column; 07913 typedef struct Db Db; 07914 typedef struct Schema Schema; 07915 typedef struct Expr Expr; 07916 typedef struct ExprList ExprList; 07917 typedef struct ExprSpan ExprSpan; 07918 typedef struct FKey FKey; 07919 typedef struct FuncDestructor FuncDestructor; 07920 typedef struct FuncDef FuncDef; 07921 typedef struct FuncDefHash FuncDefHash; 07922 typedef struct IdList IdList; 07923 typedef struct Index Index; 07924 typedef struct IndexSample IndexSample; 07925 typedef struct KeyClass KeyClass; 07926 typedef struct KeyInfo KeyInfo; 07927 typedef struct Lookaside Lookaside; 07928 typedef struct LookasideSlot LookasideSlot; 07929 typedef struct Module Module; 07930 typedef struct NameContext NameContext; 07931 typedef struct Parse Parse; 07932 typedef struct RowSet RowSet; 07933 typedef struct Savepoint Savepoint; 07934 typedef struct Select Select; 07935 typedef struct SrcList SrcList; 07936 typedef struct StrAccum StrAccum; 07937 typedef struct Table Table; 07938 typedef struct TableLock TableLock; 07939 typedef struct Token Token; 07940 typedef struct Trigger Trigger; 07941 typedef struct TriggerPrg TriggerPrg; 07942 typedef struct TriggerStep TriggerStep; 07943 typedef struct UnpackedRecord UnpackedRecord; 07944 typedef struct VTable VTable; 07945 typedef struct VtabCtx VtabCtx; 07946 typedef struct Walker Walker; 07947 typedef struct WherePlan WherePlan; 07948 typedef struct WhereInfo WhereInfo; 07949 typedef struct WhereLevel WhereLevel; 07950 07951 /* 07952 ** Defer sourcing vdbe.h and btree.h until after the "u8" and 07953 ** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque 07954 ** pointer types (i.e. FuncDef) defined above. 07955 */ 07956 /************** Include btree.h in the middle of sqliteInt.h *****************/ 07957 /************** Begin file btree.h *******************************************/ 07958 /* 07959 ** 2001 September 15 07960 ** 07961 ** The author disclaims copyright to this source code. In place of 07962 ** a legal notice, here is a blessing: 07963 ** 07964 ** May you do good and not evil. 07965 ** May you find forgiveness for yourself and forgive others. 07966 ** May you share freely, never taking more than you give. 07967 ** 07968 ************************************************************************* 07969 ** This header file defines the interface that the sqlite B-Tree file 07970 ** subsystem. See comments in the source code for a detailed description 07971 ** of what each interface routine does. 07972 */ 07973 #ifndef _BTREE_H_ 07974 #define _BTREE_H_ 07975 07976 /* TODO: This definition is just included so other modules compile. It 07977 ** needs to be revisited. 07978 */ 07979 #define SQLITE_N_BTREE_META 10 07980 07981 /* 07982 ** If defined as non-zero, auto-vacuum is enabled by default. Otherwise 07983 ** it must be turned on for each database using "PRAGMA auto_vacuum = 1". 07984 */ 07985 #ifndef SQLITE_DEFAULT_AUTOVACUUM 07986 #define SQLITE_DEFAULT_AUTOVACUUM 0 07987 #endif 07988 07989 #define BTREE_AUTOVACUUM_NONE 0 /* Do not do auto-vacuum */ 07990 #define BTREE_AUTOVACUUM_FULL 1 /* Do full auto-vacuum */ 07991 #define BTREE_AUTOVACUUM_INCR 2 /* Incremental vacuum */ 07992 07993 /* 07994 ** Forward declarations of structure 07995 */ 07996 typedef struct Btree Btree; 07997 typedef struct BtCursor BtCursor; 07998 typedef struct BtShared BtShared; 07999 08000 08001 SQLITE_PRIVATE int sqlite3BtreeOpen( 08002 sqlite3_vfs *pVfs, /* VFS to use with this b-tree */ 08003 const char *zFilename, /* Name of database file to open */ 08004 sqlite3 *db, /* Associated database connection */ 08005 Btree **ppBtree, /* Return open Btree* here */ 08006 int flags, /* Flags */ 08007 int vfsFlags /* Flags passed through to VFS open */ 08008 ); 08009 08010 /* The flags parameter to sqlite3BtreeOpen can be the bitwise or of the 08011 ** following values. 08012 ** 08013 ** NOTE: These values must match the corresponding PAGER_ values in 08014 ** pager.h. 08015 */ 08016 #define BTREE_OMIT_JOURNAL 1 /* Do not create or use a rollback journal */ 08017 #define BTREE_NO_READLOCK 2 /* Omit readlocks on readonly files */ 08018 #define BTREE_MEMORY 4 /* This is an in-memory DB */ 08019 #define BTREE_SINGLE 8 /* The file contains at most 1 b-tree */ 08020 #define BTREE_UNORDERED 16 /* Use of a hash implementation is OK */ 08021 08022 SQLITE_PRIVATE int sqlite3BtreeClose(Btree*); 08023 SQLITE_PRIVATE int sqlite3BtreeSetCacheSize(Btree*,int); 08024 SQLITE_PRIVATE int sqlite3BtreeSetSafetyLevel(Btree*,int,int,int); 08025 SQLITE_PRIVATE int sqlite3BtreeSyncDisabled(Btree*); 08026 SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix); 08027 SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree*); 08028 SQLITE_PRIVATE int sqlite3BtreeMaxPageCount(Btree*,int); 08029 SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree*); 08030 SQLITE_PRIVATE int sqlite3BtreeSecureDelete(Btree*,int); 08031 SQLITE_PRIVATE int sqlite3BtreeGetReserve(Btree*); 08032 SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int); 08033 SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *); 08034 SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int); 08035 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster); 08036 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int); 08037 SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*); 08038 SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*); 08039 SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*,int); 08040 SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, int*, int flags); 08041 SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree*); 08042 SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree*); 08043 SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree*); 08044 SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *, int, void(*)(void *)); 08045 SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *pBtree); 08046 SQLITE_PRIVATE int sqlite3BtreeLockTable(Btree *pBtree, int iTab, u8 isWriteLock); 08047 SQLITE_PRIVATE int sqlite3BtreeSavepoint(Btree *, int, int); 08048 08049 SQLITE_PRIVATE const char *sqlite3BtreeGetFilename(Btree *); 08050 SQLITE_PRIVATE const char *sqlite3BtreeGetJournalname(Btree *); 08051 SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *, Btree *); 08052 08053 SQLITE_PRIVATE int sqlite3BtreeIncrVacuum(Btree *); 08054 08055 /* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR 08056 ** of the flags shown below. 08057 ** 08058 ** Every SQLite table must have either BTREE_INTKEY or BTREE_BLOBKEY set. 08059 ** With BTREE_INTKEY, the table key is a 64-bit integer and arbitrary data 08060 ** is stored in the leaves. (BTREE_INTKEY is used for SQL tables.) With 08061 ** BTREE_BLOBKEY, the key is an arbitrary BLOB and no content is stored 08062 ** anywhere - the key is the content. (BTREE_BLOBKEY is used for SQL 08063 ** indices.) 08064 */ 08065 #define BTREE_INTKEY 1 /* Table has only 64-bit signed integer keys */ 08066 #define BTREE_BLOBKEY 2 /* Table has keys only - no data */ 08067 08068 SQLITE_PRIVATE int sqlite3BtreeDropTable(Btree*, int, int*); 08069 SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree*, int, int*); 08070 SQLITE_PRIVATE void sqlite3BtreeTripAllCursors(Btree*, int); 08071 08072 SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *pBtree, int idx, u32 *pValue); 08073 SQLITE_PRIVATE int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value); 08074 08075 /* 08076 ** The second parameter to sqlite3BtreeGetMeta or sqlite3BtreeUpdateMeta 08077 ** should be one of the following values. The integer values are assigned 08078 ** to constants so that the offset of the corresponding field in an 08079 ** SQLite database header may be found using the following formula: 08080 ** 08081 ** offset = 36 + (idx * 4) 08082 ** 08083 ** For example, the free-page-count field is located at byte offset 36 of 08084 ** the database file header. The incr-vacuum-flag field is located at 08085 ** byte offset 64 (== 36+4*7). 08086 */ 08087 #define BTREE_FREE_PAGE_COUNT 0 08088 #define BTREE_SCHEMA_VERSION 1 08089 #define BTREE_FILE_FORMAT 2 08090 #define BTREE_DEFAULT_CACHE_SIZE 3 08091 #define BTREE_LARGEST_ROOT_PAGE 4 08092 #define BTREE_TEXT_ENCODING 5 08093 #define BTREE_USER_VERSION 6 08094 #define BTREE_INCR_VACUUM 7 08095 08096 SQLITE_PRIVATE int sqlite3BtreeCursor( 08097 Btree*, /* BTree containing table to open */ 08098 int iTable, /* Index of root page */ 08099 int wrFlag, /* 1 for writing. 0 for read-only */ 08100 struct KeyInfo*, /* First argument to compare function */ 08101 BtCursor *pCursor /* Space to write cursor structure */ 08102 ); 08103 SQLITE_PRIVATE int sqlite3BtreeCursorSize(void); 08104 SQLITE_PRIVATE void sqlite3BtreeCursorZero(BtCursor*); 08105 08106 SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor*); 08107 SQLITE_PRIVATE int sqlite3BtreeMovetoUnpacked( 08108 BtCursor*, 08109 UnpackedRecord *pUnKey, 08110 i64 intKey, 08111 int bias, 08112 int *pRes 08113 ); 08114 SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor*, int*); 08115 SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor*); 08116 SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey, 08117 const void *pData, int nData, 08118 int nZero, int bias, int seekResult); 08119 SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes); 08120 SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes); 08121 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes); 08122 SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*); 08123 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes); 08124 SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor*, i64 *pSize); 08125 SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*); 08126 SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor*, int *pAmt); 08127 SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor*, int *pAmt); 08128 SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor*, u32 *pSize); 08129 SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*); 08130 SQLITE_PRIVATE void sqlite3BtreeSetCachedRowid(BtCursor*, sqlite3_int64); 08131 SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor*); 08132 08133 SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*); 08134 SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*); 08135 08136 SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*); 08137 SQLITE_PRIVATE void sqlite3BtreeCacheOverflow(BtCursor *); 08138 SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *); 08139 08140 SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion); 08141 08142 #ifndef NDEBUG 08143 SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*); 08144 #endif 08145 08146 #ifndef SQLITE_OMIT_BTREECOUNT 08147 SQLITE_PRIVATE int sqlite3BtreeCount(BtCursor *, i64 *); 08148 #endif 08149 08150 #ifdef SQLITE_TEST 08151 SQLITE_PRIVATE int sqlite3BtreeCursorInfo(BtCursor*, int*, int); 08152 SQLITE_PRIVATE void sqlite3BtreeCursorList(Btree*); 08153 #endif 08154 08155 #ifndef SQLITE_OMIT_WAL 08156 SQLITE_PRIVATE int sqlite3BtreeCheckpoint(Btree*, int, int *, int *); 08157 #endif 08158 08159 /* 08160 ** If we are not using shared cache, then there is no need to 08161 ** use mutexes to access the BtShared structures. So make the 08162 ** Enter and Leave procedures no-ops. 08163 */ 08164 #ifndef SQLITE_OMIT_SHARED_CACHE 08165 SQLITE_PRIVATE void sqlite3BtreeEnter(Btree*); 08166 SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3*); 08167 #else 08168 # define sqlite3BtreeEnter(X) 08169 # define sqlite3BtreeEnterAll(X) 08170 #endif 08171 08172 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE 08173 SQLITE_PRIVATE int sqlite3BtreeSharable(Btree*); 08174 SQLITE_PRIVATE void sqlite3BtreeLeave(Btree*); 08175 SQLITE_PRIVATE void sqlite3BtreeEnterCursor(BtCursor*); 08176 SQLITE_PRIVATE void sqlite3BtreeLeaveCursor(BtCursor*); 08177 SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3*); 08178 #ifndef NDEBUG 08179 /* These routines are used inside assert() statements only. */ 08180 SQLITE_PRIVATE int sqlite3BtreeHoldsMutex(Btree*); 08181 SQLITE_PRIVATE int sqlite3BtreeHoldsAllMutexes(sqlite3*); 08182 SQLITE_PRIVATE int sqlite3SchemaMutexHeld(sqlite3*,int,Schema*); 08183 #endif 08184 #else 08185 08186 # define sqlite3BtreeSharable(X) 0 08187 # define sqlite3BtreeLeave(X) 08188 # define sqlite3BtreeEnterCursor(X) 08189 # define sqlite3BtreeLeaveCursor(X) 08190 # define sqlite3BtreeLeaveAll(X) 08191 08192 # define sqlite3BtreeHoldsMutex(X) 1 08193 # define sqlite3BtreeHoldsAllMutexes(X) 1 08194 # define sqlite3SchemaMutexHeld(X,Y,Z) 1 08195 #endif 08196 08197 08198 #endif /* _BTREE_H_ */ 08199 08200 /************** End of btree.h ***********************************************/ 08201 /************** Continuing where we left off in sqliteInt.h ******************/ 08202 /************** Include vdbe.h in the middle of sqliteInt.h ******************/ 08203 /************** Begin file vdbe.h ********************************************/ 08204 /* 08205 ** 2001 September 15 08206 ** 08207 ** The author disclaims copyright to this source code. In place of 08208 ** a legal notice, here is a blessing: 08209 ** 08210 ** May you do good and not evil. 08211 ** May you find forgiveness for yourself and forgive others. 08212 ** May you share freely, never taking more than you give. 08213 ** 08214 ************************************************************************* 08215 ** Header file for the Virtual DataBase Engine (VDBE) 08216 ** 08217 ** This header defines the interface to the virtual database engine 08218 ** or VDBE. The VDBE implements an abstract machine that runs a 08219 ** simple program to access and modify the underlying database. 08220 */ 08221 #ifndef _SQLITE_VDBE_H_ 08222 #define _SQLITE_VDBE_H_ 08223 /* #include <stdio.h> */ 08224 08225 /* 08226 ** A single VDBE is an opaque structure named "Vdbe". Only routines 08227 ** in the source file sqliteVdbe.c are allowed to see the insides 08228 ** of this structure. 08229 */ 08230 typedef struct Vdbe Vdbe; 08231 08232 /* 08233 ** The names of the following types declared in vdbeInt.h are required 08234 ** for the VdbeOp definition. 08235 */ 08236 typedef struct VdbeFunc VdbeFunc; 08237 typedef struct Mem Mem; 08238 typedef struct SubProgram SubProgram; 08239 08240 /* 08241 ** A single instruction of the virtual machine has an opcode 08242 ** and as many as three operands. The instruction is recorded 08243 ** as an instance of the following structure: 08244 */ 08245 struct VdbeOp { 08246 u8 opcode; /* What operation to perform */ 08247 signed char p4type; /* One of the P4_xxx constants for p4 */ 08248 u8 opflags; /* Mask of the OPFLG_* flags in opcodes.h */ 08249 u8 p5; /* Fifth parameter is an unsigned character */ 08250 int p1; /* First operand */ 08251 int p2; /* Second parameter (often the jump destination) */ 08252 int p3; /* The third parameter */ 08253 union { /* fourth parameter */ 08254 int i; /* Integer value if p4type==P4_INT32 */ 08255 void *p; /* Generic pointer */ 08256 char *z; /* Pointer to data for string (char array) types */ 08257 i64 *pI64; /* Used when p4type is P4_INT64 */ 08258 double *pReal; /* Used when p4type is P4_REAL */ 08259 FuncDef *pFunc; /* Used when p4type is P4_FUNCDEF */ 08260 VdbeFunc *pVdbeFunc; /* Used when p4type is P4_VDBEFUNC */ 08261 CollSeq *pColl; /* Used when p4type is P4_COLLSEQ */ 08262 Mem *pMem; /* Used when p4type is P4_MEM */ 08263 VTable *pVtab; /* Used when p4type is P4_VTAB */ 08264 KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */ 08265 int *ai; /* Used when p4type is P4_INTARRAY */ 08266 SubProgram *pProgram; /* Used when p4type is P4_SUBPROGRAM */ 08267 int (*xAdvance)(BtCursor *, int *); 08268 } p4; 08269 #ifdef SQLITE_DEBUG 08270 char *zComment; /* Comment to improve readability */ 08271 #endif 08272 #ifdef VDBE_PROFILE 08273 int cnt; /* Number of times this instruction was executed */ 08274 u64 cycles; /* Total time spent executing this instruction */ 08275 #endif 08276 }; 08277 typedef struct VdbeOp VdbeOp; 08278 08279 08280 /* 08281 ** A sub-routine used to implement a trigger program. 08282 */ 08283 struct SubProgram { 08284 VdbeOp *aOp; /* Array of opcodes for sub-program */ 08285 int nOp; /* Elements in aOp[] */ 08286 int nMem; /* Number of memory cells required */ 08287 int nCsr; /* Number of cursors required */ 08288 void *token; /* id that may be used to recursive triggers */ 08289 SubProgram *pNext; /* Next sub-program already visited */ 08290 }; 08291 08292 /* 08293 ** A smaller version of VdbeOp used for the VdbeAddOpList() function because 08294 ** it takes up less space. 08295 */ 08296 struct VdbeOpList { 08297 u8 opcode; /* What operation to perform */ 08298 signed char p1; /* First operand */ 08299 signed char p2; /* Second parameter (often the jump destination) */ 08300 signed char p3; /* Third parameter */ 08301 }; 08302 typedef struct VdbeOpList VdbeOpList; 08303 08304 /* 08305 ** Allowed values of VdbeOp.p4type 08306 */ 08307 #define P4_NOTUSED 0 /* The P4 parameter is not used */ 08308 #define P4_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */ 08309 #define P4_STATIC (-2) /* Pointer to a static string */ 08310 #define P4_COLLSEQ (-4) /* P4 is a pointer to a CollSeq structure */ 08311 #define P4_FUNCDEF (-5) /* P4 is a pointer to a FuncDef structure */ 08312 #define P4_KEYINFO (-6) /* P4 is a pointer to a KeyInfo structure */ 08313 #define P4_VDBEFUNC (-7) /* P4 is a pointer to a VdbeFunc structure */ 08314 #define P4_MEM (-8) /* P4 is a pointer to a Mem* structure */ 08315 #define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */ 08316 #define P4_VTAB (-10) /* P4 is a pointer to an sqlite3_vtab structure */ 08317 #define P4_MPRINTF (-11) /* P4 is a string obtained from sqlite3_mprintf() */ 08318 #define P4_REAL (-12) /* P4 is a 64-bit floating point value */ 08319 #define P4_INT64 (-13) /* P4 is a 64-bit signed integer */ 08320 #define P4_INT32 (-14) /* P4 is a 32-bit signed integer */ 08321 #define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */ 08322 #define P4_SUBPROGRAM (-18) /* P4 is a pointer to a SubProgram structure */ 08323 #define P4_ADVANCE (-19) /* P4 is a pointer to BtreeNext() or BtreePrev() */ 08324 08325 /* When adding a P4 argument using P4_KEYINFO, a copy of the KeyInfo structure 08326 ** is made. That copy is freed when the Vdbe is finalized. But if the 08327 ** argument is P4_KEYINFO_HANDOFF, the passed in pointer is used. It still 08328 ** gets freed when the Vdbe is finalized so it still should be obtained 08329 ** from a single sqliteMalloc(). But no copy is made and the calling 08330 ** function should *not* try to free the KeyInfo. 08331 */ 08332 #define P4_KEYINFO_HANDOFF (-16) 08333 #define P4_KEYINFO_STATIC (-17) 08334 08335 /* 08336 ** The Vdbe.aColName array contains 5n Mem structures, where n is the 08337 ** number of columns of data returned by the statement. 08338 */ 08339 #define COLNAME_NAME 0 08340 #define COLNAME_DECLTYPE 1 08341 #define COLNAME_DATABASE 2 08342 #define COLNAME_TABLE 3 08343 #define COLNAME_COLUMN 4 08344 #ifdef SQLITE_ENABLE_COLUMN_METADATA 08345 # define COLNAME_N 5 /* Number of COLNAME_xxx symbols */ 08346 #else 08347 # ifdef SQLITE_OMIT_DECLTYPE 08348 # define COLNAME_N 1 /* Store only the name */ 08349 # else 08350 # define COLNAME_N 2 /* Store the name and decltype */ 08351 # endif 08352 #endif 08353 08354 /* 08355 ** The following macro converts a relative address in the p2 field 08356 ** of a VdbeOp structure into a negative number so that 08357 ** sqlite3VdbeAddOpList() knows that the address is relative. Calling 08358 ** the macro again restores the address. 08359 */