sqlite3.h

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

ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:56 2011 by Doxygen 1.6.1