Back to index

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